documentAutoScroller function el interval timeout var self this htmlbo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
documentAutoScroller: function (el, interval, timeout) {
var self = this,
htmlbody = $('html, body'),
$window = $(window),
scroll_time = (new Date).getTime(),
scroll_interval,
old_scroll_top = 0,
abs_value = typeof el != "object" && $.isNumeric(el) ? parseInt(el) : null;
interval = interval || 200;
timeout = timeout || 30000;
var events = "touchmove.auto_scroller touchstart.auto_scroller keydown.auto_scroller click.auto_scroller " +
"MozMousePixelScroll.auto_scroller mousewheel.auto_scroller wheel.auto_scroller scroll.auto_scroller";
var disable_scroll = function (e) {
if (e && !e.originalEvent)
return;
if (e && e.type == "scroll" && e.originalEvent && old_scroll_top == $window.scrollTop())
return;
clearInterval(scroll_interval);
scroll_interval = null;
$window.off('.auto_scroller');
};
var scroller = function () {
htmlbody.scrollTop(abs_value !== null ? abs_value : parseInt(el.offset().top));
old_scroll_top = $window.scrollTop();
if ((new Date).getTime() - scroll_time > timeout)
disable_scroll();
};
scroll_interval = setInterval(scroller, interval);
scroller();
$window.on(events, disable_scroll);
self.onRequestStart("auto_scroller", disable_scroll);
},
scrollDocument: function (hash) {
var self = this, scroll_val = parseInt(hash);
if (isNaN(scroll_val) && hash && (typeof hash == "object" || hash.length > 0)) {
if (typeof hash == "string" && hash.substr(0, 1) == '/')
return;
// Эмуляция скролла по якорю
try {
var el = typeof hash == "object" ? $(hash) : $('#' + hash + ', a[name="' + hash + '"]');
if (el.length > 0) {
self.documentAutoScroller(el, 200, 30000);
return;
}
} catch (e) { console.error(e.toString()); }
}
if (Device.browser == "firefox") {
// Mobile FireFox не нужен >_<
$('html, body').scrollTop(scroll_val || 0);
setTimeout(function () { $('html, body').scrollTop(scroll_val || 0); }, 15);
} else
$('html, body').scrollTop(scroll_val || 0);
},