forked from jamesshore/quixote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement_edge.js
52 lines (41 loc) · 1.62 KB
/
element_edge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file.
"use strict";
var ensure = require("../util/ensure.js");
var Position = require("../values/position.js");
var RelativePosition = require("./relative_position.js");
var PositionDescriptor = require("./position_descriptor.js");
var ElementSize = require("./element_size.js");
var TOP = "top";
var RIGHT = "right";
var BOTTOM = "bottom";
var LEFT = "left";
var Me = module.exports = function ElementEdge(element, position) {
var QElement = require("../q_element.js"); // break circular dependency
ensure.signature(arguments, [ QElement, String ]);
if (position === LEFT || position === RIGHT) PositionDescriptor.x(this);
else if (position === TOP || position === BOTTOM) PositionDescriptor.y(this);
else ensure.unreachable("Unknown position: " + position);
this._element = element;
this._position = position;
};
PositionDescriptor.extend(Me);
Me.top = factoryFn(TOP);
Me.right = factoryFn(RIGHT);
Me.bottom = factoryFn(BOTTOM);
Me.left = factoryFn(LEFT);
Me.prototype.value = function value() {
ensure.signature(arguments, []);
var edge = this._element.getRawPosition()[this._position];
var scroll = this._element.frame.getRawScrollPosition();
if (this._position === RIGHT || this._position === LEFT) return Position.x(edge + scroll.x);
else return Position.y(edge + scroll.y);
};
Me.prototype.toString = function toString() {
ensure.signature(arguments, []);
return this._position + " edge of " + this._element;
};
function factoryFn(position) {
return function factory(element) {
return new Me(element, position);
};
}