infinitescrolling-rails 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ tmp
4
4
  spec/support/*/Gemfile.lock
5
5
  spec/support/*/public/javascripts
6
6
  .idea/*
7
+ *.swp
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- infinitescrolling-rails (0.2.1)
4
+ infinitescrolling-rails (0.3.0)
5
5
  jquery-rails
6
6
  railties (> 3.1.0)
7
7
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "infinitescrolling-rails"
5
- s.version = "0.2.1"
5
+ s.version = "0.3.0"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Leif Bladt"]
8
8
  s.email = ["leif.bladt@gmx.de"]
@@ -1,37 +1,51 @@
1
1
  (function($){
2
- var my = {
3
- marginThreshold: 20,
2
+ function IS(loadCallback, target) {
3
+ var my = {
4
+ loadCallback: loadCallback,
5
+ target : target,
6
+ marginThreshold: 20,
7
+ delay: 250,
8
+ hasScrolled: false,
4
9
 
5
- delay: 250,
10
+ callback: function(){
11
+ if (!my.hasScrolled){
12
+ my.hasScrolled = true;
13
+ setTimeout(my.checkScroll, my.delay);
14
+ }
15
+ },
6
16
 
7
- hasScrolled: false,
8
-
9
- callback: function(){
10
- if (!my.hasScrolled){
11
- my.hasScrolled = true;
12
- setTimeout(my.checkScroll, my.delay);
13
- }
14
- },
17
+ checkScroll: function() {
18
+ my.hasScrolled = false;
19
+ if (my.lowEnough()) {
20
+ my.loadCallback();
21
+ }
22
+ },
15
23
 
16
- checkScroll: function() {
17
- my.hasScrolled = false;
18
- if (my.lowEnough()) {
19
- my.loadCallback();
24
+ lowEnough: function() {
25
+ if (this.target[0] === window || this.target[0] === document) {
26
+ var pageHeight = $(document).height();
27
+ var viewportHeight = $(window).height();
28
+ var scrollHeight = $(document).scrollTop();
29
+ return pageHeight - viewportHeight - scrollHeight < my.marginThreshold;
30
+ } else {
31
+ var pageHeight = $(this.target).find('[data-infinite-scrolling]').height();
32
+ var viewportHeight = $(this.target).height();
33
+ var scrollHeight = $(this.target).scrollTop();
34
+ return pageHeight - viewportHeight - scrollHeight < my.marginThreshold;
35
+ }
20
36
  }
21
- },
37
+ }
22
38
 
23
- lowEnough: function() {
24
- var pageHeight = $(document).height();
25
- var viewportHeight = $(window).height();
26
- var scrollHeight = $(document).scrollTop();
27
- return pageHeight - viewportHeight - scrollHeight < my.marginThreshold;
39
+ IS.prototype.callback = function() {
40
+ my.callback();
28
41
  }
29
42
  };
30
43
 
31
44
  $.fn.infiniteScrolling = function(loadCallback){
32
- my.loadCallback = loadCallback;
33
- this.bind('scroll', my.callback);
34
- this.bind('resize', my.callback);
45
+ var is = new IS(loadCallback, this);
46
+
47
+ this.on('scroll', is.callback);
48
+ this.on('resize', is.callback);
35
49
  return this;
36
50
  };
37
51
  })(jQuery);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infinitescrolling-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-23 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &2157551920 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>'
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157551920
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: jquery-rails
27
- requirement: &2157551500 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2157551500
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: bundler
38
- requirement: &2156380500 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '1.0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2156380500
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
47
62
  description: This gem provides the infinite scrolling jQuery plugin for your Rails
48
63
  3.1 application.
49
64
  email:
@@ -76,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
91
  version: '0'
77
92
  segments:
78
93
  - 0
79
- hash: 4442615722422747075
94
+ hash: -210072818456481541
80
95
  required_rubygems_version: !ruby/object:Gem::Requirement
81
96
  none: false
82
97
  requirements:
@@ -85,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
100
  version: 1.3.6
86
101
  requirements: []
87
102
  rubyforge_project:
88
- rubygems_version: 1.8.15
103
+ rubygems_version: 1.8.24
89
104
  signing_key:
90
105
  specification_version: 3
91
106
  summary: Use the infinite scrolling jQuery plugin with Rails 3.1