jquery-turbolinks 1.0.0 → 2.0.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWZlNDExMDMwMjVjZTAzN2EwYTVhMWFjNzIxM2FjNjk0N2JkZDYzNQ==
5
+ data.tar.gz: !binary |-
6
+ ZDgzMzg4YmJiMGI2NGE1ODBhNjYzMDRiZjE5MWYzMGRmNmE4M2UwZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDg3N2QzYmI2Y2I5MjBmNzEyMjAyNzgyZTg4NGRmN2E2NjU3MGIyYmUwNjk4
10
+ NzA0ZjQ0ZmQ3ODEwZTcyNWJjYTlhZTkzNWIyNGE1MjA5MDg5MTdkOTgxMjk0
11
+ NzFlNGQzZGY1MTQ5ZjQ5Y2MyODZhZDA3OTE1Y2RjNGQ0MDBlNzI=
12
+ data.tar.gz: !binary |-
13
+ MDk0NjQwZDk1NDgzODljMmRhYzJhNDNlMmQ3N2QwNDA0ODM1OWM5OTE5NzYz
14
+ MGJhZDQ5NzE2NGRhNTAwMzA0ZDQ4YjdiNmViMmQwMzc1MDkwZDkzNmJjNDhh
15
+ OGQ5MTg0YzYyODVhZDQxMDIyNzU0NzIyNTIzNDZmYzFkMWI4MTg=
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  node_modules
2
2
  *.gem
3
3
  Gemfile.lock
