-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
109 lines (87 loc) · 2.53 KB
/
Copy pathindex.js
File metadata and controls
109 lines (87 loc) · 2.53 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(function (window) {
'use strict';
// UMD
if(typeof define !== 'function') {
window.define = function(deps, definition) {
window.pintxos = window.pintxos || {};
window.pintxos.ScrollableNative = definition(jQuery, pintxos.inherit, pintxos.Component);
define = null;
};
}
define(
[
'jQuery',
'pintxos-inherit',
'pintxos-component'
], function (
$,
inherit,
Component
) {
var ScrollableNative, _defaults, _props;
/* Defaults
----------------------------------------------- */
_defaults = {
orientation: 'horizontal',
selectors: {
scrollableEl: undefined
}
};
_props = {
horizontal: {
scrollPos: 'scrollLeft',
scrollSize: 'scrollWidth',
size: 'width',
offset: 'left'
},
vertical: {
scrollPos: 'scrollTop',
scrollSize: 'scrollHeight',
size: 'height',
offset: 'top'
}
};
/* Constructor
----------------------------------------------- */
ScrollableNative = function (el, options) {
this._settings = $.extend(true, {}, _defaults, options);
Component.call(this, el, this._settings);
};
inherit(ScrollableNative, Component);
/* Methods
----------------------------------------------- */
ScrollableNative.prototype._getProp = function (prop) {
return _props[this._settings.orientation][prop];
};
ScrollableNative.prototype.getScrollPos = function () {
return Math.floor(this.getScrollableEl()[this._getProp('scrollPos')]());
};
ScrollableNative.prototype.setScrollPos = function (pos) {
this.getScrollableEl()[this._getProp('scrollPos')](pos);
};
ScrollableNative.prototype.getMaskSize = function () {
return Math.ceil(this.getScrollableEl()[this._getProp('size')]());
};
ScrollableNative.prototype.getMaxScrollPos = function () {
return this.getScrollableEl()[0][this._getProp('scrollSize')] - this.getScrollableEl()[this._getProp('size')]();
};
ScrollableNative.prototype.isEndReached = function (offset) {
offset = (typeof offset === 'undefined') ? 0 : offset;
return this.getScrollPos() >= (this.getMaxScrollPos() - offset);
};
ScrollableNative.prototype.isBeginReached = function (offset) {
offset = (typeof offset === 'undefined') ? 0 : offset;
return this.getScrollPos() <= offset;
};
/**
* Getter for scrollable el
* @return {jQuery}
*/
ScrollableNative.prototype.getScrollableEl = function () {
return this._resolveElement(this.getSettings().selectors.scrollableEl);
};
/* Export
----------------------------------------------- */
return ScrollableNative;
});
})(this);