headroom-rails 0.0.1
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.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +45 -0
- data/Rakefile +19 -0
- data/lib/headroom-rails.rb +2 -0
- data/lib/headroom/engine.rb +8 -0
- data/lib/headroom/version.rb +5 -0
- data/vendor/assets/javascripts/_headroom.angular.js +2 -0
- data/vendor/assets/javascripts/_headroom.jquery.js +2 -0
- data/vendor/assets/javascripts/angular.headroom.js +33 -0
- data/vendor/assets/javascripts/headroom.js +353 -0
- data/vendor/assets/javascripts/headroom.min.js +7 -0
- data/vendor/assets/javascripts/jQuery.headroom.js +39 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81ebfe8572c51d258f5954e6b403e976246cb798
|
4
|
+
data.tar.gz: 6e86acdd423ddbe1c1b3f122e6b4265381d6d0a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c899ab7bc0b86b6dee869f3d01018fd6778ad9924d9ca25c676ec995dd709ca633a290f9da2e1a022eab41fc33697e05f9079d88b1ad09854d63760225648ca
|
7
|
+
data.tar.gz: b8724a306635265f0f1538eb17d0611cc13adf22b1472a0e54b0891ca0b804ed36e56f90cdbed40c34915669ba83b0fa8aafecd087c1a61ef0e95a73789f5cff
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) Nick Williams (headroom.js)
|
4
|
+
Copyright (c) Brandon Hicks (headroom-rails)
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# headroom-rails
|
2
|
+
|
3
|
+
[Headroom.js](http://wicky.nillia.ms/headroom.js/) is a JS library that makes room on your page, by reacting to the users scroll to hide/display the header.
|
4
|
+
|
5
|
+
License: [MIT License](http://opensource.org/licenses/MIT) (just as headroom.js is)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'headroom-rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install headroom-rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
For CoffeeScript
|
23
|
+
|
24
|
+
(jQuery)
|
25
|
+
#= require _headroom.jquery.js
|
26
|
+
|
27
|
+
(Angular)
|
28
|
+
#= require _headroom.angular.js
|
29
|
+
|
30
|
+
For JavaScript
|
31
|
+
|
32
|
+
(jQuery)
|
33
|
+
//= require '_headroom.jquery'
|
34
|
+
|
35
|
+
(Angular)
|
36
|
+
//= require '_headroom.angular'
|
37
|
+
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/tarellel/headroom-rails/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'bundler/setup'
|
6
|
+
rescue LoadError
|
7
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
8
|
+
end
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
Rake::TestTask.new do |t|
|
14
|
+
t.libs << 'lib'
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
t.verbose = false
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
@@ -0,0 +1,33 @@
|
|
1
|
+
(function(angular) {
|
2
|
+
|
3
|
+
if(!angular) {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
|
7
|
+
///////////////
|
8
|
+
// Directive //
|
9
|
+
///////////////
|
10
|
+
|
11
|
+
angular.module('headroom', []).directive('headroom', function() {
|
12
|
+
return {
|
13
|
+
restrict: 'EA',
|
14
|
+
scope: {
|
15
|
+
tolerance: '=',
|
16
|
+
offset: '=',
|
17
|
+
classes: '='
|
18
|
+
},
|
19
|
+
link: function(scope, element) {
|
20
|
+
var options = {};
|
21
|
+
angular.forEach(Headroom.options, function(value, key) {
|
22
|
+
options[key] = scope[key] || Headroom.options[key];
|
23
|
+
});
|
24
|
+
var headroom = new Headroom(element[0], options);
|
25
|
+
headroom.init();
|
26
|
+
scope.$on('destroy', function() {
|
27
|
+
headroom.destroy();
|
28
|
+
});
|
29
|
+
}
|
30
|
+
};
|
31
|
+
});
|
32
|
+
|
33
|
+
}(window.angular));
|
@@ -0,0 +1,353 @@
|
|
1
|
+
/*!
|
2
|
+
* headroom.js v0.6.0 - Give your page some headroom. Hide your header until you need it
|
3
|
+
* Copyright (c) 2014 Nick Williams - http://wicky.nillia.ms/headroom.js
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
(function(window, document) {
|
8
|
+
|
9
|
+
'use strict';
|
10
|
+
|
11
|
+
/* exported features */
|
12
|
+
|
13
|
+
var features = {
|
14
|
+
bind : !!(function(){}.bind),
|
15
|
+
classList : 'classList' in document.documentElement,
|
16
|
+
rAF : !!(window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame)
|
17
|
+
};
|
18
|
+
window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Handles debouncing of events via requestAnimationFrame
|
22
|
+
* @see http://www.html5rocks.com/en/tutorials/speed/animations/
|
23
|
+
* @param {Function} callback The callback to handle whichever event
|
24
|
+
*/
|
25
|
+
function Debouncer (callback) {
|
26
|
+
this.callback = callback;
|
27
|
+
this.ticking = false;
|
28
|
+
}
|
29
|
+
Debouncer.prototype = {
|
30
|
+
constructor : Debouncer,
|
31
|
+
|
32
|
+
/**
|
33
|
+
* dispatches the event to the supplied callback
|
34
|
+
* @private
|
35
|
+
*/
|
36
|
+
update : function() {
|
37
|
+
this.callback && this.callback();
|
38
|
+
this.ticking = false;
|
39
|
+
},
|
40
|
+
|
41
|
+
/**
|
42
|
+
* ensures events don't get stacked
|
43
|
+
* @private
|
44
|
+
*/
|
45
|
+
requestTick : function() {
|
46
|
+
if(!this.ticking) {
|
47
|
+
requestAnimationFrame(this.rafCallback || (this.rafCallback = this.update.bind(this)));
|
48
|
+
this.ticking = true;
|
49
|
+
}
|
50
|
+
},
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Attach this as the event listeners
|
54
|
+
*/
|
55
|
+
handleEvent : function() {
|
56
|
+
this.requestTick();
|
57
|
+
}
|
58
|
+
};
|
59
|
+
/**
|
60
|
+
* Helper function for extending objects
|
61
|
+
*/
|
62
|
+
function extend (object /*, objectN ... */) {
|
63
|
+
if(arguments.length <= 0) {
|
64
|
+
throw new Error('Missing arguments in extend function');
|
65
|
+
}
|
66
|
+
|
67
|
+
var result = object || {},
|
68
|
+
key,
|
69
|
+
i;
|
70
|
+
|
71
|
+
for (i = 1; i < arguments.length; i++) {
|
72
|
+
var replacement = arguments[i] || {};
|
73
|
+
|
74
|
+
for (key in replacement) {
|
75
|
+
if(typeof result[key] === 'object') {
|
76
|
+
result[key] = extend(result[key], replacement[key]);
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
result[key] = result[key] || replacement[key];
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
return result;
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Helper function for normalizing tolerance option to object format
|
89
|
+
*/
|
90
|
+
function normalizeTolerance (t) {
|
91
|
+
return t === Object(t) ? t : { down : t, up : t };
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* UI enhancement for fixed headers.
|
96
|
+
* Hides header when scrolling down
|
97
|
+
* Shows header when scrolling up
|
98
|
+
* @constructor
|
99
|
+
* @param {DOMElement} elem the header element
|
100
|
+
* @param {Object} options options for the widget
|
101
|
+
*/
|
102
|
+
function Headroom (elem, options) {
|
103
|
+
options = extend(options, Headroom.options);
|
104
|
+
|
105
|
+
this.lastKnownScrollY = 0;
|
106
|
+
this.elem = elem;
|
107
|
+
this.debouncer = new Debouncer(this.update.bind(this));
|
108
|
+
this.tolerance = normalizeTolerance(options.tolerance);
|
109
|
+
this.classes = options.classes;
|
110
|
+
this.offset = options.offset;
|
111
|
+
this.initialised = false;
|
112
|
+
this.onPin = options.onPin;
|
113
|
+
this.onUnpin = options.onUnpin;
|
114
|
+
this.onTop = options.onTop;
|
115
|
+
this.onNotTop = options.onNotTop;
|
116
|
+
}
|
117
|
+
Headroom.prototype = {
|
118
|
+
constructor : Headroom,
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Initialises the widget
|
122
|
+
*/
|
123
|
+
init : function() {
|
124
|
+
if(!Headroom.cutsTheMustard) {
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
|
128
|
+
this.elem.classList.add(this.classes.initial);
|
129
|
+
|
130
|
+
// defer event registration to handle browser
|
131
|
+
// potentially restoring previous scroll position
|
132
|
+
setTimeout(this.attachEvent.bind(this), 100);
|
133
|
+
|
134
|
+
return this;
|
135
|
+
},
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Unattaches events and removes any classes that were added
|
139
|
+
*/
|
140
|
+
destroy : function() {
|
141
|
+
var classes = this.classes;
|
142
|
+
|
143
|
+
this.initialised = false;
|
144
|
+
window.removeEventListener('scroll', this.debouncer, false);
|
145
|
+
this.elem.classList.remove(classes.unpinned, classes.pinned, classes.top, classes.initial);
|
146
|
+
},
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Attaches the scroll event
|
150
|
+
* @private
|
151
|
+
*/
|
152
|
+
attachEvent : function() {
|
153
|
+
if(!this.initialised){
|
154
|
+
this.lastKnownScrollY = this.getScrollY();
|
155
|
+
this.initialised = true;
|
156
|
+
window.addEventListener('scroll', this.debouncer, false);
|
157
|
+
|
158
|
+
this.debouncer.handleEvent();
|
159
|
+
}
|
160
|
+
},
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Unpins the header if it's currently pinned
|
164
|
+
*/
|
165
|
+
unpin : function() {
|
166
|
+
var classList = this.elem.classList,
|
167
|
+
classes = this.classes;
|
168
|
+
|
169
|
+
if(classList.contains(classes.pinned) || !classList.contains(classes.unpinned)) {
|
170
|
+
classList.add(classes.unpinned);
|
171
|
+
classList.remove(classes.pinned);
|
172
|
+
this.onUnpin && this.onUnpin.call(this);
|
173
|
+
}
|
174
|
+
},
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Pins the header if it's currently unpinned
|
178
|
+
*/
|
179
|
+
pin : function() {
|
180
|
+
var classList = this.elem.classList,
|
181
|
+
classes = this.classes;
|
182
|
+
|
183
|
+
if(classList.contains(classes.unpinned)) {
|
184
|
+
classList.remove(classes.unpinned);
|
185
|
+
classList.add(classes.pinned);
|
186
|
+
this.onPin && this.onPin.call(this);
|
187
|
+
}
|
188
|
+
},
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Handles the top states
|
192
|
+
*/
|
193
|
+
top : function() {
|
194
|
+
var classList = this.elem.classList,
|
195
|
+
classes = this.classes;
|
196
|
+
|
197
|
+
if(!classList.contains(classes.top)) {
|
198
|
+
classList.add(classes.top);
|
199
|
+
classList.remove(classes.notTop);
|
200
|
+
this.onTop && this.onTop.call(this);
|
201
|
+
}
|
202
|
+
},
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Handles the not top state
|
206
|
+
*/
|
207
|
+
notTop : function() {
|
208
|
+
var classList = this.elem.classList,
|
209
|
+
classes = this.classes;
|
210
|
+
|
211
|
+
if(!classList.contains(classes.notTop)) {
|
212
|
+
classList.add(classes.notTop);
|
213
|
+
classList.remove(classes.top);
|
214
|
+
this.onNotTop && this.onNotTop.call(this);
|
215
|
+
}
|
216
|
+
},
|
217
|
+
|
218
|
+
/**
|
219
|
+
* Gets the Y scroll position
|
220
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY
|
221
|
+
* @return {Number} pixels the page has scrolled along the Y-axis
|
222
|
+
*/
|
223
|
+
getScrollY : function() {
|
224
|
+
return (window.pageYOffset !== undefined)
|
225
|
+
? window.pageYOffset
|
226
|
+
: (document.documentElement || document.body.parentNode || document.body).scrollTop;
|
227
|
+
},
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Gets the height of the viewport
|
231
|
+
* @see http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript
|
232
|
+
* @return {int} the height of the viewport in pixels
|
233
|
+
*/
|
234
|
+
getViewportHeight : function () {
|
235
|
+
return window.innerHeight
|
236
|
+
|| document.documentElement.clientHeight
|
237
|
+
|| document.body.clientHeight;
|
238
|
+
},
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Gets the height of the document
|
242
|
+
* @see http://james.padolsey.com/javascript/get-document-height-cross-browser/
|
243
|
+
* @return {int} the height of the document in pixels
|
244
|
+
*/
|
245
|
+
getDocumentHeight : function () {
|
246
|
+
var body = document.body,
|
247
|
+
documentElement = document.documentElement;
|
248
|
+
|
249
|
+
return Math.max(
|
250
|
+
body.scrollHeight, documentElement.scrollHeight,
|
251
|
+
body.offsetHeight, documentElement.offsetHeight,
|
252
|
+
body.clientHeight, documentElement.clientHeight
|
253
|
+
);
|
254
|
+
},
|
255
|
+
|
256
|
+
/**
|
257
|
+
* determines if the scroll position is outside of document boundaries
|
258
|
+
* @param {int} currentScrollY the current y scroll position
|
259
|
+
* @return {bool} true if out of bounds, false otherwise
|
260
|
+
*/
|
261
|
+
isOutOfBounds : function (currentScrollY) {
|
262
|
+
var pastTop = currentScrollY < 0,
|
263
|
+
pastBottom = currentScrollY + this.getViewportHeight() > this.getDocumentHeight();
|
264
|
+
|
265
|
+
return pastTop || pastBottom;
|
266
|
+
},
|
267
|
+
|
268
|
+
/**
|
269
|
+
* determines if the tolerance has been exceeded
|
270
|
+
* @param {int} currentScrollY the current scroll y position
|
271
|
+
* @return {bool} true if tolerance exceeded, false otherwise
|
272
|
+
*/
|
273
|
+
toleranceExceeded : function (currentScrollY, direction) {
|
274
|
+
return Math.abs(currentScrollY-this.lastKnownScrollY) >= this.tolerance[direction];
|
275
|
+
},
|
276
|
+
|
277
|
+
/**
|
278
|
+
* determine if it is appropriate to unpin
|
279
|
+
* @param {int} currentScrollY the current y scroll position
|
280
|
+
* @param {bool} toleranceExceeded has the tolerance been exceeded?
|
281
|
+
* @return {bool} true if should unpin, false otherwise
|
282
|
+
*/
|
283
|
+
shouldUnpin : function (currentScrollY, toleranceExceeded) {
|
284
|
+
var scrollingDown = currentScrollY > this.lastKnownScrollY,
|
285
|
+
pastOffset = currentScrollY >= this.offset;
|
286
|
+
|
287
|
+
return scrollingDown && pastOffset && toleranceExceeded;
|
288
|
+
},
|
289
|
+
|
290
|
+
/**
|
291
|
+
* determine if it is appropriate to pin
|
292
|
+
* @param {int} currentScrollY the current y scroll position
|
293
|
+
* @param {bool} toleranceExceeded has the tolerance been exceeded?
|
294
|
+
* @return {bool} true if should pin, false otherwise
|
295
|
+
*/
|
296
|
+
shouldPin : function (currentScrollY, toleranceExceeded) {
|
297
|
+
var scrollingUp = currentScrollY < this.lastKnownScrollY,
|
298
|
+
pastOffset = currentScrollY <= this.offset;
|
299
|
+
|
300
|
+
return (scrollingUp && toleranceExceeded) || pastOffset;
|
301
|
+
},
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Handles updating the state of the widget
|
305
|
+
*/
|
306
|
+
update : function() {
|
307
|
+
var currentScrollY = this.getScrollY(),
|
308
|
+
scrollDirection = currentScrollY > this.lastKnownScrollY ? 'down' : 'up',
|
309
|
+
toleranceExceeded = this.toleranceExceeded(currentScrollY, scrollDirection);
|
310
|
+
|
311
|
+
if(this.isOutOfBounds(currentScrollY)) { // Ignore bouncy scrolling in OSX
|
312
|
+
return;
|
313
|
+
}
|
314
|
+
|
315
|
+
if (currentScrollY <= this.offset ) {
|
316
|
+
this.top();
|
317
|
+
} else {
|
318
|
+
this.notTop();
|
319
|
+
}
|
320
|
+
|
321
|
+
if(this.shouldUnpin(currentScrollY, toleranceExceeded)) {
|
322
|
+
this.unpin();
|
323
|
+
}
|
324
|
+
else if(this.shouldPin(currentScrollY, toleranceExceeded)) {
|
325
|
+
this.pin();
|
326
|
+
}
|
327
|
+
|
328
|
+
this.lastKnownScrollY = currentScrollY;
|
329
|
+
}
|
330
|
+
};
|
331
|
+
/**
|
332
|
+
* Default options
|
333
|
+
* @type {Object}
|
334
|
+
*/
|
335
|
+
Headroom.options = {
|
336
|
+
tolerance : {
|
337
|
+
up : 0,
|
338
|
+
down : 0
|
339
|
+
},
|
340
|
+
offset : 0,
|
341
|
+
classes : {
|
342
|
+
pinned : 'headroom--pinned',
|
343
|
+
unpinned : 'headroom--unpinned',
|
344
|
+
top : 'headroom--top',
|
345
|
+
notTop : 'headroom--not-top',
|
346
|
+
initial : 'headroom'
|
347
|
+
}
|
348
|
+
};
|
349
|
+
Headroom.cutsTheMustard = typeof features !== 'undefined' && features.rAF && features.bind && features.classList;
|
350
|
+
|
351
|
+
window.Headroom = Headroom;
|
352
|
+
|
353
|
+
}(window, document));
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*!
|
2
|
+
* headroom.js v0.6.0 - Give your page some headroom. Hide your header until you need it
|
3
|
+
* Copyright (c) 2014 Nick Williams - http://wicky.nillia.ms/headroom.js
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
!function(a,b){"use strict";function c(a){this.callback=a,this.ticking=!1}function d(a){if(arguments.length<=0)throw new Error("Missing arguments in extend function");var b,c,e=a||{};for(c=1;c<arguments.length;c++){var f=arguments[c]||{};for(b in f)e[b]="object"==typeof e[b]?d(e[b],f[b]):e[b]||f[b]}return e}function e(a){return a===Object(a)?a:{down:a,up:a}}function f(a,b){b=d(b,f.options),this.lastKnownScrollY=0,this.elem=a,this.debouncer=new c(this.update.bind(this)),this.tolerance=e(b.tolerance),this.classes=b.classes,this.offset=b.offset,this.initialised=!1,this.onPin=b.onPin,this.onUnpin=b.onUnpin,this.onTop=b.onTop,this.onNotTop=b.onNotTop}var g={bind:!!function(){}.bind,classList:"classList"in b.documentElement,rAF:!!(a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame)};a.requestAnimationFrame=a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame,c.prototype={constructor:c,update:function(){this.callback&&this.callback(),this.ticking=!1},requestTick:function(){this.ticking||(requestAnimationFrame(this.rafCallback||(this.rafCallback=this.update.bind(this))),this.ticking=!0)},handleEvent:function(){this.requestTick()}},f.prototype={constructor:f,init:function(){return f.cutsTheMustard?(this.elem.classList.add(this.classes.initial),setTimeout(this.attachEvent.bind(this),100),this):void 0},destroy:function(){var b=this.classes;this.initialised=!1,a.removeEventListener("scroll",this.debouncer,!1),this.elem.classList.remove(b.unpinned,b.pinned,b.top,b.initial)},attachEvent:function(){this.initialised||(this.lastKnownScrollY=this.getScrollY(),this.initialised=!0,a.addEventListener("scroll",this.debouncer,!1),this.debouncer.handleEvent())},unpin:function(){var a=this.elem.classList,b=this.classes;(a.contains(b.pinned)||!a.contains(b.unpinned))&&(a.add(b.unpinned),a.remove(b.pinned),this.onUnpin&&this.onUnpin.call(this))},pin:function(){var a=this.elem.classList,b=this.classes;a.contains(b.unpinned)&&(a.remove(b.unpinned),a.add(b.pinned),this.onPin&&this.onPin.call(this))},top:function(){var a=this.elem.classList,b=this.classes;a.contains(b.top)||(a.add(b.top),a.remove(b.notTop),this.onTop&&this.onTop.call(this))},notTop:function(){var a=this.elem.classList,b=this.classes;a.contains(b.notTop)||(a.add(b.notTop),a.remove(b.top),this.onNotTop&&this.onNotTop.call(this))},getScrollY:function(){return void 0!==a.pageYOffset?a.pageYOffset:(b.documentElement||b.body.parentNode||b.body).scrollTop},getViewportHeight:function(){return a.innerHeight||b.documentElement.clientHeight||b.body.clientHeight},getDocumentHeight:function(){var a=b.body,c=b.documentElement;return Math.max(a.scrollHeight,c.scrollHeight,a.offsetHeight,c.offsetHeight,a.clientHeight,c.clientHeight)},isOutOfBounds:function(a){var b=0>a,c=a+this.getViewportHeight()>this.getDocumentHeight();return b||c},toleranceExceeded:function(a,b){return Math.abs(a-this.lastKnownScrollY)>=this.tolerance[b]},shouldUnpin:function(a,b){var c=a>this.lastKnownScrollY,d=a>=this.offset;return c&&d&&b},shouldPin:function(a,b){var c=a<this.lastKnownScrollY,d=a<=this.offset;return c&&b||d},update:function(){var a=this.getScrollY(),b=a>this.lastKnownScrollY?"down":"up",c=this.toleranceExceeded(a,b);this.isOutOfBounds(a)||(a<=this.offset?this.top():this.notTop(),this.shouldUnpin(a,c)?this.unpin():this.shouldPin(a,c)&&this.pin(),this.lastKnownScrollY=a)}},f.options={tolerance:{up:0,down:0},offset:0,classes:{pinned:"headroom--pinned",unpinned:"headroom--unpinned",top:"headroom--top",notTop:"headroom--not-top",initial:"headroom"}},f.cutsTheMustard="undefined"!=typeof g&&g.rAF&&g.bind&&g.classList,a.Headroom=f}(window,document);
|
@@ -0,0 +1,39 @@
|
|
1
|
+
(function($) {
|
2
|
+
|
3
|
+
if(!$) {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
|
7
|
+
////////////
|
8
|
+
// Plugin //
|
9
|
+
////////////
|
10
|
+
|
11
|
+
$.fn.headroom = function(option) {
|
12
|
+
return this.each(function() {
|
13
|
+
var $this = $(this),
|
14
|
+
data = $this.data('headroom'),
|
15
|
+
options = typeof option === 'object' && option;
|
16
|
+
|
17
|
+
options = $.extend(true, {}, Headroom.options, options);
|
18
|
+
|
19
|
+
if (!data) {
|
20
|
+
data = new Headroom(this, options);
|
21
|
+
data.init();
|
22
|
+
$this.data('headroom', data);
|
23
|
+
}
|
24
|
+
if (typeof option === 'string') {
|
25
|
+
data[option]();
|
26
|
+
}
|
27
|
+
});
|
28
|
+
};
|
29
|
+
|
30
|
+
//////////////
|
31
|
+
// Data API //
|
32
|
+
//////////////
|
33
|
+
|
34
|
+
$('[data-headroom]').each(function() {
|
35
|
+
var $this = $(this);
|
36
|
+
$this.headroom($this.data());
|
37
|
+
});
|
38
|
+
|
39
|
+
}(window.Zepto || window.jQuery));
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: headroom-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Hicks
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: headroom-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A lightweight that reacts to your scrolling and hides you header until
|
42
|
+
you need it.
|
43
|
+
email:
|
44
|
+
- tarellel@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/headroom-rails.rb
|
53
|
+
- lib/headroom/engine.rb
|
54
|
+
- lib/headroom/version.rb
|
55
|
+
- vendor/assets/javascripts/_headroom.angular.js
|
56
|
+
- vendor/assets/javascripts/_headroom.jquery.js
|
57
|
+
- vendor/assets/javascripts/angular.headroom.js
|
58
|
+
- vendor/assets/javascripts/headroom.js
|
59
|
+
- vendor/assets/javascripts/headroom.min.js
|
60
|
+
- vendor/assets/javascripts/jQuery.headroom.js
|
61
|
+
homepage: https://github.com/tarellel/headroom-rails
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: headroom.js packaged for the Rails assest pipeline
|
84
|
+
test_files: []
|
85
|
+
has_rdoc:
|