jquery-turbolinks 1.0.0.rc → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/Rakefile +10 -4
- data/jquery-turbolinks.gemspec +1 -2
- data/lib/jquery-turbolinks/version.rb +1 -1
- data/package.json +1 -1
- data/spec/jquery.turbolinks_spec.coffee +57 -4
- data/src/jquery.turbolinks.coffee +23 -4
- data/vendor/assets/javascripts/jquery.turbolinks.js +19 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -32,10 +32,26 @@ If you want to change it use `$.setReadyEvent` function:
|
|
32
32
|
$.setReadyEvent('page:change');
|
33
33
|
```
|
34
34
|
|
35
|
+
## `$.setFetchEvent`
|
36
|
+
|
37
|
+
By default right after trigger `page:fetch` `$.isReady` is set to false. And after `page:load` is set to true.
|
38
|
+
|
39
|
+
If you want to change default behaviour you can use `$.setFetchEvent`:
|
40
|
+
|
41
|
+
``` js
|
42
|
+
$.setReadyEvent('custom_loading_event');
|
43
|
+
```
|
44
|
+
|
35
45
|
# Changelog
|
36
46
|
|
37
47
|
This project uses [Semantic Versioning](http://semver.org/) for release numbering.
|
38
48
|
|
49
|
+
## 1.0.0-rc1 (November 28, 2012)
|
50
|
+
|
51
|
+
* Set $.isReady to false after `page:fetch` [#6](https://github.com/kossnocorp/jquery.turbolinks/issues/6);
|
52
|
+
* add `$.setFetchEvent` function;
|
53
|
+
* remove all delegated events after trigger fetch event [#8](https://github.com/kossnocorp/jquery.turbolinks/issues/8);
|
54
|
+
|
39
55
|
## 1.0.0-rc (November 8, 2012)
|
40
56
|
|
41
57
|
* Add turbolinks as dependency (kudos to [@gbchaosmaster](https://github.com/gbchaosmaster));
|
data/Rakefile
CHANGED
@@ -4,15 +4,21 @@ require 'talks'
|
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
6
6
|
require 'jquery-turbolinks/version'
|
7
|
-
|
8
|
-
namespace :
|
9
|
-
task :
|
7
|
+
|
8
|
+
namespace :release do
|
9
|
+
task :build_gem do
|
10
10
|
system 'gem build jquery-turbolinks.gemspec'
|
11
11
|
end
|
12
12
|
|
13
|
-
task
|
13
|
+
task gem: :build_gem do
|
14
14
|
system "gem push jquery-turbolinks-#{JqueryTurbolinks::VERSION}.gem"
|
15
15
|
end
|
16
|
+
|
17
|
+
task :npm do
|
18
|
+
system 'npm publish'
|
19
|
+
end
|
20
|
+
|
21
|
+
task all: [:gem, :npm]
|
16
22
|
end
|
17
23
|
|
18
24
|
namespace :js do
|
data/jquery-turbolinks.gemspec
CHANGED
@@ -9,11 +9,10 @@ Gem::Specification.new do |gem|
|
|
9
9
|
|
10
10
|
gem.authors = ['Sasha Koss']
|
11
11
|
gem.email = 'koss@nocorp.me'
|
12
|
-
gem.date = '2012-10-03'
|
13
12
|
|
14
13
|
gem.description = 'jQuery plugin for drop-in fix binded events problem caused by Turbolinks'
|
15
14
|
gem.summary = 'jQuery plugin for drop-in fix binded events problem caused by Turbolinks'
|
16
|
-
gem.homepage = 'https://github.com/kossnocorp/jquery
|
15
|
+
gem.homepage = 'https://github.com/kossnocorp/jquery.turbolinks'
|
17
16
|
|
18
17
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
18
|
gem.files = `git ls-files`.split("\n")
|
data/package.json
CHANGED
@@ -13,6 +13,10 @@ $ = require('jquery')
|
|
13
13
|
chai.should()
|
14
14
|
chai.use(sinonChai)
|
15
15
|
|
16
|
+
getUniqId = do ->
|
17
|
+
counter = 0
|
18
|
+
-> 'id_' + (counter += 1)
|
19
|
+
|
16
20
|
describe '$ Turbolinks', ->
|
17
21
|
|
18
22
|
callback1 = callback2 = null
|
@@ -20,6 +24,8 @@ describe '$ Turbolinks', ->
|
|
20
24
|
describe "DOM isn't ready", ->
|
21
25
|
|
22
26
|
beforeEach ->
|
27
|
+
$.setReadyEvent('page:load')
|
28
|
+
$.setFetchEvent('page:fetch')
|
23
29
|
$.isReady = false
|
24
30
|
|
25
31
|
$(callback1 = sinon.spy())
|
@@ -40,8 +46,30 @@ describe '$ Turbolinks', ->
|
|
40
46
|
|
41
47
|
callback1.should.have.been.calledWith($)
|
42
48
|
|
49
|
+
it '''
|
50
|
+
should remove all events delegated to
|
51
|
+
document after trigger fetch
|
52
|
+
''', ->
|
53
|
+
id = getUniqId()
|
54
|
+
selector = '#' + id
|
55
|
+
addEl = ->
|
56
|
+
$('body').empty()
|
57
|
+
$('<div>').attr(id: id).appendTo('body')
|
58
|
+
|
59
|
+
addEl()
|
60
|
+
$(document).on('event_name', selector, callback1)
|
61
|
+
$(selector).trigger('event_name')
|
62
|
+
$(document).trigger('page:fetch')
|
63
|
+
addEl()
|
64
|
+
$(selector).trigger('event_name')
|
65
|
+
callback1.should.have.been.calledOnce
|
66
|
+
|
43
67
|
describe '$.setReadyEvent', ->
|
44
68
|
|
69
|
+
beforeEach ->
|
70
|
+
$.setReadyEvent('page:load')
|
71
|
+
$.setFetchEvent('page:fetch')
|
72
|
+
|
45
73
|
it 'should unbind default (page:load) event', ->
|
46
74
|
$.setReadyEvent('random_event_name')
|
47
75
|
|
@@ -60,14 +88,39 @@ describe '$ Turbolinks', ->
|
|
60
88
|
callback1.should.have.been.calledOnce
|
61
89
|
callback2.should.have.been.calledOnce
|
62
90
|
|
63
|
-
|
91
|
+
describe '$.setFetchEvent', ->
|
92
|
+
|
93
|
+
beforeEach ->
|
94
|
+
$.setReadyEvent('page:load')
|
95
|
+
$.setFetchEvent('page:fetch')
|
96
|
+
$.isReady = true
|
97
|
+
|
98
|
+
it 'should unbind default (page:fetch) event', ->
|
99
|
+
$.setFetchEvent('random_event_name')
|
100
|
+
$(document).trigger('page:fetch')
|
101
|
+
$.isReady.should.to.be.true
|
102
|
+
|
103
|
+
it 'should bind passed fetch event', ->
|
104
|
+
$.setFetchEvent('page:loading')
|
105
|
+
$(document).trigger('page:loading')
|
106
|
+
$.isReady.should.to.be.false
|
107
|
+
|
108
|
+
describe 'DOM is ready', ->
|
64
109
|
|
65
110
|
beforeEach ->
|
111
|
+
$.setReadyEvent('page:load')
|
112
|
+
$.setFetchEvent('page:fetch')
|
66
113
|
$.isReady = true
|
67
114
|
|
115
|
+
it 'should call trigger right after add to waiting list', ->
|
116
|
+
$(callback = sinon.spy())
|
117
|
+
callback.should.have.been.calledOnce
|
118
|
+
|
119
|
+
it 'should not call trigger after page:fetch and before page:load', ->
|
120
|
+
$(document).trigger('page:fetch')
|
68
121
|
$(callback1 = sinon.spy())
|
69
|
-
|
122
|
+
callback1.should.have.not.been.called
|
70
123
|
|
71
|
-
|
72
|
-
|
124
|
+
$(document).trigger('page:load')
|
125
|
+
$(callback2 = sinon.spy())
|
73
126
|
callback2.should.have.been.calledOnce
|
@@ -1,5 +1,5 @@
|
|
1
1
|
###
|
2
|
-
jquery.turbolinks.js ~ v1.0.0-
|
2
|
+
jquery.turbolinks.js ~ v1.0.0-rc1 ~ https://github.com/kossnocorp/jquery.turbolinks
|
3
3
|
|
4
4
|
jQuery plugin for drop-in fix binded events problem caused by Turbolinks
|
5
5
|
|
@@ -17,6 +17,16 @@ callbacks = []
|
|
17
17
|
ready = ->
|
18
18
|
callback($) for callback in callbacks
|
19
19
|
|
20
|
+
# Turbolinks ready event
|
21
|
+
turbolinksReady = ->
|
22
|
+
$.isReady = true
|
23
|
+
ready()
|
24
|
+
|
25
|
+
# Fetch event handler
|
26
|
+
fetch = ->
|
27
|
+
$(document).off(undefined, '**')
|
28
|
+
$.isReady = false
|
29
|
+
|
20
30
|
# Bind `ready` to DOM ready event
|
21
31
|
$(ready)
|
22
32
|
|
@@ -28,8 +38,17 @@ $.fn.ready = (callback) ->
|
|
28
38
|
# Bind ready to passed event
|
29
39
|
$.setReadyEvent = (event) ->
|
30
40
|
$(document)
|
31
|
-
.off('.turbolinks')
|
32
|
-
.on(event + '.turbolinks',
|
41
|
+
.off('.turbolinks-ready')
|
42
|
+
.on(event + '.turbolinks-ready', turbolinksReady)
|
33
43
|
|
34
|
-
# Bind
|
44
|
+
# Bind fetch event
|
45
|
+
$.setFetchEvent = (event) ->
|
46
|
+
$(document)
|
47
|
+
.off('.turbolinks-fetch')
|
48
|
+
.on(event + '.turbolinks-fetch', fetch)
|
49
|
+
|
50
|
+
# Bind `ready` to Tubolinks page:load
|
35
51
|
$.setReadyEvent('page:load')
|
52
|
+
|
53
|
+
# Bind fetch to Turbolinks page:fetch
|
54
|
+
$.setFetchEvent('page:fetch')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// Generated by CoffeeScript 1.3.3
|
2
2
|
|
3
3
|
/*
|
4
|
-
jquery.turbolinks.js ~ v1.0.0-
|
4
|
+
jquery.turbolinks.js ~ v1.0.0-rc1 ~ https://github.com/kossnocorp/jquery.turbolinks
|
5
5
|
|
6
6
|
jQuery plugin for drop-in fix binded events problem caused by Turbolinks
|
7
7
|
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
(function() {
|
15
|
-
var $, callbacks, ready;
|
15
|
+
var $, callbacks, fetch, ready, turbolinksReady;
|
16
16
|
|
17
17
|
$ = (typeof require === "function" ? require('jquery') : void 0) || window.jQuery;
|
18
18
|
|
@@ -28,6 +28,16 @@
|
|
28
28
|
return _results;
|
29
29
|
};
|
30
30
|
|
31
|
+
turbolinksReady = function() {
|
32
|
+
$.isReady = true;
|
33
|
+
return ready();
|
34
|
+
};
|
35
|
+
|
36
|
+
fetch = function() {
|
37
|
+
$(document).off(void 0, '**');
|
38
|
+
return $.isReady = false;
|
39
|
+
};
|
40
|
+
|
31
41
|
$(ready);
|
32
42
|
|
33
43
|
$.fn.ready = function(callback) {
|
@@ -38,9 +48,15 @@
|
|
38
48
|
};
|
39
49
|
|
40
50
|
$.setReadyEvent = function(event) {
|
41
|
-
return $(document).off('.turbolinks').on(event + '.turbolinks',
|
51
|
+
return $(document).off('.turbolinks-ready').on(event + '.turbolinks-ready', turbolinksReady);
|
52
|
+
};
|
53
|
+
|
54
|
+
$.setFetchEvent = function(event) {
|
55
|
+
return $(document).off('.turbolinks-fetch').on(event + '.turbolinks-fetch', fetch);
|
42
56
|
};
|
43
57
|
|
44
58
|
$.setReadyEvent('page:load');
|
45
59
|
|
60
|
+
$.setFetchEvent('page:fetch');
|
61
|
+
|
46
62
|
}).call(this);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-turbolinks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -63,7 +63,7 @@ files:
|
|
63
63
|
- spec/jquery.turbolinks_spec.coffee
|
64
64
|
- src/jquery.turbolinks.coffee
|
65
65
|
- vendor/assets/javascripts/jquery.turbolinks.js
|
66
|
-
homepage: https://github.com/kossnocorp/jquery
|
66
|
+
homepage: https://github.com/kossnocorp/jquery.turbolinks
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
69
|
post_install_message:
|