frontend-helpers 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +5 -5
- data/Gemfile.lock +59 -58
- data/README.md +8 -0
- data/Rakefile +1 -1
- data/app/views/layouts/mail.html.haml +54 -0
- data/frontend-helpers.gemspec +29 -26
- data/lib/generators/frontend/install/install_generator.rb +5 -0
- data/vendor/assets/javascripts/backbone/authtoken.js +58 -0
- data/vendor/assets/javascripts/backbone/backbone.js +25 -16
- data/vendor/assets/javascripts/backbone/index.js +2 -1
- data/vendor/assets/javascripts/backbone/underscore.js +49 -17
- data/vendor/assets/javascripts/jquery.cookie.js +42 -35
- data/vendor/assets/javascripts/jquery.slides.js +538 -31
- data/vendor/assets/stylesheets/fancybox.css.scss +17 -17
- metadata +26 -23
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@frontend-helpers --create
|
data/Gemfile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
# Rails so we can extend it
|
4
|
-
gem "rails", "~> 3.1.0
|
4
|
+
gem "rails", "~> 3.1.0"
|
5
5
|
|
6
|
-
gem "haml-rails"
|
7
|
-
gem "sass-rails"
|
6
|
+
gem "haml-rails"
|
7
|
+
gem "sass-rails"
|
8
8
|
|
9
|
-
gem "sprockets"
|
9
|
+
gem "sprockets"
|
10
10
|
|
11
11
|
if RUBY_VERSION < "1.9"
|
12
12
|
gem "ruby-debug", ">= 0.10.3"
|
@@ -14,5 +14,5 @@ end
|
|
14
14
|
|
15
15
|
group :development do
|
16
16
|
# Using jeweler because it's just so easy
|
17
|
-
gem "jeweler"
|
17
|
+
gem "jeweler"
|
18
18
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,48 +1,47 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionmailer (3.1.0
|
5
|
-
actionpack (= 3.1.0
|
4
|
+
actionmailer (3.1.0)
|
5
|
+
actionpack (= 3.1.0)
|
6
6
|
mail (~> 2.3.0)
|
7
|
-
actionpack (3.1.0
|
8
|
-
activemodel (= 3.1.0
|
9
|
-
activesupport (= 3.1.0
|
7
|
+
actionpack (3.1.0)
|
8
|
+
activemodel (= 3.1.0)
|
9
|
+
activesupport (= 3.1.0)
|
10
10
|
builder (~> 3.0.0)
|
11
11
|
erubis (~> 2.7.0)
|
12
12
|
i18n (~> 0.6)
|
13
|
-
rack (~> 1.3.
|
14
|
-
rack-cache (~> 1.0.
|
15
|
-
rack-mount (~> 0.8.
|
16
|
-
rack-test (~> 0.6.
|
17
|
-
sprockets (~> 2.0.0
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
bcrypt-ruby (~> 2.1.4)
|
13
|
+
rack (~> 1.3.2)
|
14
|
+
rack-cache (~> 1.0.3)
|
15
|
+
rack-mount (~> 0.8.2)
|
16
|
+
rack-test (~> 0.6.1)
|
17
|
+
sprockets (~> 2.0.0)
|
18
|
+
activemodel (3.1.0)
|
19
|
+
activesupport (= 3.1.0)
|
20
|
+
bcrypt-ruby (~> 3.0.0)
|
22
21
|
builder (~> 3.0.0)
|
23
22
|
i18n (~> 0.6)
|
24
|
-
activerecord (3.1.0
|
25
|
-
activemodel (= 3.1.0
|
26
|
-
activesupport (= 3.1.0
|
27
|
-
arel (~> 2.
|
28
|
-
tzinfo (~> 0.3.
|
29
|
-
activeresource (3.1.0
|
30
|
-
activemodel (= 3.1.0
|
31
|
-
activesupport (= 3.1.0
|
32
|
-
activesupport (3.1.0
|
23
|
+
activerecord (3.1.0)
|
24
|
+
activemodel (= 3.1.0)
|
25
|
+
activesupport (= 3.1.0)
|
26
|
+
arel (~> 2.2.1)
|
27
|
+
tzinfo (~> 0.3.29)
|
28
|
+
activeresource (3.1.0)
|
29
|
+
activemodel (= 3.1.0)
|
30
|
+
activesupport (= 3.1.0)
|
31
|
+
activesupport (3.1.0)
|
33
32
|
multi_json (~> 1.0)
|
34
|
-
arel (2.1
|
35
|
-
bcrypt-ruby (
|
33
|
+
arel (2.2.1)
|
34
|
+
bcrypt-ruby (3.0.1)
|
36
35
|
builder (3.0.0)
|
37
36
|
erubis (2.7.0)
|
38
37
|
git (1.2.5)
|
39
|
-
haml (3.1.
|
38
|
+
haml (3.1.3)
|
40
39
|
haml-rails (0.3.4)
|
41
40
|
actionpack (~> 3.0)
|
42
41
|
activesupport (~> 3.0)
|
43
42
|
haml (~> 3.0)
|
44
43
|
railties (~> 3.0)
|
45
|
-
hike (1.1
|
44
|
+
hike (1.2.1)
|
46
45
|
i18n (0.6.0)
|
47
46
|
jeweler (1.6.4)
|
48
47
|
bundler (~> 1.0)
|
@@ -54,46 +53,48 @@ GEM
|
|
54
53
|
treetop (~> 1.4.8)
|
55
54
|
mime-types (1.16)
|
56
55
|
multi_json (1.0.3)
|
57
|
-
polyglot (0.3.
|
58
|
-
rack (1.3.
|
59
|
-
rack-cache (1.0.
|
56
|
+
polyglot (0.3.2)
|
57
|
+
rack (1.3.3)
|
58
|
+
rack-cache (1.0.3)
|
60
59
|
rack (>= 0.4)
|
61
|
-
rack-mount (0.8.
|
60
|
+
rack-mount (0.8.3)
|
62
61
|
rack (>= 1.0.0)
|
63
62
|
rack-ssl (1.3.2)
|
64
63
|
rack
|
65
|
-
rack-test (0.6.
|
64
|
+
rack-test (0.6.1)
|
66
65
|
rack (>= 1.0)
|
67
|
-
rails (3.1.0
|
68
|
-
actionmailer (= 3.1.0
|
69
|
-
actionpack (= 3.1.0
|
70
|
-
activerecord (= 3.1.0
|
71
|
-
activeresource (= 3.1.0
|
72
|
-
activesupport (= 3.1.0
|
66
|
+
rails (3.1.0)
|
67
|
+
actionmailer (= 3.1.0)
|
68
|
+
actionpack (= 3.1.0)
|
69
|
+
activerecord (= 3.1.0)
|
70
|
+
activeresource (= 3.1.0)
|
71
|
+
activesupport (= 3.1.0)
|
73
72
|
bundler (~> 1.0)
|
74
|
-
railties (= 3.1.0
|
75
|
-
railties (3.1.0
|
76
|
-
actionpack (= 3.1.0
|
77
|
-
activesupport (= 3.1.0
|
73
|
+
railties (= 3.1.0)
|
74
|
+
railties (3.1.0)
|
75
|
+
actionpack (= 3.1.0)
|
76
|
+
activesupport (= 3.1.0)
|
78
77
|
rack-ssl (~> 1.3.2)
|
79
78
|
rake (>= 0.8.7)
|
80
79
|
rdoc (~> 3.4)
|
81
80
|
thor (~> 0.14.6)
|
82
81
|
rake (0.9.2)
|
83
|
-
rdoc (3.
|
84
|
-
sass (3.1.
|
85
|
-
sass-rails (3.1.
|
86
|
-
actionpack (~> 3.1.0
|
87
|
-
railties (~> 3.1.0
|
82
|
+
rdoc (3.9.4)
|
83
|
+
sass (3.1.7)
|
84
|
+
sass-rails (3.1.2)
|
85
|
+
actionpack (~> 3.1.0)
|
86
|
+
railties (~> 3.1.0)
|
88
87
|
sass (>= 3.1.4)
|
89
|
-
sprockets (
|
90
|
-
|
91
|
-
|
88
|
+
sprockets (~> 2.0.0)
|
89
|
+
tilt (~> 1.3.2)
|
90
|
+
sprockets (2.0.0)
|
91
|
+
hike (~> 1.2)
|
92
92
|
rack (~> 1.0)
|
93
|
-
tilt (
|
93
|
+
tilt (~> 1.1, != 1.3.0)
|
94
94
|
thor (0.14.6)
|
95
|
-
tilt (1.3.
|
96
|
-
treetop (1.4.
|
95
|
+
tilt (1.3.3)
|
96
|
+
treetop (1.4.10)
|
97
|
+
polyglot
|
97
98
|
polyglot (>= 0.3.1)
|
98
99
|
tzinfo (0.3.29)
|
99
100
|
|
@@ -101,8 +102,8 @@ PLATFORMS
|
|
101
102
|
ruby
|
102
103
|
|
103
104
|
DEPENDENCIES
|
104
|
-
haml-rails
|
105
|
-
jeweler
|
106
|
-
rails (~> 3.1.0
|
107
|
-
sass-rails
|
108
|
-
sprockets
|
105
|
+
haml-rails
|
106
|
+
jeweler
|
107
|
+
rails (~> 3.1.0)
|
108
|
+
sass-rails
|
109
|
+
sprockets
|
data/README.md
CHANGED
@@ -148,6 +148,14 @@ Not only did I add a bunch of wonderfully awesome javascript libs I also added a
|
|
148
148
|
@import "fancybox.css.scss"
|
149
149
|
|
150
150
|
|
151
|
+
### Email Template ###
|
152
|
+
|
153
|
+
I've done my fair share of email template work... and I know it's not fun, but I have to say Sean Powell has done a great job compiling a great starting platform for constructing your HTML emails, so I've taken his code and added it as a base layout call `email.html.haml` so you can just include it when you are sending off you emails using `layout: "email"`
|
154
|
+
|
155
|
+
* [HTML Email Boilerplate](http://htmlemailboilerplate.com/)
|
156
|
+
* [HTML Email Boilerplate Github](https://github.com/seanpowell/Email-Boilerplate)
|
157
|
+
|
158
|
+
|
151
159
|
## Thanks ##
|
152
160
|
|
153
161
|
I hope you enjoy using this Rubygem, if you have any questions, issues, or feature requests please make them in the issues section, I'll be continually adding to this so please keep checking in on the progress.
|
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
|
|
19
19
|
gem.description = %Q{Large collection of useful Rails 3.1 helpers for SEO, Metatags, Facebook OG tags, integration for analytics services like google, woopra, olark, mixpanel and much much more...}
|
20
20
|
gem.email = "me@christopherhein.com"
|
21
21
|
gem.authors = ["Christopher Hein"]
|
22
|
-
gem.version = "0.0.
|
22
|
+
gem.version = "0.0.8"
|
23
23
|
# dependencies defined in Gemfile
|
24
24
|
end
|
25
25
|
Jeweler::RubygemsDotOrgTasks.new
|
@@ -0,0 +1,54 @@
|
|
1
|
+
!!!
|
2
|
+
%html{:xmlns => "http://www.w3.org/1999/xhtml"}
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
|
5
|
+
%title Your Message Subject or Title
|
6
|
+
:css
|
7
|
+
#outlook a { padding: 0; }
|
8
|
+
body { width: 100% !important; } .ReadMsgBody { width: 100%; } .ExternalClass { width: 100%; }
|
9
|
+
body { -webkit-text-size-adjust: none; -ms-text-size-adjust: none; }
|
10
|
+
|
11
|
+
body { margin: 0; padding: 0; }
|
12
|
+
img { height: auto; line-height: 100%; outline: none; text-decoration: none; }
|
13
|
+
a img { border:none; }
|
14
|
+
#backgroundTable { margin: 0; padding: 0; width: 100% !important; }
|
15
|
+
|
16
|
+
p {
|
17
|
+
margin: 1em 0;
|
18
|
+
}
|
19
|
+
|
20
|
+
h1, h2, h3, h4, h5, h6 {
|
21
|
+
color: black !important;
|
22
|
+
line-height: 100% !important;
|
23
|
+
}
|
24
|
+
|
25
|
+
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
|
26
|
+
color: blue !important;
|
27
|
+
}
|
28
|
+
|
29
|
+
h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
|
30
|
+
color: red !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
|
31
|
+
}
|
32
|
+
|
33
|
+
h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
|
34
|
+
color: purple !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
|
35
|
+
}
|
36
|
+
|
37
|
+
table td {
|
38
|
+
border-collapse: collapse;
|
39
|
+
}
|
40
|
+
|
41
|
+
.yshortcuts, .yshortcuts a, .yshortcuts a:link,.yshortcuts a:visited, .yshortcuts a:hover, .yshortcuts a span { color: black; text-decoration: none !important; border-bottom: none !important; background: none !important; } /* Body text color for the New Yahoo. This example sets the font of Yahoo's Shortcuts to black. */
|
42
|
+
|
43
|
+
%body
|
44
|
+
%table#backgroundTable{:border => "0", :cellpadding => "0", :cellspacing => "0"}
|
45
|
+
%tr
|
46
|
+
%td
|
47
|
+
%table{:border => "0", :cellpadding => "0", :cellspacing => "0"}
|
48
|
+
%tr
|
49
|
+
%td{:width => "200"}
|
50
|
+
%td{:width => "200"}= yield
|
51
|
+
%td{:width => "200"}
|
52
|
+
%a{:href => "http://www.responsys.com/blogs/nsm/2010/07/feeling-blue-over-yahoo-email.html", :style => "color:red; text-decoration: none;", :target => "_blank", :title => "Feeling Blue Over Yahoo"}
|
53
|
+
%span{:style => "color: red;"} Here is the fix for Yahoo from Responsys/Smith Harmon
|
54
|
+
%img{:alt => "Your alt text", :height => "x", :src => "full path to image", :style => "display: block;", :title => "Your title text", :width => "x"}/
|
data/frontend-helpers.gemspec
CHANGED
@@ -4,25 +4,27 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.0.
|
7
|
+
s.name = "frontend-helpers"
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
11
|
+
s.authors = ["Christopher Hein"]
|
12
|
+
s.date = "2011-09-20"
|
13
|
+
s.description = "Large collection of useful Rails 3.1 helpers for SEO, Metatags, Facebook OG tags, integration for analytics services like google, woopra, olark, mixpanel and much much more..."
|
14
|
+
s.email = "me@christopherhein.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
+
".rvmrc",
|
20
21
|
"Gemfile",
|
21
22
|
"Gemfile.lock",
|
22
23
|
"LICENSE.txt",
|
23
24
|
"MIT-LICENSE",
|
24
25
|
"README.md",
|
25
26
|
"Rakefile",
|
27
|
+
"app/views/layouts/mail.html.haml",
|
26
28
|
"config/services.yml",
|
27
29
|
"config/settings.yml",
|
28
30
|
"frontend-helpers.gemspec",
|
@@ -87,6 +89,7 @@ Gem::Specification.new do |s|
|
|
87
89
|
"vendor/assets/images/fancybox/fancybox-x.png",
|
88
90
|
"vendor/assets/images/fancybox/fancybox-y.png",
|
89
91
|
"vendor/assets/images/fancybox/fancybox.png",
|
92
|
+
"vendor/assets/javascripts/backbone/authtoken.js",
|
90
93
|
"vendor/assets/javascripts/backbone/backbone.js",
|
91
94
|
"vendor/assets/javascripts/backbone/index.js",
|
92
95
|
"vendor/assets/javascripts/backbone/underscore.js",
|
@@ -113,34 +116,34 @@ Gem::Specification.new do |s|
|
|
113
116
|
"vendor/assets/stylesheets/reset.css.sass",
|
114
117
|
"vendor/assets/stylesheets/variables.css.sass"
|
115
118
|
]
|
116
|
-
s.homepage =
|
117
|
-
s.licenses = [
|
118
|
-
s.require_paths = [
|
119
|
-
s.rubygems_version =
|
120
|
-
s.summary =
|
119
|
+
s.homepage = "http://github.com/christopherhein/frontend-helpers"
|
120
|
+
s.licenses = ["MIT"]
|
121
|
+
s.require_paths = ["lib"]
|
122
|
+
s.rubygems_version = "1.8.10"
|
123
|
+
s.summary = "Collection of useful frontend helpers for Rails 3.1 applications."
|
121
124
|
|
122
125
|
if s.respond_to? :specification_version then
|
123
126
|
s.specification_version = 3
|
124
127
|
|
125
128
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
126
|
-
s.add_runtime_dependency(%q<rails>, ["~> 3.1.0
|
127
|
-
s.add_runtime_dependency(%q<haml-rails>, ["
|
128
|
-
s.add_runtime_dependency(%q<sass-rails>, ["
|
129
|
-
s.add_runtime_dependency(%q<sprockets>, ["
|
130
|
-
s.add_development_dependency(%q<jeweler>, ["
|
129
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"])
|
130
|
+
s.add_runtime_dependency(%q<haml-rails>, [">= 0"])
|
131
|
+
s.add_runtime_dependency(%q<sass-rails>, [">= 0"])
|
132
|
+
s.add_runtime_dependency(%q<sprockets>, [">= 0"])
|
133
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
131
134
|
else
|
132
|
-
s.add_dependency(%q<rails>, ["~> 3.1.0
|
133
|
-
s.add_dependency(%q<haml-rails>, ["
|
134
|
-
s.add_dependency(%q<sass-rails>, ["
|
135
|
-
s.add_dependency(%q<sprockets>, ["
|
136
|
-
s.add_dependency(%q<jeweler>, ["
|
135
|
+
s.add_dependency(%q<rails>, ["~> 3.1.0"])
|
136
|
+
s.add_dependency(%q<haml-rails>, [">= 0"])
|
137
|
+
s.add_dependency(%q<sass-rails>, [">= 0"])
|
138
|
+
s.add_dependency(%q<sprockets>, [">= 0"])
|
139
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
137
140
|
end
|
138
141
|
else
|
139
|
-
s.add_dependency(%q<rails>, ["~> 3.1.0
|
140
|
-
s.add_dependency(%q<haml-rails>, ["
|
141
|
-
s.add_dependency(%q<sass-rails>, ["
|
142
|
-
s.add_dependency(%q<sprockets>, ["
|
143
|
-
s.add_dependency(%q<jeweler>, ["
|
142
|
+
s.add_dependency(%q<rails>, ["~> 3.1.0"])
|
143
|
+
s.add_dependency(%q<haml-rails>, [">= 0"])
|
144
|
+
s.add_dependency(%q<sass-rails>, [">= 0"])
|
145
|
+
s.add_dependency(%q<sprockets>, [">= 0"])
|
146
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
144
147
|
end
|
145
148
|
end
|
146
149
|
|
@@ -22,6 +22,11 @@ module Frontend
|
|
22
22
|
copy_file "vendor/assets/stylesheets/variables.css.sass", "app/assets/stylesheets/variables.css.sass"
|
23
23
|
end
|
24
24
|
|
25
|
+
def copy_email_template
|
26
|
+
say_status("copying", "Email Template", :green)
|
27
|
+
copy_file "app/views/layouts/mail.html.haml", "app/views/layouts/mail.html.haml"
|
28
|
+
end
|
29
|
+
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
//
|
2
|
+
// With additions by Maciej Adwent http://github.com/Maciek416
|
3
|
+
// If token name and value are not supplied, this code Requires jQuery
|
4
|
+
//
|
5
|
+
// Adapted from:
|
6
|
+
// http://www.ngauthier.com/2011/02/backbone-and-rails-forgery-protection.html
|
7
|
+
// Nick Gauthier @ngauthier
|
8
|
+
//
|
9
|
+
|
10
|
+
var BackboneRailsAuthTokenAdapter = {
|
11
|
+
|
12
|
+
//
|
13
|
+
// Given an instance of Backbone, route its sync() function so that
|
14
|
+
// it executes through this one first, which mixes in the CSRF
|
15
|
+
// authenticity token that Rails 3 needs to protect requests from
|
16
|
+
// forgery. Optionally, the token's name and value can be supplied
|
17
|
+
// by the caller.
|
18
|
+
//
|
19
|
+
fixSync: function(Backbone, paramName /*optional*/, paramValue /*optional*/){
|
20
|
+
|
21
|
+
if(typeof(paramName)=='string' && typeof(paramValue)=='string'){
|
22
|
+
// Use paramName and paramValue as supplied
|
23
|
+
} else {
|
24
|
+
// Assume we've rendered meta tags with erb
|
25
|
+
paramName = $("meta[name='csrf-param']").attr('content');
|
26
|
+
paramValue = $("meta[name='csrf-token']").attr('content');
|
27
|
+
}
|
28
|
+
|
29
|
+
// alias away the sync method
|
30
|
+
Backbone._sync = Backbone.sync;
|
31
|
+
|
32
|
+
// define a new sync method
|
33
|
+
Backbone.sync = function(method, model, success, error) {
|
34
|
+
|
35
|
+
// only need a token for non-get requests
|
36
|
+
if (method == 'create' || method == 'update' || method == 'delete') {
|
37
|
+
|
38
|
+
// grab the token from the meta tag rails embeds
|
39
|
+
var auth_options = {};
|
40
|
+
auth_options[paramName] = paramValue;
|
41
|
+
|
42
|
+
// set it as a model attribute without triggering events
|
43
|
+
model.set(auth_options, {silent: true});
|
44
|
+
}
|
45
|
+
|
46
|
+
// proxy the call to the old sync method
|
47
|
+
return Backbone._sync(method, model, success, error);
|
48
|
+
};
|
49
|
+
},
|
50
|
+
|
51
|
+
|
52
|
+
// change Backbone's sync function back to the original one
|
53
|
+
restoreSync: function(Backbone){
|
54
|
+
Backbone.sync = Backbone._sync;
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
58
|
+
BackboneRailsAuthTokenAdapter.fixSync(Backbone);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// Backbone.js 0.5.
|
1
|
+
// Backbone.js 0.5.3
|
2
2
|
// (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.
|
3
3
|
// Backbone may be freely distributed under the MIT license.
|
4
4
|
// For all details and documentation:
|
@@ -25,7 +25,7 @@
|
|
25
25
|
}
|
26
26
|
|
27
27
|
// Current version of the library. Keep in sync with `package.json`.
|
28
|
-
Backbone.VERSION = '0.5.
|
28
|
+
Backbone.VERSION = '0.5.3';
|
29
29
|
|
30
30
|
// Require Underscore, if we're on the server, and it's not already present.
|
31
31
|
var _ = root._;
|
@@ -41,7 +41,7 @@
|
|
41
41
|
return this;
|
42
42
|
};
|
43
43
|
|
44
|
-
// Turn on `emulateHTTP` to
|
44
|
+
// Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option will
|
45
45
|
// fake `"PUT"` and `"DELETE"` requests via the `_method` parameter and set a
|
46
46
|
// `X-Http-Method-Override` header.
|
47
47
|
Backbone.emulateHTTP = false;
|
@@ -68,10 +68,10 @@
|
|
68
68
|
|
69
69
|
// Bind an event, specified by a string name, `ev`, to a `callback` function.
|
70
70
|
// Passing `"all"` will bind the callback to all events fired.
|
71
|
-
bind : function(ev, callback) {
|
71
|
+
bind : function(ev, callback, context) {
|
72
72
|
var calls = this._callbacks || (this._callbacks = {});
|
73
73
|
var list = calls[ev] || (calls[ev] = []);
|
74
|
-
list.push(callback);
|
74
|
+
list.push([callback, context]);
|
75
75
|
return this;
|
76
76
|
},
|
77
77
|
|
@@ -89,7 +89,7 @@
|
|
89
89
|
var list = calls[ev];
|
90
90
|
if (!list) return this;
|
91
91
|
for (var i = 0, l = list.length; i < l; i++) {
|
92
|
-
if (callback === list[i]) {
|
92
|
+
if (list[i] && callback === list[i][0]) {
|
93
93
|
list[i] = null;
|
94
94
|
break;
|
95
95
|
}
|
@@ -114,7 +114,7 @@
|
|
114
114
|
list.splice(i, 1); i--; l--;
|
115
115
|
} else {
|
116
116
|
args = both ? Array.prototype.slice.call(arguments, 1) : arguments;
|
117
|
-
callback.apply(this, args);
|
117
|
+
callback[0].apply(callback[1] || this, args);
|
118
118
|
}
|
119
119
|
}
|
120
120
|
}
|
@@ -133,7 +133,7 @@
|
|
133
133
|
var defaults;
|
134
134
|
attributes || (attributes = {});
|
135
135
|
if (defaults = this.defaults) {
|
136
|
-
if (_.isFunction(defaults)) defaults = defaults();
|
136
|
+
if (_.isFunction(defaults)) defaults = defaults.call(this);
|
137
137
|
attributes = _.extend({}, defaults, attributes);
|
138
138
|
}
|
139
139
|
this.attributes = {};
|
@@ -582,7 +582,7 @@
|
|
582
582
|
options || (options = {});
|
583
583
|
model = this._prepareModel(model, options);
|
584
584
|
if (!model) return false;
|
585
|
-
var already = this.getByCid(model)
|
585
|
+
var already = this.getByCid(model);
|
586
586
|
if (already) throw new Error(["Can't add the same model to a set twice", already.id]);
|
587
587
|
this._byId[model.id] = model;
|
588
588
|
this._byCid[model.cid] = model;
|
@@ -641,7 +641,7 @@
|
|
641
641
|
var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', 'detect',
|
642
642
|
'filter', 'select', 'reject', 'every', 'all', 'some', 'any', 'include',
|
643
643
|
'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size',
|
644
|
-
'first', 'rest', 'last', 'without', 'indexOf', 'lastIndexOf', 'isEmpty'];
|
644
|
+
'first', 'rest', 'last', 'without', 'indexOf', 'lastIndexOf', 'isEmpty', 'groupBy'];
|
645
645
|
|
646
646
|
// Mix in each Underscore method as a proxy to `Collection#models`.
|
647
647
|
_.each(methods, function(method) {
|
@@ -766,7 +766,7 @@
|
|
766
766
|
fragment = window.location.hash;
|
767
767
|
}
|
768
768
|
}
|
769
|
-
return fragment.replace(hashStrip, '');
|
769
|
+
return decodeURIComponent(fragment.replace(hashStrip, ''));
|
770
770
|
},
|
771
771
|
|
772
772
|
// Start the hash change handling, returning `true` if the current URL matches
|
@@ -806,11 +806,16 @@
|
|
806
806
|
if (this._wantsPushState && !this._hasPushState && !atRoot) {
|
807
807
|
this.fragment = this.getFragment(null, true);
|
808
808
|
window.location.replace(this.options.root + '#' + this.fragment);
|
809
|
+
// Return immediately as browser will do redirect to new url
|
810
|
+
return true;
|
809
811
|
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
|
810
812
|
this.fragment = loc.hash.replace(hashStrip, '');
|
811
813
|
window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
|
812
814
|
}
|
813
|
-
|
815
|
+
|
816
|
+
if (!this.options.silent) {
|
817
|
+
return this.loadUrl();
|
818
|
+
}
|
814
819
|
},
|
815
820
|
|
816
821
|
// Add a route to be tested when the fragment changes. Routes added later may
|
@@ -947,6 +952,7 @@
|
|
947
952
|
// not `change`, `submit`, and `reset` in Internet Explorer.
|
948
953
|
delegateEvents : function(events) {
|
949
954
|
if (!(events || (events = this.events))) return;
|
955
|
+
if (_.isFunction(events)) events = events.call(this);
|
950
956
|
$(this.el).unbind('.delegateEvents' + this.cid);
|
951
957
|
for (var key in events) {
|
952
958
|
var method = this[events[key]];
|
@@ -1035,8 +1041,7 @@
|
|
1035
1041
|
// Default JSON-request options.
|
1036
1042
|
var params = _.extend({
|
1037
1043
|
type: type,
|
1038
|
-
dataType: 'json'
|
1039
|
-
processData: false
|
1044
|
+
dataType: 'json'
|
1040
1045
|
}, options);
|
1041
1046
|
|
1042
1047
|
// Ensure that we have a URL.
|
@@ -1053,7 +1058,6 @@
|
|
1053
1058
|
// For older servers, emulate JSON by encoding the request into an HTML-form.
|
1054
1059
|
if (Backbone.emulateJSON) {
|
1055
1060
|
params.contentType = 'application/x-www-form-urlencoded';
|
1056
|
-
params.processData = true;
|
1057
1061
|
params.data = params.data ? {model : params.data} : {};
|
1058
1062
|
}
|
1059
1063
|
|
@@ -1069,6 +1073,11 @@
|
|
1069
1073
|
}
|
1070
1074
|
}
|
1071
1075
|
|
1076
|
+
// Don't process data on a non-GET request.
|
1077
|
+
if (params.type !== 'GET' && !Backbone.emulateJSON) {
|
1078
|
+
params.processData = false;
|
1079
|
+
}
|
1080
|
+
|
1072
1081
|
// Make the request.
|
1073
1082
|
return $.ajax(params);
|
1074
1083
|
};
|
@@ -1143,7 +1152,7 @@
|
|
1143
1152
|
|
1144
1153
|
// Helper function to escape a string for HTML rendering.
|
1145
1154
|
var escapeHTML = function(string) {
|
1146
|
-
return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
1155
|
+
return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
1147
1156
|
};
|
1148
1157
|
|
1149
1158
|
}).call(this);
|