nicescroll-rails 3.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +36 -0
- data/lib/nicescroll-rails.rb +11 -0
- data/lib/nicescroll-rails/version.rb +5 -0
- data/vendor/assets/images/zoomico.png +0 -0
- data/vendor/assets/javascripts/jquery.nicescroll.js.erb +3252 -0
- metadata +69 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# jQuery NiceScroll plugin for Rails
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/nicescroll-rails.png)](http://badge.fury.io/rb/nicescroll-rails)
|
3
|
+
|
4
|
+
A ruby gem that uses the Rails asset pipeline to include the jQuery [NiceScroll](https://github.com/inuyaksa/jquery.nicescroll) plugin by inuyaksa.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'nicescroll-rails'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install nicescroll-rails
|
19
|
+
|
20
|
+
NOTE: this is a jQuery plugin so you will also need the `jquery-rails` gem:
|
21
|
+
|
22
|
+
* https://github.com/rails/jquery-rails
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
In your `application.js` you will need to add this line:
|
27
|
+
|
28
|
+
//= require jquery.nicescroll
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
Binary file
|
@@ -0,0 +1,3252 @@
|
|
1
|
+
/* jquery.nicescroll
|
2
|
+
-- version 3.5.4
|
3
|
+
-- copyright 2013-11-13 InuYaksa*2013
|
4
|
+
-- licensed under the MIT
|
5
|
+
--
|
6
|
+
-- http://areaaperta.com/nicescroll
|
7
|
+
-- https://github.com/inuyaksa/jquery.nicescroll
|
8
|
+
--
|
9
|
+
*/
|
10
|
+
|
11
|
+
(function (factory) {
|
12
|
+
if (typeof define === 'function' && define.amd) {
|
13
|
+
// AMD. Register as anonymous module.
|
14
|
+
define(['jquery'], factory);
|
15
|
+
} else {
|
16
|
+
// Browser globals.
|
17
|
+
factory(jQuery);
|
18
|
+
}
|
19
|
+
}(function(jQuery){
|
20
|
+
|
21
|
+
// globals
|
22
|
+
var domfocus = false;
|
23
|
+
var mousefocus = false;
|
24
|
+
var zoomactive = false;
|
25
|
+
var tabindexcounter = 5000;
|
26
|
+
var ascrailcounter = 2000;
|
27
|
+
var globalmaxzindex = 0;
|
28
|
+
|
29
|
+
var $ = jQuery; // sandbox
|
30
|
+
|
31
|
+
// http://stackoverflow.com/questions/2161159/get-script-path
|
32
|
+
function getScriptPath() {
|
33
|
+
var scripts=document.getElementsByTagName('script');
|
34
|
+
var path=scripts[scripts.length-1].src.split('?')[0];
|
35
|
+
return (path.split('/').length>0) ? path.split('/').slice(0,-1).join('/')+'/' : '';
|
36
|
+
}
|
37
|
+
// var scriptpath = getScriptPath();
|
38
|
+
|
39
|
+
var vendors = ['ms','moz','webkit','o'];
|
40
|
+
|
41
|
+
var setAnimationFrame = window.requestAnimationFrame||false;
|
42
|
+
var clearAnimationFrame = window.cancelAnimationFrame||false;
|
43
|
+
|
44
|
+
if (!setAnimationFrame) {
|
45
|
+
for(var vx in vendors) {
|
46
|
+
var v = vendors[vx];
|
47
|
+
if (!setAnimationFrame) setAnimationFrame = window[v+'RequestAnimationFrame'];
|
48
|
+
if (!clearAnimationFrame) clearAnimationFrame = window[v+'CancelAnimationFrame']||window[v+'CancelRequestAnimationFrame'];
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
var clsMutationObserver = window.MutationObserver || window.WebKitMutationObserver || false;
|
53
|
+
|
54
|
+
var _globaloptions = {
|
55
|
+
zindex:"auto",
|
56
|
+
cursoropacitymin:0,
|
57
|
+
cursoropacitymax:1,
|
58
|
+
cursorcolor:"#424242",
|
59
|
+
cursorwidth:"5px",
|
60
|
+
cursorborder:"1px solid #fff",
|
61
|
+
cursorborderradius:"5px",
|
62
|
+
scrollspeed:60,
|
63
|
+
mousescrollstep:8*3,
|
64
|
+
touchbehavior:false,
|
65
|
+
hwacceleration:true,
|
66
|
+
usetransition:true,
|
67
|
+
boxzoom:false,
|
68
|
+
dblclickzoom:true,
|
69
|
+
gesturezoom:true,
|
70
|
+
grabcursorenabled:true,
|
71
|
+
autohidemode:true,
|
72
|
+
background:"",
|
73
|
+
iframeautoresize:true,
|
74
|
+
cursorminheight:32,
|
75
|
+
preservenativescrolling:true,
|
76
|
+
railoffset:false,
|
77
|
+
bouncescroll:true,
|
78
|
+
spacebarenabled:true,
|
79
|
+
railpadding:{top:0,right:0,left:0,bottom:0},
|
80
|
+
disableoutline:true,
|
81
|
+
horizrailenabled:true,
|
82
|
+
railalign:"right",
|
83
|
+
railvalign:"bottom",
|
84
|
+
enabletranslate3d:true,
|
85
|
+
enablemousewheel:true,
|
86
|
+
enablekeyboard:true,
|
87
|
+
smoothscroll:true,
|
88
|
+
sensitiverail:true,
|
89
|
+
enablemouselockapi:true,
|
90
|
+
// cursormaxheight:false,
|
91
|
+
cursorfixedheight:false,
|
92
|
+
directionlockdeadzone:6,
|
93
|
+
hidecursordelay:400,
|
94
|
+
nativeparentscrolling:true,
|
95
|
+
enablescrollonselection:true,
|
96
|
+
overflowx:true,
|
97
|
+
overflowy:true,
|
98
|
+
cursordragspeed:0.3,
|
99
|
+
rtlmode:"auto",
|
100
|
+
cursordragontouch:false,
|
101
|
+
oneaxismousemode:"auto",
|
102
|
+
scriptpath:getScriptPath()
|
103
|
+
};
|
104
|
+
|
105
|
+
var browserdetected = false;
|
106
|
+
|
107
|
+
var getBrowserDetection = function() {
|
108
|
+
|
109
|
+
if (browserdetected) return browserdetected;
|
110
|
+
|
111
|
+
var domtest = document.createElement('DIV');
|
112
|
+
|
113
|
+
var d = {};
|
114
|
+
|
115
|
+
d.haspointerlock = "pointerLockElement" in document || "mozPointerLockElement" in document || "webkitPointerLockElement" in document;
|
116
|
+
|
117
|
+
d.isopera = ("opera" in window);
|
118
|
+
d.isopera12 = (d.isopera&&("getUserMedia" in navigator));
|
119
|
+
d.isoperamini = (Object.prototype.toString.call(window.operamini) === "[object OperaMini]");
|
120
|
+
|
121
|
+
d.isie = (("all" in document) && ("attachEvent" in domtest) && !d.isopera);
|
122
|
+
d.isieold = (d.isie && !("msInterpolationMode" in domtest.style)); // IE6 and older
|
123
|
+
d.isie7 = d.isie&&!d.isieold&&(!("documentMode" in document)||(document.documentMode==7));
|
124
|
+
d.isie8 = d.isie&&("documentMode" in document)&&(document.documentMode==8);
|
125
|
+
d.isie9 = d.isie&&("performance" in window)&&(document.documentMode>=9);
|
126
|
+
d.isie10 = d.isie&&("performance" in window)&&(document.documentMode>=10);
|
127
|
+
|
128
|
+
d.isie9mobile = /iemobile.9/i.test(navigator.userAgent); //wp 7.1 mango
|
129
|
+
if (d.isie9mobile) d.isie9 = false;
|
130
|
+
d.isie7mobile = (!d.isie9mobile&&d.isie7) && /iemobile/i.test(navigator.userAgent); //wp 7.0
|
131
|
+
|
132
|
+
d.ismozilla = ("MozAppearance" in domtest.style);
|
133
|
+
|
134
|
+
d.iswebkit = ("WebkitAppearance" in domtest.style);
|
135
|
+
|
136
|
+
d.ischrome = ("chrome" in window);
|
137
|
+
d.ischrome22 = (d.ischrome&&d.haspointerlock);
|
138
|
+
d.ischrome26 = (d.ischrome&&("transition" in domtest.style)); // issue with transform detection (maintain prefix)
|
139
|
+
|
140
|
+
d.cantouch = ("ontouchstart" in document.documentElement)||("ontouchstart" in window); // detection for Chrome Touch Emulation
|
141
|
+
d.hasmstouch = (window.navigator.msPointerEnabled||false); // IE10+ pointer events
|
142
|
+
|
143
|
+
d.ismac = /^mac$/i.test(navigator.platform);
|
144
|
+
|
145
|
+
d.isios = (d.cantouch && /iphone|ipad|ipod/i.test(navigator.platform));
|
146
|
+
d.isios4 = ((d.isios)&&!("seal" in Object));
|
147
|
+
|
148
|
+
d.isandroid = (/android/i.test(navigator.userAgent));
|
149
|
+
|
150
|
+
d.trstyle = false;
|
151
|
+
d.hastransform = false;
|
152
|
+
d.hastranslate3d = false;
|
153
|
+
d.transitionstyle = false;
|
154
|
+
d.hastransition = false;
|
155
|
+
d.transitionend = false;
|
156
|
+
|
157
|
+
var check = ['transform','msTransform','webkitTransform','MozTransform','OTransform'];
|
158
|
+
for(var a=0;a<check.length;a++){
|
159
|
+
if (typeof domtest.style[check[a]] != "undefined") {
|
160
|
+
d.trstyle = check[a];
|
161
|
+
break;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
d.hastransform = (d.trstyle != false);
|
165
|
+
if (d.hastransform) {
|
166
|
+
domtest.style[d.trstyle] = "translate3d(1px,2px,3px)";
|
167
|
+
d.hastranslate3d = /translate3d/.test(domtest.style[d.trstyle]);
|
168
|
+
}
|
169
|
+
|
170
|
+
d.transitionstyle = false;
|
171
|
+
d.prefixstyle = '';
|
172
|
+
d.transitionend = false;
|
173
|
+
var check = ['transition','webkitTransition','MozTransition','OTransition','OTransition','msTransition','KhtmlTransition'];
|
174
|
+
var prefix = ['','-webkit-','-moz-','-o-','-o','-ms-','-khtml-'];
|
175
|
+
var evs = ['transitionend','webkitTransitionEnd','transitionend','otransitionend','oTransitionEnd','msTransitionEnd','KhtmlTransitionEnd'];
|
176
|
+
for(var a=0;a<check.length;a++) {
|
177
|
+
if (check[a] in domtest.style) {
|
178
|
+
d.transitionstyle = check[a];
|
179
|
+
d.prefixstyle = prefix[a];
|
180
|
+
d.transitionend = evs[a];
|
181
|
+
break;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
if (d.ischrome26) { // use always prefix
|
185
|
+
d.prefixstyle = prefix[1];
|
186
|
+
}
|
187
|
+
|
188
|
+
d.hastransition = (d.transitionstyle);
|
189
|
+
|
190
|
+
function detectCursorGrab() {
|
191
|
+
var lst = ['-moz-grab','-webkit-grab','grab'];
|
192
|
+
if ((d.ischrome&&!d.ischrome22)||d.isie) lst=[]; // force setting for IE returns false positive and chrome cursor bug
|
193
|
+
for(var a=0;a<lst.length;a++) {
|
194
|
+
var p = lst[a];
|
195
|
+
domtest.style['cursor']=p;
|
196
|
+
if (domtest.style['cursor']==p) return p;
|
197
|
+
}
|
198
|
+
return 'url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize'; // thank you google for custom cursor!
|
199
|
+
}
|
200
|
+
d.cursorgrabvalue = detectCursorGrab();
|
201
|
+
|
202
|
+
d.hasmousecapture = ("setCapture" in domtest);
|
203
|
+
|
204
|
+
d.hasMutationObserver = (clsMutationObserver !== false);
|
205
|
+
|
206
|
+
domtest = null; //memory released
|
207
|
+
|
208
|
+
browserdetected = d;
|
209
|
+
|
210
|
+
return d;
|
211
|
+
};
|
212
|
+
|
213
|
+
var NiceScrollClass = function(myopt,me) {
|
214
|
+
|
215
|
+
var self = this;
|
216
|
+
|
217
|
+
this.version = '3.5.4';
|
218
|
+
this.name = 'nicescroll';
|
219
|
+
|
220
|
+
this.me = me;
|
221
|
+
|
222
|
+
this.opt = {
|
223
|
+
doc:$("body"),
|
224
|
+
win:false
|
225
|
+
};
|
226
|
+
|
227
|
+
$.extend(this.opt,_globaloptions);
|
228
|
+
|
229
|
+
// Options for internal use
|
230
|
+
this.opt.snapbackspeed = 80;
|
231
|
+
|
232
|
+
if (myopt||false) {
|
233
|
+
for(var a in self.opt) {
|
234
|
+
if (typeof myopt[a] != "undefined") self.opt[a] = myopt[a];
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
this.doc = self.opt.doc;
|
239
|
+
this.iddoc = (this.doc&&this.doc[0])?this.doc[0].id||'':'';
|
240
|
+
this.ispage = /^BODY|HTML/.test((self.opt.win)?self.opt.win[0].nodeName:this.doc[0].nodeName);
|
241
|
+
this.haswrapper = (self.opt.win!==false);
|
242
|
+
this.win = self.opt.win||(this.ispage?$(window):this.doc);
|
243
|
+
this.docscroll = (this.ispage&&!this.haswrapper)?$(window):this.win;
|
244
|
+
this.body = $("body");
|
245
|
+
this.viewport = false;
|
246
|
+
|
247
|
+
this.isfixed = false;
|
248
|
+
|
249
|
+
this.iframe = false;
|
250
|
+
this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
|
251
|
+
|
252
|
+
this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
|
253
|
+
|
254
|
+
this.forcescreen = false; //force to use screen position on events
|
255
|
+
|
256
|
+
this.canshowonmouseevent = (self.opt.autohidemode!="scroll");
|
257
|
+
|
258
|
+
// Events jump table
|
259
|
+
this.onmousedown = false;
|
260
|
+
this.onmouseup = false;
|
261
|
+
this.onmousemove = false;
|
262
|
+
this.onmousewheel = false;
|
263
|
+
this.onkeypress = false;
|
264
|
+
this.ongesturezoom = false;
|
265
|
+
this.onclick = false;
|
266
|
+
|
267
|
+
// Nicescroll custom events
|
268
|
+
this.onscrollstart = false;
|
269
|
+
this.onscrollend = false;
|
270
|
+
this.onscrollcancel = false;
|
271
|
+
|
272
|
+
this.onzoomin = false;
|
273
|
+
this.onzoomout = false;
|
274
|
+
|
275
|
+
// Let's start!
|
276
|
+
this.view = false;
|
277
|
+
this.page = false;
|
278
|
+
|
279
|
+
this.scroll = {x:0,y:0};
|
280
|
+
this.scrollratio = {x:0,y:0};
|
281
|
+
this.cursorheight = 20;
|
282
|
+
this.scrollvaluemax = 0;
|
283
|
+
|
284
|
+
this.isrtlmode = false; //(this.opt.rtlmode=="auto") ? (this.win.css("direction")=="rtl") : (this.opt.rtlmode===true);
|
285
|
+
// this.checkrtlmode = false;
|
286
|
+
|
287
|
+
this.scrollrunning = false;
|
288
|
+
|
289
|
+
this.scrollmom = false;
|
290
|
+
|
291
|
+
this.observer = false;
|
292
|
+
this.observerremover = false; // observer on parent for remove detection
|
293
|
+
|
294
|
+
do {
|
295
|
+
this.id = "ascrail"+(ascrailcounter++);
|
296
|
+
} while (document.getElementById(this.id));
|
297
|
+
|
298
|
+
this.rail = false;
|
299
|
+
this.cursor = false;
|
300
|
+
this.cursorfreezed = false;
|
301
|
+
this.selectiondrag = false;
|
302
|
+
|
303
|
+
this.zoom = false;
|
304
|
+
this.zoomactive = false;
|
305
|
+
|
306
|
+
this.hasfocus = false;
|
307
|
+
this.hasmousefocus = false;
|
308
|
+
|
309
|
+
this.visibility = true;
|
310
|
+
this.locked = false;
|
311
|
+
this.hidden = false; // rails always hidden
|
312
|
+
this.cursoractive = true; // user can interact with cursors
|
313
|
+
|
314
|
+
this.wheelprevented = false; //prevent mousewheel event
|
315
|
+
|
316
|
+
this.overflowx = self.opt.overflowx;
|
317
|
+
this.overflowy = self.opt.overflowy;
|
318
|
+
|
319
|
+
this.nativescrollingarea = false;
|
320
|
+
this.checkarea = 0;
|
321
|
+
|
322
|
+
this.events = []; // event list for unbind
|
323
|
+
|
324
|
+
this.saved = {};
|
325
|
+
|
326
|
+
this.delaylist = {};
|
327
|
+
this.synclist = {};
|
328
|
+
|
329
|
+
this.lastdeltax = 0;
|
330
|
+
this.lastdeltay = 0;
|
331
|
+
|
332
|
+
this.detected = getBrowserDetection();
|
333
|
+
|
334
|
+
var cap = $.extend({},this.detected);
|
335
|
+
|
336
|
+
this.canhwscroll = (cap.hastransform&&self.opt.hwacceleration);
|
337
|
+
this.ishwscroll = (this.canhwscroll&&self.haswrapper);
|
338
|
+
|
339
|
+
this.istouchcapable = false; // desktop devices with touch screen support
|
340
|
+
|
341
|
+
//## Check Chrome desktop with touch support
|
342
|
+
if (cap.cantouch&&cap.ischrome&&!cap.isios&&!cap.isandroid) {
|
343
|
+
this.istouchcapable = true;
|
344
|
+
cap.cantouch = false; // parse normal desktop events
|
345
|
+
}
|
346
|
+
|
347
|
+
//## Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
|
348
|
+
if (cap.cantouch&&cap.ismozilla&&!cap.isios&&!cap.isandroid) {
|
349
|
+
this.istouchcapable = true;
|
350
|
+
cap.cantouch = false; // parse normal desktop events
|
351
|
+
}
|
352
|
+
|
353
|
+
//## disable MouseLock API on user request
|
354
|
+
|
355
|
+
if (!self.opt.enablemouselockapi) {
|
356
|
+
cap.hasmousecapture = false;
|
357
|
+
cap.haspointerlock = false;
|
358
|
+
}
|
359
|
+
|
360
|
+
this.delayed = function(name,fn,tm,lazy) {
|
361
|
+
var dd = self.delaylist[name];
|
362
|
+
var nw = (new Date()).getTime();
|
363
|
+
if (!lazy&&dd&&dd.tt) return false;
|
364
|
+
if (dd&&dd.tt) clearTimeout(dd.tt);
|
365
|
+
if (dd&&dd.last+tm>nw&&!dd.tt) {
|
366
|
+
self.delaylist[name] = {
|
367
|
+
last:nw+tm,
|
368
|
+
tt:setTimeout(function(){if(self||false){self.delaylist[name].tt=0;fn.call()}},tm)
|
369
|
+
}
|
370
|
+
}
|
371
|
+
else if (!dd||!dd.tt) {
|
372
|
+
self.delaylist[name] = {
|
373
|
+
last:nw,
|
374
|
+
tt:0
|
375
|
+
};
|
376
|
+
setTimeout(function(){fn.call();},0);
|
377
|
+
}
|
378
|
+
};
|
379
|
+
|
380
|
+
this.debounced = function(name,fn,tm) {
|
381
|
+
var dd = self.delaylist[name];
|
382
|
+
var nw = (new Date()).getTime();
|
383
|
+
self.delaylist[name] = fn;
|
384
|
+
if (!dd) {
|
385
|
+
setTimeout(function(){var fn=self.delaylist[name];self.delaylist[name]=false;fn.call();},tm);
|
386
|
+
}
|
387
|
+
};
|
388
|
+
|
389
|
+
var _onsync = false;
|
390
|
+
|
391
|
+
this.synched = function(name,fn) {
|
392
|
+
|
393
|
+
function requestSync() {
|
394
|
+
if (_onsync) return;
|
395
|
+
setAnimationFrame(function(){
|
396
|
+
_onsync = false;
|
397
|
+
for(name in self.synclist){
|
398
|
+
var fn = self.synclist[name];
|
399
|
+
if (fn) fn.call(self);
|
400
|
+
self.synclist[name] = false;
|
401
|
+
}
|
402
|
+
});
|
403
|
+
_onsync = true;
|
404
|
+
};
|
405
|
+
|
406
|
+
self.synclist[name] = fn;
|
407
|
+
requestSync();
|
408
|
+
return name;
|
409
|
+
};
|
410
|
+
|
411
|
+
this.unsynched = function(name) {
|
412
|
+
if (self.synclist[name]) self.synclist[name] = false;
|
413
|
+
};
|
414
|
+
|
415
|
+
this.css = function(el,pars) { // save & set
|
416
|
+
for(var n in pars) {
|
417
|
+
self.saved.css.push([el,n,el.css(n)]);
|
418
|
+
el.css(n,pars[n]);
|
419
|
+
}
|
420
|
+
};
|
421
|
+
|
422
|
+
this.scrollTop = function(val) {
|
423
|
+
return (typeof val == "undefined") ? self.getScrollTop() : self.setScrollTop(val);
|
424
|
+
};
|
425
|
+
|
426
|
+
this.scrollLeft = function(val) {
|
427
|
+
return (typeof val == "undefined") ? self.getScrollLeft() : self.setScrollLeft(val);
|
428
|
+
};
|
429
|
+
|
430
|
+
// derived by by Dan Pupius www.pupius.net
|
431
|
+
BezierClass = function(st,ed,spd,p1,p2,p3,p4) {
|
432
|
+
this.st = st;
|
433
|
+
this.ed = ed;
|
434
|
+
this.spd = spd;
|
435
|
+
|
436
|
+
this.p1 = p1||0;
|
437
|
+
this.p2 = p2||1;
|
438
|
+
this.p3 = p3||0;
|
439
|
+
this.p4 = p4||1;
|
440
|
+
|
441
|
+
this.ts = (new Date()).getTime();
|
442
|
+
this.df = this.ed-this.st;
|
443
|
+
};
|
444
|
+
BezierClass.prototype = {
|
445
|
+
B2:function(t){ return 3*t*t*(1-t) },
|
446
|
+
B3:function(t){ return 3*t*(1-t)*(1-t) },
|
447
|
+
B4:function(t){ return (1-t)*(1-t)*(1-t) },
|
448
|
+
getNow:function(){
|
449
|
+
var nw = (new Date()).getTime();
|
450
|
+
var pc = 1-((nw-this.ts)/this.spd);
|
451
|
+
var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
|
452
|
+
return (pc<0) ? this.ed : this.st+Math.round(this.df*bz);
|
453
|
+
},
|
454
|
+
update:function(ed,spd){
|
455
|
+
this.st = this.getNow();
|
456
|
+
this.ed = ed;
|
457
|
+
this.spd = spd;
|
458
|
+
this.ts = (new Date()).getTime();
|
459
|
+
this.df = this.ed-this.st;
|
460
|
+
return this;
|
461
|
+
}
|
462
|
+
};
|
463
|
+
|
464
|
+
if (this.ishwscroll) {
|
465
|
+
// hw accelerated scroll
|
466
|
+
this.doc.translate = {x:0,y:0,tx:"0px",ty:"0px"};
|
467
|
+
|
468
|
+
//this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
|
469
|
+
if (cap.hastranslate3d&&cap.isios) this.doc.css("-webkit-backface-visibility","hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/
|
470
|
+
|
471
|
+
//derived from http://stackoverflow.com/questions/11236090/
|
472
|
+
function getMatrixValues() {
|
473
|
+
var tr = self.doc.css(cap.trstyle);
|
474
|
+
if (tr&&(tr.substr(0,6)=="matrix")) {
|
475
|
+
return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g,'').split(/, +/);
|
476
|
+
}
|
477
|
+
return false;
|
478
|
+
}
|
479
|
+
|
480
|
+
this.getScrollTop = function(last) {
|
481
|
+
if (!last) {
|
482
|
+
var mtx = getMatrixValues();
|
483
|
+
if (mtx) return (mtx.length==16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on IE10
|
484
|
+
if (self.timerscroll&&self.timerscroll.bz) return self.timerscroll.bz.getNow();
|
485
|
+
}
|
486
|
+
return self.doc.translate.y;
|
487
|
+
};
|
488
|
+
|
489
|
+
this.getScrollLeft = function(last) {
|
490
|
+
if (!last) {
|
491
|
+
var mtx = getMatrixValues();
|
492
|
+
if (mtx) return (mtx.length==16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on IE10
|
493
|
+
if (self.timerscroll&&self.timerscroll.bh) return self.timerscroll.bh.getNow();
|
494
|
+
}
|
495
|
+
return self.doc.translate.x;
|
496
|
+
};
|
497
|
+
|
498
|
+
if (document.createEvent) {
|
499
|
+
this.notifyScrollEvent = function(el) {
|
500
|
+
var e = document.createEvent("UIEvents");
|
501
|
+
e.initUIEvent("scroll", false, true, window, 1);
|
502
|
+
el.dispatchEvent(e);
|
503
|
+
};
|
504
|
+
}
|
505
|
+
else if (document.fireEvent) {
|
506
|
+
this.notifyScrollEvent = function(el) {
|
507
|
+
var e = document.createEventObject();
|
508
|
+
el.fireEvent("onscroll");
|
509
|
+
e.cancelBubble = true;
|
510
|
+
};
|
511
|
+
}
|
512
|
+
else {
|
513
|
+
this.notifyScrollEvent = function(el,add) {}; //NOPE
|
514
|
+
}
|
515
|
+
|
516
|
+
var cxscrollleft = -1; //(this.isrtlmode) ? 1 : -1;
|
517
|
+
|
518
|
+
if (cap.hastranslate3d&&self.opt.enabletranslate3d) {
|
519
|
+
this.setScrollTop = function(val,silent) {
|
520
|
+
self.doc.translate.y = val;
|
521
|
+
self.doc.translate.ty = (val*-1)+"px";
|
522
|
+
self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");
|
523
|
+
if (!silent) self.notifyScrollEvent(self.win[0]);
|
524
|
+
};
|
525
|
+
this.setScrollLeft = function(val,silent) {
|
526
|
+
self.doc.translate.x = val;
|
527
|
+
self.doc.translate.tx = (val*cxscrollleft)+"px";
|
528
|
+
self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");
|
529
|
+
if (!silent) self.notifyScrollEvent(self.win[0]);
|
530
|
+
};
|
531
|
+
} else {
|
532
|
+
this.setScrollTop = function(val,silent) {
|
533
|
+
self.doc.translate.y = val;
|
534
|
+
self.doc.translate.ty = (val*-1)+"px";
|
535
|
+
self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
|
536
|
+
if (!silent) self.notifyScrollEvent(self.win[0]);
|
537
|
+
};
|
538
|
+
this.setScrollLeft = function(val,silent) {
|
539
|
+
self.doc.translate.x = val;
|
540
|
+
self.doc.translate.tx = (val*cxscrollleft)+"px";
|
541
|
+
self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
|
542
|
+
if (!silent) self.notifyScrollEvent(self.win[0]);
|
543
|
+
};
|
544
|
+
}
|
545
|
+
} else {
|
546
|
+
// native scroll
|
547
|
+
this.getScrollTop = function() {
|
548
|
+
return self.docscroll.scrollTop();
|
549
|
+
};
|
550
|
+
this.setScrollTop = function(val) {
|
551
|
+
return self.docscroll.scrollTop(val);
|
552
|
+
};
|
553
|
+
this.getScrollLeft = function() {
|
554
|
+
return self.docscroll.scrollLeft();
|
555
|
+
};
|
556
|
+
this.setScrollLeft = function(val) {
|
557
|
+
return self.docscroll.scrollLeft(val);
|
558
|
+
};
|
559
|
+
}
|
560
|
+
|
561
|
+
this.getTarget = function(e) {
|
562
|
+
if (!e) return false;
|
563
|
+
if (e.target) return e.target;
|
564
|
+
if (e.srcElement) return e.srcElement;
|
565
|
+
return false;
|
566
|
+
};
|
567
|
+
|
568
|
+
this.hasParent = function(e,id) {
|
569
|
+
if (!e) return false;
|
570
|
+
var el = e.target||e.srcElement||e||false;
|
571
|
+
while (el && el.id != id) {
|
572
|
+
el = el.parentNode||false;
|
573
|
+
}
|
574
|
+
return (el!==false);
|
575
|
+
};
|
576
|
+
|
577
|
+
function getZIndex() {
|
578
|
+
var dom = self.win;
|
579
|
+
if ("zIndex" in dom) return dom.zIndex(); // use jQuery UI method when available
|
580
|
+
while (dom.length>0) {
|
581
|
+
if (dom[0].nodeType==9) return false;
|
582
|
+
var zi = dom.css('zIndex');
|
583
|
+
if (!isNaN(zi)&&zi!=0) return parseInt(zi);
|
584
|
+
dom = dom.parent();
|
585
|
+
}
|
586
|
+
return false;
|
587
|
+
};
|
588
|
+
|
589
|
+
//inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
|
590
|
+
var _convertBorderWidth = {"thin":1,"medium":3,"thick":5};
|
591
|
+
function getWidthToPixel(dom,prop,chkheight) {
|
592
|
+
var wd = dom.css(prop);
|
593
|
+
var px = parseFloat(wd);
|
594
|
+
if (isNaN(px)) {
|
595
|
+
px = _convertBorderWidth[wd]||0;
|
596
|
+
var brd = (px==3) ? ((chkheight)?(self.win.outerHeight() - self.win.innerHeight()):(self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
|
597
|
+
if (self.isie8&&px) px+=1;
|
598
|
+
return (brd) ? px : 0;
|
599
|
+
}
|
600
|
+
return px;
|
601
|
+
};
|
602
|
+
|
603
|
+
this.getOffset = function() {
|
604
|
+
if (self.isfixed) return {top:parseFloat(self.win.css('top')),left:parseFloat(self.win.css('left'))};
|
605
|
+
if (!self.viewport) return self.win.offset();
|
606
|
+
var ww = self.win.offset();
|
607
|
+
var vp = self.viewport.offset();
|
608
|
+
return {top:ww.top-vp.top+self.viewport.scrollTop(),left:ww.left-vp.left+self.viewport.scrollLeft()};
|
609
|
+
};
|
610
|
+
|
611
|
+
this.updateScrollBar = function(len) {
|
612
|
+
if (self.ishwscroll) {
|
613
|
+
self.rail.css({height:self.win.innerHeight()});
|
614
|
+
if (self.railh) self.railh.css({width:self.win.innerWidth()});
|
615
|
+
} else {
|
616
|
+
var wpos = self.getOffset();
|
617
|
+
var pos = {top:wpos.top,left:wpos.left};
|
618
|
+
pos.top+= getWidthToPixel(self.win,'border-top-width',true);
|
619
|
+
var brd = (self.win.outerWidth() - self.win.innerWidth())/2;
|
620
|
+
pos.left+= (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win,'border-right-width') - self.rail.width : getWidthToPixel(self.win,'border-left-width');
|
621
|
+
|
622
|
+
var off = self.opt.railoffset;
|
623
|
+
if (off) {
|
624
|
+
if (off.top) pos.top+=off.top;
|
625
|
+
if (self.rail.align&&off.left) pos.left+=off.left;
|
626
|
+
}
|
627
|
+
|
628
|
+
if (!self.locked) self.rail.css({top:pos.top,left:pos.left,height:(len)?len.h:self.win.innerHeight()});
|
629
|
+
|
630
|
+
if (self.zoom) {
|
631
|
+
self.zoom.css({top:pos.top+1,left:(self.rail.align==1) ? pos.left-20 : pos.left+self.rail.width+4});
|
632
|
+
}
|
633
|
+
|
634
|
+
if (self.railh&&!self.locked) {
|
635
|
+
var pos = {top:wpos.top,left:wpos.left};
|
636
|
+
var y = (self.railh.align) ? pos.top + getWidthToPixel(self.win,'border-top-width',true) + self.win.innerHeight() - self.railh.height : pos.top + getWidthToPixel(self.win,'border-top-width',true);
|
637
|
+
var x = pos.left + getWidthToPixel(self.win,'border-left-width');
|
638
|
+
self.railh.css({top:y,left:x,width:self.railh.width});
|
639
|
+
}
|
640
|
+
|
641
|
+
|
642
|
+
}
|
643
|
+
};
|
644
|
+
|
645
|
+
this.doRailClick = function(e,dbl,hr) {
|
646
|
+
|
647
|
+
var fn,pg,cur,pos;
|
648
|
+
|
649
|
+
// if (self.rail.drag&&self.rail.drag.pt!=1) return;
|
650
|
+
if (self.locked) return;
|
651
|
+
// if (self.rail.drag) return;
|
652
|
+
|
653
|
+
// self.cancelScroll();
|
654
|
+
|
655
|
+
self.cancelEvent(e);
|
656
|
+
|
657
|
+
if (dbl) {
|
658
|
+
fn = (hr) ? self.doScrollLeft : self.doScrollTop;
|
659
|
+
cur = (hr) ? ((e.pageX - self.railh.offset().left - (self.cursorwidth/2)) * self.scrollratio.x) : ((e.pageY - self.rail.offset().top - (self.cursorheight/2)) * self.scrollratio.y);
|
660
|
+
fn(cur);
|
661
|
+
} else {
|
662
|
+
fn = (hr) ? self.doScrollLeftBy : self.doScrollBy;
|
663
|
+
cur = (hr) ? self.scroll.x : self.scroll.y;
|
664
|
+
pos = (hr) ? e.pageX - self.railh.offset().left : e.pageY - self.rail.offset().top;
|
665
|
+
pg = (hr) ? self.view.w : self.view.h;
|
666
|
+
(cur>=pos) ? fn(pg) : fn(-pg);
|
667
|
+
}
|
668
|
+
|
669
|
+
};
|
670
|
+
|
671
|
+
self.hasanimationframe = (setAnimationFrame);
|
672
|
+
self.hascancelanimationframe = (clearAnimationFrame);
|
673
|
+
|
674
|
+
if (!self.hasanimationframe) {
|
675
|
+
setAnimationFrame=function(fn){return setTimeout(fn,15-Math.floor((+new Date)/1000)%16)}; // 1000/60)};
|
676
|
+
clearAnimationFrame=clearInterval;
|
677
|
+
}
|
678
|
+
else if (!self.hascancelanimationframe) clearAnimationFrame=function(){self.cancelAnimationFrame=true};
|
679
|
+
|
680
|
+
this.init = function() {
|
681
|
+
|
682
|
+
self.saved.css = [];
|
683
|
+
|
684
|
+
if (cap.isie7mobile) return true; // SORRY, DO NOT WORK!
|
685
|
+
if (cap.isoperamini) return true; // SORRY, DO NOT WORK!
|
686
|
+
|
687
|
+
if (cap.hasmstouch) self.css((self.ispage)?$("html"):self.win,{'-ms-touch-action':'none'});
|
688
|
+
|
689
|
+
self.zindex = "auto";
|
690
|
+
if (!self.ispage&&self.opt.zindex=="auto") {
|
691
|
+
self.zindex = getZIndex()||"auto";
|
692
|
+
} else {
|
693
|
+
self.zindex = self.opt.zindex;
|
694
|
+
}
|
695
|
+
|
696
|
+
if (!self.ispage&&self.zindex!="auto") {
|
697
|
+
if (self.zindex>globalmaxzindex) globalmaxzindex=self.zindex;
|
698
|
+
}
|
699
|
+
|
700
|
+
if (self.isie&&self.zindex==0&&self.opt.zindex=="auto") { // fix IE auto == 0
|
701
|
+
self.zindex="auto";
|
702
|
+
}
|
703
|
+
|
704
|
+
/*
|
705
|
+
self.ispage = true;
|
706
|
+
self.haswrapper = true;
|
707
|
+
// self.win = $(window);
|
708
|
+
self.docscroll = $("body");
|
709
|
+
// self.doc = $("body");
|
710
|
+
*/
|
711
|
+
|
712
|
+
if (!self.ispage || (!cap.cantouch && !cap.isieold && !cap.isie9mobile)) {
|
713
|
+
|
714
|
+
var cont = self.docscroll;
|
715
|
+
if (self.ispage) cont = (self.haswrapper)?self.win:self.doc;
|
716
|
+
|
717
|
+
if (!cap.isie9mobile) self.css(cont,{'overflow-y':'hidden'});
|
718
|
+
|
719
|
+
if (self.ispage&&cap.isie7) {
|
720
|
+
if (self.doc[0].nodeName=='BODY') self.css($("html"),{'overflow-y':'hidden'}); //IE7 double scrollbar issue
|
721
|
+
else if (self.doc[0].nodeName=='HTML') self.css($("body"),{'overflow-y':'hidden'}); //IE7 double scrollbar issue
|
722
|
+
}
|
723
|
+
|
724
|
+
if (cap.isios&&!self.ispage&&!self.haswrapper) self.css($("body"),{"-webkit-overflow-scrolling":"touch"}); //force hw acceleration
|
725
|
+
|
726
|
+
var cursor = $(document.createElement('div'));
|
727
|
+
cursor.css({
|
728
|
+
position:"relative",top:0,"float":"right",width:self.opt.cursorwidth,height:"0px",
|
729
|
+
'background-color':self.opt.cursorcolor,
|
730
|
+
border:self.opt.cursorborder,
|
731
|
+
'background-clip':'padding-box',
|
732
|
+
'-webkit-border-radius':self.opt.cursorborderradius,
|
733
|
+
'-moz-border-radius':self.opt.cursorborderradius,
|
734
|
+
'border-radius':self.opt.cursorborderradius
|
735
|
+
});
|
736
|
+
|
737
|
+
cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());
|
738
|
+
self.cursor = cursor;
|
739
|
+
|
740
|
+
var rail = $(document.createElement('div'));
|
741
|
+
rail.attr('id',self.id);
|
742
|
+
rail.addClass('nicescroll-rails');
|
743
|
+
|
744
|
+
var v,a,kp = ["left","right"]; //"top","bottom"
|
745
|
+
for(var n in kp) {
|
746
|
+
a=kp[n];
|
747
|
+
v = self.opt.railpadding[a];
|
748
|
+
(v) ? rail.css("padding-"+a,v+"px") : self.opt.railpadding[a] = 0;
|
749
|
+
}
|
750
|
+
|
751
|
+
rail.append(cursor);
|
752
|
+
|
753
|
+
rail.width = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerWidth()) + self.opt.railpadding['left'] + self.opt.railpadding['right'];
|
754
|
+
rail.css({width:rail.width+"px",'zIndex':self.zindex,"background":self.opt.background,cursor:"default"});
|
755
|
+
|
756
|
+
rail.visibility = true;
|
757
|
+
rail.scrollable = true;
|
758
|
+
|
759
|
+
rail.align = (self.opt.railalign=="left") ? 0 : 1;
|
760
|
+
|
761
|
+
self.rail = rail;
|
762
|
+
|
763
|
+
self.rail.drag = false;
|
764
|
+
|
765
|
+
var zoom = false;
|
766
|
+
if (self.opt.boxzoom&&!self.ispage&&!cap.isieold) {
|
767
|
+
zoom = document.createElement('div');
|
768
|
+
self.bind(zoom,"click",self.doZoom);
|
769
|
+
self.zoom = $(zoom);
|
770
|
+
self.zoom.css({"cursor":"pointer",'z-index':self.zindex,'backgroundImage':'url('<%= asset_path("zoomico.png") %>')','height':18,'width':18,'backgroundPosition':'0px 0px'});
|
771
|
+
if (self.opt.dblclickzoom) self.bind(self.win,"dblclick",self.doZoom);
|
772
|
+
if (cap.cantouch&&self.opt.gesturezoom) {
|
773
|
+
self.ongesturezoom = function(e) {
|
774
|
+
if (e.scale>1.5) self.doZoomIn(e);
|
775
|
+
if (e.scale<0.8) self.doZoomOut(e);
|
776
|
+
return self.cancelEvent(e);
|
777
|
+
};
|
778
|
+
self.bind(self.win,"gestureend",self.ongesturezoom);
|
779
|
+
}
|
780
|
+
}
|
781
|
+
|
782
|
+
// init HORIZ
|
783
|
+
|
784
|
+
self.railh = false;
|
785
|
+
|
786
|
+
if (self.opt.horizrailenabled) {
|
787
|
+
|
788
|
+
self.css(cont,{'overflow-x':'hidden'});
|
789
|
+
|
790
|
+
var cursor = $(document.createElement('div'));
|
791
|
+
cursor.css({
|
792
|
+
position:"relative",top:0,height:self.opt.cursorwidth,width:"0px",
|
793
|
+
'background-color':self.opt.cursorcolor,
|
794
|
+
border:self.opt.cursorborder,
|
795
|
+
'background-clip':'padding-box',
|
796
|
+
'-webkit-border-radius':self.opt.cursorborderradius,
|
797
|
+
'-moz-border-radius':self.opt.cursorborderradius,
|
798
|
+
'border-radius':self.opt.cursorborderradius
|
799
|
+
});
|
800
|
+
|
801
|
+
cursor.wborder = parseFloat(cursor.outerWidth() - cursor.innerWidth());
|
802
|
+
self.cursorh = cursor;
|
803
|
+
|
804
|
+
var railh = $(document.createElement('div'));
|
805
|
+
railh.attr('id',self.id+'-hr');
|
806
|
+
railh.addClass('nicescroll-rails');
|
807
|
+
railh.height = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerHeight());
|
808
|
+
railh.css({height:railh.height+"px",'zIndex':self.zindex,"background":self.opt.background});
|
809
|
+
|
810
|
+
railh.append(cursor);
|
811
|
+
|
812
|
+
railh.visibility = true;
|
813
|
+
railh.scrollable = true;
|
814
|
+
|
815
|
+
railh.align = (self.opt.railvalign=="top") ? 0 : 1;
|
816
|
+
|
817
|
+
self.railh = railh;
|
818
|
+
|
819
|
+
self.railh.drag = false;
|
820
|
+
|
821
|
+
}
|
822
|
+
|
823
|
+
//
|
824
|
+
|
825
|
+
if (self.ispage) {
|
826
|
+
rail.css({position:"fixed",top:"0px",height:"100%"});
|
827
|
+
(rail.align) ? rail.css({right:"0px"}) : rail.css({left:"0px"});
|
828
|
+
self.body.append(rail);
|
829
|
+
if (self.railh) {
|
830
|
+
railh.css({position:"fixed",left:"0px",width:"100%"});
|
831
|
+
(railh.align) ? railh.css({bottom:"0px"}) : railh.css({top:"0px"});
|
832
|
+
self.body.append(railh);
|
833
|
+
}
|
834
|
+
} else {
|
835
|
+
if (self.ishwscroll) {
|
836
|
+
if (self.win.css('position')=='static') self.css(self.win,{'position':'relative'});
|
837
|
+
var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
|
838
|
+
if (self.zoom) {
|
839
|
+
self.zoom.css({position:"absolute",top:1,right:0,"margin-right":rail.width+4});
|
840
|
+
bd.append(self.zoom);
|
841
|
+
}
|
842
|
+
rail.css({position:"absolute",top:0});
|
843
|
+
(rail.align) ? rail.css({right:0}) : rail.css({left:0});
|
844
|
+
bd.append(rail);
|
845
|
+
if (railh) {
|
846
|
+
railh.css({position:"absolute",left:0,bottom:0});
|
847
|
+
(railh.align) ? railh.css({bottom:0}) : railh.css({top:0});
|
848
|
+
bd.append(railh);
|
849
|
+
}
|
850
|
+
} else {
|
851
|
+
self.isfixed = (self.win.css("position")=="fixed");
|
852
|
+
var rlpos = (self.isfixed) ? "fixed" : "absolute";
|
853
|
+
|
854
|
+
if (!self.isfixed) self.viewport = self.getViewport(self.win[0]);
|
855
|
+
if (self.viewport) {
|
856
|
+
self.body = self.viewport;
|
857
|
+
if ((/fixed|relative|absolute/.test(self.viewport.css("position")))==false) self.css(self.viewport,{"position":"relative"});
|
858
|
+
}
|
859
|
+
|
860
|
+
rail.css({position:rlpos});
|
861
|
+
if (self.zoom) self.zoom.css({position:rlpos});
|
862
|
+
self.updateScrollBar();
|
863
|
+
self.body.append(rail);
|
864
|
+
if (self.zoom) self.body.append(self.zoom);
|
865
|
+
if (self.railh) {
|
866
|
+
railh.css({position:rlpos});
|
867
|
+
self.body.append(railh);
|
868
|
+
}
|
869
|
+
}
|
870
|
+
|
871
|
+
if (cap.isios) self.css(self.win,{'-webkit-tap-highlight-color':'rgba(0,0,0,0)','-webkit-touch-callout':'none'}); // prevent grey layer on click
|
872
|
+
|
873
|
+
if (cap.isie&&self.opt.disableoutline) self.win.attr("hideFocus","true"); // IE, prevent dotted rectangle on focused div
|
874
|
+
if (cap.iswebkit&&self.opt.disableoutline) self.win.css({"outline":"none"});
|
875
|
+
// if (cap.isopera&&self.opt.disableoutline) self.win.css({"outline":"0"}); // Opera to test [TODO]
|
876
|
+
|
877
|
+
}
|
878
|
+
|
879
|
+
if (self.opt.autohidemode===false) {
|
880
|
+
self.autohidedom = false;
|
881
|
+
self.rail.css({opacity:self.opt.cursoropacitymax});
|
882
|
+
if (self.railh) self.railh.css({opacity:self.opt.cursoropacitymax});
|
883
|
+
}
|
884
|
+
else if ((self.opt.autohidemode===true)||(self.opt.autohidemode==="leave")) {
|
885
|
+
self.autohidedom = $().add(self.rail);
|
886
|
+
if (cap.isie8) self.autohidedom=self.autohidedom.add(self.cursor);
|
887
|
+
if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
|
888
|
+
if (self.railh&&cap.isie8) self.autohidedom=self.autohidedom.add(self.cursorh);
|
889
|
+
}
|
890
|
+
else if (self.opt.autohidemode=="scroll") {
|
891
|
+
self.autohidedom = $().add(self.rail);
|
892
|
+
if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
|
893
|
+
}
|
894
|
+
else if (self.opt.autohidemode=="cursor") {
|
895
|
+
self.autohidedom = $().add(self.cursor);
|
896
|
+
if (self.railh) self.autohidedom=self.autohidedom.add(self.cursorh);
|
897
|
+
}
|
898
|
+
else if (self.opt.autohidemode=="hidden") {
|
899
|
+
self.autohidedom = false;
|
900
|
+
self.hide();
|
901
|
+
self.locked = false;
|
902
|
+
}
|
903
|
+
|
904
|
+
if (cap.isie9mobile) {
|
905
|
+
|
906
|
+
self.scrollmom = new ScrollMomentumClass2D(self);
|
907
|
+
|
908
|
+
/*
|
909
|
+
var trace = function(msg) {
|
910
|
+
var db = $("#debug");
|
911
|
+
if (isNaN(msg)&&(typeof msg != "string")) {
|
912
|
+
var x = [];
|
913
|
+
for(var a in msg) {
|
914
|
+
x.push(a+":"+msg[a]);
|
915
|
+
}
|
916
|
+
msg ="{"+x.join(",")+"}";
|
917
|
+
}
|
918
|
+
if (db.children().length>0) {
|
919
|
+
db.children().eq(0).before("<div>"+msg+"</div>");
|
920
|
+
} else {
|
921
|
+
db.append("<div>"+msg+"</div>");
|
922
|
+
}
|
923
|
+
}
|
924
|
+
window.onerror = function(msg,url,ln) {
|
925
|
+
trace("ERR: "+msg+" at "+ln);
|
926
|
+
}
|
927
|
+
*/
|
928
|
+
|
929
|
+
self.onmangotouch = function(e) {
|
930
|
+
var py = self.getScrollTop();
|
931
|
+
var px = self.getScrollLeft();
|
932
|
+
|
933
|
+
if ((py == self.scrollmom.lastscrolly)&&(px == self.scrollmom.lastscrollx)) return true;
|
934
|
+
// $("#debug").html('DRAG:'+py);
|
935
|
+
|
936
|
+
var dfy = py-self.mangotouch.sy;
|
937
|
+
var dfx = px-self.mangotouch.sx;
|
938
|
+
var df = Math.round(Math.sqrt(Math.pow(dfx,2)+Math.pow(dfy,2)));
|
939
|
+
if (df==0) return;
|
940
|
+
|
941
|
+
var dry = (dfy<0)?-1:1;
|
942
|
+
var drx = (dfx<0)?-1:1;
|
943
|
+
|
944
|
+
var tm = +new Date();
|
945
|
+
if (self.mangotouch.lazy) clearTimeout(self.mangotouch.lazy);
|
946
|
+
|
947
|
+
if (((tm-self.mangotouch.tm)>80)||(self.mangotouch.dry!=dry)||(self.mangotouch.drx!=drx)) {
|
948
|
+
// trace('RESET+'+(tm-self.mangotouch.tm));
|
949
|
+
self.scrollmom.stop();
|
950
|
+
self.scrollmom.reset(px,py);
|
951
|
+
self.mangotouch.sy = py;
|
952
|
+
self.mangotouch.ly = py;
|
953
|
+
self.mangotouch.sx = px;
|
954
|
+
self.mangotouch.lx = px;
|
955
|
+
self.mangotouch.dry = dry;
|
956
|
+
self.mangotouch.drx = drx;
|
957
|
+
self.mangotouch.tm = tm;
|
958
|
+
} else {
|
959
|
+
|
960
|
+
self.scrollmom.stop();
|
961
|
+
self.scrollmom.update(self.mangotouch.sx-dfx,self.mangotouch.sy-dfy);
|
962
|
+
var gap = tm - self.mangotouch.tm;
|
963
|
+
self.mangotouch.tm = tm;
|
964
|
+
|
965
|
+
// trace('MOVE:'+df+" - "+gap);
|
966
|
+
|
967
|
+
var ds = Math.max(Math.abs(self.mangotouch.ly-py),Math.abs(self.mangotouch.lx-px));
|
968
|
+
self.mangotouch.ly = py;
|
969
|
+
self.mangotouch.lx = px;
|
970
|
+
|
971
|
+
if (ds>2) {
|
972
|
+
self.mangotouch.lazy = setTimeout(function(){
|
973
|
+
// trace('END:'+ds+'+'+gap);
|
974
|
+
self.mangotouch.lazy = false;
|
975
|
+
self.mangotouch.dry = 0;
|
976
|
+
self.mangotouch.drx = 0;
|
977
|
+
self.mangotouch.tm = 0;
|
978
|
+
self.scrollmom.doMomentum(30);
|
979
|
+
},100);
|
980
|
+
}
|
981
|
+
}
|
982
|
+
};
|
983
|
+
|
984
|
+
var top = self.getScrollTop();
|
985
|
+
var lef = self.getScrollLeft();
|
986
|
+
self.mangotouch = {sy:top,ly:top,dry:0,sx:lef,lx:lef,drx:0,lazy:false,tm:0};
|
987
|
+
|
988
|
+
self.bind(self.docscroll,"scroll",self.onmangotouch);
|
989
|
+
|
990
|
+
} else {
|
991
|
+
|
992
|
+
if (cap.cantouch||self.istouchcapable||self.opt.touchbehavior||cap.hasmstouch) {
|
993
|
+
|
994
|
+
self.scrollmom = new ScrollMomentumClass2D(self);
|
995
|
+
|
996
|
+
self.ontouchstart = function(e) {
|
997
|
+
if (e.pointerType&&e.pointerType!=2) return false;
|
998
|
+
|
999
|
+
self.hasmoving = false;
|
1000
|
+
|
1001
|
+
if (!self.locked) {
|
1002
|
+
|
1003
|
+
if (cap.hasmstouch) {
|
1004
|
+
var tg = (e.target) ? e.target : false;
|
1005
|
+
while (tg) {
|
1006
|
+
var nc = $(tg).getNiceScroll();
|
1007
|
+
if ((nc.length>0)&&(nc[0].me == self.me)) break;
|
1008
|
+
if (nc.length>0) return false;
|
1009
|
+
if ((tg.nodeName=='DIV')&&(tg.id==self.id)) break;
|
1010
|
+
tg = (tg.parentNode) ? tg.parentNode : false;
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
self.cancelScroll();
|
1015
|
+
|
1016
|
+
var tg = self.getTarget(e);
|
1017
|
+
|
1018
|
+
if (tg) {
|
1019
|
+
var skp = (/INPUT/i.test(tg.nodeName))&&(/range/i.test(tg.type));
|
1020
|
+
if (skp) return self.stopPropagation(e);
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
if (!("clientX" in e) && ("changedTouches" in e)) {
|
1024
|
+
e.clientX = e.changedTouches[0].clientX;
|
1025
|
+
e.clientY = e.changedTouches[0].clientY;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
if (self.forcescreen) {
|
1029
|
+
var le = e;
|
1030
|
+
var e = {"original":(e.original)?e.original:e};
|
1031
|
+
e.clientX = le.screenX;
|
1032
|
+
e.clientY = le.screenY;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,st:self.getScrollTop(),sl:self.getScrollLeft(),pt:2,dl:false};
|
1036
|
+
|
1037
|
+
if (self.ispage||!self.opt.directionlockdeadzone) {
|
1038
|
+
self.rail.drag.dl = "f";
|
1039
|
+
} else {
|
1040
|
+
|
1041
|
+
var view = {
|
1042
|
+
w:$(window).width(),
|
1043
|
+
h:$(window).height()
|
1044
|
+
};
|
1045
|
+
|
1046
|
+
var page = {
|
1047
|
+
w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
|
1048
|
+
h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
|
1049
|
+
};
|
1050
|
+
|
1051
|
+
var maxh = Math.max(0,page.h - view.h);
|
1052
|
+
var maxw = Math.max(0,page.w - view.w);
|
1053
|
+
|
1054
|
+
if (!self.rail.scrollable&&self.railh.scrollable) self.rail.drag.ck = (maxh>0) ? "v" : false;
|
1055
|
+
else if (self.rail.scrollable&&!self.railh.scrollable) self.rail.drag.ck = (maxw>0) ? "h" : false;
|
1056
|
+
else self.rail.drag.ck = false;
|
1057
|
+
if (!self.rail.drag.ck) self.rail.drag.dl = "f";
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
if (self.opt.touchbehavior&&self.isiframe&&cap.isie) {
|
1061
|
+
var wp = self.win.position();
|
1062
|
+
self.rail.drag.x+=wp.left;
|
1063
|
+
self.rail.drag.y+=wp.top;
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
self.hasmoving = false;
|
1067
|
+
self.lastmouseup = false;
|
1068
|
+
self.scrollmom.reset(e.clientX,e.clientY);
|
1069
|
+
if (!cap.cantouch&&!this.istouchcapable&&!cap.hasmstouch) {
|
1070
|
+
|
1071
|
+
var ip = (tg)?/INPUT|SELECT|TEXTAREA/i.test(tg.nodeName):false;
|
1072
|
+
if (!ip) {
|
1073
|
+
if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
|
1074
|
+
|
1075
|
+
if (self.opt.touchbehavior) {
|
1076
|
+
if (tg.onclick&&!(tg._onclick||false)) { // intercept DOM0 onclick event
|
1077
|
+
tg._onclick = tg.onclick;
|
1078
|
+
tg.onclick = function(e){
|
1079
|
+
if (self.hasmoving) return false;
|
1080
|
+
tg._onclick.call(this,e);
|
1081
|
+
}
|
1082
|
+
}
|
1083
|
+
return self.cancelEvent(e);
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
return self.stopPropagation(e);
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
|
1090
|
+
pc = {"tg":tg,"click":false};
|
1091
|
+
self.preventclick = pc;
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
}
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
};
|
1098
|
+
|
1099
|
+
self.ontouchend = function(e) {
|
1100
|
+
if (e.pointerType&&e.pointerType!=2) return false;
|
1101
|
+
if (self.rail.drag&&(self.rail.drag.pt==2)) {
|
1102
|
+
self.scrollmom.doMomentum();
|
1103
|
+
self.rail.drag = false;
|
1104
|
+
if (self.hasmoving) {
|
1105
|
+
self.lastmouseup = true;
|
1106
|
+
self.hideCursor();
|
1107
|
+
if (cap.hasmousecapture) document.releaseCapture();
|
1108
|
+
if (!cap.cantouch) return self.cancelEvent(e);
|
1109
|
+
}
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
};
|
1113
|
+
|
1114
|
+
var moveneedoffset = (self.opt.touchbehavior&&self.isiframe&&!cap.hasmousecapture);
|
1115
|
+
|
1116
|
+
self.ontouchmove = function(e,byiframe) {
|
1117
|
+
|
1118
|
+
if (e.pointerType&&e.pointerType!=2) return false;
|
1119
|
+
|
1120
|
+
if (self.rail.drag&&(self.rail.drag.pt==2)) {
|
1121
|
+
if (cap.cantouch&&(typeof e.original == "undefined")) return true; // prevent ios "ghost" events by clickable elements
|
1122
|
+
|
1123
|
+
self.hasmoving = true;
|
1124
|
+
|
1125
|
+
if (self.preventclick&&!self.preventclick.click) {
|
1126
|
+
self.preventclick.click = self.preventclick.tg.onclick||false;
|
1127
|
+
self.preventclick.tg.onclick = self.onpreventclick;
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
var ev = $.extend({"original":e},e);
|
1131
|
+
e = ev;
|
1132
|
+
|
1133
|
+
if (("changedTouches" in e)) {
|
1134
|
+
e.clientX = e.changedTouches[0].clientX;
|
1135
|
+
e.clientY = e.changedTouches[0].clientY;
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
if (self.forcescreen) {
|
1139
|
+
var le = e;
|
1140
|
+
var e = {"original":(e.original)?e.original:e};
|
1141
|
+
e.clientX = le.screenX;
|
1142
|
+
e.clientY = le.screenY;
|
1143
|
+
}
|
1144
|
+
|
1145
|
+
var ofx = ofy = 0;
|
1146
|
+
|
1147
|
+
if (moveneedoffset&&!byiframe) {
|
1148
|
+
var wp = self.win.position();
|
1149
|
+
ofx=-wp.left;
|
1150
|
+
ofy=-wp.top;
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
var fy = e.clientY + ofy;
|
1154
|
+
var my = (fy-self.rail.drag.y);
|
1155
|
+
var fx = e.clientX + ofx;
|
1156
|
+
var mx = (fx-self.rail.drag.x);
|
1157
|
+
|
1158
|
+
var ny = self.rail.drag.st-my;
|
1159
|
+
|
1160
|
+
if (self.ishwscroll&&self.opt.bouncescroll) {
|
1161
|
+
if (ny<0) {
|
1162
|
+
ny = Math.round(ny/2);
|
1163
|
+
// fy = 0;
|
1164
|
+
}
|
1165
|
+
else if (ny>self.page.maxh) {
|
1166
|
+
ny = self.page.maxh+Math.round((ny-self.page.maxh)/2);
|
1167
|
+
// fy = 0;
|
1168
|
+
}
|
1169
|
+
} else {
|
1170
|
+
if (ny<0) {ny=0;fy=0}
|
1171
|
+
if (ny>self.page.maxh) {ny=self.page.maxh;fy=0}
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
if (self.railh&&self.railh.scrollable) {
|
1175
|
+
var nx = self.rail.drag.sl-mx;; //(self.isrtlmode) ? mx-self.rail.drag.sl : self.rail.drag.sl-mx;
|
1176
|
+
|
1177
|
+
if (self.ishwscroll&&self.opt.bouncescroll) {
|
1178
|
+
if (nx<0) {
|
1179
|
+
nx = Math.round(nx/2);
|
1180
|
+
// fx = 0;
|
1181
|
+
}
|
1182
|
+
else if (nx>self.page.maxw) {
|
1183
|
+
nx = self.page.maxw+Math.round((nx-self.page.maxw)/2);
|
1184
|
+
// fx = 0;
|
1185
|
+
}
|
1186
|
+
} else {
|
1187
|
+
if (nx<0) {nx=0;fx=0}
|
1188
|
+
if (nx>self.page.maxw) {nx=self.page.maxw;fx=0}
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
var grabbed = false;
|
1194
|
+
if (self.rail.drag.dl) {
|
1195
|
+
grabbed = true;
|
1196
|
+
if (self.rail.drag.dl=="v") nx = self.rail.drag.sl;
|
1197
|
+
else if (self.rail.drag.dl=="h") ny = self.rail.drag.st;
|
1198
|
+
} else {
|
1199
|
+
var ay = Math.abs(my);
|
1200
|
+
var ax = Math.abs(mx);
|
1201
|
+
var dz = self.opt.directionlockdeadzone;
|
1202
|
+
if (self.rail.drag.ck=="v") {
|
1203
|
+
if (ay>dz&&(ax<=(ay*0.3))) {
|
1204
|
+
self.rail.drag = false;
|
1205
|
+
return true;
|
1206
|
+
}
|
1207
|
+
else if (ax>dz) {
|
1208
|
+
self.rail.drag.dl="f";
|
1209
|
+
$("body").scrollTop($("body").scrollTop()); // stop iOS native scrolling (when active javascript has blocked)
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
else if (self.rail.drag.ck=="h") {
|
1213
|
+
if (ax>dz&&(ay<=(ax*0.3))) {
|
1214
|
+
self.rail.drag = false;
|
1215
|
+
return true;
|
1216
|
+
}
|
1217
|
+
else if (ay>dz) {
|
1218
|
+
self.rail.drag.dl="f";
|
1219
|
+
$("body").scrollLeft($("body").scrollLeft()); // stop iOS native scrolling (when active javascript has blocked)
|
1220
|
+
}
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
self.synched("touchmove",function(){
|
1225
|
+
if (self.rail.drag&&(self.rail.drag.pt==2)) {
|
1226
|
+
if (self.prepareTransition) self.prepareTransition(0);
|
1227
|
+
if (self.rail.scrollable) self.setScrollTop(ny);
|
1228
|
+
self.scrollmom.update(fx,fy);
|
1229
|
+
if (self.railh&&self.railh.scrollable) {
|
1230
|
+
self.setScrollLeft(nx);
|
1231
|
+
self.showCursor(ny,nx);
|
1232
|
+
} else {
|
1233
|
+
self.showCursor(ny);
|
1234
|
+
}
|
1235
|
+
if (cap.isie10) document.selection.clear();
|
1236
|
+
}
|
1237
|
+
});
|
1238
|
+
|
1239
|
+
if (cap.ischrome&&self.istouchcapable) grabbed=false; //chrome touch emulation doesn't like!
|
1240
|
+
if (grabbed) return self.cancelEvent(e);
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
};
|
1244
|
+
|
1245
|
+
}
|
1246
|
+
|
1247
|
+
self.onmousedown = function(e,hronly) {
|
1248
|
+
if (self.rail.drag&&self.rail.drag.pt!=1) return;
|
1249
|
+
if (self.locked) return self.cancelEvent(e);
|
1250
|
+
self.cancelScroll();
|
1251
|
+
self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,pt:1,hr:(!!hronly)};
|
1252
|
+
var tg = self.getTarget(e);
|
1253
|
+
if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
|
1254
|
+
if (self.isiframe&&!cap.hasmousecapture) {
|
1255
|
+
self.saved["csspointerevents"] = self.doc.css("pointer-events");
|
1256
|
+
self.css(self.doc,{"pointer-events":"none"});
|
1257
|
+
}
|
1258
|
+
self.hasmoving=false;
|
1259
|
+
return self.cancelEvent(e);
|
1260
|
+
};
|
1261
|
+
|
1262
|
+
self.onmouseup = function(e) {
|
1263
|
+
if (self.rail.drag) {
|
1264
|
+
if (cap.hasmousecapture) document.releaseCapture();
|
1265
|
+
if (self.isiframe&&!cap.hasmousecapture) self.doc.css("pointer-events",self.saved["csspointerevents"]);
|
1266
|
+
if(self.rail.drag.pt!=1)return;
|
1267
|
+
self.rail.drag = false;
|
1268
|
+
//if (!self.rail.active) self.hideCursor();
|
1269
|
+
if (self.hasmoving) self.triggerScrollEnd(); // TODO - check &&!self.scrollrunning
|
1270
|
+
return self.cancelEvent(e);
|
1271
|
+
}
|
1272
|
+
};
|
1273
|
+
|
1274
|
+
self.onmousemove = function(e) {
|
1275
|
+
if (self.rail.drag) {
|
1276
|
+
if(self.rail.drag.pt!=1)return;
|
1277
|
+
|
1278
|
+
if (cap.ischrome&&e.which==0) return self.onmouseup(e);
|
1279
|
+
|
1280
|
+
self.cursorfreezed = true;
|
1281
|
+
self.hasmoving = true;
|
1282
|
+
|
1283
|
+
if (self.rail.drag.hr) {
|
1284
|
+
self.scroll.x = self.rail.drag.sx + (e.clientX-self.rail.drag.x);
|
1285
|
+
if (self.scroll.x<0) self.scroll.x=0;
|
1286
|
+
var mw = self.scrollvaluemaxw;
|
1287
|
+
if (self.scroll.x>mw) self.scroll.x=mw;
|
1288
|
+
} else {
|
1289
|
+
self.scroll.y = self.rail.drag.sy + (e.clientY-self.rail.drag.y);
|
1290
|
+
if (self.scroll.y<0) self.scroll.y=0;
|
1291
|
+
var my = self.scrollvaluemax;
|
1292
|
+
if (self.scroll.y>my) self.scroll.y=my;
|
1293
|
+
}
|
1294
|
+
|
1295
|
+
self.synched('mousemove',function(){
|
1296
|
+
if (self.rail.drag&&(self.rail.drag.pt==1)) {
|
1297
|
+
self.showCursor();
|
1298
|
+
if (self.rail.drag.hr) self.doScrollLeft(Math.round(self.scroll.x*self.scrollratio.x),self.opt.cursordragspeed);
|
1299
|
+
else self.doScrollTop(Math.round(self.scroll.y*self.scrollratio.y),self.opt.cursordragspeed);
|
1300
|
+
}
|
1301
|
+
});
|
1302
|
+
|
1303
|
+
return self.cancelEvent(e);
|
1304
|
+
}
|
1305
|
+
/*
|
1306
|
+
else {
|
1307
|
+
self.checkarea = true;
|
1308
|
+
}
|
1309
|
+
*/
|
1310
|
+
};
|
1311
|
+
|
1312
|
+
if (cap.cantouch||self.opt.touchbehavior) {
|
1313
|
+
|
1314
|
+
self.onpreventclick = function(e) {
|
1315
|
+
if (self.preventclick) {
|
1316
|
+
self.preventclick.tg.onclick = self.preventclick.click;
|
1317
|
+
self.preventclick = false;
|
1318
|
+
return self.cancelEvent(e);
|
1319
|
+
}
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
// self.onmousedown = self.ontouchstart;
|
1323
|
+
// self.onmouseup = self.ontouchend;
|
1324
|
+
// self.onmousemove = self.ontouchmove;
|
1325
|
+
|
1326
|
+
self.bind(self.win,"mousedown",self.ontouchstart); // control content dragging
|
1327
|
+
|
1328
|
+
self.onclick = (cap.isios) ? false : function(e) {
|
1329
|
+
if (self.lastmouseup) {
|
1330
|
+
self.lastmouseup = false;
|
1331
|
+
return self.cancelEvent(e);
|
1332
|
+
} else {
|
1333
|
+
return true;
|
1334
|
+
}
|
1335
|
+
};
|
1336
|
+
|
1337
|
+
if (self.opt.grabcursorenabled&&cap.cursorgrabvalue) {
|
1338
|
+
self.css((self.ispage)?self.doc:self.win,{'cursor':cap.cursorgrabvalue});
|
1339
|
+
self.css(self.rail,{'cursor':cap.cursorgrabvalue});
|
1340
|
+
}
|
1341
|
+
|
1342
|
+
} else {
|
1343
|
+
|
1344
|
+
function checkSelectionScroll(e) {
|
1345
|
+
if (!self.selectiondrag) return;
|
1346
|
+
|
1347
|
+
if (e) {
|
1348
|
+
var ww = self.win.outerHeight();
|
1349
|
+
var df = (e.pageY - self.selectiondrag.top);
|
1350
|
+
if (df>0&&df<ww) df=0;
|
1351
|
+
if (df>=ww) df-=ww;
|
1352
|
+
self.selectiondrag.df = df;
|
1353
|
+
}
|
1354
|
+
if (self.selectiondrag.df==0) return;
|
1355
|
+
|
1356
|
+
var rt = -Math.floor(self.selectiondrag.df/6)*2;
|
1357
|
+
// self.doScrollTop(self.getScrollTop(true)+rt);
|
1358
|
+
self.doScrollBy(rt);
|
1359
|
+
|
1360
|
+
self.debounced("doselectionscroll",function(){checkSelectionScroll()},50);
|
1361
|
+
};
|
1362
|
+
|
1363
|
+
if ("getSelection" in document) { // A grade - Major browsers
|
1364
|
+
self.hasTextSelected = function() {
|
1365
|
+
return (document.getSelection().rangeCount>0);
|
1366
|
+
};
|
1367
|
+
}
|
1368
|
+
else if ("selection" in document) { //IE9-
|
1369
|
+
self.hasTextSelected = function() {
|
1370
|
+
return (document.selection.type != "None");
|
1371
|
+
};
|
1372
|
+
}
|
1373
|
+
else {
|
1374
|
+
self.hasTextSelected = function() { // no support
|
1375
|
+
return false;
|
1376
|
+
};
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
self.onselectionstart = function(e) {
|
1380
|
+
if (self.ispage) return;
|
1381
|
+
self.selectiondrag = self.win.offset();
|
1382
|
+
};
|
1383
|
+
self.onselectionend = function(e) {
|
1384
|
+
self.selectiondrag = false;
|
1385
|
+
};
|
1386
|
+
self.onselectiondrag = function(e) {
|
1387
|
+
if (!self.selectiondrag) return;
|
1388
|
+
if (self.hasTextSelected()) self.debounced("selectionscroll",function(){checkSelectionScroll(e)},250);
|
1389
|
+
};
|
1390
|
+
|
1391
|
+
|
1392
|
+
}
|
1393
|
+
|
1394
|
+
if (cap.hasmstouch) {
|
1395
|
+
self.css(self.rail,{'-ms-touch-action':'none'});
|
1396
|
+
self.css(self.cursor,{'-ms-touch-action':'none'});
|
1397
|
+
|
1398
|
+
self.bind(self.win,"MSPointerDown",self.ontouchstart);
|
1399
|
+
self.bind(document,"MSPointerUp",self.ontouchend);
|
1400
|
+
self.bind(document,"MSPointerMove",self.ontouchmove);
|
1401
|
+
self.bind(self.cursor,"MSGestureHold",function(e){e.preventDefault()});
|
1402
|
+
self.bind(self.cursor,"contextmenu",function(e){e.preventDefault()});
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
if (this.istouchcapable) { //desktop with screen touch enabled
|
1406
|
+
self.bind(self.win,"touchstart",self.ontouchstart);
|
1407
|
+
self.bind(document,"touchend",self.ontouchend);
|
1408
|
+
self.bind(document,"touchcancel",self.ontouchend);
|
1409
|
+
self.bind(document,"touchmove",self.ontouchmove);
|
1410
|
+
}
|
1411
|
+
|
1412
|
+
self.bind(self.cursor,"mousedown",self.onmousedown);
|
1413
|
+
self.bind(self.cursor,"mouseup",self.onmouseup);
|
1414
|
+
|
1415
|
+
if (self.railh) {
|
1416
|
+
self.bind(self.cursorh,"mousedown",function(e){self.onmousedown(e,true)});
|
1417
|
+
|
1418
|
+
self.bind(self.cursorh,"mouseup",self.onmouseup);
|
1419
|
+
|
1420
|
+
|
1421
|
+
/*
|
1422
|
+
self.bind(self.cursorh,"mouseup",function(e){
|
1423
|
+
if (self.rail.drag&&self.rail.drag.pt==2) return;
|
1424
|
+
self.rail.drag = false;
|
1425
|
+
self.hasmoving = false;
|
1426
|
+
self.hideCursor();
|
1427
|
+
if (cap.hasmousecapture) document.releaseCapture();
|
1428
|
+
return self.cancelEvent(e);
|
1429
|
+
});
|
1430
|
+
*/
|
1431
|
+
|
1432
|
+
}
|
1433
|
+
|
1434
|
+
if (self.opt.cursordragontouch||!cap.cantouch&&!self.opt.touchbehavior) {
|
1435
|
+
|
1436
|
+
self.rail.css({"cursor":"default"});
|
1437
|
+
self.railh&&self.railh.css({"cursor":"default"});
|
1438
|
+
|
1439
|
+
self.jqbind(self.rail,"mouseenter",function() {
|
1440
|
+
if (!self.win.is(":visible")) return false;
|
1441
|
+
if (self.canshowonmouseevent) self.showCursor();
|
1442
|
+
self.rail.active = true;
|
1443
|
+
});
|
1444
|
+
self.jqbind(self.rail,"mouseleave",function() {
|
1445
|
+
self.rail.active = false;
|
1446
|
+
if (!self.rail.drag) self.hideCursor();
|
1447
|
+
});
|
1448
|
+
|
1449
|
+
if (self.opt.sensitiverail) {
|
1450
|
+
self.bind(self.rail,"click",function(e){self.doRailClick(e,false,false)});
|
1451
|
+
self.bind(self.rail,"dblclick",function(e){self.doRailClick(e,true,false)});
|
1452
|
+
self.bind(self.cursor,"click",function(e){self.cancelEvent(e)});
|
1453
|
+
self.bind(self.cursor,"dblclick",function(e){self.cancelEvent(e)});
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
if (self.railh) {
|
1457
|
+
self.jqbind(self.railh,"mouseenter",function() {
|
1458
|
+
if (!self.win.is(":visible")) return false;
|
1459
|
+
if (self.canshowonmouseevent) self.showCursor();
|
1460
|
+
self.rail.active = true;
|
1461
|
+
});
|
1462
|
+
self.jqbind(self.railh,"mouseleave",function() {
|
1463
|
+
self.rail.active = false;
|
1464
|
+
if (!self.rail.drag) self.hideCursor();
|
1465
|
+
});
|
1466
|
+
|
1467
|
+
if (self.opt.sensitiverail) {
|
1468
|
+
self.bind(self.railh, "click", function(e){self.doRailClick(e,false,true)});
|
1469
|
+
self.bind(self.railh, "dblclick", function(e){self.doRailClick(e, true, true) });
|
1470
|
+
self.bind(self.cursorh, "click", function (e) { self.cancelEvent(e) });
|
1471
|
+
self.bind(self.cursorh, "dblclick", function (e) { self.cancelEvent(e) });
|
1472
|
+
}
|
1473
|
+
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
if (!cap.cantouch&&!self.opt.touchbehavior) {
|
1479
|
+
|
1480
|
+
self.bind((cap.hasmousecapture)?self.win:document,"mouseup",self.onmouseup);
|
1481
|
+
self.bind(document,"mousemove",self.onmousemove);
|
1482
|
+
if (self.onclick) self.bind(document,"click",self.onclick);
|
1483
|
+
|
1484
|
+
if (!self.ispage&&self.opt.enablescrollonselection) {
|
1485
|
+
self.bind(self.win[0],"mousedown",self.onselectionstart);
|
1486
|
+
self.bind(document,"mouseup",self.onselectionend);
|
1487
|
+
self.bind(self.cursor,"mouseup",self.onselectionend);
|
1488
|
+
if (self.cursorh) self.bind(self.cursorh,"mouseup",self.onselectionend);
|
1489
|
+
self.bind(document,"mousemove",self.onselectiondrag);
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
if (self.zoom) {
|
1493
|
+
self.jqbind(self.zoom,"mouseenter",function() {
|
1494
|
+
if (self.canshowonmouseevent) self.showCursor();
|
1495
|
+
self.rail.active = true;
|
1496
|
+
});
|
1497
|
+
self.jqbind(self.zoom,"mouseleave",function() {
|
1498
|
+
self.rail.active = false;
|
1499
|
+
if (!self.rail.drag) self.hideCursor();
|
1500
|
+
});
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
} else {
|
1504
|
+
|
1505
|
+
self.bind((cap.hasmousecapture)?self.win:document,"mouseup",self.ontouchend);
|
1506
|
+
self.bind(document,"mousemove",self.ontouchmove);
|
1507
|
+
if (self.onclick) self.bind(document,"click",self.onclick);
|
1508
|
+
|
1509
|
+
if (self.opt.cursordragontouch) {
|
1510
|
+
self.bind(self.cursor,"mousedown",self.onmousedown);
|
1511
|
+
self.bind(self.cursor,"mousemove",self.onmousemove);
|
1512
|
+
self.cursorh&&self.bind(self.cursorh,"mousedown",function(e){self.onmousedown(e,true)});
|
1513
|
+
self.cursorh&&self.bind(self.cursorh,"mousemove",self.onmousemove);
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
}
|
1517
|
+
|
1518
|
+
if (self.opt.enablemousewheel) {
|
1519
|
+
if (!self.isiframe) self.bind((cap.isie&&self.ispage) ? document : self.win /*self.docscroll*/ ,"mousewheel",self.onmousewheel);
|
1520
|
+
self.bind(self.rail,"mousewheel",self.onmousewheel);
|
1521
|
+
if (self.railh) self.bind(self.railh,"mousewheel",self.onmousewheelhr);
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
if (!self.ispage&&!cap.cantouch&&!(/HTML|^BODY/.test(self.win[0].nodeName))) {
|
1525
|
+
if (!self.win.attr("tabindex")) self.win.attr({"tabindex":tabindexcounter++});
|
1526
|
+
|
1527
|
+
self.jqbind(self.win,"focus",function(e) {
|
1528
|
+
domfocus = (self.getTarget(e)).id||true;
|
1529
|
+
self.hasfocus = true;
|
1530
|
+
if (self.canshowonmouseevent) self.noticeCursor();
|
1531
|
+
});
|
1532
|
+
self.jqbind(self.win,"blur",function(e) {
|
1533
|
+
domfocus = false;
|
1534
|
+
self.hasfocus = false;
|
1535
|
+
});
|
1536
|
+
|
1537
|
+
self.jqbind(self.win,"mouseenter",function(e) {
|
1538
|
+
mousefocus = (self.getTarget(e)).id||true;
|
1539
|
+
self.hasmousefocus = true;
|
1540
|
+
if (self.canshowonmouseevent) self.noticeCursor();
|
1541
|
+
});
|
1542
|
+
self.jqbind(self.win,"mouseleave",function() {
|
1543
|
+
mousefocus = false;
|
1544
|
+
self.hasmousefocus = false;
|
1545
|
+
if (!self.rail.drag) self.hideCursor();
|
1546
|
+
});
|
1547
|
+
|
1548
|
+
};
|
1549
|
+
|
1550
|
+
} // !ie9mobile
|
1551
|
+
|
1552
|
+
//Thanks to http://www.quirksmode.org !!
|
1553
|
+
self.onkeypress = function(e) {
|
1554
|
+
if (self.locked&&self.page.maxh==0) return true;
|
1555
|
+
|
1556
|
+
e = (e) ? e : window.e;
|
1557
|
+
var tg = self.getTarget(e);
|
1558
|
+
if (tg&&/INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
|
1559
|
+
var tp = tg.getAttribute('type')||tg.type||false;
|
1560
|
+
if ((!tp)||!(/submit|button|cancel/i.tp)) return true;
|
1561
|
+
}
|
1562
|
+
|
1563
|
+
if ($(tg).attr('contenteditable')) return true;
|
1564
|
+
|
1565
|
+
if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
|
1566
|
+
var key = e.keyCode;
|
1567
|
+
|
1568
|
+
if (self.locked&&key!=27) return self.cancelEvent(e);
|
1569
|
+
|
1570
|
+
var ctrl = e.ctrlKey||false;
|
1571
|
+
var shift = e.shiftKey || false;
|
1572
|
+
|
1573
|
+
var ret = false;
|
1574
|
+
switch (key) {
|
1575
|
+
case 38:
|
1576
|
+
case 63233: //safari
|
1577
|
+
self.doScrollBy(24*3);
|
1578
|
+
ret = true;
|
1579
|
+
break;
|
1580
|
+
case 40:
|
1581
|
+
case 63235: //safari
|
1582
|
+
self.doScrollBy(-24*3);
|
1583
|
+
ret = true;
|
1584
|
+
break;
|
1585
|
+
case 37:
|
1586
|
+
case 63232: //safari
|
1587
|
+
if (self.railh) {
|
1588
|
+
(ctrl) ? self.doScrollLeft(0) : self.doScrollLeftBy(24*3);
|
1589
|
+
ret = true;
|
1590
|
+
}
|
1591
|
+
break;
|
1592
|
+
case 39:
|
1593
|
+
case 63234: //safari
|
1594
|
+
if (self.railh) {
|
1595
|
+
(ctrl) ? self.doScrollLeft(self.page.maxw) : self.doScrollLeftBy(-24*3);
|
1596
|
+
ret = true;
|
1597
|
+
}
|
1598
|
+
break;
|
1599
|
+
case 33:
|
1600
|
+
case 63276: // safari
|
1601
|
+
self.doScrollBy(self.view.h);
|
1602
|
+
ret = true;
|
1603
|
+
break;
|
1604
|
+
case 34:
|
1605
|
+
case 63277: // safari
|
1606
|
+
self.doScrollBy(-self.view.h);
|
1607
|
+
ret = true;
|
1608
|
+
break;
|
1609
|
+
case 36:
|
1610
|
+
case 63273: // safari
|
1611
|
+
(self.railh&&ctrl) ? self.doScrollPos(0,0) : self.doScrollTo(0);
|
1612
|
+
ret = true;
|
1613
|
+
break;
|
1614
|
+
case 35:
|
1615
|
+
case 63275: // safari
|
1616
|
+
(self.railh&&ctrl) ? self.doScrollPos(self.page.maxw,self.page.maxh) : self.doScrollTo(self.page.maxh);
|
1617
|
+
ret = true;
|
1618
|
+
break;
|
1619
|
+
case 32:
|
1620
|
+
if (self.opt.spacebarenabled) {
|
1621
|
+
(shift) ? self.doScrollBy(self.view.h) : self.doScrollBy(-self.view.h);
|
1622
|
+
ret = true;
|
1623
|
+
}
|
1624
|
+
break;
|
1625
|
+
case 27: // ESC
|
1626
|
+
if (self.zoomactive) {
|
1627
|
+
self.doZoom();
|
1628
|
+
ret = true;
|
1629
|
+
}
|
1630
|
+
break;
|
1631
|
+
}
|
1632
|
+
if (ret) return self.cancelEvent(e);
|
1633
|
+
}
|
1634
|
+
};
|
1635
|
+
|
1636
|
+
if (self.opt.enablekeyboard) self.bind(document,(cap.isopera&&!cap.isopera12)?"keypress":"keydown",self.onkeypress);
|
1637
|
+
|
1638
|
+
self.bind(document,"keydown",function(e){
|
1639
|
+
var ctrl = e.ctrlKey||false;
|
1640
|
+
if (ctrl) self.wheelprevented = true;
|
1641
|
+
});
|
1642
|
+
self.bind(document,"keyup",function(e){
|
1643
|
+
var ctrl = e.ctrlKey||false;
|
1644
|
+
if (!ctrl) self.wheelprevented = false;
|
1645
|
+
});
|
1646
|
+
|
1647
|
+
self.bind(window,'resize',self.lazyResize);
|
1648
|
+
self.bind(window,'orientationchange',self.lazyResize);
|
1649
|
+
|
1650
|
+
self.bind(window,"load",self.lazyResize);
|
1651
|
+
|
1652
|
+
if (cap.ischrome&&!self.ispage&&!self.haswrapper) { //chrome void scrollbar bug - it persists in version 26
|
1653
|
+
var tmp=self.win.attr("style");
|
1654
|
+
var ww = parseFloat(self.win.css("width"))+1;
|
1655
|
+
self.win.css('width',ww);
|
1656
|
+
self.synched("chromefix",function(){self.win.attr("style",tmp)});
|
1657
|
+
}
|
1658
|
+
|
1659
|
+
|
1660
|
+
// Trying a cross-browser implementation - good luck!
|
1661
|
+
|
1662
|
+
self.onAttributeChange = function(e) {
|
1663
|
+
self.lazyResize(250);
|
1664
|
+
};
|
1665
|
+
|
1666
|
+
if (!self.ispage&&!self.haswrapper) {
|
1667
|
+
// redesigned MutationObserver for Chrome18+/Firefox14+/iOS6+ with support for: remove div, add/remove content
|
1668
|
+
if (clsMutationObserver !== false) {
|
1669
|
+
self.observer = new clsMutationObserver(function(mutations) {
|
1670
|
+
mutations.forEach(self.onAttributeChange);
|
1671
|
+
});
|
1672
|
+
self.observer.observe(self.win[0],{childList: true, characterData: false, attributes: true, subtree: false});
|
1673
|
+
|
1674
|
+
self.observerremover = new clsMutationObserver(function(mutations) {
|
1675
|
+
mutations.forEach(function(mo){
|
1676
|
+
if (mo.removedNodes.length>0) {
|
1677
|
+
for (var dd in mo.removedNodes) {
|
1678
|
+
if (mo.removedNodes[dd]==self.win[0]) return self.remove();
|
1679
|
+
}
|
1680
|
+
}
|
1681
|
+
});
|
1682
|
+
});
|
1683
|
+
self.observerremover.observe(self.win[0].parentNode,{childList: true, characterData: false, attributes: false, subtree: false});
|
1684
|
+
|
1685
|
+
} else {
|
1686
|
+
self.bind(self.win,(cap.isie&&!cap.isie9)?"propertychange":"DOMAttrModified",self.onAttributeChange);
|
1687
|
+
if (cap.isie9) self.win[0].attachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
|
1688
|
+
self.bind(self.win,"DOMNodeRemoved",function(e){
|
1689
|
+
if (e.target==self.win[0]) self.remove();
|
1690
|
+
});
|
1691
|
+
}
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
//
|
1695
|
+
|
1696
|
+
if (!self.ispage&&self.opt.boxzoom) self.bind(window,"resize",self.resizeZoom);
|
1697
|
+
if (self.istextarea) self.bind(self.win,"mouseup",self.lazyResize);
|
1698
|
+
|
1699
|
+
// self.checkrtlmode = true;
|
1700
|
+
self.lazyResize(30);
|
1701
|
+
|
1702
|
+
}
|
1703
|
+
|
1704
|
+
if (this.doc[0].nodeName == 'IFRAME') {
|
1705
|
+
function oniframeload(e) {
|
1706
|
+
self.iframexd = false;
|
1707
|
+
try {
|
1708
|
+
var doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
|
1709
|
+
var a = doc.domain;
|
1710
|
+
} catch(e){self.iframexd = true;doc=false};
|
1711
|
+
|
1712
|
+
if (self.iframexd) {
|
1713
|
+
if ("console" in window) console.log('NiceScroll error: policy restriced iframe');
|
1714
|
+
return true; //cross-domain - I can't manage this
|
1715
|
+
}
|
1716
|
+
|
1717
|
+
self.forcescreen = true;
|
1718
|
+
|
1719
|
+
if (self.isiframe) {
|
1720
|
+
self.iframe = {
|
1721
|
+
"doc":$(doc),
|
1722
|
+
"html":self.doc.contents().find('html')[0],
|
1723
|
+
"body":self.doc.contents().find('body')[0]
|
1724
|
+
};
|
1725
|
+
self.getContentSize = function(){
|
1726
|
+
return {
|
1727
|
+
w:Math.max(self.iframe.html.scrollWidth,self.iframe.body.scrollWidth),
|
1728
|
+
h:Math.max(self.iframe.html.scrollHeight,self.iframe.body.scrollHeight)
|
1729
|
+
};
|
1730
|
+
};
|
1731
|
+
self.docscroll = $(self.iframe.body);//$(this.contentWindow);
|
1732
|
+
}
|
1733
|
+
|
1734
|
+
if (!cap.isios&&self.opt.iframeautoresize&&!self.isiframe) {
|
1735
|
+
self.win.scrollTop(0); // reset position
|
1736
|
+
self.doc.height(""); //reset height to fix browser bug
|
1737
|
+
var hh=Math.max(doc.getElementsByTagName('html')[0].scrollHeight,doc.body.scrollHeight);
|
1738
|
+
self.doc.height(hh);
|
1739
|
+
}
|
1740
|
+
self.lazyResize(30);
|
1741
|
+
|
1742
|
+
if (cap.isie7) self.css($(self.iframe.html),{'overflow-y':'hidden'});
|
1743
|
+
//self.css($(doc.body),{'overflow-y':'hidden'});
|
1744
|
+
self.css($(self.iframe.body),{'overflow-y':'hidden'});
|
1745
|
+
|
1746
|
+
if (cap.isios&&self.haswrapper) {
|
1747
|
+
self.css($(doc.body),{'-webkit-transform':'translate3d(0,0,0)'}); // avoid iFrame content clipping - thanks to http://blog.derraab.com/2012/04/02/avoid-iframe-content-clipping-with-css-transform-on-ios/
|
1748
|
+
}
|
1749
|
+
|
1750
|
+
if ('contentWindow' in this) {
|
1751
|
+
self.bind(this.contentWindow,"scroll",self.onscroll); //IE8 & minor
|
1752
|
+
} else {
|
1753
|
+
self.bind(doc,"scroll",self.onscroll);
|
1754
|
+
}
|
1755
|
+
|
1756
|
+
if (self.opt.enablemousewheel) {
|
1757
|
+
self.bind(doc,"mousewheel",self.onmousewheel);
|
1758
|
+
}
|
1759
|
+
|
1760
|
+
if (self.opt.enablekeyboard) self.bind(doc,(cap.isopera)?"keypress":"keydown",self.onkeypress);
|
1761
|
+
|
1762
|
+
if (cap.cantouch||self.opt.touchbehavior) {
|
1763
|
+
self.bind(doc,"mousedown",self.ontouchstart);
|
1764
|
+
self.bind(doc,"mousemove",function(e){self.ontouchmove(e,true)});
|
1765
|
+
if (self.opt.grabcursorenabled&&cap.cursorgrabvalue) self.css($(doc.body),{'cursor':cap.cursorgrabvalue});
|
1766
|
+
}
|
1767
|
+
|
1768
|
+
self.bind(doc,"mouseup",self.ontouchend);
|
1769
|
+
|
1770
|
+
if (self.zoom) {
|
1771
|
+
if (self.opt.dblclickzoom) self.bind(doc,'dblclick',self.doZoom);
|
1772
|
+
if (self.ongesturezoom) self.bind(doc,"gestureend",self.ongesturezoom);
|
1773
|
+
}
|
1774
|
+
};
|
1775
|
+
|
1776
|
+
if (this.doc[0].readyState&&this.doc[0].readyState=="complete"){
|
1777
|
+
setTimeout(function(){oniframeload.call(self.doc[0],false)},500);
|
1778
|
+
}
|
1779
|
+
self.bind(this.doc,"load",oniframeload);
|
1780
|
+
|
1781
|
+
}
|
1782
|
+
|
1783
|
+
};
|
1784
|
+
|
1785
|
+
this.showCursor = function(py,px) {
|
1786
|
+
if (self.cursortimeout) {
|
1787
|
+
clearTimeout(self.cursortimeout);
|
1788
|
+
self.cursortimeout = 0;
|
1789
|
+
}
|
1790
|
+
if (!self.rail) return;
|
1791
|
+
if (self.autohidedom) {
|
1792
|
+
self.autohidedom.stop().css({opacity:self.opt.cursoropacitymax});
|
1793
|
+
self.cursoractive = true;
|
1794
|
+
}
|
1795
|
+
|
1796
|
+
if (!self.rail.drag||self.rail.drag.pt!=1) {
|
1797
|
+
if ((typeof py != "undefined")&&(py!==false)) {
|
1798
|
+
self.scroll.y = Math.round(py * 1/self.scrollratio.y);
|
1799
|
+
}
|
1800
|
+
if (typeof px != "undefined") {
|
1801
|
+
self.scroll.x = Math.round(px * 1/self.scrollratio.x); //-cxscrollleft * Math.round(px * 1/self.scrollratio.x);
|
1802
|
+
}
|
1803
|
+
}
|
1804
|
+
|
1805
|
+
self.cursor.css({height:self.cursorheight,top:self.scroll.y});
|
1806
|
+
if (self.cursorh) {
|
1807
|
+
(!self.rail.align&&self.rail.visibility) ? self.cursorh.css({width:self.cursorwidth,left:self.scroll.x+self.rail.width}) : self.cursorh.css({width:self.cursorwidth,left:self.scroll.x});
|
1808
|
+
self.cursoractive = true;
|
1809
|
+
}
|
1810
|
+
|
1811
|
+
if (self.zoom) self.zoom.stop().css({opacity:self.opt.cursoropacitymax});
|
1812
|
+
};
|
1813
|
+
|
1814
|
+
this.hideCursor = function(tm) {
|
1815
|
+
if (self.cursortimeout) return;
|
1816
|
+
if (!self.rail) return;
|
1817
|
+
if (!self.autohidedom) return;
|
1818
|
+
if (self.hasmousefocus&&self.opt.autohidemode=="leave") return;
|
1819
|
+
self.cursortimeout = setTimeout(function() {
|
1820
|
+
if (!self.rail.active||!self.showonmouseevent) {
|
1821
|
+
self.autohidedom.stop().animate({opacity:self.opt.cursoropacitymin});
|
1822
|
+
if (self.zoom) self.zoom.stop().animate({opacity:self.opt.cursoropacitymin});
|
1823
|
+
self.cursoractive = false;
|
1824
|
+
}
|
1825
|
+
self.cursortimeout = 0;
|
1826
|
+
},tm||self.opt.hidecursordelay);
|
1827
|
+
};
|
1828
|
+
|
1829
|
+
this.noticeCursor = function(tm,py,px) {
|
1830
|
+
self.showCursor(py,px);
|
1831
|
+
if (!self.rail.active) self.hideCursor(tm);
|
1832
|
+
};
|
1833
|
+
|
1834
|
+
this.getContentSize =
|
1835
|
+
(self.ispage) ?
|
1836
|
+
function(){
|
1837
|
+
return {
|
1838
|
+
w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
|
1839
|
+
h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
|
1840
|
+
}
|
1841
|
+
}
|
1842
|
+
: (self.haswrapper) ?
|
1843
|
+
function(){
|
1844
|
+
return {
|
1845
|
+
w:self.doc.outerWidth()+parseInt(self.win.css('paddingLeft'))+parseInt(self.win.css('paddingRight')),
|
1846
|
+
h:self.doc.outerHeight()+parseInt(self.win.css('paddingTop'))+parseInt(self.win.css('paddingBottom'))
|
1847
|
+
}
|
1848
|
+
}
|
1849
|
+
: function() {
|
1850
|
+
return {
|
1851
|
+
w:self.docscroll[0].scrollWidth,
|
1852
|
+
h:self.docscroll[0].scrollHeight
|
1853
|
+
}
|
1854
|
+
};
|
1855
|
+
|
1856
|
+
this.onResize = function(e,page) {
|
1857
|
+
|
1858
|
+
if (!self||!self.win) return false;
|
1859
|
+
|
1860
|
+
if (!self.haswrapper&&!self.ispage) {
|
1861
|
+
if (self.win.css('display')=='none') {
|
1862
|
+
if (self.visibility) self.hideRail().hideRailHr();
|
1863
|
+
return false;
|
1864
|
+
} else {
|
1865
|
+
if (!self.hidden&&!self.visibility) self.showRail().showRailHr();
|
1866
|
+
}
|
1867
|
+
}
|
1868
|
+
|
1869
|
+
var premaxh = self.page.maxh;
|
1870
|
+
var premaxw = self.page.maxw;
|
1871
|
+
|
1872
|
+
var preview = {h:self.view.h,w:self.view.w};
|
1873
|
+
|
1874
|
+
self.view = {
|
1875
|
+
w:(self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
|
1876
|
+
h:(self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
|
1877
|
+
};
|
1878
|
+
|
1879
|
+
self.page = (page) ? page : self.getContentSize();
|
1880
|
+
|
1881
|
+
self.page.maxh = Math.max(0,self.page.h - self.view.h);
|
1882
|
+
self.page.maxw = Math.max(0,self.page.w - self.view.w);
|
1883
|
+
|
1884
|
+
if ((self.page.maxh==premaxh)&&(self.page.maxw==premaxw)&&(self.view.w==preview.w)) {
|
1885
|
+
// test position
|
1886
|
+
if (!self.ispage) {
|
1887
|
+
var pos = self.win.offset();
|
1888
|
+
if (self.lastposition) {
|
1889
|
+
var lst = self.lastposition;
|
1890
|
+
if ((lst.top==pos.top)&&(lst.left==pos.left)) return self; //nothing to do
|
1891
|
+
}
|
1892
|
+
self.lastposition = pos;
|
1893
|
+
} else {
|
1894
|
+
return self; //nothing to do
|
1895
|
+
}
|
1896
|
+
}
|
1897
|
+
|
1898
|
+
if (self.page.maxh==0) {
|
1899
|
+
self.hideRail();
|
1900
|
+
self.scrollvaluemax = 0;
|
1901
|
+
self.scroll.y = 0;
|
1902
|
+
self.scrollratio.y = 0;
|
1903
|
+
self.cursorheight = 0;
|
1904
|
+
self.setScrollTop(0);
|
1905
|
+
self.rail.scrollable = false;
|
1906
|
+
} else {
|
1907
|
+
self.rail.scrollable = true;
|
1908
|
+
}
|
1909
|
+
|
1910
|
+
if (self.page.maxw==0) {
|
1911
|
+
self.hideRailHr();
|
1912
|
+
self.scrollvaluemaxw = 0;
|
1913
|
+
self.scroll.x = 0;
|
1914
|
+
self.scrollratio.x = 0;
|
1915
|
+
self.cursorwidth = 0;
|
1916
|
+
self.setScrollLeft(0);
|
1917
|
+
self.railh.scrollable = false;
|
1918
|
+
} else {
|
1919
|
+
self.railh.scrollable = true;
|
1920
|
+
}
|
1921
|
+
|
1922
|
+
self.locked = (self.page.maxh==0)&&(self.page.maxw==0);
|
1923
|
+
if (self.locked) {
|
1924
|
+
if (!self.ispage) self.updateScrollBar(self.view);
|
1925
|
+
return false;
|
1926
|
+
}
|
1927
|
+
|
1928
|
+
if (!self.hidden&&!self.visibility) {
|
1929
|
+
self.showRail().showRailHr();
|
1930
|
+
}
|
1931
|
+
else if (!self.hidden&&!self.railh.visibility) self.showRailHr();
|
1932
|
+
|
1933
|
+
if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;
|
1934
|
+
|
1935
|
+
self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
|
1936
|
+
self.cursorheight = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorheight);
|
1937
|
+
|
1938
|
+
self.cursorwidth = Math.min(self.view.w,Math.round(self.view.w * (self.view.w / self.page.w)));
|
1939
|
+
self.cursorwidth = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorwidth);
|
1940
|
+
|
1941
|
+
self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder;
|
1942
|
+
|
1943
|
+
if (self.railh) {
|
1944
|
+
self.railh.width = (self.page.maxh>0) ? (self.view.w-self.rail.width) : self.view.w;
|
1945
|
+
self.scrollvaluemaxw = self.railh.width-self.cursorwidth-self.cursorh.wborder;
|
1946
|
+
}
|
1947
|
+
|
1948
|
+
/*
|
1949
|
+
if (self.checkrtlmode&&self.railh) {
|
1950
|
+
self.checkrtlmode = false;
|
1951
|
+
if (self.opt.rtlmode&&self.scroll.x==0) self.setScrollLeft(self.page.maxw);
|
1952
|
+
}
|
1953
|
+
*/
|
1954
|
+
|
1955
|
+
if (!self.ispage) self.updateScrollBar(self.view);
|
1956
|
+
|
1957
|
+
self.scrollratio = {
|
1958
|
+
x:(self.page.maxw/self.scrollvaluemaxw),
|
1959
|
+
y:(self.page.maxh/self.scrollvaluemax)
|
1960
|
+
};
|
1961
|
+
|
1962
|
+
var sy = self.getScrollTop();
|
1963
|
+
if (sy>self.page.maxh) {
|
1964
|
+
self.doScrollTop(self.page.maxh);
|
1965
|
+
} else {
|
1966
|
+
self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
|
1967
|
+
self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
|
1968
|
+
if (self.cursoractive) self.noticeCursor();
|
1969
|
+
}
|
1970
|
+
|
1971
|
+
if (self.scroll.y&&(self.getScrollTop()==0)) self.doScrollTo(Math.floor(self.scroll.y*self.scrollratio.y));
|
1972
|
+
|
1973
|
+
return self;
|
1974
|
+
};
|
1975
|
+
|
1976
|
+
this.resize = self.onResize;
|
1977
|
+
|
1978
|
+
this.lazyResize = function(tm) { // event debounce
|
1979
|
+
tm = (isNaN(tm)) ? 30 : tm;
|
1980
|
+
self.delayed('resize',self.resize,tm);
|
1981
|
+
return self;
|
1982
|
+
};
|
1983
|
+
|
1984
|
+
// modified by MDN https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/wheel
|
1985
|
+
function _modernWheelEvent(dom,name,fn,bubble) {
|
1986
|
+
self._bind(dom,name,function(e){
|
1987
|
+
var e = (e) ? e : window.event;
|
1988
|
+
var event = {
|
1989
|
+
original: e,
|
1990
|
+
target: e.target || e.srcElement,
|
1991
|
+
type: "wheel",
|
1992
|
+
deltaMode: e.type == "MozMousePixelScroll" ? 0 : 1,
|
1993
|
+
deltaX: 0,
|
1994
|
+
deltaZ: 0,
|
1995
|
+
preventDefault: function() {
|
1996
|
+
e.preventDefault ? e.preventDefault() : e.returnValue = false;
|
1997
|
+
return false;
|
1998
|
+
},
|
1999
|
+
stopImmediatePropagation: function() {
|
2000
|
+
(e.stopImmediatePropagation) ? e.stopImmediatePropagation() : e.cancelBubble = true;
|
2001
|
+
}
|
2002
|
+
};
|
2003
|
+
|
2004
|
+
if (name=="mousewheel") {
|
2005
|
+
event.deltaY = - 1/40 * e.wheelDelta;
|
2006
|
+
e.wheelDeltaX && (event.deltaX = - 1/40 * e.wheelDeltaX);
|
2007
|
+
} else {
|
2008
|
+
event.deltaY = e.detail;
|
2009
|
+
}
|
2010
|
+
|
2011
|
+
return fn.call(dom,event);
|
2012
|
+
},bubble);
|
2013
|
+
};
|
2014
|
+
|
2015
|
+
this._bind = function(el,name,fn,bubble) { // primitive bind
|
2016
|
+
self.events.push({e:el,n:name,f:fn,b:bubble,q:false});
|
2017
|
+
if (el.addEventListener) {
|
2018
|
+
el.addEventListener(name,fn,bubble||false);
|
2019
|
+
}
|
2020
|
+
else if (el.attachEvent) {
|
2021
|
+
el.attachEvent("on"+name,fn);
|
2022
|
+
}
|
2023
|
+
else {
|
2024
|
+
el["on"+name] = fn;
|
2025
|
+
}
|
2026
|
+
};
|
2027
|
+
|
2028
|
+
this.jqbind = function(dom,name,fn) { // use jquery bind for non-native events (mouseenter/mouseleave)
|
2029
|
+
self.events.push({e:dom,n:name,f:fn,q:true});
|
2030
|
+
$(dom).bind(name,fn);
|
2031
|
+
};
|
2032
|
+
|
2033
|
+
this.bind = function(dom,name,fn,bubble) { // touch-oriented & fixing jquery bind
|
2034
|
+
var el = ("jquery" in dom) ? dom[0] : dom;
|
2035
|
+
|
2036
|
+
if (name=='mousewheel') {
|
2037
|
+
if ("onwheel" in self.win) {
|
2038
|
+
self._bind(el,"wheel",fn,bubble||false);
|
2039
|
+
} else {
|
2040
|
+
var wname = (typeof document.onmousewheel != "undefined") ? "mousewheel" : "DOMMouseScroll"; // older IE/Firefox
|
2041
|
+
_modernWheelEvent(el,wname,fn,bubble||false);
|
2042
|
+
if (wname=="DOMMouseScroll") _modernWheelEvent(el,"MozMousePixelScroll",fn,bubble||false); // Firefox legacy
|
2043
|
+
}
|
2044
|
+
}
|
2045
|
+
else if (el.addEventListener) {
|
2046
|
+
if (cap.cantouch && /mouseup|mousedown|mousemove/.test(name)) { // touch device support
|
2047
|
+
var tt=(name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
|
2048
|
+
self._bind(el,tt,function(e){
|
2049
|
+
if (e.touches) {
|
2050
|
+
if (e.touches.length<2) {var ev=(e.touches.length)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
|
2051
|
+
}
|
2052
|
+
else if (e.changedTouches) {var ev=e.changedTouches[0];ev.original=e;fn.call(this,ev);} //blackberry
|
2053
|
+
},bubble||false);
|
2054
|
+
}
|
2055
|
+
self._bind(el,name,fn,bubble||false);
|
2056
|
+
if (cap.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
|
2057
|
+
}
|
2058
|
+
else {
|
2059
|
+
self._bind(el,name,function(e) {
|
2060
|
+
e = e||window.event||false;
|
2061
|
+
if (e) {
|
2062
|
+
if (e.srcElement) e.target=e.srcElement;
|
2063
|
+
}
|
2064
|
+
if (!("pageY" in e)) {
|
2065
|
+
e.pageX = e.clientX + document.documentElement.scrollLeft;
|
2066
|
+
e.pageY = e.clientY + document.documentElement.scrollTop;
|
2067
|
+
}
|
2068
|
+
return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
|
2069
|
+
});
|
2070
|
+
}
|
2071
|
+
};
|
2072
|
+
|
2073
|
+
this._unbind = function(el,name,fn,bub) { // primitive unbind
|
2074
|
+
if (el.removeEventListener) {
|
2075
|
+
el.removeEventListener(name,fn,bub);
|
2076
|
+
}
|
2077
|
+
else if (el.detachEvent) {
|
2078
|
+
el.detachEvent('on'+name,fn);
|
2079
|
+
} else {
|
2080
|
+
el['on'+name] = false;
|
2081
|
+
}
|
2082
|
+
};
|
2083
|
+
|
2084
|
+
this.unbindAll = function() {
|
2085
|
+
for(var a=0;a<self.events.length;a++) {
|
2086
|
+
var r = self.events[a];
|
2087
|
+
(r.q) ? r.e.unbind(r.n,r.f) : self._unbind(r.e,r.n,r.f,r.b);
|
2088
|
+
}
|
2089
|
+
};
|
2090
|
+
|
2091
|
+
// Thanks to http://www.switchonthecode.com !!
|
2092
|
+
this.cancelEvent = function(e) {
|
2093
|
+
var e = (e.original) ? e.original : (e) ? e : window.event||false;
|
2094
|
+
if (!e) return false;
|
2095
|
+
if(e.preventDefault) e.preventDefault();
|
2096
|
+
if(e.stopPropagation) e.stopPropagation();
|
2097
|
+
if(e.preventManipulation) e.preventManipulation(); //IE10
|
2098
|
+
e.cancelBubble = true;
|
2099
|
+
e.cancel = true;
|
2100
|
+
e.returnValue = false;
|
2101
|
+
return false;
|
2102
|
+
};
|
2103
|
+
|
2104
|
+
this.stopPropagation = function(e) {
|
2105
|
+
var e = (e.original) ? e.original : (e) ? e : window.event||false;
|
2106
|
+
if (!e) return false;
|
2107
|
+
if (e.stopPropagation) return e.stopPropagation();
|
2108
|
+
if (e.cancelBubble) e.cancelBubble=true;
|
2109
|
+
return false;
|
2110
|
+
};
|
2111
|
+
|
2112
|
+
this.showRail = function() {
|
2113
|
+
if ((self.page.maxh!=0)&&(self.ispage||self.win.css('display')!='none')) {
|
2114
|
+
self.visibility = true;
|
2115
|
+
self.rail.visibility = true;
|
2116
|
+
self.rail.css('display','block');
|
2117
|
+
}
|
2118
|
+
return self;
|
2119
|
+
};
|
2120
|
+
|
2121
|
+
this.showRailHr = function() {
|
2122
|
+
if (!self.railh) return self;
|
2123
|
+
if ((self.page.maxw!=0)&&(self.ispage||self.win.css('display')!='none')) {
|
2124
|
+
self.railh.visibility = true;
|
2125
|
+
self.railh.css('display','block');
|
2126
|
+
}
|
2127
|
+
return self;
|
2128
|
+
};
|
2129
|
+
|
2130
|
+
this.hideRail = function() {
|
2131
|
+
self.visibility = false;
|
2132
|
+
self.rail.visibility = false;
|
2133
|
+
self.rail.css('display','none');
|
2134
|
+
return self;
|
2135
|
+
};
|
2136
|
+
|
2137
|
+
this.hideRailHr = function() {
|
2138
|
+
if (!self.railh) return self;
|
2139
|
+
self.railh.visibility = false;
|
2140
|
+
self.railh.css('display','none');
|
2141
|
+
return self;
|
2142
|
+
};
|
2143
|
+
|
2144
|
+
this.show = function() {
|
2145
|
+
self.hidden = false;
|
2146
|
+
self.locked = false;
|
2147
|
+
return self.showRail().showRailHr();
|
2148
|
+
};
|
2149
|
+
|
2150
|
+
this.hide = function() {
|
2151
|
+
self.hidden = true;
|
2152
|
+
self.locked = true;
|
2153
|
+
return self.hideRail().hideRailHr();
|
2154
|
+
};
|
2155
|
+
|
2156
|
+
this.toggle = function() {
|
2157
|
+
return (self.hidden) ? self.show() : self.hide();
|
2158
|
+
};
|
2159
|
+
|
2160
|
+
this.remove = function() {
|
2161
|
+
self.stop();
|
2162
|
+
if (self.cursortimeout) clearTimeout(self.cursortimeout);
|
2163
|
+
self.doZoomOut();
|
2164
|
+
self.unbindAll();
|
2165
|
+
|
2166
|
+
if (cap.isie9) self.win[0].detachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
|
2167
|
+
|
2168
|
+
if (self.observer !== false) self.observer.disconnect();
|
2169
|
+
if (self.observerremover !== false) self.observerremover.disconnect();
|
2170
|
+
|
2171
|
+
self.events = null;
|
2172
|
+
|
2173
|
+
if (self.cursor) {
|
2174
|
+
self.cursor.remove();
|
2175
|
+
}
|
2176
|
+
if (self.cursorh) {
|
2177
|
+
self.cursorh.remove();
|
2178
|
+
}
|
2179
|
+
if (self.rail) {
|
2180
|
+
self.rail.remove();
|
2181
|
+
}
|
2182
|
+
if (self.railh) {
|
2183
|
+
self.railh.remove();
|
2184
|
+
}
|
2185
|
+
if (self.zoom) {
|
2186
|
+
self.zoom.remove();
|
2187
|
+
}
|
2188
|
+
for(var a=0;a<self.saved.css.length;a++) {
|
2189
|
+
var d=self.saved.css[a];
|
2190
|
+
d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
|
2191
|
+
}
|
2192
|
+
self.saved = false;
|
2193
|
+
self.me.data('__nicescroll',''); //erase all traces
|
2194
|
+
|
2195
|
+
// memory leak fixed by GianlucaGuarini - thanks a lot!
|
2196
|
+
// remove the current nicescroll from the $.nicescroll array & normalize array
|
2197
|
+
var lst = $.nicescroll;
|
2198
|
+
lst.each(function(i){
|
2199
|
+
if (!this) return;
|
2200
|
+
if(this.id === self.id) {
|
2201
|
+
delete lst[i];
|
2202
|
+
for(var b=++i;b<lst.length;b++,i++) lst[i]=lst[b];
|
2203
|
+
lst.length--;
|
2204
|
+
if (lst.length) delete lst[lst.length];
|
2205
|
+
}
|
2206
|
+
});
|
2207
|
+
|
2208
|
+
for (var i in self) {
|
2209
|
+
self[i] = null;
|
2210
|
+
delete self[i];
|
2211
|
+
}
|
2212
|
+
|
2213
|
+
self = null;
|
2214
|
+
|
2215
|
+
};
|
2216
|
+
|
2217
|
+
this.scrollstart = function(fn) {
|
2218
|
+
this.onscrollstart = fn;
|
2219
|
+
return self;
|
2220
|
+
};
|
2221
|
+
this.scrollend = function(fn) {
|
2222
|
+
this.onscrollend = fn;
|
2223
|
+
return self;
|
2224
|
+
};
|
2225
|
+
this.scrollcancel = function(fn) {
|
2226
|
+
this.onscrollcancel = fn;
|
2227
|
+
return self;
|
2228
|
+
};
|
2229
|
+
|
2230
|
+
this.zoomin = function(fn) {
|
2231
|
+
this.onzoomin = fn;
|
2232
|
+
return self;
|
2233
|
+
};
|
2234
|
+
this.zoomout = function(fn) {
|
2235
|
+
this.onzoomout = fn;
|
2236
|
+
return self;
|
2237
|
+
};
|
2238
|
+
|
2239
|
+
this.isScrollable = function(e) {
|
2240
|
+
var dom = (e.target) ? e.target : e;
|
2241
|
+
if (dom.nodeName == 'OPTION') return true;
|
2242
|
+
while (dom&&(dom.nodeType==1)&&!(/^BODY|HTML/.test(dom.nodeName))) {
|
2243
|
+
var dd = $(dom);
|
2244
|
+
var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
|
2245
|
+
if (/scroll|auto/.test(ov)) return (dom.clientHeight!=dom.scrollHeight);
|
2246
|
+
dom = (dom.parentNode) ? dom.parentNode : false;
|
2247
|
+
}
|
2248
|
+
return false;
|
2249
|
+
};
|
2250
|
+
|
2251
|
+
this.getViewport = function(me) {
|
2252
|
+
var dom = (me&&me.parentNode) ? me.parentNode : false;
|
2253
|
+
while (dom&&(dom.nodeType==1)&&!(/^BODY|HTML/.test(dom.nodeName))) {
|
2254
|
+
var dd = $(dom);
|
2255
|
+
if (/fixed|absolute/.test(dd.css("position"))) return dd;
|
2256
|
+
var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
|
2257
|
+
if ((/scroll|auto/.test(ov))&&(dom.clientHeight!=dom.scrollHeight)) return dd;
|
2258
|
+
if (dd.getNiceScroll().length>0) return dd;
|
2259
|
+
dom = (dom.parentNode) ? dom.parentNode : false;
|
2260
|
+
}
|
2261
|
+
return (dom) ? $(dom) : false;
|
2262
|
+
};
|
2263
|
+
|
2264
|
+
this.triggerScrollEnd = function() {
|
2265
|
+
if (!self.onscrollend) return;
|
2266
|
+
|
2267
|
+
var px = self.getScrollLeft();
|
2268
|
+
var py = self.getScrollTop();
|
2269
|
+
|
2270
|
+
var info = {"type":"scrollend","current":{"x":px,"y":py},"end":{"x":px,"y":py}};
|
2271
|
+
self.onscrollend.call(self,info);
|
2272
|
+
}
|
2273
|
+
|
2274
|
+
function execScrollWheel(e,hr,chkscroll) {
|
2275
|
+
var px,py;
|
2276
|
+
var rt = 1;
|
2277
|
+
|
2278
|
+
if (e.deltaMode==0) { // PIXEL
|
2279
|
+
px = -Math.floor(e.deltaX*(self.opt.mousescrollstep/(18*3)));
|
2280
|
+
py = -Math.floor(e.deltaY*(self.opt.mousescrollstep/(18*3)));
|
2281
|
+
}
|
2282
|
+
else if (e.deltaMode==1) { // LINE
|
2283
|
+
px = -Math.floor(e.deltaX*self.opt.mousescrollstep);
|
2284
|
+
py = -Math.floor(e.deltaY*self.opt.mousescrollstep);
|
2285
|
+
}
|
2286
|
+
|
2287
|
+
if (hr&&self.opt.oneaxismousemode&&(px==0)&&py) { // classic vertical-only mousewheel + browser with x/y support
|
2288
|
+
px = py;
|
2289
|
+
py = 0;
|
2290
|
+
}
|
2291
|
+
|
2292
|
+
if (px) {
|
2293
|
+
if (self.scrollmom) {self.scrollmom.stop()}
|
2294
|
+
self.lastdeltax+=px;
|
2295
|
+
self.debounced("mousewheelx",function(){var dt=self.lastdeltax;self.lastdeltax=0;if(!self.rail.drag){self.doScrollLeftBy(dt)}},15);
|
2296
|
+
}
|
2297
|
+
if (py) {
|
2298
|
+
if (self.opt.nativeparentscrolling&&chkscroll&&!self.ispage&&!self.zoomactive) {
|
2299
|
+
if (py<0) {
|
2300
|
+
if (self.getScrollTop()>=self.page.maxh) return true;
|
2301
|
+
} else {
|
2302
|
+
if (self.getScrollTop()<=0) return true;
|
2303
|
+
}
|
2304
|
+
}
|
2305
|
+
if (self.scrollmom) {self.scrollmom.stop()}
|
2306
|
+
self.lastdeltay+=py;
|
2307
|
+
self.debounced("mousewheely",function(){var dt=self.lastdeltay;self.lastdeltay=0;if(!self.rail.drag){self.doScrollBy(dt)}},15);
|
2308
|
+
}
|
2309
|
+
|
2310
|
+
e.stopImmediatePropagation();
|
2311
|
+
return e.preventDefault();
|
2312
|
+
// return self.cancelEvent(e);
|
2313
|
+
};
|
2314
|
+
|
2315
|
+
this.onmousewheel = function(e) {
|
2316
|
+
if (self.wheelprevented) return;
|
2317
|
+
if (self.locked) {
|
2318
|
+
self.debounced("checkunlock",self.resize,250);
|
2319
|
+
return true;
|
2320
|
+
}
|
2321
|
+
if (self.rail.drag) return self.cancelEvent(e);
|
2322
|
+
|
2323
|
+
if (self.opt.oneaxismousemode=="auto"&&e.deltaX!=0) self.opt.oneaxismousemode = false; // check two-axis mouse support (not very elegant)
|
2324
|
+
|
2325
|
+
if (self.opt.oneaxismousemode&&e.deltaX==0) {
|
2326
|
+
if (!self.rail.scrollable) {
|
2327
|
+
if (self.railh&&self.railh.scrollable) {
|
2328
|
+
return self.onmousewheelhr(e);
|
2329
|
+
} else {
|
2330
|
+
return true;
|
2331
|
+
}
|
2332
|
+
}
|
2333
|
+
}
|
2334
|
+
|
2335
|
+
var nw = +(new Date());
|
2336
|
+
var chk = false;
|
2337
|
+
if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
|
2338
|
+
// self.checkarea = false;
|
2339
|
+
self.nativescrollingarea = self.isScrollable(e);
|
2340
|
+
chk = true;
|
2341
|
+
}
|
2342
|
+
self.checkarea = nw;
|
2343
|
+
if (self.nativescrollingarea) return true; // this isn't my business
|
2344
|
+
// if (self.locked) return self.cancelEvent(e);
|
2345
|
+
var ret = execScrollWheel(e,false,chk);
|
2346
|
+
if (ret) self.checkarea = 0;
|
2347
|
+
return ret;
|
2348
|
+
};
|
2349
|
+
|
2350
|
+
this.onmousewheelhr = function(e) {
|
2351
|
+
if (self.wheelprevented) return;
|
2352
|
+
if (self.locked||!self.railh.scrollable) return true;
|
2353
|
+
if (self.rail.drag) return self.cancelEvent(e);
|
2354
|
+
|
2355
|
+
var nw = +(new Date());
|
2356
|
+
var chk = false;
|
2357
|
+
if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
|
2358
|
+
// self.checkarea = false;
|
2359
|
+
self.nativescrollingarea = self.isScrollable(e);
|
2360
|
+
chk = true;
|
2361
|
+
}
|
2362
|
+
self.checkarea = nw;
|
2363
|
+
if (self.nativescrollingarea) return true; // this isn't my business
|
2364
|
+
if (self.locked) return self.cancelEvent(e);
|
2365
|
+
|
2366
|
+
return execScrollWheel(e,true,chk);
|
2367
|
+
};
|
2368
|
+
|
2369
|
+
this.stop = function() {
|
2370
|
+
self.cancelScroll();
|
2371
|
+
if (self.scrollmon) self.scrollmon.stop();
|
2372
|
+
self.cursorfreezed = false;
|
2373
|
+
self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
|
2374
|
+
self.noticeCursor();
|
2375
|
+
return self;
|
2376
|
+
};
|
2377
|
+
|
2378
|
+
this.getTransitionSpeed = function(dif) {
|
2379
|
+
var sp = Math.round(self.opt.scrollspeed*10);
|
2380
|
+
var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
|
2381
|
+
return (ex>20) ? ex : 0;
|
2382
|
+
};
|
2383
|
+
|
2384
|
+
if (!self.opt.smoothscroll) {
|
2385
|
+
this.doScrollLeft = function(x,spd) { //direct
|
2386
|
+
var y = self.getScrollTop();
|
2387
|
+
self.doScrollPos(x,y,spd);
|
2388
|
+
};
|
2389
|
+
this.doScrollTop = function(y,spd) { //direct
|
2390
|
+
var x = self.getScrollLeft();
|
2391
|
+
self.doScrollPos(x,y,spd);
|
2392
|
+
};
|
2393
|
+
this.doScrollPos = function(x,y,spd) { //direct
|
2394
|
+
var nx = (x>self.page.maxw) ? self.page.maxw : x;
|
2395
|
+
if (nx<0) nx=0;
|
2396
|
+
var ny = (y>self.page.maxh) ? self.page.maxh : y;
|
2397
|
+
if (ny<0) ny=0;
|
2398
|
+
self.synched('scroll',function(){
|
2399
|
+
self.setScrollTop(ny);
|
2400
|
+
self.setScrollLeft(nx);
|
2401
|
+
});
|
2402
|
+
};
|
2403
|
+
this.cancelScroll = function() {}; // direct
|
2404
|
+
}
|
2405
|
+
else if (self.ishwscroll&&cap.hastransition&&self.opt.usetransition) {
|
2406
|
+
this.prepareTransition = function(dif,istime) {
|
2407
|
+
var ex = (istime) ? ((dif>20)?dif:0) : self.getTransitionSpeed(dif);
|
2408
|
+
var trans = (ex) ? cap.prefixstyle+'transform '+ex+'ms ease-out' : '';
|
2409
|
+
if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
|
2410
|
+
self.lasttransitionstyle = trans;
|
2411
|
+
self.doc.css(cap.transitionstyle,trans);
|
2412
|
+
}
|
2413
|
+
return ex;
|
2414
|
+
};
|
2415
|
+
|
2416
|
+
this.doScrollLeft = function(x,spd) { //trans
|
2417
|
+
var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
|
2418
|
+
self.doScrollPos(x,y,spd);
|
2419
|
+
};
|
2420
|
+
|
2421
|
+
this.doScrollTop = function(y,spd) { //trans
|
2422
|
+
var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
|
2423
|
+
self.doScrollPos(x,y,spd);
|
2424
|
+
};
|
2425
|
+
|
2426
|
+
this.doScrollPos = function(x,y,spd) { //trans
|
2427
|
+
|
2428
|
+
var py = self.getScrollTop();
|
2429
|
+
var px = self.getScrollLeft();
|
2430
|
+
|
2431
|
+
if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll(); //inverted movement detection
|
2432
|
+
|
2433
|
+
if (self.opt.bouncescroll==false) {
|
2434
|
+
if (y<0) y=0;
|
2435
|
+
else if (y>self.page.maxh) y=self.page.maxh;
|
2436
|
+
if (x<0) x=0;
|
2437
|
+
else if (x>self.page.maxw) x=self.page.maxw;
|
2438
|
+
}
|
2439
|
+
|
2440
|
+
if (self.scrollrunning&&x==self.newscrollx&&y==self.newscrolly) return false;
|
2441
|
+
|
2442
|
+
self.newscrolly = y;
|
2443
|
+
self.newscrollx = x;
|
2444
|
+
|
2445
|
+
self.newscrollspeed = spd||false;
|
2446
|
+
|
2447
|
+
if (self.timer) return false;
|
2448
|
+
|
2449
|
+
self.timer = setTimeout(function(){
|
2450
|
+
|
2451
|
+
var top = self.getScrollTop();
|
2452
|
+
var lft = self.getScrollLeft();
|
2453
|
+
|
2454
|
+
var dst = {};
|
2455
|
+
dst.x = x-lft;
|
2456
|
+
dst.y = y-top;
|
2457
|
+
dst.px = lft;
|
2458
|
+
dst.py = top;
|
2459
|
+
|
2460
|
+
var dd = Math.round(Math.sqrt(Math.pow(dst.x,2)+Math.pow(dst.y,2)));
|
2461
|
+
|
2462
|
+
// var df = (self.newscrollspeed) ? self.newscrollspeed : dd;
|
2463
|
+
|
2464
|
+
var ms = (self.newscrollspeed && self.newscrollspeed>1) ? self.newscrollspeed : self.getTransitionSpeed(dd);
|
2465
|
+
if (self.newscrollspeed&&self.newscrollspeed<=1) ms*=self.newscrollspeed;
|
2466
|
+
|
2467
|
+
self.prepareTransition(ms,true);
|
2468
|
+
|
2469
|
+
if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
|
2470
|
+
|
2471
|
+
if (ms>0) {
|
2472
|
+
|
2473
|
+
if (!self.scrollrunning&&self.onscrollstart) {
|
2474
|
+
var info = {"type":"scrollstart","current":{"x":lft,"y":top},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
|
2475
|
+
self.onscrollstart.call(self,info);
|
2476
|
+
}
|
2477
|
+
|
2478
|
+
if (cap.transitionend) {
|
2479
|
+
if (!self.scrollendtrapped) {
|
2480
|
+
self.scrollendtrapped = true;
|
2481
|
+
self.bind(self.doc,cap.transitionend,self.onScrollTransitionEnd,false); //I have got to do something usefull!!
|
2482
|
+
}
|
2483
|
+
} else {
|
2484
|
+
if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
|
2485
|
+
self.scrollendtrapped = setTimeout(self.onScrollTransitionEnd,ms); // simulate transitionend event
|
2486
|
+
}
|
2487
|
+
|
2488
|
+
var py = top;
|
2489
|
+
var px = lft;
|
2490
|
+
self.timerscroll = {
|
2491
|
+
bz: new BezierClass(py,self.newscrolly,ms,0,0,0.58,1),
|
2492
|
+
bh: new BezierClass(px,self.newscrollx,ms,0,0,0.58,1)
|
2493
|
+
};
|
2494
|
+
if (!self.cursorfreezed) self.timerscroll.tm=setInterval(function(){self.showCursor(self.getScrollTop(),self.getScrollLeft())},60);
|
2495
|
+
|
2496
|
+
}
|
2497
|
+
|
2498
|
+
self.synched("doScroll-set",function(){
|
2499
|
+
self.timer = 0;
|
2500
|
+
if (self.scrollendtrapped) self.scrollrunning = true;
|
2501
|
+
self.setScrollTop(self.newscrolly);
|
2502
|
+
self.setScrollLeft(self.newscrollx);
|
2503
|
+
if (!self.scrollendtrapped) self.onScrollTransitionEnd();
|
2504
|
+
});
|
2505
|
+
|
2506
|
+
|
2507
|
+
},50);
|
2508
|
+
|
2509
|
+
};
|
2510
|
+
|
2511
|
+
this.cancelScroll = function() {
|
2512
|
+
if (!self.scrollendtrapped) return true;
|
2513
|
+
var py = self.getScrollTop();
|
2514
|
+
var px = self.getScrollLeft();
|
2515
|
+
self.scrollrunning = false;
|
2516
|
+
if (!cap.transitionend) clearTimeout(cap.transitionend);
|
2517
|
+
self.scrollendtrapped = false;
|
2518
|
+
self._unbind(self.doc,cap.transitionend,self.onScrollTransitionEnd);
|
2519
|
+
self.prepareTransition(0);
|
2520
|
+
self.setScrollTop(py); // fire event onscroll
|
2521
|
+
if (self.railh) self.setScrollLeft(px);
|
2522
|
+
if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
|
2523
|
+
self.timerscroll = false;
|
2524
|
+
|
2525
|
+
self.cursorfreezed = false;
|
2526
|
+
|
2527
|
+
//self.noticeCursor(false,py,px);
|
2528
|
+
self.showCursor(py,px);
|
2529
|
+
return self;
|
2530
|
+
};
|
2531
|
+
this.onScrollTransitionEnd = function() {
|
2532
|
+
if (self.scrollendtrapped) self._unbind(self.doc,cap.transitionend,self.onScrollTransitionEnd);
|
2533
|
+
self.scrollendtrapped = false;
|
2534
|
+
self.prepareTransition(0);
|
2535
|
+
if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
|
2536
|
+
self.timerscroll = false;
|
2537
|
+
var py = self.getScrollTop();
|
2538
|
+
var px = self.getScrollLeft();
|
2539
|
+
self.setScrollTop(py); // fire event onscroll
|
2540
|
+
if (self.railh) self.setScrollLeft(px); // fire event onscroll left
|
2541
|
+
|
2542
|
+
self.noticeCursor(false,py,px);
|
2543
|
+
|
2544
|
+
self.cursorfreezed = false;
|
2545
|
+
|
2546
|
+
if (py<0) py=0
|
2547
|
+
else if (py>self.page.maxh) py=self.page.maxh;
|
2548
|
+
if (px<0) px=0
|
2549
|
+
else if (px>self.page.maxw) px=self.page.maxw;
|
2550
|
+
if((py!=self.newscrolly)||(px!=self.newscrollx)) return self.doScrollPos(px,py,self.opt.snapbackspeed);
|
2551
|
+
|
2552
|
+
if (self.onscrollend&&self.scrollrunning) {
|
2553
|
+
// var info = {"type":"scrollend","current":{"x":px,"y":py},"end":{"x":self.newscrollx,"y":self.newscrolly}};
|
2554
|
+
// self.onscrollend.call(self,info);
|
2555
|
+
self.triggerScrollEnd();
|
2556
|
+
}
|
2557
|
+
self.scrollrunning = false;
|
2558
|
+
|
2559
|
+
};
|
2560
|
+
|
2561
|
+
} else {
|
2562
|
+
|
2563
|
+
this.doScrollLeft = function(x,spd) { //no-trans
|
2564
|
+
var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
|
2565
|
+
self.doScrollPos(x,y,spd);
|
2566
|
+
};
|
2567
|
+
|
2568
|
+
this.doScrollTop = function(y,spd) { //no-trans
|
2569
|
+
var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
|
2570
|
+
self.doScrollPos(x,y,spd);
|
2571
|
+
};
|
2572
|
+
|
2573
|
+
this.doScrollPos = function(x,y,spd) { //no-trans
|
2574
|
+
var y = ((typeof y == "undefined")||(y===false)) ? self.getScrollTop(true) : y;
|
2575
|
+
|
2576
|
+
if ((self.timer)&&(self.newscrolly==y)&&(self.newscrollx==x)) return true;
|
2577
|
+
|
2578
|
+
if (self.timer) clearAnimationFrame(self.timer);
|
2579
|
+
self.timer = 0;
|
2580
|
+
|
2581
|
+
var py = self.getScrollTop();
|
2582
|
+
var px = self.getScrollLeft();
|
2583
|
+
|
2584
|
+
if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll(); //inverted movement detection
|
2585
|
+
|
2586
|
+
self.newscrolly = y;
|
2587
|
+
self.newscrollx = x;
|
2588
|
+
|
2589
|
+
if (!self.bouncescroll||!self.rail.visibility) {
|
2590
|
+
if (self.newscrolly<0) {
|
2591
|
+
self.newscrolly = 0;
|
2592
|
+
}
|
2593
|
+
else if (self.newscrolly>self.page.maxh) {
|
2594
|
+
self.newscrolly = self.page.maxh;
|
2595
|
+
}
|
2596
|
+
}
|
2597
|
+
if (!self.bouncescroll||!self.railh.visibility) {
|
2598
|
+
if (self.newscrollx<0) {
|
2599
|
+
self.newscrollx = 0;
|
2600
|
+
}
|
2601
|
+
else if (self.newscrollx>self.page.maxw) {
|
2602
|
+
self.newscrollx = self.page.maxw;
|
2603
|
+
}
|
2604
|
+
}
|
2605
|
+
|
2606
|
+
self.dst = {};
|
2607
|
+
self.dst.x = x-px;
|
2608
|
+
self.dst.y = y-py;
|
2609
|
+
self.dst.px = px;
|
2610
|
+
self.dst.py = py;
|
2611
|
+
|
2612
|
+
var dst = Math.round(Math.sqrt(Math.pow(self.dst.x,2)+Math.pow(self.dst.y,2)));
|
2613
|
+
|
2614
|
+
self.dst.ax = self.dst.x / dst;
|
2615
|
+
self.dst.ay = self.dst.y / dst;
|
2616
|
+
|
2617
|
+
var pa = 0;
|
2618
|
+
var pe = dst;
|
2619
|
+
|
2620
|
+
if (self.dst.x==0) {
|
2621
|
+
pa = py;
|
2622
|
+
pe = y;
|
2623
|
+
self.dst.ay = 1;
|
2624
|
+
self.dst.py = 0;
|
2625
|
+
} else if (self.dst.y==0) {
|
2626
|
+
pa = px;
|
2627
|
+
pe = x;
|
2628
|
+
self.dst.ax = 1;
|
2629
|
+
self.dst.px = 0;
|
2630
|
+
}
|
2631
|
+
|
2632
|
+
var ms = self.getTransitionSpeed(dst);
|
2633
|
+
if (spd&&spd<=1) ms*=spd;
|
2634
|
+
if (ms>0) {
|
2635
|
+
self.bzscroll = (self.bzscroll) ? self.bzscroll.update(pe,ms) : new BezierClass(pa,pe,ms,0,1,0,1);
|
2636
|
+
} else {
|
2637
|
+
self.bzscroll = false;
|
2638
|
+
}
|
2639
|
+
|
2640
|
+
if (self.timer) return;
|
2641
|
+
|
2642
|
+
if ((py==self.page.maxh&&y>=self.page.maxh)||(px==self.page.maxw&&x>=self.page.maxw)) self.checkContentSize();
|
2643
|
+
|
2644
|
+
var sync = 1;
|
2645
|
+
|
2646
|
+
function scrolling() {
|
2647
|
+
if (self.cancelAnimationFrame) return true;
|
2648
|
+
|
2649
|
+
self.scrollrunning = true;
|
2650
|
+
|
2651
|
+
sync = 1-sync;
|
2652
|
+
if (sync) return (self.timer = setAnimationFrame(scrolling)||1);
|
2653
|
+
|
2654
|
+
var done = 0;
|
2655
|
+
|
2656
|
+
var sc = sy = self.getScrollTop();
|
2657
|
+
if (self.dst.ay) {
|
2658
|
+
sc = (self.bzscroll) ? self.dst.py + (self.bzscroll.getNow()*self.dst.ay) : self.newscrolly;
|
2659
|
+
var dr=sc-sy;
|
2660
|
+
if ((dr<0&&sc<self.newscrolly)||(dr>0&&sc>self.newscrolly)) sc = self.newscrolly;
|
2661
|
+
self.setScrollTop(sc);
|
2662
|
+
if (sc == self.newscrolly) done=1;
|
2663
|
+
} else {
|
2664
|
+
done=1;
|
2665
|
+
}
|
2666
|
+
|
2667
|
+
var scx = sx = self.getScrollLeft();
|
2668
|
+
if (self.dst.ax) {
|
2669
|
+
scx = (self.bzscroll) ? self.dst.px + (self.bzscroll.getNow()*self.dst.ax) : self.newscrollx;
|
2670
|
+
var dr=scx-sx;
|
2671
|
+
if ((dr<0&&scx<self.newscrollx)||(dr>0&&scx>self.newscrollx)) scx = self.newscrollx;
|
2672
|
+
self.setScrollLeft(scx);
|
2673
|
+
if (scx == self.newscrollx) done+=1;
|
2674
|
+
} else {
|
2675
|
+
done+=1;
|
2676
|
+
}
|
2677
|
+
|
2678
|
+
if (done==2) {
|
2679
|
+
self.timer = 0;
|
2680
|
+
self.cursorfreezed = false;
|
2681
|
+
self.bzscroll = false;
|
2682
|
+
self.scrollrunning = false;
|
2683
|
+
if (sc<0) sc=0;
|
2684
|
+
else if (sc>self.page.maxh) sc=self.page.maxh;
|
2685
|
+
if (scx<0) scx=0;
|
2686
|
+
else if (scx>self.page.maxw) scx=self.page.maxw;
|
2687
|
+
if ((scx!=self.newscrollx)||(sc!=self.newscrolly)) self.doScrollPos(scx,sc);
|
2688
|
+
else {
|
2689
|
+
if (self.onscrollend) {
|
2690
|
+
/*
|
2691
|
+
var info = {"type":"scrollend","current":{"x":sx,"y":sy},"end":{"x":self.newscrollx,"y":self.newscrolly}};
|
2692
|
+
self.onscrollend.call(self,info);
|
2693
|
+
*/
|
2694
|
+
self.triggerScrollEnd();
|
2695
|
+
}
|
2696
|
+
}
|
2697
|
+
} else {
|
2698
|
+
self.timer = setAnimationFrame(scrolling)||1;
|
2699
|
+
}
|
2700
|
+
};
|
2701
|
+
self.cancelAnimationFrame=false;
|
2702
|
+
self.timer = 1;
|
2703
|
+
|
2704
|
+
if (self.onscrollstart&&!self.scrollrunning) {
|
2705
|
+
var info = {"type":"scrollstart","current":{"x":px,"y":py},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
|
2706
|
+
self.onscrollstart.call(self,info);
|
2707
|
+
}
|
2708
|
+
|
2709
|
+
scrolling();
|
2710
|
+
|
2711
|
+
if ((py==self.page.maxh&&y>=py)||(px==self.page.maxw&&x>=px)) self.checkContentSize();
|
2712
|
+
|
2713
|
+
self.noticeCursor();
|
2714
|
+
};
|
2715
|
+
|
2716
|
+
this.cancelScroll = function() {
|
2717
|
+
if (self.timer) clearAnimationFrame(self.timer);
|
2718
|
+
self.timer = 0;
|
2719
|
+
self.bzscroll = false;
|
2720
|
+
self.scrollrunning = false;
|
2721
|
+
return self;
|
2722
|
+
};
|
2723
|
+
|
2724
|
+
}
|
2725
|
+
|
2726
|
+
this.doScrollBy = function(stp,relative) {
|
2727
|
+
var ny = 0;
|
2728
|
+
if (relative) {
|
2729
|
+
ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
|
2730
|
+
} else {
|
2731
|
+
var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
|
2732
|
+
ny = sy-stp;
|
2733
|
+
}
|
2734
|
+
if (self.bouncescroll) {
|
2735
|
+
var haf = Math.round(self.view.h/2);
|
2736
|
+
if (ny<-haf) ny=-haf
|
2737
|
+
else if (ny>(self.page.maxh+haf)) ny = (self.page.maxh+haf);
|
2738
|
+
}
|
2739
|
+
self.cursorfreezed = false;
|
2740
|
+
|
2741
|
+
py = self.getScrollTop(true);
|
2742
|
+
if (ny<0&&py<=0) return self.noticeCursor();
|
2743
|
+
else if (ny>self.page.maxh&&py>=self.page.maxh) {
|
2744
|
+
self.checkContentSize();
|
2745
|
+
return self.noticeCursor();
|
2746
|
+
}
|
2747
|
+
|
2748
|
+
self.doScrollTop(ny);
|
2749
|
+
};
|
2750
|
+
|
2751
|
+
this.doScrollLeftBy = function(stp,relative) {
|
2752
|
+
var nx = 0;
|
2753
|
+
if (relative) {
|
2754
|
+
nx = Math.floor((self.scroll.x-stp)*self.scrollratio.x)
|
2755
|
+
} else {
|
2756
|
+
var sx = (self.timer) ? self.newscrollx : self.getScrollLeft(true);
|
2757
|
+
nx = sx-stp;
|
2758
|
+
}
|
2759
|
+
if (self.bouncescroll) {
|
2760
|
+
var haf = Math.round(self.view.w/2);
|
2761
|
+
if (nx<-haf) nx=-haf;
|
2762
|
+
else if (nx>(self.page.maxw+haf)) nx = (self.page.maxw+haf);
|
2763
|
+
}
|
2764
|
+
self.cursorfreezed = false;
|
2765
|
+
|
2766
|
+
px = self.getScrollLeft(true);
|
2767
|
+
if (nx<0&&px<=0) return self.noticeCursor();
|
2768
|
+
else if (nx>self.page.maxw&&px>=self.page.maxw) return self.noticeCursor();
|
2769
|
+
|
2770
|
+
self.doScrollLeft(nx);
|
2771
|
+
};
|
2772
|
+
|
2773
|
+
this.doScrollTo = function(pos,relative) {
|
2774
|
+
var ny = (relative) ? Math.round(pos*self.scrollratio.y) : pos;
|
2775
|
+
if (ny<0) ny=0;
|
2776
|
+
else if (ny>self.page.maxh) ny = self.page.maxh;
|
2777
|
+
self.cursorfreezed = false;
|
2778
|
+
self.doScrollTop(pos);
|
2779
|
+
};
|
2780
|
+
|
2781
|
+
this.checkContentSize = function() {
|
2782
|
+
var pg = self.getContentSize();
|
2783
|
+
if ((pg.h!=self.page.h)||(pg.w!=self.page.w)) self.resize(false,pg);
|
2784
|
+
};
|
2785
|
+
|
2786
|
+
self.onscroll = function(e) {
|
2787
|
+
if (self.rail.drag) return;
|
2788
|
+
if (!self.cursorfreezed) {
|
2789
|
+
self.synched('scroll',function(){
|
2790
|
+
self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
|
2791
|
+
if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
|
2792
|
+
self.noticeCursor();
|
2793
|
+
});
|
2794
|
+
}
|
2795
|
+
};
|
2796
|
+
self.bind(self.docscroll,"scroll",self.onscroll);
|
2797
|
+
|
2798
|
+
this.doZoomIn = function(e) {
|
2799
|
+
if (self.zoomactive) return;
|
2800
|
+
self.zoomactive = true;
|
2801
|
+
|
2802
|
+
self.zoomrestore = {
|
2803
|
+
style:{}
|
2804
|
+
};
|
2805
|
+
var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
|
2806
|
+
var win = self.win[0].style;
|
2807
|
+
for(var a in lst) {
|
2808
|
+
var pp = lst[a];
|
2809
|
+
self.zoomrestore.style[pp] = (typeof win[pp] != "undefined") ? win[pp] : '';
|
2810
|
+
}
|
2811
|
+
|
2812
|
+
self.zoomrestore.style.width = self.win.css('width');
|
2813
|
+
self.zoomrestore.style.height = self.win.css('height');
|
2814
|
+
|
2815
|
+
self.zoomrestore.padding = {
|
2816
|
+
w:self.win.outerWidth()-self.win.width(),
|
2817
|
+
h:self.win.outerHeight()-self.win.height()
|
2818
|
+
};
|
2819
|
+
|
2820
|
+
if (cap.isios4) {
|
2821
|
+
self.zoomrestore.scrollTop = $(window).scrollTop();
|
2822
|
+
$(window).scrollTop(0);
|
2823
|
+
}
|
2824
|
+
|
2825
|
+
self.win.css({
|
2826
|
+
"position":(cap.isios4)?"absolute":"fixed",
|
2827
|
+
"top":0,
|
2828
|
+
"left":0,
|
2829
|
+
"z-index":globalmaxzindex+100,
|
2830
|
+
"margin":"0px"
|
2831
|
+
});
|
2832
|
+
var bkg = self.win.css("backgroundColor");
|
2833
|
+
if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
|
2834
|
+
self.rail.css({"z-index":globalmaxzindex+101});
|
2835
|
+
self.zoom.css({"z-index":globalmaxzindex+102});
|
2836
|
+
self.zoom.css('backgroundPosition','0px -18px');
|
2837
|
+
self.resizeZoom();
|
2838
|
+
|
2839
|
+
if (self.onzoomin) self.onzoomin.call(self);
|
2840
|
+
|
2841
|
+
return self.cancelEvent(e);
|
2842
|
+
};
|
2843
|
+
|
2844
|
+
this.doZoomOut = function(e) {
|
2845
|
+
if (!self.zoomactive) return;
|
2846
|
+
self.zoomactive = false;
|
2847
|
+
|
2848
|
+
self.win.css("margin","");
|
2849
|
+
self.win.css(self.zoomrestore.style);
|
2850
|
+
|
2851
|
+
if (cap.isios4) {
|
2852
|
+
$(window).scrollTop(self.zoomrestore.scrollTop);
|
2853
|
+
}
|
2854
|
+
|
2855
|
+
self.rail.css({"z-index":self.zindex});
|
2856
|
+
self.zoom.css({"z-index":self.zindex});
|
2857
|
+
self.zoomrestore = false;
|
2858
|
+
self.zoom.css('backgroundPosition','0px 0px');
|
2859
|
+
self.onResize();
|
2860
|
+
|
2861
|
+
if (self.onzoomout) self.onzoomout.call(self);
|
2862
|
+
|
2863
|
+
return self.cancelEvent(e);
|
2864
|
+
};
|
2865
|
+
|
2866
|
+
this.doZoom = function(e) {
|
2867
|
+
return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
|
2868
|
+
};
|
2869
|
+
|
2870
|
+
this.resizeZoom = function() {
|
2871
|
+
if (!self.zoomactive) return;
|
2872
|
+
|
2873
|
+
var py = self.getScrollTop(); //preserve scrolling position
|
2874
|
+
self.win.css({
|
2875
|
+
width:$(window).width()-self.zoomrestore.padding.w+"px",
|
2876
|
+
height:$(window).height()-self.zoomrestore.padding.h+"px"
|
2877
|
+
});
|
2878
|
+
self.onResize();
|
2879
|
+
|
2880
|
+
self.setScrollTop(Math.min(self.page.maxh,py));
|
2881
|
+
};
|
2882
|
+
|
2883
|
+
this.init();
|
2884
|
+
|
2885
|
+
$.nicescroll.push(this);
|
2886
|
+
|
2887
|
+
};
|
2888
|
+
|
2889
|
+
// Inspired by the work of Kin Blas
|
2890
|
+
// http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
|
2891
|
+
|
2892
|
+
|
2893
|
+
var ScrollMomentumClass2D = function(nc) {
|
2894
|
+
var self = this;
|
2895
|
+
this.nc = nc;
|
2896
|
+
|
2897
|
+
this.lastx = 0;
|
2898
|
+
this.lasty = 0;
|
2899
|
+
this.speedx = 0;
|
2900
|
+
this.speedy = 0;
|
2901
|
+
this.lasttime = 0;
|
2902
|
+
this.steptime = 0;
|
2903
|
+
this.snapx = false;
|
2904
|
+
this.snapy = false;
|
2905
|
+
this.demulx = 0;
|
2906
|
+
this.demuly = 0;
|
2907
|
+
|
2908
|
+
this.lastscrollx = -1;
|
2909
|
+
this.lastscrolly = -1;
|
2910
|
+
|
2911
|
+
this.chkx = 0;
|
2912
|
+
this.chky = 0;
|
2913
|
+
|
2914
|
+
this.timer = 0;
|
2915
|
+
|
2916
|
+
this.time = function() {
|
2917
|
+
return +new Date();//beautifull hack
|
2918
|
+
};
|
2919
|
+
|
2920
|
+
this.reset = function(px,py) {
|
2921
|
+
self.stop();
|
2922
|
+
var now = self.time();
|
2923
|
+
self.steptime = 0;
|
2924
|
+
self.lasttime = now;
|
2925
|
+
self.speedx = 0;
|
2926
|
+
self.speedy = 0;
|
2927
|
+
self.lastx = px;
|
2928
|
+
self.lasty = py;
|
2929
|
+
self.lastscrollx = -1;
|
2930
|
+
self.lastscrolly = -1;
|
2931
|
+
};
|
2932
|
+
|
2933
|
+
this.update = function(px,py) {
|
2934
|
+
var now = self.time();
|
2935
|
+
self.steptime = now - self.lasttime;
|
2936
|
+
self.lasttime = now;
|
2937
|
+
var dy = py - self.lasty;
|
2938
|
+
var dx = px - self.lastx;
|
2939
|
+
var sy = self.nc.getScrollTop();
|
2940
|
+
var sx = self.nc.getScrollLeft();
|
2941
|
+
var newy = sy + dy;
|
2942
|
+
var newx = sx + dx;
|
2943
|
+
self.snapx = (newx<0)||(newx>self.nc.page.maxw);
|
2944
|
+
self.snapy = (newy<0)||(newy>self.nc.page.maxh);
|
2945
|
+
self.speedx = dx;
|
2946
|
+
self.speedy = dy;
|
2947
|
+
self.lastx = px;
|
2948
|
+
self.lasty = py;
|
2949
|
+
};
|
2950
|
+
|
2951
|
+
this.stop = function() {
|
2952
|
+
self.nc.unsynched("domomentum2d");
|
2953
|
+
if (self.timer) clearTimeout(self.timer);
|
2954
|
+
self.timer = 0;
|
2955
|
+
self.lastscrollx = -1;
|
2956
|
+
self.lastscrolly = -1;
|
2957
|
+
};
|
2958
|
+
|
2959
|
+
this.doSnapy = function(nx,ny) {
|
2960
|
+
var snap = false;
|
2961
|
+
|
2962
|
+
if (ny<0) {
|
2963
|
+
ny=0;
|
2964
|
+
snap=true;
|
2965
|
+
}
|
2966
|
+
else if (ny>self.nc.page.maxh) {
|
2967
|
+
ny=self.nc.page.maxh;
|
2968
|
+
snap=true;
|
2969
|
+
}
|
2970
|
+
|
2971
|
+
if (nx<0) {
|
2972
|
+
nx=0;
|
2973
|
+
snap=true;
|
2974
|
+
}
|
2975
|
+
else if (nx>self.nc.page.maxw) {
|
2976
|
+
nx=self.nc.page.maxw;
|
2977
|
+
snap=true;
|
2978
|
+
}
|
2979
|
+
|
2980
|
+
(snap) ? self.nc.doScrollPos(nx,ny,self.nc.opt.snapbackspeed) : self.nc.triggerScrollEnd();
|
2981
|
+
};
|
2982
|
+
|
2983
|
+
this.doMomentum = function(gp) {
|
2984
|
+
var t = self.time();
|
2985
|
+
var l = (gp) ? t+gp : self.lasttime;
|
2986
|
+
|
2987
|
+
var sl = self.nc.getScrollLeft();
|
2988
|
+
var st = self.nc.getScrollTop();
|
2989
|
+
|
2990
|
+
var pageh = self.nc.page.maxh;
|
2991
|
+
var pagew = self.nc.page.maxw;
|
2992
|
+
|
2993
|
+
self.speedx = (pagew>0) ? Math.min(60,self.speedx) : 0;
|
2994
|
+
self.speedy = (pageh>0) ? Math.min(60,self.speedy) : 0;
|
2995
|
+
|
2996
|
+
var chk = l && (t - l) <= 60;
|
2997
|
+
|
2998
|
+
if ((st<0)||(st>pageh)||(sl<0)||(sl>pagew)) chk = false;
|
2999
|
+
|
3000
|
+
var sy = (self.speedy && chk) ? self.speedy : false;
|
3001
|
+
var sx = (self.speedx && chk) ? self.speedx : false;
|
3002
|
+
|
3003
|
+
if (sy||sx) {
|
3004
|
+
var tm = Math.max(16,self.steptime); //timeout granularity
|
3005
|
+
|
3006
|
+
if (tm>50) { // do smooth
|
3007
|
+
var xm = tm/50;
|
3008
|
+
self.speedx*=xm;
|
3009
|
+
self.speedy*=xm;
|
3010
|
+
tm = 50;
|
3011
|
+
}
|
3012
|
+
|
3013
|
+
self.demulxy = 0;
|
3014
|
+
|
3015
|
+
self.lastscrollx = self.nc.getScrollLeft();
|
3016
|
+
self.chkx = self.lastscrollx;
|
3017
|
+
self.lastscrolly = self.nc.getScrollTop();
|
3018
|
+
self.chky = self.lastscrolly;
|
3019
|
+
|
3020
|
+
var nx = self.lastscrollx;
|
3021
|
+
var ny = self.lastscrolly;
|
3022
|
+
|
3023
|
+
var onscroll = function(){
|
3024
|
+
var df = ((self.time()-t)>600) ? 0.04 : 0.02;
|
3025
|
+
|
3026
|
+
if (self.speedx) {
|
3027
|
+
nx = Math.floor(self.lastscrollx - (self.speedx*(1-self.demulxy)));
|
3028
|
+
self.lastscrollx = nx;
|
3029
|
+
if ((nx<0)||(nx>pagew)) df=0.10;
|
3030
|
+
}
|
3031
|
+
|
3032
|
+
if (self.speedy) {
|
3033
|
+
ny = Math.floor(self.lastscrolly - (self.speedy*(1-self.demulxy)));
|
3034
|
+
self.lastscrolly = ny;
|
3035
|
+
if ((ny<0)||(ny>pageh)) df=0.10;
|
3036
|
+
}
|
3037
|
+
|
3038
|
+
self.demulxy = Math.min(1,self.demulxy+df);
|
3039
|
+
|
3040
|
+
self.nc.synched("domomentum2d",function(){
|
3041
|
+
|
3042
|
+
if (self.speedx) {
|
3043
|
+
var scx = self.nc.getScrollLeft();
|
3044
|
+
if (scx!=self.chkx) self.stop();
|
3045
|
+
self.chkx=nx;
|
3046
|
+
self.nc.setScrollLeft(nx);
|
3047
|
+
}
|
3048
|
+
|
3049
|
+
if (self.speedy) {
|
3050
|
+
var scy = self.nc.getScrollTop();
|
3051
|
+
if (scy!=self.chky) self.stop();
|
3052
|
+
self.chky=ny;
|
3053
|
+
self.nc.setScrollTop(ny);
|
3054
|
+
}
|
3055
|
+
|
3056
|
+
if(!self.timer) {
|
3057
|
+
self.nc.hideCursor();
|
3058
|
+
self.doSnapy(nx,ny);
|
3059
|
+
}
|
3060
|
+
|
3061
|
+
});
|
3062
|
+
|
3063
|
+
if (self.demulxy<1) {
|
3064
|
+
self.timer = setTimeout(onscroll,tm);
|
3065
|
+
} else {
|
3066
|
+
self.stop();
|
3067
|
+
self.nc.hideCursor();
|
3068
|
+
self.doSnapy(nx,ny);
|
3069
|
+
}
|
3070
|
+
};
|
3071
|
+
|
3072
|
+
onscroll();
|
3073
|
+
|
3074
|
+
} else {
|
3075
|
+
self.doSnapy(self.nc.getScrollLeft(),self.nc.getScrollTop());
|
3076
|
+
}
|
3077
|
+
|
3078
|
+
}
|
3079
|
+
|
3080
|
+
};
|
3081
|
+
|
3082
|
+
|
3083
|
+
// override jQuery scrollTop
|
3084
|
+
|
3085
|
+
var _scrollTop = jQuery.fn.scrollTop; // preserve original function
|
3086
|
+
|
3087
|
+
jQuery.cssHooks["pageYOffset"] = {
|
3088
|
+
get: function(elem,computed,extra) {
|
3089
|
+
var nice = $.data(elem,'__nicescroll')||false;
|
3090
|
+
return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
|
3091
|
+
},
|
3092
|
+
set: function(elem,value) {
|
3093
|
+
var nice = $.data(elem,'__nicescroll')||false;
|
3094
|
+
(nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
|
3095
|
+
return this;
|
3096
|
+
}
|
3097
|
+
};
|
3098
|
+
|
3099
|
+
/*
|
3100
|
+
$.fx.step["scrollTop"] = function(fx){
|
3101
|
+
$.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
|
3102
|
+
};
|
3103
|
+
*/
|
3104
|
+
|
3105
|
+
jQuery.fn.scrollTop = function(value) {
|
3106
|
+
if (typeof value == "undefined") {
|
3107
|
+
var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
|
3108
|
+
return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
|
3109
|
+
} else {
|
3110
|
+
return this.each(function() {
|
3111
|
+
var nice = $.data(this,'__nicescroll')||false;
|
3112
|
+
(nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
|
3113
|
+
});
|
3114
|
+
}
|
3115
|
+
};
|
3116
|
+
|
3117
|
+
// override jQuery scrollLeft
|
3118
|
+
|
3119
|
+
var _scrollLeft = jQuery.fn.scrollLeft; // preserve original function
|
3120
|
+
|
3121
|
+
$.cssHooks.pageXOffset = {
|
3122
|
+
get: function(elem,computed,extra) {
|
3123
|
+
var nice = $.data(elem,'__nicescroll')||false;
|
3124
|
+
return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
|
3125
|
+
},
|
3126
|
+
set: function(elem,value) {
|
3127
|
+
var nice = $.data(elem,'__nicescroll')||false;
|
3128
|
+
(nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call(elem,value);
|
3129
|
+
return this;
|
3130
|
+
}
|
3131
|
+
};
|
3132
|
+
|
3133
|
+
/*
|
3134
|
+
$.fx.step["scrollLeft"] = function(fx){
|
3135
|
+
$.cssHooks["scrollLeft"].set( fx.elem, fx.now + fx.unit );
|
3136
|
+
};
|
3137
|
+
*/
|
3138
|
+
|
3139
|
+
jQuery.fn.scrollLeft = function(value) {
|
3140
|
+
if (typeof value == "undefined") {
|
3141
|
+
var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
|
3142
|
+
return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
|
3143
|
+
} else {
|
3144
|
+
return this.each(function() {
|
3145
|
+
var nice = $.data(this,'__nicescroll')||false;
|
3146
|
+
(nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call($(this),value);
|
3147
|
+
});
|
3148
|
+
}
|
3149
|
+
};
|
3150
|
+
|
3151
|
+
var NiceScrollArray = function(doms) {
|
3152
|
+
var self = this;
|
3153
|
+
this.length = 0;
|
3154
|
+
this.name = "nicescrollarray";
|
3155
|
+
|
3156
|
+
this.each = function(fn) {
|
3157
|
+
for(var a=0,i=0;a<self.length;a++) fn.call(self[a],i++);
|
3158
|
+
return self;
|
3159
|
+
};
|
3160
|
+
|
3161
|
+
this.push = function(nice) {
|
3162
|
+
self[self.length]=nice;
|
3163
|
+
self.length++;
|
3164
|
+
};
|
3165
|
+
|
3166
|
+
this.eq = function(idx) {
|
3167
|
+
return self[idx];
|
3168
|
+
};
|
3169
|
+
|
3170
|
+
if (doms) {
|
3171
|
+
for(var a=0;a<doms.length;a++) {
|
3172
|
+
var nice = $.data(doms[a],'__nicescroll')||false;
|
3173
|
+
if (nice) {
|
3174
|
+
this[this.length]=nice;
|
3175
|
+
this.length++;
|
3176
|
+
}
|
3177
|
+
};
|
3178
|
+
}
|
3179
|
+
|
3180
|
+
return this;
|
3181
|
+
};
|
3182
|
+
|
3183
|
+
function mplex(el,lst,fn) {
|
3184
|
+
for(var a=0;a<lst.length;a++) fn(el,lst[a]);
|
3185
|
+
};
|
3186
|
+
mplex(
|
3187
|
+
NiceScrollArray.prototype,
|
3188
|
+
['show','hide','toggle','onResize','resize','remove','stop','doScrollPos'],
|
3189
|
+
function(e,n) {
|
3190
|
+
e[n] = function(){
|
3191
|
+
var args = arguments;
|
3192
|
+
return this.each(function(){
|
3193
|
+
this[n].apply(this,args);
|
3194
|
+
});
|
3195
|
+
};
|
3196
|
+
}
|
3197
|
+
);
|
3198
|
+
|
3199
|
+
jQuery.fn.getNiceScroll = function(index) {
|
3200
|
+
if (typeof index == "undefined") {
|
3201
|
+
return new NiceScrollArray(this);
|
3202
|
+
} else {
|
3203
|
+
var nice = this[index]&&$.data(this[index],'__nicescroll')||false;
|
3204
|
+
return nice;
|
3205
|
+
}
|
3206
|
+
};
|
3207
|
+
|
3208
|
+
jQuery.extend(jQuery.expr[':'], {
|
3209
|
+
nicescroll: function(a) {
|
3210
|
+
return ($.data(a,'__nicescroll'))?true:false;
|
3211
|
+
}
|
3212
|
+
});
|
3213
|
+
|
3214
|
+
$.fn.niceScroll = function(wrapper,opt) {
|
3215
|
+
if (typeof opt=="undefined") {
|
3216
|
+
if ((typeof wrapper=="object")&&!("jquery" in wrapper)) {
|
3217
|
+
opt = wrapper;
|
3218
|
+
wrapper = false;
|
3219
|
+
}
|
3220
|
+
}
|
3221
|
+
var ret = new NiceScrollArray();
|
3222
|
+
if (typeof opt=="undefined") opt = {};
|
3223
|
+
|
3224
|
+
if (wrapper||false) {
|
3225
|
+
opt.doc = $(wrapper);
|
3226
|
+
opt.win = $(this);
|
3227
|
+
}
|
3228
|
+
var docundef = !("doc" in opt);
|
3229
|
+
if (!docundef&&!("win" in opt)) opt.win = $(this);
|
3230
|
+
|
3231
|
+
this.each(function() {
|
3232
|
+
var nice = $(this).data('__nicescroll')||false;
|
3233
|
+
if (!nice) {
|
3234
|
+
opt.doc = (docundef) ? $(this) : opt.doc;
|
3235
|
+
nice = new NiceScrollClass(opt,$(this));
|
3236
|
+
$(this).data('__nicescroll',nice);
|
3237
|
+
}
|
3238
|
+
ret.push(nice);
|
3239
|
+
});
|
3240
|
+
return (ret.length==1) ? ret[0] : ret;
|
3241
|
+
};
|
3242
|
+
|
3243
|
+
window.NiceScroll = {
|
3244
|
+
getjQuery:function(){return jQuery}
|
3245
|
+
};
|
3246
|
+
|
3247
|
+
if (!$.nicescroll) {
|
3248
|
+
$.nicescroll = new NiceScrollArray();
|
3249
|
+
$.nicescroll.options = _globaloptions;
|
3250
|
+
}
|
3251
|
+
|
3252
|
+
}));
|