rails_antiscroll 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module RailsAntiscroll
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsAntiscroll
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,403 @@
1
+
2
+ (function ($) {
3
+
4
+ /**
5
+ * Augment jQuery prototype.
6
+ */
7
+
8
+ $.fn.antiscroll = function (options) {
9
+ return this.each(function () {
10
+ if ($(this).data('antiscroll')) {
11
+ $(this).data('antiscroll').destroy();
12
+ }
13
+
14
+ $(this).data('antiscroll', new $.Antiscroll(this, options));
15
+ });
16
+ };
17
+
18
+ /**
19
+ * Expose constructor.
20
+ */
21
+
22
+ $.Antiscroll = Antiscroll;
23
+
24
+ /**
25
+ * Antiscroll pane constructor.
26
+ *
27
+ * @param {Element|jQuery} main pane
28
+ * @parma {Object} options
29
+ * @api public
30
+ */
31
+
32
+ function Antiscroll (el, opts) {
33
+ this.el = $(el);
34
+ this.options = opts || {};
35
+ this.padding = undefined == this.options.padding ? 2 : this.options.padding;
36
+ this.inner = this.el.find('.antiscroll-inner');
37
+ this.inner.css({
38
+ 'width': '+=' + scrollbarSize()
39
+ , 'height': '+=' + scrollbarSize()
40
+ });
41
+
42
+ if (this.inner.get(0).scrollWidth > this.el.width()) {
43
+ this.horizontal = new Scrollbar.Horizontal(this);
44
+ }
45
+
46
+ if (this.inner.get(0).scrollHeight > this.el.height()) {
47
+ this.vertical = new Scrollbar.Vertical(this);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Cleans up.
53
+ *
54
+ * @return {Antiscroll} for chaining
55
+ * @api public
56
+ */
57
+
58
+ Antiscroll.prototype.destroy = function () {
59
+ if (this.horizontal) {
60
+ this.horizontal.destroy();
61
+ }
62
+ if (this.vertical) {
63
+ this.vertical.destroy();
64
+ }
65
+ return this;
66
+ };
67
+
68
+ /**
69
+ * Scrolbar constructor.
70
+ *
71
+ * @param {Element|jQuery} element
72
+ * @api public
73
+ */
74
+
75
+ function Scrollbar (pane) {
76
+ this.pane = pane;
77
+ this.pane.el.append(this.el);
78
+ this.innerEl = this.pane.inner.get(0);
79
+
80
+ this.dragging = false;
81
+ this.enter = false;
82
+ this.shown = false;
83
+
84
+ // hovering
85
+ this.pane.el.mouseenter($.proxy(this, 'mouseenter'));
86
+ this.pane.el.mouseleave($.proxy(this, 'mouseleave'));
87
+
88
+ // dragging
89
+ this.el.mousedown($.proxy(this, 'mousedown'));
90
+
91
+ // scrolling
92
+ this.pane.inner.scroll($.proxy(this, 'scroll'));
93
+
94
+ // wheel -optional-
95
+ this.pane.inner.bind('mousewheel', $.proxy(this, 'mousewheel'));
96
+
97
+ // show
98
+ var initialDisplay = this.pane.options.initialDisplay;
99
+
100
+ if (initialDisplay !== false) {
101
+ this.show();
102
+ this.hiding = setTimeout($.proxy(this, 'hide'), parseInt(initialDisplay, 10) || 3000);
103
+ }
104
+ };
105
+
106
+ /**
107
+ * Cleans up.
108
+ *
109
+ * @return {Scrollbar} for chaining
110
+ * @api public
111
+ */
112
+
113
+ Scrollbar.prototype.destroy = function () {
114
+ this.el.remove();
115
+ return this;
116
+ };
117
+
118
+ /**
119
+ * Called upon mouseenter.
120
+ *
121
+ * @api private
122
+ */
123
+
124
+ Scrollbar.prototype.mouseenter = function () {
125
+ this.enter = true;
126
+ this.show();
127
+ };
128
+
129
+ /**
130
+ * Called upon mouseleave.
131
+ *
132
+ * @api private
133
+ */
134
+
135
+ Scrollbar.prototype.mouseleave = function () {
136
+ this.enter = false;
137
+
138
+ if (!this.dragging) {
139
+ this.hide();
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Called upon wrap scroll.
145
+ *
146
+ * @api private
147
+ */
148
+
149
+ Scrollbar.prototype.scroll = function () {
150
+ if (!this.shown) {
151
+ this.show();
152
+ if (!this.enter && !this.dragging) {
153
+ this.hiding = setTimeout($.proxy(this, 'hide'), 1500);
154
+ }
155
+ }
156
+
157
+ this.update();
158
+ };
159
+
160
+ /**
161
+ * Called upon scrollbar mousedown.
162
+ *
163
+ * @api private
164
+ */
165
+
166
+ Scrollbar.prototype.mousedown = function (ev) {
167
+ ev.preventDefault();
168
+
169
+ this.dragging = true;
170
+
171
+ this.startPageY = ev.pageY - parseInt(this.el.css('top'), 10);
172
+ this.startPageX = ev.pageX - parseInt(this.el.css('left'), 10);
173
+
174
+ // prevent crazy selections on IE
175
+ document.onselectstart = function () { return false; };
176
+
177
+ var pane = this.pane
178
+ , move = $.proxy(this, 'mousemove')
179
+ , self = this
180
+
181
+ $(document)
182
+ .mousemove(move)
183
+ .mouseup(function () {
184
+ self.dragging = false;
185
+ document.onselectstart = null;
186
+
187
+ $(document).unbind('mousemove', move);
188
+
189
+ if (!self.enter) {
190
+ self.hide();
191
+ }
192
+ })
193
+ };
194
+
195
+ /**
196
+ * Show scrollbar.
197
+ *
198
+ * @api private
199
+ */
200
+
201
+ Scrollbar.prototype.show = function (duration) {
202
+ if (!this.shown) {
203
+ this.update();
204
+ this.el.addClass('antiscroll-scrollbar-shown');
205
+ if (this.hiding) {
206
+ clearTimeout(this.hiding);
207
+ this.hiding = null;
208
+ }
209
+ this.shown = true;
210
+ }
211
+ };
212
+
213
+ /**
214
+ * Hide scrollbar.
215
+ *
216
+ * @api private
217
+ */
218
+
219
+ Scrollbar.prototype.hide = function () {
220
+ if (this.shown) {
221
+ // check for dragging
222
+ this.el.removeClass('antiscroll-scrollbar-shown');
223
+ this.shown = false;
224
+ }
225
+ };
226
+
227
+ /**
228
+ * Horizontal scrollbar constructor
229
+ *
230
+ * @api private
231
+ */
232
+
233
+ Scrollbar.Horizontal = function (pane) {
234
+ this.el = $('<div class="antiscroll-scrollbar antiscroll-scrollbar-horizontal">');
235
+ Scrollbar.call(this, pane);
236
+ }
237
+
238
+ /**
239
+ * Inherits from Scrollbar.
240
+ */
241
+
242
+ inherits(Scrollbar.Horizontal, Scrollbar);
243
+
244
+ /**
245
+ * Updates size/position of scrollbar.
246
+ *
247
+ * @api private
248
+ */
249
+
250
+ Scrollbar.Horizontal.prototype.update = function () {
251
+ var paneWidth = this.pane.el.width()
252
+ , trackWidth = paneWidth - this.pane.padding * 2
253
+ , innerEl = this.pane.inner.get(0)
254
+
255
+ this.el
256
+ .css('width', trackWidth * paneWidth / innerEl.scrollWidth)
257
+ .css('left', trackWidth * innerEl.scrollLeft / innerEl.scrollWidth)
258
+ }
259
+
260
+ /**
261
+ * Called upon drag.
262
+ *
263
+ * @api private
264
+ */
265
+
266
+ Scrollbar.Horizontal.prototype.mousemove = function (ev) {
267
+ var trackWidth = this.pane.el.width() - this.pane.padding * 2
268
+ , pos = ev.pageX - this.startPageX
269
+ , barWidth = this.el.width()
270
+ , innerEl = this.pane.inner.get(0)
271
+
272
+ // minimum top is 0, maximum is the track height
273
+ var y = Math.min(Math.max(pos, 0), trackWidth - barWidth)
274
+
275
+ innerEl.scrollLeft = (innerEl.scrollWidth - this.pane.el.width())
276
+ * y / (trackWidth - barWidth)
277
+ };
278
+
279
+ /**
280
+ * Called upon container mousewheel.
281
+ *
282
+ * @api private
283
+ */
284
+
285
+ Scrollbar.Horizontal.prototype.mousewheel = function (ev, delta, x, y) {
286
+ if ((x < 0 && 0 == this.pane.inner.get(0).scrollLeft) ||
287
+ (x > 0 && (this.innerEl.scrollLeft + this.pane.el.width()
288
+ == this.innerEl.scrollWidth))) {
289
+ ev.preventDefault();
290
+ return false;
291
+ }
292
+ };
293
+
294
+ /**
295
+ * Vertical scrollbar constructor
296
+ *
297
+ * @api private
298
+ */
299
+
300
+ Scrollbar.Vertical = function (pane) {
301
+ this.el = $('<div class="antiscroll-scrollbar antiscroll-scrollbar-vertical">');
302
+ Scrollbar.call(this, pane);
303
+ };
304
+
305
+ /**
306
+ * Inherits from Scrollbar.
307
+ */
308
+
309
+ inherits(Scrollbar.Vertical, Scrollbar);
310
+
311
+ /**
312
+ * Updates size/position of scrollbar.
313
+ *
314
+ * @api private
315
+ */
316
+
317
+ Scrollbar.Vertical.prototype.update = function () {
318
+ var paneHeight = this.pane.el.height()
319
+ , trackHeight = paneHeight - this.pane.padding * 2
320
+ , innerEl = this.innerEl
321
+
322
+ this.el
323
+ .css('height', trackHeight * paneHeight / innerEl.scrollHeight)
324
+ .css('top', trackHeight * innerEl.scrollTop / innerEl.scrollHeight)
325
+ };
326
+
327
+ /**
328
+ * Called upon drag.
329
+ *
330
+ * @api private
331
+ */
332
+
333
+ Scrollbar.Vertical.prototype.mousemove = function (ev) {
334
+ var paneHeight = this.pane.el.height()
335
+ , trackHeight = paneHeight - this.pane.padding * 2
336
+ , pos = ev.pageY - this.startPageY
337
+ , barHeight = this.el.height()
338
+ , innerEl = this.innerEl
339
+
340
+ // minimum top is 0, maximum is the track height
341
+ var y = Math.min(Math.max(pos, 0), trackHeight - barHeight)
342
+
343
+ innerEl.scrollTop = (innerEl.scrollHeight - paneHeight)
344
+ * y / (trackHeight - barHeight)
345
+ };
346
+
347
+ /**
348
+ * Called upon container mousewheel.
349
+ *
350
+ * @api private
351
+ */
352
+
353
+ Scrollbar.Vertical.prototype.mousewheel = function (ev, delta, x, y) {
354
+ if ((y > 0 && 0 == this.innerEl.scrollTop) ||
355
+ (y < 0 && (this.innerEl.scrollTop + this.pane.el.height()
356
+ == this.innerEl.scrollHeight))) {
357
+ ev.preventDefault();
358
+ return false;
359
+ }
360
+ };
361
+
362
+ /**
363
+ * Cross-browser inheritance.
364
+ *
365
+ * @param {Function} constructor
366
+ * @param {Function} constructor we inherit from
367
+ * @api private
368
+ */
369
+
370
+ function inherits (ctorA, ctorB) {
371
+ function f() {};
372
+ f.prototype = ctorB.prototype;
373
+ ctorA.prototype = new f;
374
+ };
375
+
376
+ /**
377
+ * Scrollbar size detection.
378
+ */
379
+
380
+ var size;
381
+
382
+ function scrollbarSize () {
383
+ if (!size) {
384
+ var div = $(
385
+ '<div style="width:50px;height:50px;overflow:hidden;'
386
+ + 'position:absolute;top:-200px;left:-200px;"><div style="height:100px;">'
387
+ + '</div>'
388
+ );
389
+
390
+ $('body').append(div);
391
+
392
+ var w1 = $('div', div).innerWidth();
393
+ div.css('overflow-y', 'scroll');
394
+ var w2 = $('div', div).innerWidth();
395
+ $(div).remove();
396
+
397
+ size = w1 - w2;
398
+ }
399
+
400
+ return size;
401
+ };
402
+
403
+ })(jQuery);
@@ -0,0 +1,84 @@
1
+ /*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
2
+ * Licensed under the MIT License (LICENSE.txt).
3
+ *
4
+ * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
5
+ * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
6
+ * Thanks to: Seamus Leahy for adding deltaX and deltaY
7
+ *
8
+ * Version: 3.0.6
9
+ *
10
+ * Requires: 1.2.2+
11
+ */
12
+
13
+ (function($) {
14
+
15
+ var types = ['DOMMouseScroll', 'mousewheel'];
16
+
17
+ if ($.event.fixHooks) {
18
+ for ( var i=types.length; i; ) {
19
+ $.event.fixHooks[ types[--i] ] = $.event.mouseHooks;
20
+ }
21
+ }
22
+
23
+ $.event.special.mousewheel = {
24
+ setup: function() {
25
+ if ( this.addEventListener ) {
26
+ for ( var i=types.length; i; ) {
27
+ this.addEventListener( types[--i], handler, false );
28
+ }
29
+ } else {
30
+ this.onmousewheel = handler;
31
+ }
32
+ },
33
+
34
+ teardown: function() {
35
+ if ( this.removeEventListener ) {
36
+ for ( var i=types.length; i; ) {
37
+ this.removeEventListener( types[--i], handler, false );
38
+ }
39
+ } else {
40
+ this.onmousewheel = null;
41
+ }
42
+ }
43
+ };
44
+
45
+ $.fn.extend({
46
+ mousewheel: function(fn) {
47
+ return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
48
+ },
49
+
50
+ unmousewheel: function(fn) {
51
+ return this.unbind("mousewheel", fn);
52
+ }
53
+ });
54
+
55
+
56
+ function handler(event) {
57
+ var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
58
+ event = $.event.fix(orgEvent);
59
+ event.type = "mousewheel";
60
+
61
+ // Old school scrollwheel delta
62
+ if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
63
+ if ( orgEvent.detail ) { delta = -orgEvent.detail/3; }
64
+
65
+ // New school multidimensional scroll (touchpads) deltas
66
+ deltaY = delta;
67
+
68
+ // Gecko
69
+ if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
70
+ deltaY = 0;
71
+ deltaX = -1*delta;
72
+ }
73
+
74
+ // Webkit
75
+ if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
76
+ if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
77
+
78
+ // Add event and delta to the front of the arguments
79
+ args.unshift(event, delta, deltaX, deltaY);
80
+
81
+ return ($.event.dispatch || $.event.handle).apply(this, args);
82
+ }
83
+
84
+ })(jQuery);
@@ -0,0 +1,47 @@
1
+ .antiscroll-wrap {
2
+ display: inline-block;
3
+ position: relative;
4
+ overflow: hidden;
5
+ }
6
+
7
+ .antiscroll-scrollbar {
8
+ background: #666;
9
+ background: rgba(0, 0, 0, .6);
10
+ -webkit-border-radius: 7px;
11
+ -moz-border-radius: 7px;
12
+ border-radius: 7px;
13
+ position: absolute;
14
+ opacity: 0;
15
+ filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
16
+ -webkit-transition: linear 300ms opacity;
17
+ -moz-transition: linear 300ms opacity;
18
+ -o-transition: linear 300ms opacity;
19
+ }
20
+
21
+ .antiscroll-scrollbar-shown {
22
+ opacity: 1;
23
+ filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
24
+ }
25
+
26
+ .antiscroll-scrollbar-horizontal {
27
+ height: 7px;
28
+ margin-left: 2px;
29
+ bottom: 2px;
30
+ left: 0;
31
+ }
32
+
33
+ .antiscroll-scrollbar-vertical {
34
+ width: 7px;
35
+ margin-top: 2px;
36
+ right: 2px;
37
+ top: 0;
38
+ }
39
+
40
+ .antiscroll-inner {
41
+ overflow: scroll;
42
+ }
43
+
44
+ .antiscroll-inner::-webkit-scrollbar, .antiscroll-inner::scrollbar {
45
+ width: 0;
46
+ height: 0;
47
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_antiscroll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70340928110180 !ruby/object:Gem::Requirement
16
+ requirement: &70303279899340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70340928110180
24
+ version_requirements: *70303279899340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70340928112260 !ruby/object:Gem::Requirement
27
+ requirement: &70303279898360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70340928112260
35
+ version_requirements: *70303279898360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &70340931848860 !ruby/object:Gem::Requirement
38
+ requirement: &70303279897480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3.1'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70340931848860
46
+ version_requirements: *70303279897480
47
47
  description: Add the jquery antiscroll script to your rails app by adding this gem.
48
48
  No lines in the manifest.
49
49
  email:
@@ -56,8 +56,12 @@ files:
56
56
  - Gemfile
57
57
  - Rakefile
58
58
  - lib/rails_antiscroll.rb
59
+ - lib/rails_antiscroll/engine.rb
59
60
  - lib/rails_antiscroll/version.rb
60
61
  - rails_antiscroll.gemspec
62
+ - vendor/javascripts/antiscroll.js
63
+ - vendor/javascripts/jquery.mousewheel.js
64
+ - vendor/stylesheets/antiscroll.css
61
65
  homepage: ''
62
66
  licenses: []
63
67
  post_install_message: