rpageless 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/helpers/pageless_helper.rb +12 -0
- data/lib/rpageless/version.rb +3 -0
- data/lib/rpageless.rb +6 -0
- data/rpageless.gemspec +24 -0
- data/vendor/assets/images/load.gif +0 -0
- data/vendor/assets/images/load1.gif +0 -0
- data/vendor/assets/javascripts/jquery.pageless.js +248 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ratnakar
|
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,29 @@
|
|
1
|
+
# Rpageless
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rpageless'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rpageless
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
def pageless(total_pages, url=nil, container=nil)
|
2
|
+
opts = {
|
3
|
+
:totalPages => total_pages,
|
4
|
+
:url => url,
|
5
|
+
:loaderMsg => 'Loading more pages...',
|
6
|
+
:loaderImage => image_path('load.gif')
|
7
|
+
}
|
8
|
+
|
9
|
+
container && opts[:container] ||= container
|
10
|
+
|
11
|
+
javascript_tag("$('#results').pageless(#{opts.to_json});")
|
12
|
+
end
|
data/lib/rpageless.rb
ADDED
data/rpageless.gemspec
ADDED
@@ -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 'rpageless/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rpageless"
|
8
|
+
spec.version = Rpageless::VERSION
|
9
|
+
spec.authors = ["ratnakar"]
|
10
|
+
spec.email = ["ratnakarrao_nyros@yahoo.com"]
|
11
|
+
spec.description = %q{jquery pageless}
|
12
|
+
spec.summary = %q{jquery pageless}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency "rails", ">= 3.1"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,248 @@
|
|
1
|
+
// =======================================================================
|
2
|
+
// PageLess - endless page
|
3
|
+
//
|
4
|
+
// Pageless is a jQuery plugin.
|
5
|
+
// As you scroll down you see more results coming back at you automatically.
|
6
|
+
// It provides an automatic pagination in an accessible way : if javascript
|
7
|
+
// is disabled your standard pagination is supposed to work.
|
8
|
+
//
|
9
|
+
// Licensed under the MIT:
|
10
|
+
// http://www.opensource.org/licenses/mit-license.php
|
11
|
+
//
|
12
|
+
// Parameters:
|
13
|
+
// currentPage: current page (string or function; e.g. <%= params[:page] %>)
|
14
|
+
// distance: distance to the end of page in px when ajax query is fired
|
15
|
+
// loader: selector of the loader div (ajax activity indicator)
|
16
|
+
// loaderHtml: html code of the div if loader not used
|
17
|
+
// loaderImage: image inside the loader
|
18
|
+
// loaderMsg: displayed ajax message
|
19
|
+
// pagination: selector of the paginator divs.
|
20
|
+
// if javascript is disabled paginator is provided
|
21
|
+
// params: paramaters for the ajax query (hash or function), you can pass auth_token here
|
22
|
+
// totalPages: total number of pages (integer or function)
|
23
|
+
// url: URL used to request more data (string or function)
|
24
|
+
// method: HTML method for call URL, default - get
|
25
|
+
//
|
26
|
+
// Callback Parameters:
|
27
|
+
// scrape: A function to modify the incoming data.
|
28
|
+
// complete: A function to call when a new page has been loaded (optional)
|
29
|
+
// end: A function to call when the last page has been loaded (optional)
|
30
|
+
//
|
31
|
+
// Usage:
|
32
|
+
// $('#results').pageless({ totalPages: 10
|
33
|
+
// , url: '/articles/'
|
34
|
+
// , loaderMsg: 'Loading more results'
|
35
|
+
// });
|
36
|
+
//
|
37
|
+
// Requires: jquery
|
38
|
+
//
|
39
|
+
// Author: Jean-Sébastien Ney (https://github.com/jney)
|
40
|
+
//
|
41
|
+
// Contributors:
|
42
|
+
// Alexander Lang (https://github.com/langalex)
|
43
|
+
// Lukas Rieder (https://github.com/Overbryd)
|
44
|
+
// Kathryn Reeve (https://github.com/BinaryKitten)
|
45
|
+
//
|
46
|
+
// Thanks to:
|
47
|
+
// * codemonky.com/post/34940898
|
48
|
+
// * www.unspace.ca/discover/pageless/
|
49
|
+
// * famspam.com/facebox
|
50
|
+
// =======================================================================
|
51
|
+
|
52
|
+
/*global document:true, jQuery:true, location:true, window:true*/
|
53
|
+
|
54
|
+
(function ($, window) {
|
55
|
+
|
56
|
+
var element;
|
57
|
+
var isLoading = false;
|
58
|
+
var loader;
|
59
|
+
var namespace = '.pageless';
|
60
|
+
var SCROLL = 'scroll' + namespace;
|
61
|
+
var RESIZE = 'resize' + namespace;
|
62
|
+
var settings = {
|
63
|
+
container: window,
|
64
|
+
currentPage: 1,
|
65
|
+
distance: 100,
|
66
|
+
pagination: '.pagination',
|
67
|
+
params: {},
|
68
|
+
url: location.href,
|
69
|
+
loaderImage: "/images/load.gif",
|
70
|
+
method: 'get'
|
71
|
+
};
|
72
|
+
var container;
|
73
|
+
var $container;
|
74
|
+
|
75
|
+
$.pageless = function (opts) {
|
76
|
+
if ($.isFunction(opts)) {
|
77
|
+
opts.call();
|
78
|
+
} else {
|
79
|
+
init(opts);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
$.pagelessReset = function () {
|
84
|
+
settings = {
|
85
|
+
container: window,
|
86
|
+
currentPage: 1,
|
87
|
+
distance: 100,
|
88
|
+
pagination: '.pagination',
|
89
|
+
params: {},
|
90
|
+
url: location.href,
|
91
|
+
loaderImage: "/images/load.gif",
|
92
|
+
method: 'get'
|
93
|
+
};
|
94
|
+
stopListener();
|
95
|
+
// if there is a afterStopListener callback we call it
|
96
|
+
if (settings.end) {
|
97
|
+
settings.end.call();
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
var loaderHtml = function () {
|
102
|
+
return settings.loaderHtml ||
|
103
|
+
'<div id="pageless-loader" style="display:none;text-align:center;width:100%;">' +
|
104
|
+
'<div class="msg" style="color:#e9e9e9;font-size:1em"></div>' +
|
105
|
+
'<img src="' + settings.loaderImage + '" alt="loading more results" style="margin:10px auto" />' +
|
106
|
+
'</div>';
|
107
|
+
};
|
108
|
+
|
109
|
+
// settings params: totalPages
|
110
|
+
function init(opts) {
|
111
|
+
if (settings.inited) {
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
|
115
|
+
settings.inited = true;
|
116
|
+
|
117
|
+
if (opts) {
|
118
|
+
$.extend(settings, opts);
|
119
|
+
}
|
120
|
+
|
121
|
+
container = settings.container;
|
122
|
+
$container = $(container);
|
123
|
+
|
124
|
+
// for accessibility we can keep pagination links
|
125
|
+
// but since we have javascript enabled we remove pagination links
|
126
|
+
if (settings.pagination) {
|
127
|
+
$(settings.pagination).remove();
|
128
|
+
}
|
129
|
+
|
130
|
+
// start the listener
|
131
|
+
startListener();
|
132
|
+
}
|
133
|
+
|
134
|
+
$.fn.pageless = function (opts) {
|
135
|
+
var $el = $(this);
|
136
|
+
var $loader = $(opts.loader, $el);
|
137
|
+
|
138
|
+
init(opts);
|
139
|
+
element = $el;
|
140
|
+
|
141
|
+
// loader element
|
142
|
+
if (opts.loader && $loader.length) {
|
143
|
+
loader = $loader;
|
144
|
+
} else {
|
145
|
+
loader = $(loaderHtml());
|
146
|
+
$el.append(loader);
|
147
|
+
// if we use the default loader, set the message
|
148
|
+
if (!opts.loaderHtml) {
|
149
|
+
$('#pageless-loader .msg').html(opts.loaderMsg).css(opts.msgStyles || {});
|
150
|
+
}
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
//
|
155
|
+
function loading(bool) {
|
156
|
+
isLoading = bool;
|
157
|
+
if (loader) {
|
158
|
+
if (isLoading) {
|
159
|
+
loader.fadeIn('normal');
|
160
|
+
} else {
|
161
|
+
loader.fadeOut('normal');
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
// distance to end of the container
|
167
|
+
function distanceToBottom() {
|
168
|
+
return (container === window)
|
169
|
+
? $(document).height()
|
170
|
+
- $container.scrollTop()
|
171
|
+
- $container.height()
|
172
|
+
: $container[0].scrollHeight
|
173
|
+
- $container.scrollTop()
|
174
|
+
- $container.height();
|
175
|
+
}
|
176
|
+
|
177
|
+
function settingOrFunc(name) {
|
178
|
+
var ret = settings[name];
|
179
|
+
return $.isFunction(settings[name]) ? ret() : ret;
|
180
|
+
}
|
181
|
+
|
182
|
+
function stopListener() {
|
183
|
+
$container.unbind(namespace);
|
184
|
+
}
|
185
|
+
|
186
|
+
// * bind a scroll event
|
187
|
+
// * trigger is once in case of reload
|
188
|
+
function startListener() {
|
189
|
+
$container
|
190
|
+
.bind(SCROLL + ' ' + RESIZE, watch)
|
191
|
+
.trigger(SCROLL);
|
192
|
+
}
|
193
|
+
|
194
|
+
function watch() {
|
195
|
+
var currentPage = settingOrFunc('currentPage');
|
196
|
+
var totalPages = settingOrFunc('totalPages');
|
197
|
+
|
198
|
+
// listener was stopped or we've run out of pages
|
199
|
+
if (totalPages <= currentPage) {
|
200
|
+
if (!$.isFunction(settings.currentPage) && !$.isFunction(settings.totalPages)) {
|
201
|
+
stopListener();
|
202
|
+
// if there is a afterStopListener callback we call it
|
203
|
+
if (settings.end) {
|
204
|
+
settings.end.call();
|
205
|
+
}
|
206
|
+
}
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
|
210
|
+
// if slider past our scroll offset, then fire a request for more data
|
211
|
+
if (!isLoading && (distanceToBottom() < settings.distance)) {
|
212
|
+
var url = settingOrFunc('url');
|
213
|
+
var requestParams = settingOrFunc('params');
|
214
|
+
|
215
|
+
loading(true);
|
216
|
+
// move to next page
|
217
|
+
currentPage++;
|
218
|
+
if (!$.isFunction(settings.currentPage)) {
|
219
|
+
settings.currentPage = currentPage;
|
220
|
+
}
|
221
|
+
|
222
|
+
// set up ajax query params
|
223
|
+
$.extend(requestParams, { page: currentPage });
|
224
|
+
// finally ajax query
|
225
|
+
$.ajax({
|
226
|
+
data: requestParams,
|
227
|
+
dataType: 'html',
|
228
|
+
url: url,
|
229
|
+
method: settings.method,
|
230
|
+
success: function (data) {
|
231
|
+
if ($.isFunction(settings.scrape)) {
|
232
|
+
data = settings.scrape(data);
|
233
|
+
}
|
234
|
+
if (loader) {
|
235
|
+
loader.before(data);
|
236
|
+
} else {
|
237
|
+
element.append(data);
|
238
|
+
}
|
239
|
+
loading(false);
|
240
|
+
// if there is a complete callback we call it
|
241
|
+
if (settings.complete) {
|
242
|
+
settings.complete.call();
|
243
|
+
}
|
244
|
+
}
|
245
|
+
});
|
246
|
+
}
|
247
|
+
}
|
248
|
+
})(jQuery, window);
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpageless
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ratnakar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
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: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: jquery pageless
|
63
|
+
email:
|
64
|
+
- ratnakarrao_nyros@yahoo.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- app/helpers/pageless_helper.rb
|
75
|
+
- lib/rpageless.rb
|
76
|
+
- lib/rpageless/version.rb
|
77
|
+
- rpageless.gemspec
|
78
|
+
- vendor/assets/images/load.gif
|
79
|
+
- vendor/assets/images/load1.gif
|
80
|
+
- vendor/assets/javascripts/jquery.pageless.js
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 65345135
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: 65345135
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.23
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: jquery pageless
|
112
|
+
test_files: []
|