jquery-turbolinks 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ node_modules
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'guard'
5
+ gem 'guard-rake'
6
+ gem 'talks', '0.4.0'
7
+ gem 'terminal-notifier'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ffi (1.1.0)
5
+ guard (1.2.3)
6
+ listen (>= 0.4.2)
7
+ thor (>= 0.14.6)
8
+ guard-rake (0.0.7)
9
+ guard
10
+ rake
11
+ listen (0.4.7)
12
+ rb-fchange (~> 0.0.5)
13
+ rb-fsevent (~> 0.9.1)
14
+ rb-inotify (~> 0.8.8)
15
+ notifier (0.2.1)
16
+ rake (0.9.2.2)
17
+ rb-fchange (0.0.5)
18
+ ffi
19
+ rb-fsevent (0.9.1)
20
+ rb-inotify (0.8.8)
21
+ ffi (>= 0.5.0)
22
+ talks (0.4.0)
23
+ notifier
24
+ terminal-notifier (1.3.0)
25
+ thor (0.15.4)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ guard
32
+ guard-rake
33
+ talks (= 0.4.0)
34
+ terminal-notifier
data/Guardfile ADDED
@@ -0,0 +1,3 @@
1
+ guard :rake, task: 'test', notification: false do
2
+ watch(/^(src|spec)\/(.+)\.coffee$/)
3
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012 Sasha Koss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # jQuery Turbolinks
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.
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.
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.
8
+
9
+ ## Usage
10
+
11
+ Gemfile:
12
+ ``` js
13
+ gem 'jquery-turbolinks'
14
+ ```
15
+
16
+ JavaScript manifest file:
17
+ ``` js
18
+ //= require jquery.turbolinks
19
+ ```
20
+
21
+ And now it just works!
22
+
23
+ # Changelog
24
+
25
+ This project uses [Semantic Versioning](http://semver.org/) for release numbering.
26
+
27
+ ## 0.1.0 (October 3, 2012)
28
+
29
+ * First, initial release
30
+
31
+ # Contributors
32
+
33
+ Idea and code by [@kossnocorp](http://koss.nocorp.me/).
34
+
35
+ # [The MIT License](https://github.com/kossnocorp/jquery.turbolinks/blob/master/LICENSE.md)
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'open3'
3
+ require 'talks'
4
+
5
+ task :test do
6
+ stdin, stdout, stderr = Open3.popen3 \
7
+ './node_modules/mocha/bin/mocha ./spec/*_spec.coffee --compilers coffee:coffee-script -R spec -c'
8
+
9
+ puts stdout_array = stdout.readlines
10
+ puts stderr_array = stderr.readlines
11
+
12
+ stdout_strings = stdout_array.to_s
13
+ stderr_strings = stderr_array.to_s
14
+
15
+ if stderr_strings and
16
+ error_match = stderr_strings.match(/(\d+) of (\d+) (test[s]?) failed/)
17
+
18
+ failed_count, total_count, tests_failed_str = error_match.captures
19
+
20
+ message = "#{failed_count} of #{total_count} #{tests_failed_str} failed"
21
+
22
+ elsif stdout_strings_match = stdout_strings.match(/(\d+) (test[s]?) complete/)
23
+ complete_count, tests_complete_str = stdout_strings_match.captures
24
+
25
+ if pending_matches = stdout_strings.match(/(\d+) test[s]? pending/)
26
+ pending_count, tests_pending_str = pending_matches.captures
27
+ end
28
+
29
+ message = "#{complete_count} #{tests_complete_str} complete"
30
+ message += ", #{pending_count} #{tests_pending_str} pending" if pending_count
31
+
32
+ else
33
+ message = 'Something wrong, check console output.'
34
+ end
35
+
36
+ `bundle exec terminal-notifier -message '#{message}' -title 'Test results' -remove TEST_RESULTS -group TEST_RESULTS`
37
+ Talks.say message, detach: true
38
+ end
39
+
40
+ task :build do
41
+ `./node_modules/coffee-script/bin/coffee --compile --output ./vendor/assets/javascripts/ ./src/jquery.turbolinks.coffee`
42
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/jquery-turbolinks/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'jquery-turbolinks'
7
+ gem.rubyforge_project = 'jquery-turbolinks'
8
+ gem.version = JqueryTurbolinks::VERSION
9
+
10
+ gem.authors = ['Sasha Koss']
11
+ gem.email = 'koss@nocorp.me'
12
+ gem.date = '2012-10-03'
13
+
14
+ gem.description = 'jQuery plugin for drop-in fix binded events problem caused by Turbolinks'
15
+ gem.summary = 'jQuery plugin for drop-in fix binded events problem caused by Turbolinks'
16
+ gem.homepage = 'https://github.com/kossnocorp/jquery-turbolinks'
17
+
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+
22
+ gem.licenses = ['MIT']
23
+
24
+ gem.require_paths = ['lib']
25
+
26
+ gem.rubygems_version = '1.8.15'
27
+
28
+ gem.add_dependency 'rails', '>= 3.1.0'
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'jquery-turbolinks/version'
2
+ require 'jquery-turbolinks/engine'
@@ -0,0 +1,4 @@
1
+ module JqueryTurbolinks
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryTurbolinks
2
+ VERSION = '0.1.1'
3
+ end
data/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "jquery.turbolinks",
3
+ "version": "0.1.0",
4
+ "author": "Sasha Koss <koss@nocorp.me>",
5
+ "description": "jQuery plugin for ",
6
+
7
+ "devDependencies": {
8
+ "coffee-script": "*",
9
+ "mocha": "*",
10
+ "chai": "*",
11
+ "sinon": "*",
12
+ "sinon-chai": "*",
13
+ "uglify-js": "*",
14
+ "jquery": "*"
15
+ },
16
+
17
+ "license": "MIT",
18
+
19
+ "engine": {
20
+ "node": ">=0.4"
21
+ },
22
+
23
+ "scripts": {
24
+ "test": "./node_modules/mocha/bin/mocha ./spec/*_spec.coffee --compilers coffee:coffee-script -R spec -c"
25
+ }
26
+ }
@@ -0,0 +1,24 @@
1
+ require('../src/jquery.turbolinks.coffee')
2
+
3
+ chai = require('chai')
4
+ sinon = require('sinon')
5
+ sinonChai = require('sinon-chai')
6
+ jQuery = require('jquery')
7
+
8
+ chai.should()
9
+ chai.use(sinonChai)
10
+
11
+ describe 'jQuery Turbolinks', ->
12
+
13
+ it '''
14
+ should trigger callbacks passed to
15
+ `jQuery()` and `jQuery.ready()` when page:change
16
+ event fired
17
+ ''', ->
18
+ jQuery(callback1 = sinon.spy())
19
+ jQuery(callback2 = sinon.spy())
20
+
21
+ jQuery(document).trigger('page:change')
22
+
23
+ callback1.should.have.been.calledTwice
24
+ callback2.should.have.been.calledTwice
@@ -0,0 +1,28 @@
1
+ ###
2
+ jquery.turbolinks.js ~ v0.1.0 ~ https://github.com/kossnocorp/jquery.turbolinks
3
+
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
9
+ ###
10
+
11
+ $ = require?('jquery') || window.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
+ # Bind `ready` to DOM ready event
21
+ $(ready)
22
+
23
+ # Store callbacks in list on `$` and `$.ready`
24
+ $.fn.ready = (callback) ->
25
+ callbacks.push(callback)
26
+
27
+ # Bind `ready` to Tubolinks page change event
28
+ $(document).on('page:change', ready)
@@ -0,0 +1,39 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+
3
+ /*
4
+ jquery.turbolinks.js ~ v0.1.0 ~ https://github.com/kossnocorp/jquery.turbolinks
5
+
6
+ jQuery plugin for drop-in fix binded events problem caused by Turbolinks
7
+
8
+ The MIT License
9
+
10
+ Copyright (c) 2012 Sasha Koss
11
+ */
12
+
13
+
14
+ (function() {
15
+ var $, callbacks, ready;
16
+
17
+ $ = (typeof require === "function" ? require('jquery') : void 0) || window.jQuery;
18
+
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
+ $(ready);
32
+
33
+ $.fn.ready = function(callback) {
34
+ return callbacks.push(callback);
35
+ };
36
+
37
+ $(document).on('page:change', ready);
38
+
39
+ }).call(this);
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-turbolinks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sasha Koss
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-03 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.0
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.0
30
+ description: jQuery plugin for drop-in fix binded events problem caused by Turbolinks
31
+ email: koss@nocorp.me
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - Guardfile
40
+ - LICENSE.md
41
+ - README.md
42
+ - Rakefile
43
+ - jquery-turbolinks.gemspec
44
+ - lib/jquery-turbolinks.rb
45
+ - lib/jquery-turbolinks/engine.rb
46
+ - lib/jquery-turbolinks/version.rb
47
+ - package.json
48
+ - spec/jquery.turbolinks_spec.coffee
49
+ - src/jquery.turbolinks.coffee
50
+ - vendor/assets/javascripts/jquery.turbolinks.js
51
+ homepage: https://github.com/kossnocorp/jquery-turbolinks
52
+ licenses:
53
+ - MIT
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project: jquery-turbolinks
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: jQuery plugin for drop-in fix binded events problem caused by Turbolinks
76
+ test_files:
77
+ - spec/jquery.turbolinks_spec.coffee