jquery-turbolinks 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  node_modules
2
+ *.gem
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # jQuery Turbolinks
2
2
 
3
- Do you like [Turbolinks](https://github.com/rails/turbolinks)? It's easy and fast way to imporove user experience of surfing on your site.
3
+ Do you like [Turbolinks](https://github.com/rails/turbolinks)? It's easy and fast way to improve user experience of surfing on your website.
4
4
 
5
- But if you have large codebase with lots of `$(el).bind(...)` Turbolinks will surprise you. Most part of you JavaScripts stop working in usual way. It's because the nodes on which you bind events no longer exist.
5
+ But if you have a large codebase with lots of `$(el).bind(...)` Turbolinks will surprise you. Most part of your JavaScripts will stop working in usual way. It's because the nodes on which you bind events no longer exist.
6
6
 
7
- I wrote jquery.turbolinks to solve this problem in [my project](http://amplifr.com). It's easy to use: just require it *after* `jquery.js` and `tubrolinks.js`, but before rest scripts.
7
+ I wrote jquery.turbolinks to solve this problem in [my project](http://amplifr.com). It's easy to use: just require it *after* `jquery.js` and `tubrolinks.js`, but before other scripts.
8
+
9
+ Sponsored by [Evil Martians](http://evilmartians.com/).
8
10
 
9
11
  ## Usage
10
12
 
@@ -18,12 +20,27 @@ JavaScript manifest file:
18
20
  //= require jquery.turbolinks
19
21
  ```
20
22
 
21
- And now it just works!
23
+ And it just works!
24
+
25
+ ## `$.setReadyEvent`
26
+
27
+ By default [ready](https://github.com/kossnocorp/jquery.turbolinks/blob/master/src/jquery.turbolinks.coffee#L17:L18) function is binded to [page:load](https://github.com/rails/turbolinks/#events) event.
28
+
29
+ If you want to change it use `$.setReadyEvent` function:
30
+
31
+ ``` js
32
+ $.setReadyEvent('page:change');
33
+ ```
22
34
 
23
35
  # Changelog
24
36
 
25
37
  This project uses [Semantic Versioning](http://semver.org/) for release numbering.
26
38
 
39
+ ## 0.2.0 (October 10, 2012)
40
+
41
+ * Change event: `page:change` -> `page:load` (kudos to [@davydotcom](https://github.com/davydotcom));
42
+ * added ability to change ready event via `$.setReadyEvent`
43
+
27
44
  ## 0.1.0 (October 3, 2012)
28
45
 
29
46
  * First, initial release
@@ -1,3 +1,3 @@
1
1
  module JqueryTurbolinks
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "jquery.turbolinks",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "Sasha Koss <koss@nocorp.me>",
5
- "description": "jQuery plugin for ",
5
+ "description": "jQuery plugin for drop-in fix binded events problem caused by Turbolinks",
6
6
 
7
7
  "devDependencies": {
8
8
  "coffee-script": "*",
@@ -11,7 +11,8 @@
11
11
  "sinon": "*",
12
12
  "sinon-chai": "*",
13
13
  "uglify-js": "*",
14
- "jquery": "*"
14
+ "jquery": "*",
15
+ "jsdom": "*"
15
16
  },
16
17
 
17
18
  "license": "MIT",
@@ -1,24 +1,52 @@
1
+ jsdom = require('jsdom').jsdom
2
+
3
+ global.document = jsdom()
4
+ global.window = document.createWindow()
5
+
1
6
  require('../src/jquery.turbolinks.coffee')
2
7
 
3
8
  chai = require('chai')
4
9
  sinon = require('sinon')
5
10
  sinonChai = require('sinon-chai')
6
- jQuery = require('jquery')
11
+ $ = require('jquery')
7
12
 
8
13
  chai.should()
9
14
  chai.use(sinonChai)
10
15
 
11
- describe 'jQuery Turbolinks', ->
16
+ describe '$ Turbolinks', ->
17
+
18
+ callback1 = callback2 = null
19
+
20
+ beforeEach ->
21
+ $(callback1 = sinon.spy())
22
+ $(callback2 = sinon.spy())
12
23
 
13
24
  it '''
14
25
  should trigger callbacks passed to
15
- `jQuery()` and `jQuery.ready()` when page:change
26
+ `$()` and `$.ready()` when page:load
16
27
  event fired
17
28
  ''', ->
18
- jQuery(callback1 = sinon.spy())
19
- jQuery(callback2 = sinon.spy())
29
+ $(document).trigger('page:load')
30
+
31
+ callback1.should.have.been.calledOnce
32
+ callback2.should.have.been.calledOnce
33
+
34
+ describe '$.setReadyEvent', ->
35
+
36
+ it 'should unbind default (page:load) event', ->
37
+ $.setReadyEvent('random_event_name')
38
+
39
+ $(document).trigger('page:load')
40
+
41
+ callback1.should.have.not.been.called
42
+ callback2.should.have.not.been.called
43
+
44
+ it 'should bind ready to passed function', ->
45
+ $.setReadyEvent('page:change')
20
46
 
21
- jQuery(document).trigger('page:change')
47
+ $(document)
48
+ .trigger('page:load')
49
+ .trigger('page:change')
22
50
 
23
- callback1.should.have.been.calledTwice
24
- callback2.should.have.been.calledTwice
51
+ callback1.should.have.been.calledOnce
52
+ callback2.should.have.been.calledOnce
@@ -1,5 +1,5 @@
1
1
  ###
2
- jquery.turbolinks.js ~ v0.1.0 ~ https://github.com/kossnocorp/jquery.turbolinks
2
+ jquery.turbolinks.js ~ v0.2.0 ~ https://github.com/kossnocorp/jquery.turbolinks
3
3
 
4
4
  jQuery plugin for drop-in fix binded events problem caused by Turbolinks
5
5
 
@@ -24,5 +24,11 @@ $(ready)
24
24
  $.fn.ready = (callback) ->
25
25
  callbacks.push(callback)
26
26
 
27
- # Bind `ready` to Tubolinks page change event
28
- $(document).on('page:change', ready)
27
+ # Bind ready to passed event
28
+ $.setReadyEvent = (event) ->
29
+ $(document)
30
+ .off('.turbolinks')
31
+ .on(event + '.turbolinks', ready)
32
+
33
+ # Bind `ready` to Tubolinks page load event
34
+ $.setReadyEvent('page:load')
@@ -1,7 +1,7 @@
1
1
  // Generated by CoffeeScript 1.3.3
2
2
 
3
3
  /*
4
- jquery.turbolinks.js ~ v0.1.0 ~ https://github.com/kossnocorp/jquery.turbolinks
4
+ jquery.turbolinks.js ~ v0.2.0 ~ https://github.com/kossnocorp/jquery.turbolinks
5
5
 
6
6
  jQuery plugin for drop-in fix binded events problem caused by Turbolinks
7
7
 
@@ -34,6 +34,10 @@
34
34
  return callbacks.push(callback);
35
35
  };
36
36
 
37
- $(document).on('page:change', ready);
37
+ $.setReadyEvent = function(event) {
38
+ return $(document).off('.turbolinks').on(event + '.turbolinks', ready);
39
+ };
40
+
41
+ $.setReadyEvent('page:load');
38
42
 
39
43
  }).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: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: