pagesjs 0.0.2 → 0.0.3
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.
- data/ChangeLog +11 -0
- data/README.md +3 -1
- data/vendor/assets/javascripts/pages.js +61 -47
- metadata +7 -5
data/ChangeLog
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
== 0.0.3 (Sergey Muravyov-Apostol)
|
|
2
|
+
* Allow to add listener for all new content.
|
|
3
|
+
* Allow to set animation page options in JS.
|
|
4
|
+
* Cache page options to tag data.
|
|
5
|
+
* Fix gemspec issue with Bundler.
|
|
6
|
+
|
|
7
|
+
== 0.0.2 (Kondraty Ryleyev)
|
|
8
|
+
* Fix Pages.js disabling in onready event.
|
|
9
|
+
|
|
10
|
+
== 0.0.1 (Pavel Pestel)
|
|
11
|
+
* Initial release.
|
data/README.md
CHANGED
|
@@ -57,7 +57,7 @@ For Ruby on Rails you can use gem for Assets Pipeline.
|
|
|
57
57
|
1. Add `pagesjs` gem to `Gemfile`:
|
|
58
58
|
|
|
59
59
|
```ruby
|
|
60
|
-
gem
|
|
60
|
+
gem "pagesjs"
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
2. Install gems:
|
|
@@ -110,6 +110,8 @@ by `selector`:
|
|
|
110
110
|
visible (it is happened when document ready and when URL is changed).
|
|
111
111
|
* `close`: `function ($, $$, page)` which will be called, when page becomes
|
|
112
112
|
hidden (URL changed and another page become to be open).
|
|
113
|
+
* `animation`: `function (prev)` to return animation, depend on previous page.
|
|
114
|
+
For simple solution use `data-page-animation` attribute in page or link tags.
|
|
113
115
|
|
|
114
116
|
Callbacks get three arguments:
|
|
115
117
|
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
window.Pages = {
|
|
34
34
|
|
|
35
35
|
// Is history management disabled.
|
|
36
|
-
disabled:
|
|
36
|
+
disabled: false,
|
|
37
37
|
|
|
38
38
|
// jQuery node for current page.
|
|
39
39
|
//
|
|
@@ -74,14 +74,16 @@
|
|
|
74
74
|
animations: { },
|
|
75
75
|
|
|
76
76
|
// Add description for page with `selector`. Allow options:
|
|
77
|
-
// * `load`:
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
// * `open`:
|
|
81
|
-
//
|
|
82
|
-
// URL is changed).
|
|
77
|
+
// * `load`: `function ($, $$, page)` which is called, when page is loaded
|
|
78
|
+
// (contained in document or loaded after by AJAX).
|
|
79
|
+
// Good place to add events handlers to HTML tags.
|
|
80
|
+
// * `open`: `function ($, $$, page)` which is called, when page become
|
|
81
|
+
// to be visible (called on document ready and when URL is changed).
|
|
83
82
|
// * `close`: `function ($, $$, page)` which is called, when page become
|
|
84
|
-
//
|
|
83
|
+
// to be hidden (URL changed and another page become to be open).
|
|
84
|
+
// * `animation`: `function (prev)` to return animation, depend on
|
|
85
|
+
// previous page. For simple solution use `data-page-animation` attribute
|
|
86
|
+
// in page or link tags.
|
|
85
87
|
//
|
|
86
88
|
// Pages.add('.comments-page', {
|
|
87
89
|
// load: function($, $$, page) {
|
|
@@ -109,18 +111,32 @@
|
|
|
109
111
|
// Pages.add('.comments-page', function($, $$, page) {
|
|
110
112
|
// $$('.pagination').ajaxPagination();
|
|
111
113
|
// });
|
|
114
|
+
//
|
|
115
|
+
// You can set callback to be runned on every content added to DOM
|
|
116
|
+
// (for example, to bind events for controls common for all pages).
|
|
117
|
+
// Just miss `selector`:
|
|
118
|
+
//
|
|
119
|
+
// Pages.add(function($, $$, content) {
|
|
120
|
+
// $$('[rel=submit]').click(function() {
|
|
121
|
+
// $(this).closest('form').submit();
|
|
122
|
+
// });
|
|
123
|
+
// });
|
|
112
124
|
add: function(selector, options) {
|
|
113
|
-
if ( typeof(options) == '
|
|
114
|
-
|
|
125
|
+
if ( typeof(options) == 'undefined' ) {
|
|
126
|
+
this._liveCallbacks.push(selector);
|
|
127
|
+
} else {
|
|
128
|
+
if ( typeof(options) == 'function' ) {
|
|
129
|
+
options = { load: options };
|
|
130
|
+
}
|
|
131
|
+
options.selector = selector;
|
|
132
|
+
this._pages.push(options);
|
|
115
133
|
}
|
|
116
|
-
options.selector = selector;
|
|
117
|
-
this._pages.push(options);
|
|
118
134
|
},
|
|
119
135
|
|
|
120
136
|
// Run Pages.js. It’s called automatically on document ready.
|
|
121
137
|
// It’s used for tests.
|
|
122
138
|
init: function() {
|
|
123
|
-
this.
|
|
139
|
+
this._enlive($(this._document));
|
|
124
140
|
var current = this._findCurrent();
|
|
125
141
|
if ( current.length ) {
|
|
126
142
|
this._setCurrent(current);
|
|
@@ -303,6 +319,9 @@
|
|
|
303
319
|
// Event listeners are already binded.
|
|
304
320
|
_events: false,
|
|
305
321
|
|
|
322
|
+
// Callbacks was setted by `Pages.live`.
|
|
323
|
+
_liveCallbacks: [],
|
|
324
|
+
|
|
306
325
|
// Find first current page.
|
|
307
326
|
_findCurrent: function() {
|
|
308
327
|
return $(this.pagesSelector + ':visible:first', this._document)
|
|
@@ -315,16 +334,22 @@
|
|
|
315
334
|
};
|
|
316
335
|
},
|
|
317
336
|
|
|
318
|
-
// Find pages in new content and trigger load event on them.
|
|
319
|
-
|
|
320
|
-
var
|
|
337
|
+
// Find pages in new content, set caches and trigger load event on them.
|
|
338
|
+
_enlive: function(nodes) {
|
|
339
|
+
var $$ = this._subfind(nodes);
|
|
340
|
+
for (var i = 0; i < this._liveCallbacks.length; i++) {
|
|
341
|
+
this._liveCallbacks[i].call(nodes, $, $$, nodes);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
var page;
|
|
321
345
|
for (var i = 0; i < this._pages.length; i++) {
|
|
322
346
|
page = this._pages[i];
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
347
|
+
var divs = nodes.filter(page.selector);
|
|
348
|
+
divs = divs.add( nodes.find(page.selector) );
|
|
349
|
+
if ( divs.length ) {
|
|
350
|
+
divs.data('page', page);
|
|
351
|
+
if ( page.load ) {
|
|
352
|
+
page.load.call(divs, $, this._subfind(divs), divs);
|
|
328
353
|
}
|
|
329
354
|
}
|
|
330
355
|
}
|
|
@@ -333,32 +358,16 @@
|
|
|
333
358
|
// Find page descriptions for current and next page and fire `close` and
|
|
334
359
|
// `open` events.
|
|
335
360
|
_setCurrent: function(next) {
|
|
336
|
-
var
|
|
337
|
-
if ( current
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if ( current.is(page.selector) ) {
|
|
342
|
-
currentPage = page;
|
|
343
|
-
break
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
for (var i = 0; i < this._pages.length; i++) {
|
|
349
|
-
page = this._pages[i];
|
|
350
|
-
if ( page.open ) {
|
|
351
|
-
if ( next.is(page.selector) ) {
|
|
352
|
-
nextPage = page;
|
|
353
|
-
break
|
|
354
|
-
}
|
|
361
|
+
var current = this.current;
|
|
362
|
+
if ( current ) {
|
|
363
|
+
var currentPage = current.data('page');
|
|
364
|
+
if ( currentPage && currentPage.close ) {
|
|
365
|
+
currentPage.close.call(current, $, this._subfind(current), current);
|
|
355
366
|
}
|
|
356
367
|
}
|
|
357
368
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
if ( nextPage ) {
|
|
369
|
+
var nextPage = next.data('page');
|
|
370
|
+
if ( nextPage && nextPage.open ) {
|
|
362
371
|
nextPage.open.call(next, $, this._subfind(next), next);
|
|
363
372
|
}
|
|
364
373
|
|
|
@@ -384,8 +393,13 @@
|
|
|
384
393
|
|
|
385
394
|
// Open loaded page.
|
|
386
395
|
_openPage: function(page, data) {
|
|
387
|
-
|
|
388
|
-
|
|
396
|
+
var pageData = page.data();
|
|
397
|
+
data = $.extend(pageData, data);
|
|
398
|
+
if ( pageData.page && pageData.page.animation ) {
|
|
399
|
+
var anim = page.data('page').animation(this.current);
|
|
400
|
+
} else {
|
|
401
|
+
var anim = data.pageAnimation || Pages.animation;
|
|
402
|
+
}
|
|
389
403
|
this.animating.wait(function() {
|
|
390
404
|
if ( typeof(data.title) != 'undefined' ) {
|
|
391
405
|
Pages.title(data.title);
|
|
@@ -422,7 +436,7 @@
|
|
|
422
436
|
data.link.trigger('page-loaded', data);
|
|
423
437
|
}
|
|
424
438
|
|
|
425
|
-
Pages.
|
|
439
|
+
Pages._enlive(nodes);
|
|
426
440
|
callback(nodes);
|
|
427
441
|
});
|
|
428
442
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pagesjs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,19 +9,19 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-05-
|
|
12
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: sprockets
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &8204980 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: 2
|
|
21
|
+
version: '2'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *8204980
|
|
25
25
|
description: Pages.js allow you to manage pages JS code and forget about low-level
|
|
26
26
|
History API.
|
|
27
27
|
email:
|
|
@@ -31,11 +31,13 @@ extensions: []
|
|
|
31
31
|
extra_rdoc_files:
|
|
32
32
|
- LICENSE
|
|
33
33
|
- README.md
|
|
34
|
+
- ChangeLog
|
|
34
35
|
files:
|
|
35
36
|
- vendor/assets/javascripts/pages.js
|
|
36
37
|
- lib/pagesjs.rb
|
|
37
38
|
- LICENSE
|
|
38
39
|
- README.md
|
|
40
|
+
- ChangeLog
|
|
39
41
|
homepage: https://github.com/ai/pages.js
|
|
40
42
|
licenses: []
|
|
41
43
|
post_install_message:
|