jquery-turbolinks-2.1.0/0000755000076400007640000000000012551470011014253 5ustar pravipravijquery-turbolinks-2.1.0/vendor/0000755000076400007640000000000012551470011015550 5ustar pravipravijquery-turbolinks-2.1.0/vendor/assets/0000755000076400007640000000000012551470011017052 5ustar pravipravijquery-turbolinks-2.1.0/vendor/assets/javascripts/0000755000076400007640000000000012551470011021403 5ustar pravipravijquery-turbolinks-2.1.0/CONTRIBUTING.md0000644000076400007640000000064512551470011016511 0ustar pravipravi# How to contribute ## Run tests ``` sh # Bundle gems bundle # Install npm packages npm install # Run tests rake test # ... or run auto tests bundle exec guard ``` ## Sending pull-request 1. Fork 2. Run the tests 3. Add test for your change 4. Make tests green 5. Push 6. Send pull-request ## Please do not * Driving drunk * Hide the fact of finding Bigfoot * Mess with versions, gemspec file, package.json etc jquery-turbolinks-2.1.0/Gemfile0000644000076400007640000000023412551470011015545 0ustar pravipravisource 'https://rubygems.org' group :development do gem 'uglifier' gem 'guard' gem 'guard-rake' gem 'talks', '0.4.0' gem 'terminal-notifier' end jquery-turbolinks-2.1.0/lib/0000755000076400007640000000000012551470011015021 5ustar pravipravijquery-turbolinks-2.1.0/lib/jquery-turbolinks/0000755000076400007640000000000012551470011020532 5ustar pravipravijquery-turbolinks-2.1.0/lib/jquery-turbolinks/version.rb0000644000076400007640000000006012551470011022540 0ustar pravipravimodule JqueryTurbolinks VERSION = '2.1.0' end jquery-turbolinks-2.1.0/lib/jquery-turbolinks/engine.rb0000644000076400007640000000010312551470011022316 0ustar pravipravimodule JqueryTurbolinks class Engine < ::Rails::Engine end end jquery-turbolinks-2.1.0/lib/jquery-turbolinks.rb0000644000076400007640000000010712551470011021055 0ustar pravipravirequire 'jquery-turbolinks/version' require 'jquery-turbolinks/engine' jquery-turbolinks-2.1.0/LICENSE.md0000644000076400007640000000205712551470011015663 0ustar pravipraviThe MIT License Copyright (c) 2012 Sasha Koss 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. jquery-turbolinks-2.1.0/src/0000755000076400007640000000000012551470011015042 5ustar pravipravijquery-turbolinks-2.1.0/src/jquery.turbolinks.coffee0000644000076400007640000000226312551470011021730 0ustar pravipravi### jQuery.Turbolinks ~ https://github.com/kossnocorp/jquery.turbolinks jQuery plugin for drop-in fix binded events problem caused by Turbolinks The MIT License Copyright (c) 2012-2013 Sasha Koss & Rico Sta. Cruz ### $ = window.jQuery or require?('jquery') $document = $(document) $.turbo = version: '2.1.0' isReady: false # Hook onto the events that Turbolinks triggers. use: (load, fetch) -> $document .off('.turbo') .on("#{load}.turbo", @onLoad) .on("#{fetch}.turbo", @onFetch) addCallback: (callback) -> if $.turbo.isReady callback($) $document.on 'turbo:ready', -> callback($) onLoad: -> $.turbo.isReady = true $document.trigger('turbo:ready') onFetch: -> $.turbo.isReady = false # Registers jQuery.Turbolinks by monkey-patching jQuery's # `ready` handler. (Internal) # # [1] Trigger the stored `ready` events on first load. # [2] Override `$(function)` and `$(document).ready(function)` by # registering callbacks under a new event called `turbo:ready`. # register: -> $(@onLoad) #[1] $.fn.ready = @addCallback #[2] # Use with Turbolinks. $.turbo.register() $.turbo.use('page:load', 'page:fetch') jquery-turbolinks-2.1.0/Guardfile0000644000076400007640000000013412551470011016076 0ustar pravipraviguard :rake, task: 'test', notification: false do watch(/^(src|spec)\/(.+)\.coffee$/) end jquery-turbolinks-2.1.0/package.json0000644000076400007640000000130212551470011016535 0ustar pravipravi{ "name": "jquery.turbolinks", "version": "2.1.0", "authors": [ "Sasha Koss ", "Rico Sta. Cruz " ], "description": "jQuery plugin for drop-in fix binded events problem caused by Turbolinks", "devDependencies": { "coffee-script": "~1.7.1", "mocha": "~1.21.4", "chai": "~1.9.1", "sinon": "~1.10.3", "sinon-chai": "~2.5.0", "jquery": "~2.1.1", "jsdom": "~1.0.0-pre.4" }, "license": "MIT", "engine": { "node": ">=0.4" }, "scripts": { "test": "./node_modules/mocha/bin/mocha ./spec/*_spec.coffee --compilers coffee:coffee-script/register -R spec -c" } } jquery-turbolinks-2.1.0/NOTES.md0000644000076400007640000000130512551470011015464 0ustar pravipravi# Development notes Version bumping --------------- Edit the following files: * lib/jquery-turbolinks/version.rb * package.json * src/jquery.turbolinks.coffee Updating .js files ------------------ Update the .js files from the source CoffeeScript file using: (do this before releasing) $ rake build Testing ------- Simply use npm/mocha: $ npm install $ npm test Or: $ rake test Releasing new versions ---------------------- * Bump version (see above) * Build .js (`rake build`) * Release into npm and rubygems (`rake release:all`) * Draft release in https://github.com/kossnocorp/jquery.turbolinks/releases Release it into npm/rubygems using: $ rake release:all jquery-turbolinks-2.1.0/.gitignore0000644000076400007640000000005612551470011016244 0ustar pravipravinode_modules *.gem Gemfile.lock .ruby-version jquery-turbolinks-2.1.0/spec/0000755000076400007640000000000012551470011015205 5ustar pravipravijquery-turbolinks-2.1.0/spec/jquery.turbolinks_spec.coffee0000644000076400007640000000704112551470011023104 0ustar pravipravibefore (next) -> require('jsdom').env html: "", done: (errors, window) -> global.window = window global.document = window.document if (errors) errors.forEach(console.error) throw new Error(errors[0].data.error + " (" + errors[0].data.filename + ")") next() before -> global.$ = require('jquery') global.jQuery = require('jquery') require('../src/jquery.turbolinks.coffee') chai = require('chai') sinon = require('sinon') sinonChai = require('sinon-chai') chai.should() chai.use(sinonChai) getUniqId = do -> counter = 0 -> 'id_' + (counter += 1) describe '$ Turbolinks', -> callback1 = callback2 = null # Simulate a reset. beforeEach -> $.turbo.isReady = false $.turbo.use 'page:load', 'page:fetch' $(document).off('turbo:ready') describe "DOM isn't ready", -> beforeEach -> $(callback1 = sinon.spy()) $(callback2 = sinon.spy()) it ''' should trigger callbacks passed to `$()` and `$.ready()` when page:load event fired ''', -> $(document).trigger('page:load') callback1.should.have.been.calledOnce callback2.should.have.been.calledOnce it 'should pass $ as the first argument to callbacks', (done) -> $ ($$) -> $$.fn.should.be.an.object done() $(document).trigger 'page:load' describe '$.turbo.use', -> beforeEach -> $.turbo.use('page:load', 'page:fetch') it 'should unbind default (page:load) event', -> $.turbo.use('other1', 'other2') $(document).trigger('page:load') callback1.should.have.not.been.called callback2.should.have.not.been.called it 'should bind ready to passed function', -> $(document) .trigger('page:load') .trigger('page:change') callback1.should.have.been.calledOnce callback2.should.have.been.calledOnce describe '$.setFetchEvent', -> beforeEach -> $.turbo.use('page:load', 'page:fetch') $.turbo.isReady = true it 'should unbind default (page:fetch) event', -> $.turbo.use('page:load', 'random_event_name') $(document).trigger('page:fetch') $.turbo.isReady.should.to.be.true it 'should bind passed fetch event', -> $.turbo.use('page:load', 'page:loading') $(document).trigger('page:loading') $.turbo.isReady.should.to.be.false describe 'DOM is ready', -> beforeEach -> $.turbo.use('page:load', 'page:fetch') $.turbo.isReady = true it 'should call trigger right after add to waiting list', -> $(callback = sinon.spy()) callback.should.have.been.calledOnce it 'should not call trigger after page:fetch and before page:load', -> $(document).trigger('page:fetch') $(callback1 = sinon.spy()) callback1.should.have.not.been.called $(document).trigger('page:load') $(callback2 = sinon.spy()) callback2.should.have.been.calledOnce it 'should call trigger after a subsequent page:fetch and before page:load', -> $(document).trigger('page:fetch') $(document).trigger('page:load') $(callback1 = sinon.spy()) callback1.should.have.been.calledOnce $(document).trigger('page:fetch') $(document).trigger('page:load') callback1.should.have.been.calledTwice it 'should pass $ as the first argument to callbacks', (done) -> $ ($$) -> $$.fn.should.be.an.object done() jquery-turbolinks-2.1.0/Rakefile0000644000076400007640000000350712551470011015725 0ustar pravipravirequire 'rubygems' require 'open3' require 'talks' $LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'jquery-turbolinks/version' namespace :release do task :build_gem do system 'gem build jquery-turbolinks.gemspec' end task gem: :build_gem do system "gem push jquery-turbolinks-#{JqueryTurbolinks::VERSION}.gem" end task :npm do system 'npm publish' end task all: [:gem, :npm] end desc 'Rebuilds and compresses' task :build => %w[js:build js:uglify] namespace :js do desc 'Build JavaScript from CoffeeScript source code' task :build do command = [ './node_modules/coffee-script/bin/coffee', '--compile', '--output ./vendor/assets/javascripts/', './src/*.coffee' ] system command.join(' ') end desc 'Use UglifyJS to compress JavaScript' task :uglify do require 'uglifier' Dir['./vendor/assets/javascripts/*.js'] .select { |f| not f.match(/min\.js$/) } .each do |file_name| source = File.read(file_name) compressed = Uglifier.compile(source, copyright: false) min_file_name = file_name.gsub(/\.js$/, '.min.js') File.open(min_file_name, 'w') do |f| f.write(compressed) end uglify_rate = compressed.length.to_f / source.length gzipped_size = `cat #{min_file_name} | gzip -9f | wc -c`.to_i gzip_rate = gzipped_size.to_f / source.length puts "# #{file_name}.js" puts "Original size: #{source.length}b or #{(source.length.to_f / 1024).round(2)}kb" puts "Uglified size: #{compressed.length}b (#{(uglify_rate * 100).round}% from original size)" puts "GZipped size: #{gzipped_size}b or #{(gzipped_size.to_f / 1025).round(2)}kb (#{(gzip_rate * 100).round}% from original size)" end end end task :test do system "npm test" end jquery-turbolinks-2.1.0/README.md0000644000076400007640000000764312551470011015544 0ustar pravipravi# jQuery Turbolinks [![Build Status](https://secure.travis-ci.org/kossnocorp/jquery.turbolinks.png?branch=master)](http://travis-ci.org/kossnocorp/jquery.turbolinks) Do you like [Turbolinks](https://github.com/rails/turbolinks)? It's easy and fast way to improve user experience of surfing on your website. 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. I wrote jquery.turbolinks to solve this problem in [my project](http://amplifr.com). It's easy to use: just require it *immediately after* `jquery.js`. Your other scripts should be loaded after `jquery.turbolinks.js`, and `turbolinks.js` should be after your other scripts. Initially sponsored by [Evil Martians](http://evilmartians.com/). This project is a member of the [OSS Manifesto](http://ossmanifesto.org/). ## Important This readme points to the latest version (v2.x) of jQuery Turbolinks, which features new 2.0 API. For older versions, see [v1.0.0rc2 README][oldreadme]. ## Usage Gemfile: ``` js gem 'jquery-turbolinks' ``` Add it to your JavaScript manifest file, in this order: ``` js //= require jquery //= require jquery.turbolinks //= require jquery_ujs // // ... your other scripts here ... // //= require turbolinks ``` And it just works! **Checkout "[Faster page loads with Turbolinks](https://coderwall.com/p/ypzfdw)" for deeper explanation how to use jQuery Turbolink in real world**. ## API and Customization ### $.turbo.use By default, jQuery.Turbolinks is bound to [page:load] and [page:fetch]. To use different events (say, if you're not using Turbolinks), use: ``` js $.turbo.use('pjax:start', 'pjax:end'); ``` ## $.turbo.isReady You can check if the page is ready by checking `$.turbo.isReady`, which will be either `true` or `false` depending on whether the page is loading. ## Troubleshooting ### Events firing twice or more If you find that some events are being fired multiple times after using jQuery Turbolinks, you may have been binding your `document` events inside a `$(function())` block. For instance, this example below can be a common occurrence and should be avoided: ``` javascript /* BAD: don't bind 'document' events while inside $()! */ $(function() { $(document).on('click', 'button', function() { ... }) }); ``` You should be binding your events outside a `$(function())` block. This will ensure that your events will only ever be bound once. ``` javascript /* Good: events are bound outside a $() wrapper. */ $(document).on('click', 'button', function() { ... }) ``` ### Not working with `$(document).on('ready')` jQuery Turbolinks doesn't support ready events bound via `$(document).on('ready', function)`. Instead, use `$(document).ready(function)` or `$(function)`. ``` javascript // BAD: this will not work. $(document).on('ready', function () { /* ... */ }); // OK: these two are guaranteed to work. $(document).ready(function () { /* ... */ }); $(function () { /* ... */ }); ``` ## Changelog This project uses [Semantic Versioning](http://semver.org/) for release numbering. For changelog notes, checkout [releases page](https://github.com/kossnocorp/jquery.turbolinks/releases). ## Contributors Initial idea and code by [@kossnocorp](http://koss.nocorp.me/), with special thanks to [@rstacruz](https://github.com/rstacruz) and other the project's [contributors](https://github.com/kossnocorp/jquery.turbolinks/graphs/contributors). ## License [The MIT License](https://github.com/kossnocorp/jquery.turbolinks/blob/master/LICENSE.md) [page:load]: https://github.com/rails/turbolinks/#events [page:fetch]: https://github.com/rails/turbolinks/#events [oldreadme]: https://github.com/kossnocorp/jquery.turbolinks/blob/v1.0.0.rc2/README.md [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/kossnocorp/jquery.turbolinks/trend.png)](https://bitdeli.com/free "Bitdeli Badge") jquery-turbolinks-2.1.0/.travis.yml0000644000076400007640000000004412551470011016362 0ustar pravipravilanguage: node_js node_js: ["0.10"] jquery-turbolinks-2.1.0/metadata.yml0000644000076400007640000000425012551470011016557 0ustar pravipravi--- !ruby/object:Gem::Specification name: jquery-turbolinks version: !ruby/object:Gem::Version version: 2.1.0 platform: ruby authors: - Sasha Koss autorequire: bindir: bin cert_chain: [] date: 2014-08-29 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: railties requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.1.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 3.1.0 - !ruby/object:Gem::Dependency name: turbolinks requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: jQuery plugin for drop-in fix binded events problem caused by Turbolinks email: koss@nocorp.me executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".travis.yml" - CONTRIBUTING.md - Gemfile - Guardfile - LICENSE.md - NOTES.md - README.md - Rakefile - jquery-turbolinks.gemspec - lib/jquery-turbolinks.rb - lib/jquery-turbolinks/engine.rb - lib/jquery-turbolinks/version.rb - package.json - spec/jquery.turbolinks_spec.coffee - src/jquery.turbolinks.coffee - vendor/assets/javascripts/jquery.turbolinks.js - vendor/assets/javascripts/jquery.turbolinks.min.js homepage: https://github.com/kossnocorp/jquery.turbolinks licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: jquery-turbolinks rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: jQuery plugin for drop-in fix binded events problem caused by Turbolinks test_files: - spec/jquery.turbolinks_spec.coffee jquery-turbolinks-2.1.0/jquery-turbolinks.gemspec0000644000076400007640000000203312551470011021327 0ustar pravipravi# -*- encoding: utf-8 -*- require File.expand_path('../lib/jquery-turbolinks/version', __FILE__) Gem::Specification.new do |gem| gem.name = 'jquery-turbolinks' gem.rubyforge_project = 'jquery-turbolinks' gem.version = JqueryTurbolinks::VERSION gem.authors = ['Sasha Koss'] gem.email = 'koss@nocorp.me' gem.description = 'jQuery plugin for drop-in fix binded events problem caused by Turbolinks' gem.summary = 'jQuery plugin for drop-in fix binded events problem caused by Turbolinks' gem.homepage = 'https://github.com/kossnocorp/jquery.turbolinks' gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.licenses = ['MIT'] gem.require_paths = ['lib'] gem.rubygems_version = '1.8.15' gem.add_dependency 'railties', '>= 3.1.0' gem.add_dependency 'turbolinks' end