4
+ .ruby-version
@@ -0,0 +1,36 @@
1
+ # Development notes
2
+
3
+ Version bumping
4
+ ---------------
5
+
6
+ Edit the following files:
7
+
8
+ * lib/jquery-turbolinks/version.rb
9
+ * package.json
10
+ * src/jquery.turbolinks.coffee
11
+
12
+ Updating .js files
13
+ ------------------
14
+
15
+ Update the .js files from the source CoffeeScript file using:
16
+
17
+ $ rake js:bulid js:uglify
18
+
19
+ Testing
20
+ -------
21
+
22
+ Simply use npm/mocha:
23
+
24
+ $ npm install
25
+ $ npm test
26
+
27
+ Or:
28
+
29
+ $ rake test
30
+
31
+ Releasing
32
+ ---------
33
+
34
+ Release it into npm/rubygems using:
35
+
36
+ $ rake release
data/README.md CHANGED
@@ -12,41 +12,47 @@ Initially sponsored by [Evil Martians](http://evilmartians.com/).
12
12
 
13
13
  This project is a member of the [OSS Manifesto](http://ossmanifesto.org/).
14
14
 
15
+ ## Important
16
+
17
+ This readme points to the `master` version (v2.0.0) of jQuery Turbolinks. For
18
+ older versions, see [v1.0.0rc2 README][oldreadme].
19
+
15
20
  ## Usage
16
21
 
17
22
  Gemfile:
23
+
18
24
  ``` js
19
25
  gem 'jquery-turbolinks'
20
26
  ```
21
27
 
22
- JavaScript manifest file:
28
+ Add it to your JavaScript manifest file, in this order:
29
+
23
30
  ``` js
31
+ //= require jquery
24
32
  //= require jquery.turbolinks
33
+ //
34
+ // ... your other scripts here ...
35
+ //
36
+ //= require turbolinks
25
37
  ```
26
38
 
27
39
  And it just works!
28
40
 
29
- ## Customization
30
-
31
- ### $.setReadyEvent
41
+ ## API and Customization
32
42
 
33
- By default [ready](https://github.com/kossnocorp/jquery.turbolinks/blob/master/src/jquery.turbolinks.coffee#L17:L18) function is bound to [page:load](https://github.com/rails/turbolinks/#events) event.
43
+ ### $.turbo.use
34
44
 
35
- If you want to change it use `$.setReadyEvent` function:
45
+ By default, jQuery.Turbolinks is bound to [page:load] and [page:fetch]. To use
46
+ different events (say, if you're not using Turbolinks), use:
36
47
 
37
48
  ``` js
38
- $.setReadyEvent('page:change');
49
+ $.turbo.use('pjax:start', 'pjax:end');
39
50
  ```
40
51
 
41
- ### $.setFetchEvent
42
-
43
- By default right after trigger `page:fetch` `$.isReady` is set to false. And after `page:load` is set to true.
52
+ ## $.turbo.isReady
44
53
 
45
- If you want to change default behaviour you can use `$.setFetchEvent`:
46
-
47
- ``` js
48
- $.setReadyEvent('custom_loading_event');
49
- ```
54
+ You can check if the page is ready by checking `$.turbo.isReady`, which will be
55
+ either `true` or `false` depending on whether the page is loading.
50
56
 
51
57
  ## Troubleshooting
52
58
 
@@ -72,6 +78,11 @@ $(document).on('click', 'button', function() { ... })
72
78
 
73
79
  This project uses [Semantic Versioning](http://semver.org/) for release numbering.
74
80
 
81
+ ### 2.0.0 (unreleased - master)
82
+
83
+ * Rewritten, smaller, with a completely new API. This deprecates the old
84
+ `$.setFetchEvent` and `$.setReadyEvent` API.
85
+
75
86
  ### 1.0.0 (April 5, 2013)
76
87
 
77
88
  * Add uglified version.
@@ -112,3 +123,7 @@ Initial idea and code by [@kossnocorp](http://koss.nocorp.me/), with special tha
112
123
  ## License
113
124
 
114
125
  [The MIT License](https://github.com/kossnocorp/jquery.turbolinks/blob/master/LICENSE.md)
126
+
127
+ [page:load]: https://github.com/rails/turbolinks/#events
128
+ [page:fetch]: https://github.com/rails/turbolinks/#events
129
+ [oldreadme]: https://github.com/kossnocorp/jquery.turbolinks/blob/v1.0.0.rc2/README.md
@@ -1,3 +1,3 @@
1
1
  module JqueryTurbolinks
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jquery.turbolinks",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "author": "Sasha Koss <kossnocorp@gmail.com>",
5
5
  "description": "jQuery plugin for drop-in fix binded events problem caused by Turbolinks",
6
6
 
@@ -24,9 +24,7 @@ describe '$ Turbolinks', ->
24
24
  describe "DOM isn't ready", ->
25
25
 
26
26
  beforeEach ->
27
- $.setReadyEvent('page:load')
28
- $.setFetchEvent('page:fetch')
29
- $.isReady = false
27
+ $.turbo.isReady = false
30
28
 
31
29
  $(callback1 = sinon.spy())
32
30
  $(callback2 = sinon.spy())
@@ -41,19 +39,12 @@ describe '$ Turbolinks', ->
41
39
  callback1.should.have.been.calledOnce
42
40
  callback2.should.have.been.calledOnce
43
41
 
44
- it 'should pass jQuery object to callbacks', ->
45
- $(document).trigger('page:load')
46
-
47
- callback1.should.have.been.calledWith($)
48
-
49
- describe '$.setReadyEvent', ->
50
-
42
+ describe '$.turbo.use', ->
51
43
  beforeEach ->
52
- $.setReadyEvent('page:load')
53
- $.setFetchEvent('page:fetch')
44
+ $.turbo.use('page:load', 'page:fetch')
54
45
 
55
46
  it 'should unbind default (page:load) event', ->
56
- $.setReadyEvent('random_event_name')
47
+ $.turbo.use('other1', 'other2')
57
48
 
58
49
  $(document).trigger('page:load')
59
50
 
@@ -61,8 +52,6 @@ describe '$ Turbolinks', ->
61
52
  callback2.should.have.not.been.called
62
53
 
63
54
  it 'should bind ready to passed function', ->
64
- $.setReadyEvent('page:change')
65
-
66
55
  $(document)
67
56
  .trigger('page:load')
68
57
  .trigger('page:change')
@@ -73,26 +62,24 @@ describe '$ Turbolinks', ->
73
62
  describe '$.setFetchEvent', ->
74
63
 
75
64
  beforeEach ->
76
- $.setReadyEvent('page:load')
77
- $.setFetchEvent('page:fetch')
78
- $.isReady = true
65
+ $.turbo.use('page:load', 'page:fetch')
66
+ $.turbo.isReady = true
79
67
 
80
68
  it 'should unbind default (page:fetch) event', ->
81
- $.setFetchEvent('random_event_name')
69
+ $.turbo.use('page:load', 'random_event_name')
82
70
  $(document).trigger('page:fetch')
83
- $.isReady.should.to.be.true
71
+ $.turbo.isReady.should.to.be.true
84
72
 
85
73
  it 'should bind passed fetch event', ->
86
- $.setFetchEvent('page:loading')
74
+ $.turbo.use('page:load', 'page:loading')
87
75
  $(document).trigger('page:loading')
88
- $.isReady.should.to.be.false
76
+ $.turbo.isReady.should.to.be.false
89
77
 
90
78
  describe 'DOM is ready', ->
91
79
 
92
80
  beforeEach ->
93
- $.setReadyEvent('page:load')
94
- $.setFetchEvent('page:fetch')
95
- $.isReady = true
81
+ $.turbo.use('page:load', 'page:fetch')
82
+ $.turbo.isReady = true
96
83
 
97
84
  it 'should call trigger right after add to waiting list', ->
98
85
  $(callback = sinon.spy())
@@ -1,53 +1,48 @@
1
1
  ###
2
- jquery.turbolinks.js ~ v1.0.0 ~ https://github.com/kossnocorp/jquery.turbolinks
2
+ jQuery.Turbolinks ~ https://github.com/kossnocorp/jquery.turbolinks
3
+ jQuery plugin for drop-in fix binded events problem caused by Turbolinks
3
4
 
4
- jQuery plugin for drop-in fix binded events problem caused by Turbolinks
5
-
6
- The MIT License
7
-
8
- Copyright (c) 2012 Sasha Koss
5
+ The MIT License
6
+ Copyright (c) 2012-2013 Sasha Koss & Rico Sta. Cruz
9
7
  ###
10
8
 
11
9
  $ = window.jQuery or require?('jquery')
12
-
13
- # List for store callbacks passed to `$` or `$.ready`
14
- callbacks = []
15
-
16
- # Call each callback in list
17
- ready = ->
18
- callback($) for callback in callbacks
19
-
20
- # Turbolinks ready event
21
- turbolinksReady = ->
22
- $.isReady = true
23
- ready()
24
-
25
- # Fetch event handler
26
- fetch = ->
27
- $.isReady = false
28
-
29
- # Bind `ready` to DOM ready event
30
- $(ready)
31
-
32
- # Store callbacks in list on `$` and `$.ready`
33
- $.fn.ready = (callback) ->
34
- callbacks.push(callback)
35
- callback($) if $.isReady
36
-
37
- # Bind ready to passed event
38
- $.setReadyEvent = (event) ->
39
- $(document)
40
- .off('.turbolinks-ready')
41
- .on(event + '.turbolinks-ready', turbolinksReady)
42
-
43
- # Bind fetch event
44
- $.setFetchEvent = (event) ->
45
- $(document)
46
- .off('.turbolinks-fetch')
47
- .on(event + '.turbolinks-fetch', fetch)
48
-
49
- # Bind `ready` to Tubolinks page:load
50
- $.setReadyEvent('page:load')
51
-
52
- # Bind fetch to Turbolinks page:fetch
53
- $.setFetchEvent('page:fetch')
10
+ $document = $(document)
11
+
12
+ $.turbo =
13
+ version: '2.0.0'
14
+
15
+ isReady: false
16
+
17
+ # Hook onto the events that Turbolinks triggers.
18
+ use: (load, fetch) ->
19
+ $document
20
+ .off('.turbo')
21
+ .on("#{load}.turbo", @onLoad)
22
+ .on("#{fetch}.turbo", @onFetch)
23
+
24
+ addCallback: (callback) ->
25
+ $document.on('turbo:ready', callback)
26
+ callback($) if $.turbo.isReady
27
+
28
+ onLoad: ->
29
+ $.turbo.isReady = true
30
+ $document.trigger('turbo:ready')
31
+
32
+ onFetch: ->
33
+ $.turbo.isReady = false
34
+
35
+ # Registers jQuery.Turbolinks by monkey-patching jQuery's
36
+ # `ready` handler. (Internal)
37
+ #
38
+ # [1] Trigger the stored `ready` events on first load.
39
+ # [2] Override `$(function)` and `$(document).ready(function)` by
40
+ # registering callbacks under a new event called `turbo:ready`.
41
+ #
42
+ register: ->
43
+ $(@onLoad) #[1]
44
+ $.fn.ready = @addCallback #[2]
45
+
46
+ # Use with Turbolinks.
47
+ $.turbo.register()
48
+ $.turbo.use('page:load', 'page:fetch')
@@ -1,61 +1,47 @@
1
- // Generated by CoffeeScript 1.4.0
2
-
1
+ // Generated by CoffeeScript 1.6.3
3
2
  /*
4
- jquery.turbolinks.js ~ v1.0.0 ~ https://github.com/kossnocorp/jquery.turbolinks
5
-
6
- jQuery plugin for drop-in fix binded events problem caused by Turbolinks
3
+ jQuery.Turbolinks ~ https://github.com/kossnocorp/jquery.turbolinks
4
+ jQuery plugin for drop-in fix binded events problem caused by Turbolinks
7
5
 
8
- The MIT License
9
-
10
- Copyright (c) 2012 Sasha Koss
6
+ The MIT License
7
+ Copyright (c) 2012-2013 Sasha Koss & Rico Sta. Cruz
11
8
  */
12
9
 
13
10
 
14
11
  (function() {
15
- var $, callbacks, fetch, ready, turbolinksReady;
12
+ var $, $document;
16
13
 
17
14
  $ = window.jQuery || (typeof require === "function" ? require('jquery') : void 0);
18
15
 
19
- callbacks = [];
20
-
21
- ready = function() {
22
- var callback, _i, _len, _results;
23
- _results = [];
24
- for (_i = 0, _len = callbacks.length; _i < _len; _i++) {
25
- callback = callbacks[_i];
26
- _results.push(callback($));
27
- }
28
- return _results;
29
- };
30
-
31
- turbolinksReady = function() {
32
- $.isReady = true;
33
- return ready();
34
- };
35
-
36
- fetch = function() {
37
- return $.isReady = false;
38
- };
39
-
40
- $(ready);
41
-
42
- $.fn.ready = function(callback) {
43
- callbacks.push(callback);
44
- if ($.isReady) {
45
- return callback($);
16
+ $document = $(document);
17
+
18
+ $.turbo = {
19
+ version: '2.0.0',
20
+ isReady: false,
21
+ use: function(load, fetch) {
22
+ return $document.off('.turbo').on("" + load + ".turbo", this.onLoad).on("" + fetch + ".turbo", this.onFetch);
23
+ },
24
+ addCallback: function(callback) {
25
+ $document.on('turbo:ready', callback);
26
+ if ($.turbo.isReady) {
27
+ return callback($);
28
+ }
29
+ },
30
+ onLoad: function() {
31
+ $.turbo.isReady = true;
32
+ return $document.trigger('turbo:ready');
33
+ },
34
+ onFetch: function() {
35
+ return $.turbo.isReady = false;
36
+ },
37
+ register: function() {
38
+ $(this.onLoad);
39
+ return $.fn.ready = this.addCallback;
46
40
  }
47
41
  };
48
42
 
49
- $.setReadyEvent = function(event) {
50
- return $(document).off('.turbolinks-ready').on(event + '.turbolinks-ready', turbolinksReady);
51
- };
52
-
53
- $.setFetchEvent = function(event) {
54
- return $(document).off('.turbolinks-fetch').on(event + '.turbolinks-fetch', fetch);
55
- };
56
-
57
- $.setReadyEvent('page:load');
43
+ $.turbo.register();
58
44
 
59
- $.setFetchEvent('page:fetch');
45
+ $.turbo.use('page:load', 'page:fetch');
60
46
 
61
47
  }).call(this);
@@ -1 +1 @@
1
- (function(){var e,t,n,r,i;e=window.jQuery||(typeof require=="function"?require("jquery"):void 0),t=[],r=function(){var n,r,i,s;s=[];for(r=0,i=t.length;r<i;r++)n=t[r],s.push(n(e));return s},i=function(){return e.isReady=!0,r()},n=function(){return e.isReady=!1},e(r),e.fn.ready=function(n){t.push(n);if(e.isReady)return n(e)},e.setReadyEvent=function(t){return e(document).off(".turbolinks-ready").on(t+".turbolinks-ready",i)},e.setFetchEvent=function(t){return e(document).off(".turbolinks-fetch").on(t+".turbolinks-fetch",n)},e.setReadyEvent("page:load"),e.setFetchEvent("page:fetch")}).call(this);
1
+ !function(){var r,o;r=window.jQuery||("function"==typeof require?require("jquery"):void 0),o=r(document),r.turbo={version:"2.0.0",isReady:!1,use:function(r,t){return o.off(".turbo").on(""+r+".turbo",this.onLoad).on(""+t+".turbo",this.onFetch)},addCallback:function(t){return o.on("turbo:ready",t),r.turbo.isReady?t(r):void 0},onLoad:function(){return r.turbo.isReady=!0,o.trigger("turbo:ready")},onFetch:function(){return r.turbo.isReady=!1},register:function(){return r(this.onLoad),r.fn.ready=this.addCallback}},r.turbo.register(),r.turbo.use("page:load","page:fetch")}.call(this);
metadata CHANGED
@@ -1,48 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-turbolinks
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.0
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sasha Koss
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2013-08-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
14
+ prerelease: false
15
+ name: railties
15
16
  version_requirements: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ! '>='
18
19
  - !ruby/object:Gem::Version
19
20
  version: 3.1.0
20
- none: false
21
- name: railties
22
- type: :runtime
23
- prerelease: false
24
21
  requirement: !ruby/object:Gem::Requirement
25
22
  requirements:
26
23
  - - ! '>='
27
24
  - !ruby/object:Gem::Version
28
25
  version: 3.1.0
29
- none: false
26
+ type: :runtime
30
27
  - !ruby/object:Gem::Dependency
28
+ prerelease: false
29
+ name: turbolinks
31
30
  version_requirements: !ruby/object:Gem::Requirement
32
31
  requirements:
33
32
  - - ! '>='
34
33
  - !ruby/object:Gem::Version
35
34
  version: '0'
36
- none: false
37
- name: turbolinks
38
- type: :runtime
39
- prerelease: false
40
35
  requirement: !ruby/object:Gem::Requirement
41
36
  requirements:
42
37
  - - ! '>='
43
38
  - !ruby/object:Gem::Version
44
39
  version: '0'
45
- none: false
40
+ type: :runtime
46
41
  description: jQuery plugin for drop-in fix binded events problem caused by Turbolinks
47
42
  email: koss@nocorp.me
48
43
  executables: []
@@ -55,6 +50,7 @@ files:
55
50
  - Gemfile
56
51
  - Guardfile
57
52
  - LICENSE.md
53
+ - NOTES.md
58
54
  - README.md
59
55
  - Rakefile
60
56
  - jquery-turbolinks.gemspec
@@ -69,6 +65,7 @@ files:
69
65
  homepage: https://github.com/kossnocorp/jquery.turbolinks
70
66
  licenses:
71
67
  - MIT
68
+ metadata: {}
72
69
  post_install_message:
73
70
  rdoc_options: []
74
71
  require_paths:
@@ -78,18 +75,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
75
  - - ! '>='
79
76
  - !ruby/object:Gem::Version
80
77
  version: '0'
81
- none: false
82
78
  required_rubygems_version: !ruby/object:Gem::Requirement
83
79
  requirements:
84
80
  - - ! '>='
85
81
  - !ruby/object:Gem::Version
86
82
  version: '0'
87
- none: false
88
83
  requirements: []
89
84
  rubyforge_project: jquery-turbolinks
90
- rubygems_version: 1.8.23
85
+ rubygems_version: 2.0.3
91
86
  signing_key:
92
- specification_version: 3
87
+ specification_version: 4
93
88
  summary: jQuery plugin for drop-in fix binded events problem caused by Turbolinks
94
89
  test_files:
95
90
  - spec/jquery.turbolinks_spec.coffee
91
+ has_rdoc: