1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('dd-scroll', function (Y, NAME) {
6
* Base scroller class used to create the Plugin.DDNodeScroll and Plugin.DDWinScroll.
7
* This class should not be called on it's own, it's designed to be a plugin.
12
* Base scroller class used to create the Plugin.DDNodeScroll and Plugin.DDWinScroll.
13
* This class should not be called on it's own, it's designed to be a plugin.
21
S.superclass.constructor.apply(this, arguments);
27
PARENT_SCROLL = 'parentScroll',
28
WINDOW_SCROLL = 'windowScroll',
29
SCROLL_TOP = 'scrollTop',
30
SCROLL_LEFT = 'scrollLeft',
31
OFFSET_WIDTH = 'offsetWidth',
32
OFFSET_HEIGHT = 'offsetHeight';
37
* Internal config option to hold the node that we are scrolling. Should not be set by the developer.
38
* @attribute parentScroll
43
setter: function(node) {
51
* The number of pixels from the edge of the screen to turn on scrolling. Default: 30
57
validator: Y.Lang.isNumber
60
* The number of milliseconds delay to pass to the auto scroller. Default: 235
61
* @attribute scrollDelay
66
validator: Y.Lang.isNumber
69
* The host we are plugged into.
77
* Turn on window scroll support, default: false
78
* @attribute windowScroll
83
validator: Y.Lang.isBoolean
86
* Allow vertical scrolling, default: true.
92
validator: Y.Lang.isBoolean
95
* Allow horizontal scrolling, default: true.
96
* @attribute horizontal
101
validator: Y.Lang.isBoolean
105
Y.extend(S, Y.Base, {
107
* Tells if we are actively scrolling or not.
109
* @property _scrolling
114
* Cache of the Viewport dims.
116
* @property _vpRegionCache
119
_vpRegionCache: null,
121
* Cache of the dragNode dims.
123
* @property _dimCache
128
* Holder for the Timer object returned from Y.later.
130
* @property _scrollTimer
135
* Sets the _vpRegionCache property with an Object containing the dims from the viewport.
137
* @method _getVPRegion
139
_getVPRegion: function() {
141
n = this.get(PARENT_SCROLL),
142
b = this.get(BUFFER),
143
ws = this.get(WINDOW_SCROLL),
144
xy = ((ws) ? [] : n.getXY()),
145
w = ((ws) ? 'winWidth' : OFFSET_WIDTH),
146
h = ((ws) ? 'winHeight' : OFFSET_HEIGHT),
147
t = ((ws) ? n.get(SCROLL_TOP) : xy[1]),
148
l = ((ws) ? n.get(SCROLL_LEFT) : xy[0]);
152
right: (n.get(w) + l) - b,
153
bottom: (n.get(h) + t) - b,
156
this._vpRegionCache = r;
159
initializer: function() {
160
var h = this.get(HOST);
161
h.after('drag:start', Y.bind(this.start, this));
162
h.after('drag:end', Y.bind(this.end, this));
163
h.on('drag:align', Y.bind(this.align, this));
165
//TODO - This doesn't work yet??
166
Y.one('win').on('scroll', Y.bind(function() {
167
this._vpRegionCache = null;
171
* Check to see if we need to fire the scroll timer. If scroll timer is running this will scroll the window.
173
* @method _checkWinScroll
174
* @param {Boolean} move Should we move the window. From Y.later
176
_checkWinScroll: function(move) {
177
var r = this._getVPRegion(),
179
ws = this.get(WINDOW_SCROLL),
182
b = this.get(BUFFER),
183
win = this.get(PARENT_SCROLL),
184
sTop = win.get(SCROLL_TOP),
185
sLeft = win.get(SCROLL_LEFT),
186
w = this._dimCache.w,
187
h = this._dimCache.h,
197
if (this.get('horizontal')) {
198
if (left <= r.left) {
200
nl = xy[0] - ((ws) ? b : 0);
203
if (right >= r.right) {
205
nl = xy[0] + ((ws) ? b : 0);
209
if (this.get('vertical')) {
210
if (bottom >= r.bottom) {
212
nt = xy[1] + ((ws) ? b : 0);
218
nt = xy[1] - ((ws) ? b : 0);
241
ho._alignNode([nl, nt], true); //We are srolling..
244
ho._moveNode({ node: win, top: st, left: sl});
246
this._cancelScroll();
252
this._cancelScroll();
257
* Cancel a previous scroll timer and init a new one.
259
* @method _initScroll
261
_initScroll: function() {
262
this._cancelScroll();
263
this._scrollTimer = Y.Lang.later(this.get('scrollDelay'), this, this._checkWinScroll, [true], true);
267
* Cancel a currently running scroll timer.
269
* @method _cancelScroll
271
_cancelScroll: function() {
272
this._scrolling = false;
273
if (this._scrollTimer) {
274
this._scrollTimer.cancel();
275
delete this._scrollTimer;
279
* Called from the drag:align event to determine if we need to scroll.
283
if (this._scrolling) {
284
this._cancelScroll();
287
if (!this._scrolling) {
288
this._checkWinScroll();
292
* Set the cache of the dragNode dims.
294
* @method _setDimCache
296
_setDimCache: function() {
297
var node = this.get(HOST).get('dragNode');
299
h: node.get(OFFSET_HEIGHT),
300
w: node.get(OFFSET_WIDTH)
304
* Called from the drag:start event
311
* Called from the drag:end event
315
this._dimCache = null;
316
this._cancelScroll();
320
Y.namespace('Plugin');
324
* Extends the Scroll class to make the window scroll while dragging.
325
* @class DDWindowScroll
331
WS.superclass.constructor.apply(this, arguments);
333
WS.ATTRS = Y.merge(S.ATTRS, {
335
* Turn on window scroll support, default: true
336
* @attribute windowScroll
341
setter: function(scroll) {
343
this.set(PARENT_SCROLL, Y.one('win'));
350
//Shouldn't have to do this..
351
initializer: function() {
352
this.set('windowScroll', this.get('windowScroll'));
356
* The Scroll instance will be placed on the Drag instance under the winscroll namespace.
364
WS.NAME = WS.NS = 'winscroll';
365
Y.Plugin.DDWinScroll = WS;
369
* Extends the Scroll class to make a parent node scroll while dragging.
370
* @class DDNodeScroll
376
NS.superclass.constructor.apply(this, arguments);
379
NS.ATTRS = Y.merge(S.ATTRS, {
381
* The node we want to scroll. Used to set the internal parentScroll attribute.
387
setter: function(node) {
390
if (node !== false) {
391
Y.error('DDNodeScroll: Invalid Node Given: ' + node);
394
this.set(PARENT_SCROLL, n);
401
//Shouldn't have to do this..
402
initializer: function() {
403
this.set('node', this.get('node'));
407
* The NodeScroll instance will be placed on the Drag instance under the nodescroll namespace.
409
* @default nodescroll
415
NS.NAME = NS.NS = 'nodescroll';
416
Y.Plugin.DDNodeScroll = NS;
423
}, '3.9.1', {"requires": ["dd-drag"]});