onScreen-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in onScreen-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 producao02
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 @@
1
+ # onScreen-rails
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,262 @@
1
+ (function($) {
2
+
3
+ $.fn.onScreen = function(options) {
4
+
5
+ var params = {
6
+ container: window,
7
+ direction: 'vertical',
8
+ toggleClass: null,
9
+ doIn: null,
10
+ doOut: null,
11
+ tolerance: 0,
12
+ throttle: null,
13
+ lazyAttr: null,
14
+ lazyPlaceholder: 'data:image/gif;base64,R0lGODlhEAAFAIAAAP///////yH/C05FVFNDQVBFMi4wAwE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PVm9kGWKcEQxkkACH5BAkJAAIALAAAAAAQAAUAgfT29Pz6/P///wAAAAIRlI8SAZsPYnuJMUCRnNksWwAAOw==',
15
+ debug: false
16
+ };
17
+
18
+ if (options !== 'remove') {
19
+ $.extend(params, options);
20
+ }
21
+
22
+ return this.each(function() {
23
+
24
+ var self = this;
25
+ var isOnScreen = false; // Initialize boolean
26
+ var scrollTop; // Initialize Vertical Scroll Position
27
+ var scrollLeft; // Initialize Horizontal Scroll Position
28
+ var $el = $(this); // Matched element
29
+
30
+ // Initialize Viewport dimensions
31
+ var $container;
32
+ var containerHeight;
33
+ var containerWidth;
34
+ var containerBottom;
35
+ var containerRight;
36
+
37
+ // Initialize element dimensions & position
38
+ var elHeight;
39
+ var elWidth;
40
+ var elTop;
41
+ var elLeft;
42
+
43
+ // Checks if params.container is the Window Object
44
+ var containerIsWindow = $.isWindow(params.container);
45
+
46
+ // Remove bindings from onScreen container
47
+ function remove() {
48
+ $(self).off('scroll.onScreen resize.onScreen');
49
+ $(window).off('resize.onScreen');
50
+ };
51
+
52
+ function verticalIn() {
53
+ if (containerIsWindow) {
54
+ return elTop < containerBottom - params.tolerance &&
55
+ scrollTop < (elTop + elHeight) - params.tolerance;
56
+ } else {
57
+ return elTop < containerHeight - params.tolerance &&
58
+ elTop > (-elHeight) + params.tolerance;
59
+ }
60
+ }
61
+
62
+ function verticalOut() {
63
+ if (containerIsWindow) {
64
+ return elTop + (elHeight - params.tolerance) < scrollTop ||
65
+ elTop > containerBottom - params.tolerance;
66
+ } else {
67
+ return elTop > containerHeight - params.tolerance ||
68
+ -elHeight + params.tolerance > elTop;
69
+ }
70
+ }
71
+
72
+ function horizontalIn() {
73
+ if (containerIsWindow) {
74
+ return elLeft < containerRight - params.tolerance &&
75
+ scrollLeft < (elLeft + elWidth) - params.tolerance;
76
+ } else {
77
+ return elLeft < containerWidth - params.tolerance &&
78
+ elLeft > (-elWidth) + params.tolerance;
79
+ }
80
+ }
81
+
82
+ function horizontalOut() {
83
+ if (containerIsWindow) {
84
+ return elLeft + (elWidth - params.tolerance) < scrollLeft ||
85
+ elLeft > containerRight - params.tolerance;
86
+ } else {
87
+ return elLeft > containerWidth - params.tolerance ||
88
+ -elWidth + params.tolerance > elLeft;
89
+ }
90
+ }
91
+
92
+ function directionIn() {
93
+ if (isOnScreen) {
94
+ return false;
95
+ }
96
+
97
+ if (params.direction === 'horizontal') {
98
+ return horizontalIn();
99
+ } else {
100
+ return verticalIn();
101
+ }
102
+ }
103
+
104
+ function directionOut() {
105
+ if (!isOnScreen) {
106
+ return false;
107
+ }
108
+
109
+ if (params.direction === 'horizontal') {
110
+ return horizontalOut();
111
+ } else {
112
+ return verticalOut();
113
+ }
114
+ }
115
+
116
+ function throttle(fn, timeout, ctx) {
117
+ var timer, args, needInvoke;
118
+ return function() {
119
+ args = arguments;
120
+ needInvoke = true;
121
+ ctx = ctx || this;
122
+ if (!timer) {
123
+ (function() {
124
+ if (needInvoke) {
125
+ fn.apply(ctx, args);
126
+ needInvoke = false;
127
+ timer = setTimeout(arguments.callee, timeout);
128
+ } else {
129
+ timer = null;
130
+ }
131
+ })();
132
+ }
133
+
134
+ };
135
+
136
+ }
137
+
138
+ if (options === 'remove') {
139
+ remove();
140
+ return;
141
+ }
142
+
143
+ var checkPos = function() {
144
+ // Make container relative
145
+ if (!containerIsWindow && $(params.container).css('position') === 'static') {
146
+ $(params.container).css('position', 'relative');
147
+ }
148
+
149
+ // Update Viewport dimensions
150
+ $container = $(params.container);
151
+ containerHeight = $container.height();
152
+ containerWidth = $container.width();
153
+ containerBottom = $container.scrollTop() + containerHeight;
154
+ containerRight = $container.scrollLeft() + containerWidth;
155
+
156
+ // Update element dimensions & position
157
+ elHeight = $el.outerHeight(true);
158
+ elWidth = $el.outerWidth(true);
159
+
160
+ if (containerIsWindow) {
161
+ var offset = $el.offset();
162
+ elTop = offset.top;
163
+ elLeft = offset.left;
164
+ } else {
165
+ var position = $el.position();
166
+ elTop = position.top;
167
+ elLeft = position.left;
168
+ }
169
+
170
+ // Update scroll position
171
+ scrollTop = $container.scrollTop();
172
+ scrollLeft = $container.scrollLeft();
173
+
174
+ // This will spam A LOT of messages in your console
175
+ if (params.debug) {
176
+ console.log(
177
+ 'Container: ' + params.container + '\n' +
178
+ 'Width: ' + containerHeight + '\n' +
179
+ 'Height: ' + containerWidth + '\n' +
180
+ 'Bottom: ' + containerBottom + '\n' +
181
+ 'Right: ' + containerRight
182
+ );
183
+ console.log(
184
+ 'Matched element: ' + ($el.attr('class') !== undefined ? $el.prop('tagName').toLowerCase() + '.' + $el.attr('class') : $el.prop('tagName').toLowerCase()) + '\n' +
185
+ 'Left: ' + elLeft + '\n' +
186
+ 'Top: ' + elTop + '\n' +
187
+ 'Width: ' + elWidth + '\n' +
188
+ 'Height: ' + elHeight
189
+ );
190
+ }
191
+
192
+ if (directionIn()) {
193
+ if (params.toggleClass) {
194
+ $el.addClass(params.toggleClass);
195
+ }
196
+ if ($.isFunction(params.doIn)) {
197
+ params.doIn.call($el[0]);
198
+ }
199
+ if (params.lazyAttr && $el.prop('tagName') === 'IMG') {
200
+ var lazyImg = $el.attr(params.lazyAttr);
201
+ if (lazyImg !== $el.prop('src')) {
202
+ $el.css({
203
+ background: 'url(' + params.lazyPlaceholder + ') 50% 50% no-repeat',
204
+ minHeight: '5px',
205
+ minWidth: '16px'
206
+ });
207
+
208
+ $el.prop('src', lazyImg).load(function() {
209
+ $(this).css({
210
+ background: 'none'
211
+ });
212
+ });
213
+ }
214
+ }
215
+ isOnScreen = true;
216
+ } else if (directionOut()) {
217
+ if (params.toggleClass) {
218
+ $el.removeClass(params.toggleClass);
219
+ }
220
+ if ($.isFunction(params.doOut)) {
221
+ params.doOut.call($el[0]);
222
+ }
223
+ isOnScreen = false;
224
+ }
225
+ };
226
+
227
+ if (window.location.hash) {
228
+ throttle(checkPos, 50);
229
+ } else {
230
+ checkPos();
231
+ }
232
+
233
+ if (params.throttle) {
234
+ checkPos = throttle(checkPos, params.throttle);
235
+ }
236
+
237
+ // Attach checkPos
238
+ $(params.container).on('scroll.onScreen resize.onScreen', checkPos);
239
+
240
+ // Since <div>s don't have a resize event, we have
241
+ // to attach checkPos to the window object as well
242
+ if (!containerIsWindow) {
243
+ $(window).on('resize.onScreen', checkPos);
244
+ }
245
+
246
+ // Module support
247
+ if (typeof module === 'object' && module && typeof module.exports === 'object') {
248
+ // Node.js module pattern
249
+ module.exports = jQuery;
250
+ } else {
251
+ // AMD
252
+ if (typeof define === 'function' && define.amd) {
253
+ define('jquery-onscreen', [], function() {
254
+ return jQuery;
255
+ });
256
+ }
257
+ }
258
+
259
+ });
260
+ };
261
+
262
+ })(jQuery);
@@ -0,0 +1,15 @@
1
+ /*
2
+ * onScreen 0.0.0
3
+ * Checks if matched elements are inside the viewport.
4
+ * Built on Mon Mar 09 2015 13:11:43
5
+ *
6
+ * Copyright 2015 Silvestre Herrera <silvestre.herrera@gmail.com> and contributors, Licensed under the MIT license:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ *
9
+ * You can find a list of contributors at:
10
+ * https://github.com/silvestreh/onScreen/graphs/contributors
11
+ */
12
+
13
+
14
+ !function(a){a.fn.onScreen=function(b){var c={container:window,direction:"vertical",toggleClass:null,doIn:null,doOut:null,tolerance:0,throttle:null,lazyAttr:null,lazyPlaceholder:"data:image/gif;base64,R0lGODlhEAAFAIAAAP///////yH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCQAAACwAAAAAEAAFAAACCIyPqcvtD00BACH5BAkJAAIALAAAAAAQAAUAgfT29Pz6/P///wAAAAIQTGCiywKPmjxUNhjtMlWrAgAh+QQJCQAFACwAAAAAEAAFAIK8urzc2tzEwsS8vrzc3tz///8AAAAAAAADFEiyUf6wCEBHvLPemIHdTzCMDegkACH5BAkJAAYALAAAAAAQAAUAgoSChLS2tIyKjLy+vIyOjMTCxP///wAAAAMUWCQ09jAaAiqQmFosdeXRUAkBCCUAIfkECQkACAAsAAAAABAABQCDvLq83N7c3Nrc9Pb0xMLE/P78vL68/Pr8////AAAAAAAAAAAAAAAAAAAAAAAAAAAABCEwkCnKGbegvQn4RjGMx8F1HxBi5Il4oEiap2DcVYlpZwQAIfkECQkACAAsAAAAABAABQCDvLq85OLkxMLE9Pb0vL685ObkxMbE/Pr8////AAAAAAAAAAAAAAAAAAAAAAAAAAAABCDwnCGHEcIMxPn4VAGMQNBx0zQEZHkiYNiap5RaBKG9EQAh+QQJCQAJACwAAAAAEAAFAIOEgoTMysyMjozs6uyUlpSMiozMzsyUkpTs7uz///8AAAAAAAAAAAAAAAAAAAAAAAAEGTBJiYgoBM09DfhAwHEeKI4dGKLTIHzCwEUAIfkECQkACAAsAAAAABAABQCDvLq85OLkxMLE9Pb0vL685ObkxMbE/Pr8////AAAAAAAAAAAAAAAAAAAAAAAAAAAABCAQSTmMEGaco8+UBSACwWBqHxKOJYd+q1iaXFoRRMbtEQAh+QQJCQAIACwAAAAAEAAFAIO8urzc3tzc2tz09vTEwsT8/vy8vrz8+vz///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAEIhBJWc6wJZAtJh3gcRBAaXiIZV2kiRbgNZbA6VXiUAhGL0QAIfkECQkABgAsAAAAABAABQCChIKEtLa0jIqMvL68jI6MxMLE////AAAAAxRoumxFgoxGCbiANos145e3DJcQJAAh+QQJCQAFACwAAAAAEAAFAIK8urzc2tzEwsS8vrzc3tz///8AAAAAAAADFFi6XCQwtCmAHbPVm9kGWKcEQxkkACH5BAkJAAIALAAAAAAQAAUAgfT29Pz6/P///wAAAAIRlI8SAZsPYnuJMUCRnNksWwAAOw==",debug:!1};return"remove"!==b&&a.extend(c,b),this.each(function(){function d(){a(w).off("scroll.onScreen resize.onScreen"),a(window).off("resize.onScreen")}function e(){return z?u<q-c.tolerance&&l<u+s-c.tolerance:u<o-c.tolerance&&u>-s+c.tolerance}function f(){return z?u+(s-c.tolerance)<l||u>q-c.tolerance:u>o-c.tolerance||-s+c.tolerance>u}function g(){return z?v<r-c.tolerance&&m<v+t-c.tolerance:v<p-c.tolerance&&v>-t+c.tolerance}function h(){return z?v+(t-c.tolerance)<m||v>r-c.tolerance:v>p-c.tolerance||-t+c.tolerance>v}function i(){return x?!1:"horizontal"===c.direction?g():e()}function j(){return x?"horizontal"===c.direction?h():f():!1}function k(a,b,c){var d,e,f;return function(){e=arguments,f=!0,c=c||this,d||!function(){f?(a.apply(c,e),f=!1,d=setTimeout(arguments.callee,b)):d=null}()}}var l,m,n,o,p,q,r,s,t,u,v,w=this,x=!1,y=a(this),z=a.isWindow(c.container);if("remove"===b)return void d();var A=function(){if(z||"static"!==a(c.container).css("position")||a(c.container).css("position","relative"),n=a(c.container),o=n.height(),p=n.width(),q=n.scrollTop()+o,r=n.scrollLeft()+p,s=y.outerHeight(!0),t=y.outerWidth(!0),z){var b=y.offset();u=b.top,v=b.left}else{var d=y.position();u=d.top,v=d.left}if(l=n.scrollTop(),m=n.scrollLeft(),c.debug,i()){if(c.toggleClass&&y.addClass(c.toggleClass),a.isFunction(c.doIn)&&c.doIn.call(y[0]),c.lazyAttr&&"IMG"===y.prop("tagName")){var e=y.attr(c.lazyAttr);e!==y.prop("src")&&(y.css({background:"url("+c.lazyPlaceholder+") 50% 50% no-repeat",minHeight:"5px",minWidth:"16px"}),y.prop("src",e).load(function(){a(this).css({background:"none"})}))}x=!0}else j()&&(c.toggleClass&&y.removeClass(c.toggleClass),a.isFunction(c.doOut)&&c.doOut.call(y[0]),x=!1)};window.location.hash?k(A,50):A(),c.throttle&&(A=k(A,c.throttle)),a(c.container).on("scroll.onScreen resize.onScreen",A),z||a(window).on("resize.onScreen",A),"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=jQuery:"function"==typeof define&&define.amd&&define("jquery-onscreen",[],function(){return jQuery})})}}(jQuery);
15
+ //# sourceMappingURL=jquery.onscreen.min.js.map
@@ -0,0 +1,8 @@
1
+ require "onScreen-rails/version"
2
+
3
+ module OnScreen
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module OnScreen
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'onScreen-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "onScreen-rails"
8
+ spec.version = OnScreen::Rails::VERSION
9
+ spec.authors = ["TwoWeb"]
10
+ spec.email = ["dev@twoweb.com.br"]
11
+ spec.summary = "gem Jquery OnScreen for rails"
12
+ spec.description = "A jQuery plugin that does stuff to elements when they enter or leave the viewport"
13
+ spec.homepage = "https://github.com/twoweb/onScreen-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onScreen-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TwoWeb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-23 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.7'
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.7'
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: '10.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: '10.0'
46
+ description: A jQuery plugin that does stuff to elements when they enter or leave
47
+ the viewport
48
+ email:
49
+ - dev@twoweb.com.br
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - app/assets/javascripts/jquery.onscreen.js
59
+ - app/assets/javascripts/jquery.onscreen.min.js
60
+ - lib/onScreen-rails.rb
61
+ - lib/onScreen-rails/version.rb
62
+ - onScreen-rails.gemspec
63
+ homepage: https://github.com/twoweb/onScreen-rails
64
+ licenses:
65
+ - MIT
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: gem Jquery OnScreen for rails
88
+ test_files: []