scrollToFixed_rails 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/scrolltofixed.js +542 -0
- data/lib/scrollToFixed_rails/version.rb +3 -0
- data/lib/scrollToFixed_rails.rb +8 -0
- data/scrollToFixed_rails.gemspec +24 -0
- metadata +102 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Guy Israeli
|
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,37 @@
|
|
1
|
+
# ScrollToFixedRails
|
2
|
+
|
3
|
+
This is an asset pipeline wrapper for scrollToFixed.js (https://github.com/bigspotteddog/ScrollToFixed)
|
4
|
+
|
5
|
+
jQuery is needed
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'scrollToFixed_rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install scrollToFixed_rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
add
|
24
|
+
|
25
|
+
//= require scrolltofixed
|
26
|
+
|
27
|
+
to application.js manifest
|
28
|
+
|
29
|
+
and see http://bigspotteddog.github.io/ScrollToFixed/ for demo
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,542 @@
|
|
1
|
+
// Copyright (c) 2011 Joseph Cava-Lynch
|
2
|
+
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
// this software and associated documentation files (the "Software"), to deal in
|
5
|
+
// the Software without restriction, including without limitation the rights to
|
6
|
+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
// the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
// subject to the following conditions:
|
9
|
+
|
10
|
+
// The above copyright notice and this permission notice shall be included in all
|
11
|
+
// copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
// Version for debugging - 1.0.0
|
21
|
+
|
22
|
+
(function($) {
|
23
|
+
$.isScrollToFixed = function(el) {
|
24
|
+
return !!$(el).data('ScrollToFixed');
|
25
|
+
};
|
26
|
+
|
27
|
+
$.ScrollToFixed = function(el, options) {
|
28
|
+
// To avoid scope issues, use 'base' instead of 'this' to reference this
|
29
|
+
// class from internal events and functions.
|
30
|
+
var base = this;
|
31
|
+
|
32
|
+
// Access to jQuery and DOM versions of element.
|
33
|
+
base.$el = $(el);
|
34
|
+
base.el = el;
|
35
|
+
|
36
|
+
// Add a reverse reference to the DOM object.
|
37
|
+
base.$el.data('ScrollToFixed', base);
|
38
|
+
|
39
|
+
// A flag so we know if the scroll has been reset.
|
40
|
+
var isReset = false;
|
41
|
+
|
42
|
+
// The element that was given to us to fix if scrolled above the top of
|
43
|
+
// the page.
|
44
|
+
var target = base.$el;
|
45
|
+
|
46
|
+
var position;
|
47
|
+
var originalPosition;
|
48
|
+
|
49
|
+
var originalOffset;
|
50
|
+
|
51
|
+
// The offset top of the element when resetScroll was called. This is
|
52
|
+
// used to determine if we have scrolled past the top of the element.
|
53
|
+
var offsetTop = 0;
|
54
|
+
|
55
|
+
// The offset left of the element when resetScroll was called. This is
|
56
|
+
// used to move the element left or right relative to the horizontal
|
57
|
+
// scroll.
|
58
|
+
var offsetLeft = 0;
|
59
|
+
var originalOffsetLeft = -1;
|
60
|
+
|
61
|
+
// This last offset used to move the element horizontally. This is used
|
62
|
+
// to determine if we need to move the element because we would not want
|
63
|
+
// to do that for no reason.
|
64
|
+
var lastOffsetLeft = -1;
|
65
|
+
|
66
|
+
// This is the element used to fill the void left by the target element
|
67
|
+
// when it goes fixed; otherwise, everything below it moves up the page.
|
68
|
+
var spacer = null;
|
69
|
+
|
70
|
+
var spacerClass;
|
71
|
+
|
72
|
+
var className;
|
73
|
+
|
74
|
+
// Capture the original offsets for the target element. This needs to be
|
75
|
+
// called whenever the page size changes or when the page is first
|
76
|
+
// scrolled. For some reason, calling this before the page is first
|
77
|
+
// scrolled causes the element to become fixed too late.
|
78
|
+
function resetScroll() {
|
79
|
+
// Set the element to it original positioning.
|
80
|
+
target.trigger('preUnfixed.ScrollToFixed');
|
81
|
+
setUnfixed();
|
82
|
+
target.trigger('unfixed.ScrollToFixed');
|
83
|
+
|
84
|
+
// Reset the last offset used to determine if the page has moved
|
85
|
+
// horizontally.
|
86
|
+
lastOffsetLeft = -1;
|
87
|
+
|
88
|
+
// Capture the offset top of the target element.
|
89
|
+
offsetTop = target.offset().top;
|
90
|
+
|
91
|
+
// Capture the offset left of the target element.
|
92
|
+
offsetLeft = target.offset().left;
|
93
|
+
|
94
|
+
// If the offsets option is on, alter the left offset.
|
95
|
+
if (base.options.offsets) {
|
96
|
+
offsetLeft += (target.offset().left - target.position().left);
|
97
|
+
}
|
98
|
+
|
99
|
+
if (originalOffsetLeft == -1) {
|
100
|
+
originalOffsetLeft = offsetLeft;
|
101
|
+
}
|
102
|
+
|
103
|
+
position = target.css('position');
|
104
|
+
|
105
|
+
// Set that this has been called at least once.
|
106
|
+
isReset = true;
|
107
|
+
|
108
|
+
if (base.options.bottom != -1) {
|
109
|
+
target.trigger('preFixed.ScrollToFixed');
|
110
|
+
setFixed();
|
111
|
+
target.trigger('fixed.ScrollToFixed');
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
function getLimit() {
|
116
|
+
var limit = base.options.limit;
|
117
|
+
if (!limit) return 0;
|
118
|
+
|
119
|
+
if (typeof(limit) === 'function') {
|
120
|
+
return limit.apply(target);
|
121
|
+
}
|
122
|
+
return limit;
|
123
|
+
}
|
124
|
+
|
125
|
+
// Returns whether the target element is fixed or not.
|
126
|
+
function isFixed() {
|
127
|
+
return position === 'fixed';
|
128
|
+
}
|
129
|
+
|
130
|
+
// Returns whether the target element is absolute or not.
|
131
|
+
function isAbsolute() {
|
132
|
+
return position === 'absolute';
|
133
|
+
}
|
134
|
+
|
135
|
+
function isUnfixed() {
|
136
|
+
return !(isFixed() || isAbsolute());
|
137
|
+
}
|
138
|
+
|
139
|
+
// Sets the target element to fixed. Also, sets the spacer to fill the
|
140
|
+
// void left by the target element.
|
141
|
+
function setFixed() {
|
142
|
+
// Only fix the target element and the spacer if we need to.
|
143
|
+
if (!isFixed()) {
|
144
|
+
// Set the spacer to fill the height and width of the target
|
145
|
+
// element, then display it.
|
146
|
+
spacer.css({
|
147
|
+
'display' : target.css('display'),
|
148
|
+
'width' : target.outerWidth(true),
|
149
|
+
'height' : target.outerHeight(true),
|
150
|
+
'float' : target.css('float')
|
151
|
+
});
|
152
|
+
|
153
|
+
// Set the target element to fixed and set its width so it does
|
154
|
+
// not fill the rest of the page horizontally. Also, set its top
|
155
|
+
// to the margin top specified in the options.
|
156
|
+
|
157
|
+
cssOptions={
|
158
|
+
'position' : 'fixed',
|
159
|
+
'top' : base.options.bottom == -1?getMarginTop():'',
|
160
|
+
'bottom' : base.options.bottom == -1?'':base.options.bottom,
|
161
|
+
'margin-left' : '0px'
|
162
|
+
}
|
163
|
+
if (!base.options.dontSetWidth){ cssOptions['width']=target.width(); };
|
164
|
+
|
165
|
+
target.css(cssOptions);
|
166
|
+
|
167
|
+
target.addClass('scroll-to-fixed-fixed');
|
168
|
+
|
169
|
+
if (base.options.className) {
|
170
|
+
target.addClass(base.options.className);
|
171
|
+
}
|
172
|
+
|
173
|
+
position = 'fixed';
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
function setAbsolute() {
|
178
|
+
|
179
|
+
var top = getLimit();
|
180
|
+
var left = offsetLeft;
|
181
|
+
|
182
|
+
if (base.options.removeOffsets) {
|
183
|
+
left = 0;
|
184
|
+
top = top - offsetTop;
|
185
|
+
}
|
186
|
+
|
187
|
+
cssOptions={
|
188
|
+
'position' : 'absolute',
|
189
|
+
'top' : top,
|
190
|
+
'left' : left,
|
191
|
+
'margin-left' : '0px',
|
192
|
+
'bottom' : ''
|
193
|
+
}
|
194
|
+
if (!base.options.dontSetWidth){ cssOptions['width']=target.width(); };
|
195
|
+
|
196
|
+
target.css(cssOptions);
|
197
|
+
|
198
|
+
position = 'absolute';
|
199
|
+
}
|
200
|
+
|
201
|
+
// Sets the target element back to unfixed. Also, hides the spacer.
|
202
|
+
function setUnfixed() {
|
203
|
+
// Only unfix the target element and the spacer if we need to.
|
204
|
+
if (!isUnfixed()) {
|
205
|
+
lastOffsetLeft = -1;
|
206
|
+
|
207
|
+
// Hide the spacer now that the target element will fill the
|
208
|
+
// space.
|
209
|
+
spacer.css('display', 'none');
|
210
|
+
|
211
|
+
// Remove the style attributes that were added to the target.
|
212
|
+
// This will reverse the target back to the its original style.
|
213
|
+
target.css({
|
214
|
+
'width' : '',
|
215
|
+
'position' : originalPosition,
|
216
|
+
'left' : '',
|
217
|
+
'top' : originalOffset.top,
|
218
|
+
'margin-left' : ''
|
219
|
+
});
|
220
|
+
|
221
|
+
target.removeClass('scroll-to-fixed-fixed');
|
222
|
+
|
223
|
+
if (base.options.className) {
|
224
|
+
target.removeClass(base.options.className);
|
225
|
+
}
|
226
|
+
|
227
|
+
position = null;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
// Moves the target element left or right relative to the horizontal
|
232
|
+
// scroll position.
|
233
|
+
function setLeft(x) {
|
234
|
+
// Only if the scroll is not what it was last time we did this.
|
235
|
+
if (x != lastOffsetLeft) {
|
236
|
+
// Move the target element horizontally relative to its original
|
237
|
+
// horizontal position.
|
238
|
+
target.css('left', offsetLeft - x);
|
239
|
+
|
240
|
+
// Hold the last horizontal position set.
|
241
|
+
lastOffsetLeft = x;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
245
|
+
function getMarginTop() {
|
246
|
+
var marginTop = base.options.marginTop;
|
247
|
+
if (!marginTop) return 0;
|
248
|
+
|
249
|
+
if (typeof(marginTop) === 'function') {
|
250
|
+
return marginTop.apply(target);
|
251
|
+
}
|
252
|
+
return marginTop;
|
253
|
+
}
|
254
|
+
|
255
|
+
// Checks to see if we need to do something based on new scroll position
|
256
|
+
// of the page.
|
257
|
+
function checkScroll() {
|
258
|
+
if (!$.isScrollToFixed(target)) return;
|
259
|
+
var wasReset = isReset;
|
260
|
+
|
261
|
+
// If resetScroll has not yet been called, call it. This only
|
262
|
+
// happens once.
|
263
|
+
if (!isReset) {
|
264
|
+
resetScroll();
|
265
|
+
}
|
266
|
+
|
267
|
+
// Grab the current horizontal scroll position.
|
268
|
+
var x = $(window).scrollLeft();
|
269
|
+
|
270
|
+
// Grab the current vertical scroll position.
|
271
|
+
var y = $(window).scrollTop();
|
272
|
+
|
273
|
+
// Get the limit, if there is one.
|
274
|
+
var limit = getLimit();
|
275
|
+
|
276
|
+
// If the vertical scroll position, plus the optional margin, would
|
277
|
+
// put the target element at the specified limit, set the target
|
278
|
+
// element to absolute.
|
279
|
+
if (base.options.minWidth && $(window).width() < base.options.minWidth) {
|
280
|
+
if (!isUnfixed() || !wasReset) {
|
281
|
+
postPosition();
|
282
|
+
target.trigger('preUnfixed.ScrollToFixed');
|
283
|
+
setUnfixed();
|
284
|
+
target.trigger('unfixed.ScrollToFixed');
|
285
|
+
}
|
286
|
+
} else if (base.options.bottom == -1) {
|
287
|
+
// If the vertical scroll position, plus the optional margin, would
|
288
|
+
// put the target element at the specified limit, set the target
|
289
|
+
// element to absolute.
|
290
|
+
if (limit > 0 && y >= limit - getMarginTop()) {
|
291
|
+
if (!isAbsolute() || !wasReset) {
|
292
|
+
postPosition();
|
293
|
+
target.trigger('preAbsolute.ScrollToFixed');
|
294
|
+
setAbsolute();
|
295
|
+
target.trigger('unfixed.ScrollToFixed');
|
296
|
+
}
|
297
|
+
// If the vertical scroll position, plus the optional margin, would
|
298
|
+
// put the target element above the top of the page, set the target
|
299
|
+
// element to fixed.
|
300
|
+
} else if (y >= offsetTop - getMarginTop()) {
|
301
|
+
if (!isFixed() || !wasReset) {
|
302
|
+
postPosition();
|
303
|
+
target.trigger('preFixed.ScrollToFixed');
|
304
|
+
|
305
|
+
// Set the target element to fixed.
|
306
|
+
setFixed();
|
307
|
+
|
308
|
+
// Reset the last offset left because we just went fixed.
|
309
|
+
lastOffsetLeft = -1;
|
310
|
+
|
311
|
+
target.trigger('fixed.ScrollToFixed');
|
312
|
+
}
|
313
|
+
// If the page has been scrolled horizontally as well, move the
|
314
|
+
// target element accordingly.
|
315
|
+
setLeft(x);
|
316
|
+
} else {
|
317
|
+
// Set the target element to unfixed, placing it where it was
|
318
|
+
// before.
|
319
|
+
if (!isUnfixed() || !wasReset) {
|
320
|
+
postPosition();
|
321
|
+
target.trigger('preUnfixed.ScrollToFixed');
|
322
|
+
setUnfixed();
|
323
|
+
target.trigger('unfixed.ScrollToFixed');
|
324
|
+
}
|
325
|
+
}
|
326
|
+
} else {
|
327
|
+
if (limit > 0) {
|
328
|
+
if (y + $(window).height() - target.outerHeight(true) >= limit - (getMarginTop() || -getBottom())) {
|
329
|
+
if (isFixed()) {
|
330
|
+
postPosition();
|
331
|
+
target.trigger('preUnfixed.ScrollToFixed');
|
332
|
+
|
333
|
+
if (originalPosition === 'absolute') {
|
334
|
+
setAbsolute();
|
335
|
+
} else {
|
336
|
+
setUnfixed();
|
337
|
+
}
|
338
|
+
|
339
|
+
target.trigger('unfixed.ScrollToFixed');
|
340
|
+
}
|
341
|
+
} else {
|
342
|
+
if (!isFixed()) {
|
343
|
+
postPosition();
|
344
|
+
target.trigger('preFixed.ScrollToFixed');
|
345
|
+
setFixed();
|
346
|
+
}
|
347
|
+
setLeft(x);
|
348
|
+
target.trigger('fixed.ScrollToFixed');
|
349
|
+
}
|
350
|
+
} else {
|
351
|
+
setLeft(x);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
function getBottom() {
|
357
|
+
if (!base.options.bottom) return 0;
|
358
|
+
return base.options.bottom;
|
359
|
+
}
|
360
|
+
|
361
|
+
function postPosition() {
|
362
|
+
var position = target.css('position');
|
363
|
+
|
364
|
+
if (position == 'absolute') {
|
365
|
+
target.trigger('postAbsolute.ScrollToFixed');
|
366
|
+
} else if (position == 'fixed') {
|
367
|
+
target.trigger('postFixed.ScrollToFixed');
|
368
|
+
} else {
|
369
|
+
target.trigger('postUnfixed.ScrollToFixed');
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
var windowResize = function(event) {
|
374
|
+
// Check if the element is visible before updating it's position, which
|
375
|
+
// improves behavior with responsive designs where this element is hidden.
|
376
|
+
if(target.is(':visible')) {
|
377
|
+
isReset = false;
|
378
|
+
checkScroll();
|
379
|
+
}
|
380
|
+
}
|
381
|
+
|
382
|
+
var windowScroll = function(event) {
|
383
|
+
checkScroll();
|
384
|
+
}
|
385
|
+
|
386
|
+
// From: http://kangax.github.com/cft/#IS_POSITION_FIXED_SUPPORTED
|
387
|
+
var isPositionFixedSupported = function() {
|
388
|
+
var container = document.body;
|
389
|
+
|
390
|
+
if (document.createElement && container && container.appendChild && container.removeChild) {
|
391
|
+
var el = document.createElement('div');
|
392
|
+
|
393
|
+
if (!el.getBoundingClientRect) return null;
|
394
|
+
|
395
|
+
el.innerHTML = 'x';
|
396
|
+
el.style.cssText = 'position:fixed;top:100px;';
|
397
|
+
container.appendChild(el);
|
398
|
+
|
399
|
+
var originalHeight = container.style.height,
|
400
|
+
originalScrollTop = container.scrollTop;
|
401
|
+
|
402
|
+
container.style.height = '3000px';
|
403
|
+
container.scrollTop = 500;
|
404
|
+
|
405
|
+
var elementTop = el.getBoundingClientRect().top;
|
406
|
+
container.style.height = originalHeight;
|
407
|
+
|
408
|
+
var isSupported = (elementTop === 100);
|
409
|
+
container.removeChild(el);
|
410
|
+
container.scrollTop = originalScrollTop;
|
411
|
+
|
412
|
+
return isSupported;
|
413
|
+
}
|
414
|
+
|
415
|
+
return null;
|
416
|
+
}
|
417
|
+
|
418
|
+
var preventDefault = function(e) {
|
419
|
+
e = e || window.event;
|
420
|
+
if (e.preventDefault) {
|
421
|
+
e.preventDefault();
|
422
|
+
}
|
423
|
+
e.returnValue = false;
|
424
|
+
}
|
425
|
+
|
426
|
+
// Initializes this plugin. Captures the options passed in, turns this
|
427
|
+
// off for devices that do not support fixed position, adds the spacer,
|
428
|
+
// and binds to the window scroll and resize events.
|
429
|
+
base.init = function() {
|
430
|
+
// Capture the options for this plugin.
|
431
|
+
base.options = $
|
432
|
+
.extend({}, $.ScrollToFixed.defaultOptions, options);
|
433
|
+
|
434
|
+
// Turn off this functionality for devices that do not support it.
|
435
|
+
// if (!(base.options && base.options.dontCheckForPositionFixedSupport)) {
|
436
|
+
// var fixedSupported = isPositionFixedSupported();
|
437
|
+
// if (!fixedSupported) return;
|
438
|
+
// }
|
439
|
+
|
440
|
+
// Put the target element on top of everything that could be below
|
441
|
+
// it. This reduces flicker when the target element is transitioning
|
442
|
+
// to fixed.
|
443
|
+
base.$el.css('z-index', base.options.zIndex);
|
444
|
+
|
445
|
+
// Create a spacer element to fill the void left by the target
|
446
|
+
// element when it goes fixed.
|
447
|
+
spacer = $('<div />');
|
448
|
+
|
449
|
+
position = target.css('position');
|
450
|
+
originalPosition = target.css('position');
|
451
|
+
|
452
|
+
originalOffset = $.extend({}, target.offset());
|
453
|
+
|
454
|
+
// Place the spacer right after the target element.
|
455
|
+
if (isUnfixed()) base.$el.after(spacer);
|
456
|
+
|
457
|
+
// Reset the target element offsets when the window is resized, then
|
458
|
+
// check to see if we need to fix or unfix the target element.
|
459
|
+
$(window).bind('resize.ScrollToFixed', windowResize);
|
460
|
+
|
461
|
+
// When the window scrolls, check to see if we need to fix or unfix
|
462
|
+
// the target element.
|
463
|
+
$(window).bind('scroll.ScrollToFixed', windowScroll);
|
464
|
+
|
465
|
+
if (base.options.preFixed) {
|
466
|
+
target.bind('preFixed.ScrollToFixed', base.options.preFixed);
|
467
|
+
}
|
468
|
+
if (base.options.postFixed) {
|
469
|
+
target.bind('postFixed.ScrollToFixed', base.options.postFixed);
|
470
|
+
}
|
471
|
+
if (base.options.preUnfixed) {
|
472
|
+
target.bind('preUnfixed.ScrollToFixed', base.options.preUnfixed);
|
473
|
+
}
|
474
|
+
if (base.options.postUnfixed) {
|
475
|
+
target.bind('postUnfixed.ScrollToFixed', base.options.postUnfixed);
|
476
|
+
}
|
477
|
+
if (base.options.preAbsolute) {
|
478
|
+
target.bind('preAbsolute.ScrollToFixed', base.options.preAbsolute);
|
479
|
+
}
|
480
|
+
if (base.options.postAbsolute) {
|
481
|
+
target.bind('postAbsolute.ScrollToFixed', base.options.postAbsolute);
|
482
|
+
}
|
483
|
+
if (base.options.fixed) {
|
484
|
+
target.bind('fixed.ScrollToFixed', base.options.fixed);
|
485
|
+
}
|
486
|
+
if (base.options.unfixed) {
|
487
|
+
target.bind('unfixed.ScrollToFixed', base.options.unfixed);
|
488
|
+
}
|
489
|
+
|
490
|
+
if (base.options.spacerClass) {
|
491
|
+
spacer.addClass(base.options.spacerClass);
|
492
|
+
}
|
493
|
+
|
494
|
+
target.bind('resize.ScrollToFixed', function() {
|
495
|
+
spacer.height(target.height());
|
496
|
+
});
|
497
|
+
|
498
|
+
target.bind('scroll.ScrollToFixed', function() {
|
499
|
+
target.trigger('preUnfixed.ScrollToFixed');
|
500
|
+
setUnfixed();
|
501
|
+
target.trigger('unfixed.ScrollToFixed');
|
502
|
+
checkScroll();
|
503
|
+
});
|
504
|
+
|
505
|
+
target.bind('detach.ScrollToFixed', function(ev) {
|
506
|
+
preventDefault(ev);
|
507
|
+
|
508
|
+
target.trigger('preUnfixed.ScrollToFixed');
|
509
|
+
setUnfixed();
|
510
|
+
target.trigger('unfixed.ScrollToFixed');
|
511
|
+
|
512
|
+
$(window).unbind('resize.ScrollToFixed', windowResize);
|
513
|
+
$(window).unbind('scroll.ScrollToFixed', windowScroll);
|
514
|
+
|
515
|
+
target.unbind('.ScrollToFixed');
|
516
|
+
base.$el.removeData('ScrollToFixed');
|
517
|
+
});
|
518
|
+
|
519
|
+
// Reset everything.
|
520
|
+
windowResize();
|
521
|
+
};
|
522
|
+
|
523
|
+
// Initialize the plugin.
|
524
|
+
base.init();
|
525
|
+
};
|
526
|
+
|
527
|
+
// Sets the option defaults.
|
528
|
+
$.ScrollToFixed.defaultOptions = {
|
529
|
+
marginTop : 0,
|
530
|
+
limit : 0,
|
531
|
+
bottom : -1,
|
532
|
+
zIndex : 1000
|
533
|
+
};
|
534
|
+
|
535
|
+
// Returns enhanced elements that will fix to the top of the page when the
|
536
|
+
// page is scrolled.
|
537
|
+
$.fn.scrollToFixed = function(options) {
|
538
|
+
return this.each(function() {
|
539
|
+
(new $.ScrollToFixed(this, options));
|
540
|
+
});
|
541
|
+
};
|
542
|
+
})(jQuery);
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'scrollToFixed_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "scrollToFixed_rails"
|
8
|
+
spec.version = ScrollToFixedRails::VERSION
|
9
|
+
spec.authors = ["Guy Israeli"]
|
10
|
+
spec.description = %q{An asset pipeline compatible wrapper for scrollToFixed.js}
|
11
|
+
spec.summary = %q{9gag like Scroll 'n Float magic made possible with scrollToFixed.js}
|
12
|
+
spec.homepage = "https://github.com/guyisra/scrollToFixed_rails"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_dependency "railties", ">=3.1"
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrollToFixed_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guy Israeli
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: railties
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
description: An asset pipeline compatible wrapper for scrollToFixed.js
|
63
|
+
email:
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- app/assets/javascripts/scrolltofixed.js
|
74
|
+
- lib/scrollToFixed_rails.rb
|
75
|
+
- lib/scrollToFixed_rails/version.rb
|
76
|
+
- scrollToFixed_rails.gemspec
|
77
|
+
homepage: https://github.com/guyisra/scrollToFixed_rails
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: 9gag like Scroll 'n Float magic made possible with scrollToFixed.js
|
102
|
+
test_files: []
|