backbone-fetch-event 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/backbone-fetch-event.gemspec +19 -0
- data/lib/backbone-fetch-event.rb +8 -0
- data/lib/backbone-fetch-event/version.rb +3 -0
- data/vendor/assets/javascripts/backbone-fetch-event.js +17 -0
- metadata +57 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tim Branyen, Todd Eichel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# backbone-fetch-event
|
2
|
+
|
3
|
+
Patches Backbone's Model and Collection to fire a `fetch` event when starting a fetch operation.
|
4
|
+
Useful for showing a loading indicator while data is being retrieved.
|
5
|
+
|
6
|
+
Original blog post and code: [http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress](http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress)
|
7
|
+
|
8
|
+
This gem makes it easy to include in Rails 3.1 projects using the asset pipeline. It just bundles
|
9
|
+
the JavaScript file and makes it available to your application.
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's `Gemfile`:
|
15
|
+
|
16
|
+
gem 'backbone-fetch-event'
|
17
|
+
|
18
|
+
Then require it somewhere, e.g. `app/assets/javascripts/application.js`:
|
19
|
+
|
20
|
+
//= require backbone-fetch-event
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Just bind to the `fetch` event on a model or collection. A view that shows a spinner whenever its
|
26
|
+
collection is being fetched might look like this:
|
27
|
+
|
28
|
+
Repos.Views.List = Backbone.View.extend({
|
29
|
+
initialize: function () {
|
30
|
+
// Display a loading indication whenever the Collection is fetching.
|
31
|
+
this.collection.on("fetch", function () {
|
32
|
+
this.html("<img src='/assets/img/spinner.gif'>");
|
33
|
+
}, this);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
|
37
|
+
|
38
|
+
## Contributors
|
39
|
+
|
40
|
+
- [Tim Branyen](http://tbranyen.com): original idea and code
|
41
|
+
- [Todd Eichel](http://toddeichel.com): packaging for the Rails asset pipeline
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backbone-fetch-event/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "backbone-fetch-event"
|
8
|
+
gem.version = BackboneFetchEvent::VERSION
|
9
|
+
gem.authors = ["Tim Branyen", "Todd Eichel"]
|
10
|
+
gem.email = ["tim@tabdeveloper.com", "todd@toddeichel.com"]
|
11
|
+
gem.description = %q{Code by Tim Branyen (http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress). Packaged by Todd Eichel.}
|
12
|
+
gem.summary = %q{Triggers an event when a Model or Collection starts a fetch.}
|
13
|
+
gem.homepage = "https://github.com/tfe/backbone-fetch-event"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Patch Model and Collection so they emit a 'fetch' event when starting to fetch data
|
2
|
+
// http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress
|
3
|
+
_.each(["Model", "Collection"], function(name) {
|
4
|
+
// Cache Backbone constructor.
|
5
|
+
var ctor = Backbone[name];
|
6
|
+
// Cache original fetch.
|
7
|
+
var fetch = ctor.prototype.fetch;
|
8
|
+
|
9
|
+
// Override the fetch method to emit a fetch event.
|
10
|
+
ctor.prototype.fetch = function() {
|
11
|
+
// Trigger the fetch event on the instance.
|
12
|
+
this.trigger("fetch", this);
|
13
|
+
|
14
|
+
// Pass through to original fetch.
|
15
|
+
return fetch.apply(this, arguments);
|
16
|
+
};
|
17
|
+
});
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backbone-fetch-event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tim Branyen
|
9
|
+
- Todd Eichel
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Code by Tim Branyen (http://tbranyen.com/post/how-to-indicate-backbone-fetch-progress).
|
16
|
+
Packaged by Todd Eichel.
|
17
|
+
email:
|
18
|
+
- tim@tabdeveloper.com
|
19
|
+
- todd@toddeichel.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- .gitignore
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- backbone-fetch-event.gemspec
|
30
|
+
- lib/backbone-fetch-event.rb
|
31
|
+
- lib/backbone-fetch-event/version.rb
|
32
|
+
- vendor/assets/javascripts/backbone-fetch-event.js
|
33
|
+
homepage: https://github.com/tfe/backbone-fetch-event
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Triggers an event when a Model or Collection starts a fetch.
|
57
|
+
test_files: []
|