/usr/share/hotot/js/widget.scrollbar.js is in hotot-common 1:0.9.8.14-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | (function() {
var Scrollbar, root, _ref;
Scrollbar = (function() {
function Scrollbar(track, content, margin) {
if (typeof track !== 'string') {
this.track = $(track);
} else {
this.track = track;
}
if (typeof track !== 'string') {
this.content = $(content);
} else {
this.content = content;
}
this.disabled = false;
this.margin = margin;
this.handle = this.track.find('.scrollbar_handle');
this.content_height = 0;
this.handle_height = 0;
if (this.track.length === 0 && this.content.length === 0 && this.handle.length === 0) {
return null;
}
this.recalculate_layout();
this.bind();
}
Scrollbar.prototype.disable = function() {
this.disabled = true;
this.content.css({
'overflow-y': 'auto',
'overflow-x': 'hidden'
});
return this.track.hide();
};
Scrollbar.prototype.enable = function() {
this.disabled = false;
this.content.css({
'overflow-y': 'hidden',
'overflow-x': 'hidden'
});
return this.track.show();
};
Scrollbar.prototype.recalculate_layout = function() {
var pos;
if (this.disabled) return;
this.content_height = this.content.height();
this.track.css('height', (this.content_height - (this.track.outerHeight(true) - this.track.outerHeight())) + 'px');
this.track_height = this.track.height();
if (this.content.get(0).scrollHeight <= this.content_height) {
this.hide();
} else {
this.show();
this.handle.css('height', (this.track_height * this.content_height / this.content.get(0).scrollHeight) + 'px');
}
this.handle_height = this.handle.height();
pos = this.content.get(0).scrollTop * (this.track_height - this.handle_height) / this.content.get(0).scrollHeight;
this.handle.css('top', pos + 'px');
};
Scrollbar.prototype.on_wheel = function(ev) {
var delta, offsetY;
if (this.disabled) return;
if (event.wheelDeltaY > 1 || event.wheelDeltaY < -1) {
if (event.wheelDelta) delta = event.wheelDelta / 2.5;
offsetY = this.content.get(0).offsetTop - delta;
this.scroll(offsetY);
return false;
} else {
return true;
}
};
Scrollbar.prototype.activate = function() {
this.on_active = true;
return this.track.addClass('active');
};
Scrollbar.prototype.deactivate = function() {
this.on_active = false;
return this.track.removeClass('active');
};
Scrollbar.prototype.show = function() {
return this.track.show();
};
Scrollbar.prototype.hide = function() {
return this.track.hide();
};
Scrollbar.prototype.scroll_to = function(pos) {
return this.content.get(0).scrollTop = pos;
};
Scrollbar.prototype.scroll = function(offset) {
var pos;
pos = this.content_pos_check(this.content.get(0).scrollTop + offset);
return this.content.get(0).scrollTop = pos;
};
Scrollbar.prototype.scroll_by_handle = function(pos) {
this.handle.css('top', pos + 'px');
return this.content.get(0).scrollTop = pos * this.content.get(0).scrollHeight / (this.track_height - this.handle_height);
};
Scrollbar.prototype.handle_pos_check = function(pos) {
if (pos < 0) pos = 0;
if (pos > this.track_height - this.handle_height) {
pos = this.track_height - this.handle_height;
}
return pos;
};
Scrollbar.prototype.content_pos_check = function(pos) {
if (pos < 0) pos = 0;
if (pos > this.content.get(0).scrollHeight) {
pos = this.content.get(0).scrollHeight;
}
return pos;
};
Scrollbar.prototype.bind = function() {
var _this = this;
this.handle.mousedown(function(ev) {
_this.activate();
_this.track_scroll_y = ev.clientY - _this.track.get(0).offsetTop - _this.handle.get(0).offsetTop;
root._active_scrollbar = _this;
return false;
}).mouseup(function(ev) {
return _this.deactivate();
});
this.track.mousedown(function(ev) {
var pos;
_this.activate();
pos = _this.handle_pos_check(ev.clientY - _this.track.offset().top - _this.handle_height * 0.5);
_this.scroll_by_handle(pos);
return false;
}).mouseup(function(ev) {
return _this.deactivate();
});
this.content.on('mousewheel', function(ev) {
return _this.on_wheel(ev);
});
this.content.on('DOMMouseScroll', function(ev) {
return _this.on_wheel(ev);
});
return this.content.scroll(function(ev) {
var pos;
if (!_this.on_active && !_this.disabled) {
pos = _this.content.get(0).scrollTop * (_this.track_height - _this.handle_height) / _this.content.get(0).scrollHeight;
return _this.handle.css('top', pos + 'px');
}
});
};
Scrollbar.prototype.destory = function() {
this.track.off();
this.track = null;
this.handle.off();
this.handle = null;
this.content.off();
return this.content = null;
};
return Scrollbar;
})();
root = typeof exports !== "undefined" && exports !== null ? exports : this;
root.widget = (_ref = root.widget) != null ? _ref : {};
root.widget.Scrollbar = Scrollbar;
root.widget.Scrollbar.register = function() {
var _this = this;
$(document).mousemove(function(ev) {
var pos, sb;
if (root._active_scrollbar) {
sb = root._active_scrollbar;
if (sb.on_active && !sb.disabled && sb.track_scroll_y) {
pos = sb.handle_pos_check(ev.clientY - sb.track.get(0).offsetTop - sb.track_scroll_y);
sb.scroll_by_handle(pos);
}
return false;
}
}).mouseup(function(ev) {
var sb;
if (root._active_scrollbar) {
sb = root._active_scrollbar;
return sb.deactivate();
}
});
};
root._active_scrollbar = null;
}).call(this);
|