ng-sticky-rails 1.7.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8c39c9ca4dedc3061d9d799a81ec7b93461ea48
4
+ data.tar.gz: abd022c28dd1d3e3c90250ced6bfd6bce6050385
5
+ SHA512:
6
+ metadata.gz: f81ad86a8b2216b6418fffb77026ed2e026848f15913e9373ff1bd23ac95140d5db6cb9a20754607d7f9cd2cf8230e08a76851ce9168243cfeaeb92e4e143eaa
7
+ data.tar.gz: a055c9f20bc21daf30d953e46a50142b00584114803c1628902cf46cc5baf3f7fd70b4cef54a1c083966906d101321b53c553b4c205b105128d8ba2f66d6962e
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ng-sticky-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Fernando Di Bartolo
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.
@@ -0,0 +1,38 @@
1
+ # ng-sticky-rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ng-sticky-rails.svg)](http://badge.fury.io/rb/ng-sticky-rails)
4
+
5
+ ng-sticky-rails wraps the [ngSitcky](https://github.com/d-oliveros/ngSticky) library in a rails engine for simple use with the asset pipeline provided by Rails 3.1 and higher. The gem includes the development (non-minified) source for ease of exploration. The asset pipeline will minify in production.
6
+
7
+ For more info on customizing the library, please refer to the official [doc](https://github.com/d-oliveros/ngSticky)
8
+
9
+ ## Usage
10
+
11
+ Add the following to your gemfile:
12
+
13
+ gem 'ng-sticky-rails'
14
+
15
+ Add the following directive to your Javascript manifest file (application.js):
16
+
17
+ //= require sticky
18
+
19
+ Then, just follow the official [doc](https://github.com/d-oliveros/ngSticky).
20
+
21
+ ```html
22
+ <div sticky> Hey there! </div>
23
+ ```
24
+
25
+ Make sure you include the module on your angular app:
26
+
27
+ ```js
28
+ angular.module('main', ['sticky'])
29
+ ...
30
+ ```
31
+
32
+ ## Versioning
33
+
34
+ ng-sticky-rails 1.7.9 == ngSticky 1.7.9
35
+
36
+ Every attempt is made to mirror the currently shipping ngSticky version number wherever possible.
37
+ The major, minor, and patch version numbers will always represent the ngSticky version. Should a gem
38
+ bug be discovered, a 4th version identifier will be added and incremented.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require "ng-sticky-rails/version"
2
+ require 'ng-sticky-rails/engine' if ::Rails.version >= '3.1'
3
+
4
+ module NgSticky
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module NgSticky
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module NgSticky
2
+ module Rails
3
+ STICKY_VERSION = "1.7.9"
4
+ VERSION = "#{STICKY_VERSION}.0"
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ng-sticky-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["fdibartolo"]
6
+ gem.email = ["fernando.di.bartolo@gmail.com"]
7
+ gem.description = 'Rails engine for d-oliveros/ngSticky: "AngularJS directive to make elements stick when scrolling down"'
8
+ gem.summary = 'Rails engine for d-oliveros/ngSticky'
9
+ gem.homepage = "https://github.com/fdibartolo/ng-sticky-rails"
10
+ gem.licenses = ['MIT']
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "ng-sticky-rails"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = NgSticky::Rails::VERSION
18
+ end
@@ -0,0 +1,249 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ var module = angular.module('sticky', []);
5
+
6
+ // Directive: sticky
7
+ //
8
+ module.directive('sticky', function() {
9
+ return {
10
+ restrict: 'A', // this directive can only be used as an attribute.
11
+ link: linkFn
12
+ };
13
+
14
+ function linkFn($scope, $elem, $attrs) {
15
+ var mediaQuery, stickyClass, bodyClass, elem, $window, $body,
16
+ doc, initialCSS, initialStyle, isPositionFixed, isSticking,
17
+ stickyLine, offset, anchor, prevOffset, matchMedia, usePlaceholder, placeholder;
18
+
19
+ isPositionFixed = false;
20
+ isSticking = false;
21
+
22
+ matchMedia = window.matchMedia;
23
+
24
+ // elements
25
+ $window = angular.element(window);
26
+ $body = angular.element(document.body);
27
+ elem = $elem[0];
28
+ doc = document.documentElement;
29
+
30
+ // attributes
31
+ mediaQuery = $attrs.mediaQuery || false;
32
+ stickyClass = $attrs.stickyClass || '';
33
+ bodyClass = $attrs.bodyClass || '';
34
+
35
+ usePlaceholder = $attrs.useplaceholder == undefined ? false : true;
36
+
37
+ initialStyle = $elem.attr('style');
38
+
39
+ offset = typeof $attrs.offset === 'string' ?
40
+ parseInt($attrs.offset.replace(/px;?/, '')) :
41
+ 0;
42
+
43
+ anchor = typeof $attrs.anchor === 'string' ?
44
+ $attrs.anchor.toLowerCase().trim()
45
+ : 'top';
46
+
47
+ // initial style
48
+ initialCSS = {
49
+ top: $elem.css('top'),
50
+ width: $elem.css('width'),
51
+ position: $elem.css('position'),
52
+ marginTop: $elem.css('margin-top'),
53
+ cssLeft: $elem.css('left')
54
+ };
55
+
56
+ switch (anchor) {
57
+ case 'top':
58
+ case 'bottom':
59
+ break;
60
+ default:
61
+ console.log('Unknown anchor '+anchor+', defaulting to top');
62
+ anchor = 'top';
63
+ break;
64
+ }
65
+
66
+
67
+ // Listeners
68
+ //
69
+ $window.on('scroll', checkIfShouldStick);
70
+ $window.on('resize', $scope.$apply.bind($scope, onResize));
71
+ $scope.$on('$destroy', onDestroy);
72
+
73
+ function onResize() {
74
+ initialCSS.offsetWidth = elem.offsetWidth;
75
+ unstickElement();
76
+ checkIfShouldStick();
77
+
78
+ if(isSticking){
79
+ var parent = window.getComputedStyle(elem.parentElement, null),
80
+ initialOffsetWidth = elem.parentElement.offsetWidth -
81
+ parent.getPropertyValue('padding-right').replace('px', '') -
82
+ parent.getPropertyValue('padding-left').replace('px', '');
83
+
84
+ $elem.css('width', initialOffsetWidth+'px');
85
+ }
86
+ }
87
+
88
+ function onDestroy() {
89
+ $window.off('scroll', checkIfShouldStick);
90
+ $window.off('resize', onResize);
91
+
92
+ if ( bodyClass ) {
93
+ $body.removeClass(bodyClass);
94
+ }
95
+
96
+ if ( placeholder ) {
97
+ placeholder.remove();
98
+ }
99
+ }
100
+
101
+
102
+ // Watcher
103
+ //
104
+ prevOffset = _getTopOffset(elem);
105
+
106
+ $scope.$watch( function() { // triggered on load and on digest cycle
107
+ if ( isSticking ) return prevOffset;
108
+
109
+ prevOffset =
110
+ (anchor === 'top') ?
111
+ _getTopOffset(elem) :
112
+ _getBottomOffset(elem);
113
+
114
+ return prevOffset;
115
+
116
+ }, function(newVal, oldVal) {
117
+ if ( newVal !== oldVal || typeof stickyLine === 'undefined' ) {
118
+ stickyLine = newVal - offset;
119
+ checkIfShouldStick();
120
+ }
121
+ });
122
+
123
+
124
+ // Methods
125
+ //
126
+ function checkIfShouldStick() {
127
+ var scrollTop, shouldStick, scrollBottom, scrolledDistance;
128
+
129
+ if ( mediaQuery && !(matchMedia('('+mediaQuery+')').matches || matchMedia(mediaQuery).matches) )
130
+ return;
131
+
132
+ if ( anchor === 'top' ) {
133
+ scrolledDistance = window.pageYOffset || doc.scrollTop;
134
+ scrollTop = scrolledDistance - (doc.clientTop || 0);
135
+ shouldStick = scrollTop >= stickyLine;
136
+ } else {
137
+ scrollBottom = window.pageYOffset + window.innerHeight;
138
+ shouldStick = scrollBottom <= stickyLine;
139
+ }
140
+
141
+ // Switch the sticky mode if the element crosses the sticky line
142
+ if ( shouldStick && !isSticking )
143
+ stickElement();
144
+
145
+ else if ( !shouldStick && isSticking )
146
+ unstickElement();
147
+ }
148
+
149
+ function stickElement() {
150
+ var rect, absoluteLeft;
151
+
152
+ rect = $elem[0].getBoundingClientRect();
153
+ absoluteLeft = rect.left;
154
+
155
+ initialCSS.offsetWidth = elem.offsetWidth;
156
+
157
+ isSticking = true;
158
+
159
+ if ( bodyClass ) {
160
+ $body.addClass(bodyClass);
161
+ }
162
+
163
+ if ( stickyClass ) {
164
+ $elem.addClass(stickyClass);
165
+ }
166
+
167
+ $elem
168
+ .css('width', elem.offsetWidth+'px')
169
+ .css('position', 'fixed')
170
+ .css(anchor, offset+'px')
171
+ .css('left', absoluteLeft+'px')
172
+ .css('margin-top', 0);
173
+
174
+ if ( anchor === 'bottom' ) {
175
+ $elem.css('margin-bottom', 0);
176
+ }
177
+
178
+ //create placeholder to avoid jump
179
+ if( usePlaceholder ) {
180
+ placeholder = angular.element("<div>");
181
+ var elemntsHeight = $elem.height();
182
+ placeholder.css("height", elemntsHeight + "px");
183
+ $elem.after(placeholder);
184
+ }
185
+ }
186
+
187
+ function unstickElement() {
188
+ $elem.attr('style', $elem.initialStyle);
189
+ isSticking = false;
190
+
191
+ if ( bodyClass ) {
192
+ $body.removeClass(bodyClass);
193
+ }
194
+
195
+ if ( stickyClass ) {
196
+ $elem.removeClass(stickyClass);
197
+ }
198
+
199
+ $elem
200
+ .css('width', '')
201
+ .css('top', initialCSS.top)
202
+ .css('position', initialCSS.position)
203
+ .css('left', initialCSS.cssLeft)
204
+ .css('margin-top', initialCSS.marginTop);
205
+
206
+ if ( placeholder ) {
207
+ placeholder.remove();
208
+ }
209
+ }
210
+
211
+ function _getTopOffset (element) {
212
+ var pixels = 0;
213
+
214
+ if (element.offsetParent) {
215
+ do {
216
+ pixels += element.offsetTop;
217
+ element = element.offsetParent;
218
+ } while (element);
219
+ }
220
+
221
+ return pixels;
222
+ }
223
+
224
+ function _getBottomOffset (element) {
225
+ return element.offsetTop + element.clientHeight;
226
+ }
227
+ }
228
+
229
+ });
230
+
231
+ // Shiv: matchMedia
232
+ //
233
+ window.matchMedia = window.matchMedia || (function() {
234
+ var warning = 'angular-sticky: This browser does not support '+
235
+ 'matchMedia, therefore the minWidth option will not work on '+
236
+ 'this browser. Polyfill matchMedia to fix this issue.';
237
+
238
+ if ( window.console && console.warn ) {
239
+ console.warn(warning);
240
+ }
241
+
242
+ return function() {
243
+ return {
244
+ matches: true
245
+ };
246
+ };
247
+ }());
248
+
249
+ }());
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ng-sticky-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.9.0
5
+ platform: ruby
6
+ authors:
7
+ - fdibartolo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Rails engine for d-oliveros/ngSticky: "AngularJS directive to make elements
14
+ stick when scrolling down"'
15
+ email:
16
+ - fernando.di.bartolo@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/ng-sticky-rails.rb
27
+ - lib/ng-sticky-rails/engine.rb
28
+ - lib/ng-sticky-rails/version.rb
29
+ - ng-sticky-rails.gemspec
30
+ - vendor/assets/javascripts/sticky.js
31
+ homepage: https://github.com/fdibartolo/ng-sticky-rails
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.1.8
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Rails engine for d-oliveros/ngSticky
55
+ test_files: []