beautiful_scaffold 0.3.0.rc6 → 0.3.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/CHANGELOG +12 -0
- data/README.rdoc +1 -1
- data/beautiful_scaffold.gemspec +1 -1
- data/lib/generators/beautiful_migration_generator.rb +3 -0
- data/lib/generators/templates/app/assets/javascripts/application-bs.js +9 -0
- data/lib/generators/templates/app/controllers/base.rb +6 -18
- data/lib/generators/templates/app/helpers/beautiful_helper.rb +1 -1
- data/lib/generators/templates/app/views/_modal_columns.html.erb +1 -1
- data/lib/generators/templates/app/views/index.html.erb +4 -4
- data/lib/generators/templates/app/views/layout.html.erb +3 -6
- data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +2 -2
- metadata +5 -6
- data/lib/generators/templates/app/assets/javascripts/jquery.pjax.js +0 -370
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 0.3.1
|
2
|
+
|
3
|
+
* enhancement
|
4
|
+
* Spinner works with turbolink
|
5
|
+
|
6
|
+
* bugfix
|
7
|
+
* Remove PJAX references
|
8
|
+
* i18n bug names of columns
|
9
|
+
* Flash notice/error with redirect_to fixed
|
10
|
+
* Change Info string to Error in flash[:error] div
|
11
|
+
* Add new attributes in model's permitted attributes and columns select and mass inserting form
|
12
|
+
|
1
13
|
== 0.3.0.rc6
|
2
14
|
|
3
15
|
* enhancement
|
data/README.rdoc
CHANGED
data/beautiful_scaffold.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "beautiful_scaffold"
|
6
|
-
s.version = "0.3.
|
6
|
+
s.version = "0.3.1"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.summary = "Beautiful Scaffold generate fully customizable scaffold"
|
9
9
|
s.email = "claudel.sylvain@gmail.com"
|
@@ -41,6 +41,8 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
41
41
|
inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ActiveRecord::Base")
|
42
42
|
a += "_id"
|
43
43
|
end
|
44
|
+
|
45
|
+
inject_into_file("app/models/#{model}.rb", ":#{a},", :after => "def self.permitted_attributes\n return ")
|
44
46
|
}
|
45
47
|
end
|
46
48
|
|
@@ -54,6 +56,7 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
54
56
|
inject_into_file("#{commonpath}index.html.erb", render_partial("app/views/partials/_index_header.html.erb"), :before => "<!-- Beautiful_scaffold - AddField - Header - Do not remove -->\n" )
|
55
57
|
inject_into_file("#{commonpath}index.html.erb", render_partial("app/views/partials/_index_column.html.erb"), :before => "<!-- Beautiful_scaffold - AddField - Column - Do not remove -->\n" )
|
56
58
|
inject_into_file("#{commonpath}index.html.erb", render_partial("app/views/partials/_index_search.html.erb"), :before => "<!-- Beautiful_scaffold - AddField - Search - Do not remove -->\n" )
|
59
|
+
inject_into_file("#{commonpath}index.html.erb", myattributes.map{ |attr| a,t = attr.split(':');(['references', 'reference'].include?(t) ? "'#{a}_id'" : "'#{a}'") }.join(',') + ',', :after => ":model_columns => [" )
|
57
60
|
# Show
|
58
61
|
inject_into_file("#{commonpath}show.html.erb", render_partial("app/views/partials/_show_field.html.erb"), :before => "<!-- Beautiful_scaffold - AddField - Field - Do not remove -->\n" )
|
59
62
|
end
|
@@ -37,6 +37,15 @@ function initPage(){
|
|
37
37
|
}
|
38
38
|
$(function() {
|
39
39
|
initPage();
|
40
|
+
function startSpinner(){
|
41
|
+
$('.loader').show();
|
42
|
+
}
|
43
|
+
function stopSpinner(){
|
44
|
+
$('.loader').hide();
|
45
|
+
}
|
46
|
+
document.addEventListener("page:fetch", startSpinner);
|
47
|
+
document.addEventListener("page:receive", stopSpinner);
|
48
|
+
document.addEventListener("page:restore", stopSpinner);
|
40
49
|
});
|
41
50
|
$(window).bind('page:change', function() {
|
42
51
|
initPage();
|
@@ -35,11 +35,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
35
35
|
|
36
36
|
respond_to do |format|
|
37
37
|
format.html{
|
38
|
-
|
39
|
-
render :layout => false
|
40
|
-
else
|
41
|
-
render
|
42
|
-
end
|
38
|
+
render
|
43
39
|
}
|
44
40
|
format.json{
|
45
41
|
render :json => @<%= model %>_scope.all
|
@@ -67,11 +63,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
67
63
|
def show
|
68
64
|
respond_to do |format|
|
69
65
|
format.html{
|
70
|
-
|
71
|
-
render :layout => false
|
72
|
-
else
|
73
|
-
render
|
74
|
-
end
|
66
|
+
render
|
75
67
|
}
|
76
68
|
format.json { render :json => @<%= model %> }
|
77
69
|
end
|
@@ -82,11 +74,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
82
74
|
|
83
75
|
respond_to do |format|
|
84
76
|
format.html{
|
85
|
-
|
86
|
-
render :layout => false
|
87
|
-
else
|
88
|
-
render
|
89
|
-
end
|
77
|
+
render
|
90
78
|
}
|
91
79
|
format.json { render :json => @<%= model %> }
|
92
80
|
end
|
@@ -105,14 +93,14 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
105
93
|
if params[:mass_inserting] then
|
106
94
|
redirect_to <%= namespace_for_route %><%= model_pluralize %>_path(:mass_inserting => true)
|
107
95
|
else
|
108
|
-
redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :notice => t(:create_success, :model => "<%= model %>")
|
96
|
+
redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :flash => { :notice => t(:create_success, :model => "<%= model %>") }
|
109
97
|
end
|
110
98
|
}
|
111
99
|
format.json { render :json => @<%= model %>, :status => :created, :location => @<%= model %> }
|
112
100
|
else
|
113
101
|
format.html {
|
114
102
|
if params[:mass_inserting] then
|
115
|
-
redirect_to <%= namespace_for_route %><%= model_pluralize %>_path(:mass_inserting => true), :error => t(:error, "Error")
|
103
|
+
redirect_to <%= namespace_for_route %><%= model_pluralize %>_path(:mass_inserting => true), :flash => { :error => t(:error, "Error") }
|
116
104
|
else
|
117
105
|
render :action => "new"
|
118
106
|
end
|
@@ -126,7 +114,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
|
|
126
114
|
|
127
115
|
respond_to do |format|
|
128
116
|
if @<%= model %>.update_attributes(params_for_model)
|
129
|
-
format.html { redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :notice => t(:update_success, :model => "<%= model %>") }
|
117
|
+
format.html { redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :flash => { :notice => t(:update_success, :model => "<%= model %>") }}
|
130
118
|
format.json { head :ok }
|
131
119
|
else
|
132
120
|
format.html { render :action => "edit" }
|
@@ -249,7 +249,7 @@ module BeautifulHelper
|
|
249
249
|
def build_treeview(obj, child_relation, caption_method = "caption")
|
250
250
|
out = '
|
251
251
|
<li id="treeelt_' + obj.id.to_s + '" data-id="' + obj.id.to_s + '">
|
252
|
-
<a href="#"
|
252
|
+
<a href="#">' + obj.send(caption_method).to_s + '</a>
|
253
253
|
<ul>'
|
254
254
|
ar = obj.send(child_relation.to_sym)
|
255
255
|
ar = ar.order('position') if obj.class.column_names.include?("position")
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<div class="modal-body">
|
7
7
|
<% for field in model_columns %>
|
8
8
|
<label class="checkbox">
|
9
|
-
<input type="checkbox" name="field[]" value="<%= field %>" <%= "checked" if session[:fields][model_name.to_sym].include?(field) %>> <%= t(field, :default => field.capitalize) %>
|
9
|
+
<input type="checkbox" name="field[]" value="<%= field %>" <%= "checked" if session[:fields][model_name.to_sym].include?(field) %>> <%= t("app.models.#{model_name}.bs_attributes.#{field}", :default => field.capitalize) %>
|
10
10
|
</label><br />
|
11
11
|
<% end %>
|
12
12
|
</div>
|
@@ -94,10 +94,10 @@
|
|
94
94
|
|
95
95
|
</div>
|
96
96
|
<div class="btn-group pull-right">
|
97
|
-
<%%= link_to '<i class="icon-download"></i> CSV'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :csv), :class => "
|
98
|
-
<%%= link_to '<i class="icon-download"></i> XML'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :xml), :class => "
|
99
|
-
<%%= link_to '<i class="icon-download"></i> JSON'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :json), :class => "
|
100
|
-
<%%= link_to '<i class="icon-download"></i> PDF'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :pdf), :class => "
|
97
|
+
<%%= link_to '<i class="icon-download"></i> CSV'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :csv), :class => "btn" %>
|
98
|
+
<%%= link_to '<i class="icon-download"></i> XML'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :xml), :class => "btn" %>
|
99
|
+
<%%= link_to '<i class="icon-download"></i> JSON'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :json), :class => "btn" %>
|
100
|
+
<%%= link_to '<i class="icon-download"></i> PDF'.html_safe, <%= namespace_for_route %><%= plural_table_name %>_path(:format => :pdf), :class => "btn" %>
|
101
101
|
</div>
|
102
102
|
</div>
|
103
103
|
<%% end %>
|
@@ -26,7 +26,7 @@
|
|
26
26
|
</li>
|
27
27
|
<li class="hidden-desktop">
|
28
28
|
<!-- Mobile navbar -->
|
29
|
-
<a href="#"
|
29
|
+
<a href="#" data-toggle="collapse" data-target=".nav-collapse">
|
30
30
|
<i class="icon-th-list"></i>
|
31
31
|
</a>
|
32
32
|
</li>
|
@@ -38,7 +38,6 @@
|
|
38
38
|
</ul>
|
39
39
|
<div class="nav-collapse collapse">
|
40
40
|
<ul class="nav hidden-desktop">
|
41
|
-
<%% @nopjax = "nopjax" %>
|
42
41
|
<%%= render :partial => "layouts/beautiful_menu" %>
|
43
42
|
</ul>
|
44
43
|
</div>
|
@@ -56,7 +55,6 @@
|
|
56
55
|
</ul>
|
57
56
|
</div>
|
58
57
|
<div class="span10">
|
59
|
-
<!-- Zone PJAX -->
|
60
58
|
<%% if not flash[:notice].blank? then %>
|
61
59
|
<div class="alert alert-info">
|
62
60
|
<a class="close" data-dismiss="alert" href="#">×</a>
|
@@ -67,14 +65,13 @@
|
|
67
65
|
<%% if not flash[:error].blank? then %>
|
68
66
|
<div class="alert alert-error">
|
69
67
|
<a class="close" data-dismiss="alert" href="#">×</a>
|
70
|
-
<h4 class="alert-heading">
|
68
|
+
<h4 class="alert-heading">Error : </h4>
|
71
69
|
<%%= flash[:error] %>
|
72
70
|
</div>
|
73
71
|
<%% end %>
|
74
|
-
<div
|
72
|
+
<div>
|
75
73
|
<%%= yield %>
|
76
74
|
</div>
|
77
|
-
<!-- FIN Zone PJAX -->
|
78
75
|
</div>
|
79
76
|
</div>
|
80
77
|
</div>
|
@@ -13,6 +13,6 @@
|
|
13
13
|
</div>
|
14
14
|
<%%= f.submit t(:sign_in, :default => "Sign in"), :class => "btn" %>
|
15
15
|
<%% end %>
|
16
|
-
<a data-toggle="modal" href="#modal-forget-password"
|
17
|
-
<a data-toggle="modal" href="#modal-register-form"
|
16
|
+
<a data-toggle="modal" href="#modal-forget-password"><%%= t(:forgot_your_password, :default => "Forgot your password?") %></a>
|
17
|
+
<a data-toggle="modal" href="#modal-register-form"><%%= t(:register, :default => "Register") %></a>
|
18
18
|
</div>
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beautiful_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sylvain Claudel
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Beautiful Scaffold generate a complete scaffold (sort, export, paginate
|
15
15
|
and filter data) http://www.beautiful-scaffold.com
|
@@ -47,7 +47,6 @@ files:
|
|
47
47
|
- lib/generators/templates/app/assets/javascripts/jquery-barcode.js
|
48
48
|
- lib/generators/templates/app/assets/javascripts/jquery.jstree.js
|
49
49
|
- lib/generators/templates/app/assets/javascripts/jquery.livequery.js
|
50
|
-
- lib/generators/templates/app/assets/javascripts/jquery.pjax.js
|
51
50
|
- lib/generators/templates/app/assets/javascripts/modernizr.custom.js
|
52
51
|
- lib/generators/templates/app/assets/javascripts/tagit.js
|
53
52
|
- lib/generators/templates/app/assets/stylesheets/application-bs.css
|
@@ -241,9 +240,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
240
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
241
|
none: false
|
243
242
|
requirements:
|
244
|
-
- - ! '
|
243
|
+
- - ! '>='
|
245
244
|
- !ruby/object:Gem::Version
|
246
|
-
version:
|
245
|
+
version: '0'
|
247
246
|
requirements: []
|
248
247
|
rubyforge_project: beautiful_scaffold
|
249
248
|
rubygems_version: 1.8.25
|
@@ -1,370 +0,0 @@
|
|
1
|
-
// jquery.pjax.js
|
2
|
-
// copyright chris wanstrath
|
3
|
-
// https://github.com/defunkt/jquery-pjax
|
4
|
-
|
5
|
-
(function($){
|
6
|
-
|
7
|
-
// When called on a link, fetches the href with ajax into the
|
8
|
-
// container specified as the first parameter or with the data-pjax
|
9
|
-
// attribute on the link itself.
|
10
|
-
//
|
11
|
-
// Tries to make sure the back button and ctrl+click work the way
|
12
|
-
// you'd expect.
|
13
|
-
//
|
14
|
-
// Accepts a jQuery ajax options object that may include these
|
15
|
-
// pjax specific options:
|
16
|
-
//
|
17
|
-
// container - Where to stick the response body. Usually a String selector.
|
18
|
-
// $(container).html(xhr.responseBody)
|
19
|
-
// push - Whether to pushState the URL. Defaults to true (of course).
|
20
|
-
// replace - Want to use replaceState instead? That's cool.
|
21
|
-
//
|
22
|
-
// For convenience the first parameter can be either the container or
|
23
|
-
// the options object.
|
24
|
-
//
|
25
|
-
// Returns the jQuery object
|
26
|
-
$.fn.pjax = function( container, options ) {
|
27
|
-
options = optionsFor(container, options)
|
28
|
-
return this.live('click', function(event){
|
29
|
-
return handleClick(event, options)
|
30
|
-
})
|
31
|
-
}
|
32
|
-
|
33
|
-
// Public: pjax on click handler
|
34
|
-
//
|
35
|
-
// Exported as $.pjax.click.
|
36
|
-
//
|
37
|
-
// event - "click" jQuery.Event
|
38
|
-
// options - pjax options
|
39
|
-
//
|
40
|
-
// Examples
|
41
|
-
//
|
42
|
-
// $('a').live('click', $.pjax.click)
|
43
|
-
// // is the same as
|
44
|
-
// $('a').pjax()
|
45
|
-
//
|
46
|
-
// $(document).on('click', 'a', function(event) {
|
47
|
-
// var container = $(this).closest('[data-pjax-container]')
|
48
|
-
// return $.pjax.click(event, container)
|
49
|
-
// })
|
50
|
-
//
|
51
|
-
// Returns false if pjax runs, otherwise nothing.
|
52
|
-
function handleClick(event, container, options) {
|
53
|
-
options = optionsFor(container, options)
|
54
|
-
|
55
|
-
var link = event.currentTarget
|
56
|
-
|
57
|
-
// Middle click, cmd click, and ctrl click should open
|
58
|
-
// links in a new tab as normal.
|
59
|
-
if ( event.which > 1 || event.metaKey )
|
60
|
-
return
|
61
|
-
|
62
|
-
// Ignore cross origin links
|
63
|
-
if ( location.protocol !== link.protocol || location.host !== link.host )
|
64
|
-
return
|
65
|
-
|
66
|
-
// Ignore anchors on the same page
|
67
|
-
if ( link.hash && link.href.replace(link.hash, '') ===
|
68
|
-
location.href.replace(location.hash, '') )
|
69
|
-
return
|
70
|
-
|
71
|
-
var defaults = {
|
72
|
-
url: link.href,
|
73
|
-
container: $(link).attr('data-pjax'),
|
74
|
-
clickedElement: $(link),
|
75
|
-
fragment: null
|
76
|
-
}
|
77
|
-
|
78
|
-
$.pjax($.extend({}, defaults, options))
|
79
|
-
|
80
|
-
event.preventDefault()
|
81
|
-
return false
|
82
|
-
}
|
83
|
-
|
84
|
-
|
85
|
-
// Loads a URL with ajax, puts the response body inside a container,
|
86
|
-
// then pushState()'s the loaded URL.
|
87
|
-
//
|
88
|
-
// Works just like $.ajax in that it accepts a jQuery ajax
|
89
|
-
// settings object (with keys like url, type, data, etc).
|
90
|
-
//
|
91
|
-
// Accepts these extra keys:
|
92
|
-
//
|
93
|
-
// container - Where to stick the response body.
|
94
|
-
// $(container).html(xhr.responseBody)
|
95
|
-
// push - Whether to pushState the URL. Defaults to true (of course).
|
96
|
-
// replace - Want to use replaceState instead? That's cool.
|
97
|
-
//
|
98
|
-
// Use it just like $.ajax:
|
99
|
-
//
|
100
|
-
// var xhr = $.pjax({ url: this.href, container: '#main' })
|
101
|
-
// console.log( xhr.readyState )
|
102
|
-
//
|
103
|
-
// Returns whatever $.ajax returns.
|
104
|
-
var pjax = $.pjax = function( options ) {
|
105
|
-
var $container = findContainerFor(options.container),
|
106
|
-
success = options.success || $.noop
|
107
|
-
|
108
|
-
// We don't want to let anyone override our success handler.
|
109
|
-
delete options.success
|
110
|
-
|
111
|
-
options = $.extend(true, {}, pjax.defaults, options)
|
112
|
-
|
113
|
-
if ( $.isFunction(options.url) ) {
|
114
|
-
options.url = options.url()
|
115
|
-
}
|
116
|
-
|
117
|
-
options.context = $container
|
118
|
-
|
119
|
-
options.success = function(data){
|
120
|
-
if ( options.fragment ) {
|
121
|
-
// If they specified a fragment, look for it in the response
|
122
|
-
// and pull it out.
|
123
|
-
var $fragment = $(data).find(options.fragment)
|
124
|
-
if ( $fragment.length )
|
125
|
-
data = $fragment.children()
|
126
|
-
else
|
127
|
-
return window.location = options.url
|
128
|
-
} else {
|
129
|
-
// If we got no data or an entire web page, go directly
|
130
|
-
// to the page and let normal error handling happen.
|
131
|
-
if ( !$.trim(data) || /<html/i.test(data) )
|
132
|
-
return window.location = options.url
|
133
|
-
}
|
134
|
-
|
135
|
-
// Make it happen.
|
136
|
-
this.html(data)
|
137
|
-
|
138
|
-
// If there's a <title> tag in the response, use it as
|
139
|
-
// the page's title.
|
140
|
-
var oldTitle = document.title,
|
141
|
-
title = $.trim( this.find('title').remove().text() )
|
142
|
-
|
143
|
-
// No <title>? Fragment? Look for data-title and title attributes.
|
144
|
-
if ( !title && options.fragment ) {
|
145
|
-
title = $fragment.attr('title') || $fragment.data('title')
|
146
|
-
}
|
147
|
-
|
148
|
-
if ( title ) document.title = title
|
149
|
-
|
150
|
-
var state = {
|
151
|
-
pjax: $container.selector,
|
152
|
-
fragment: options.fragment,
|
153
|
-
timeout: options.timeout
|
154
|
-
}
|
155
|
-
|
156
|
-
// If there are extra params, save the complete URL in the state object
|
157
|
-
var query = $.param(options.data)
|
158
|
-
if ( query != "_pjax=true" )
|
159
|
-
state.url = options.url + (/\?/.test(options.url) ? "&" : "?") + query
|
160
|
-
|
161
|
-
if ( options.replace ) {
|
162
|
-
pjax.active = true
|
163
|
-
window.history.replaceState(state, document.title, options.url)
|
164
|
-
} else if ( options.push ) {
|
165
|
-
// this extra replaceState before first push ensures good back
|
166
|
-
// button behavior
|
167
|
-
if ( !pjax.active ) {
|
168
|
-
window.history.replaceState($.extend({}, state, {url:null}), oldTitle)
|
169
|
-
pjax.active = true
|
170
|
-
}
|
171
|
-
|
172
|
-
window.history.pushState(state, document.title, options.url)
|
173
|
-
}
|
174
|
-
|
175
|
-
// Google Analytics support
|
176
|
-
if ( (options.replace || options.push) && window._gaq )
|
177
|
-
_gaq.push(['_trackPageview'])
|
178
|
-
|
179
|
-
// If the URL has a hash in it, make sure the browser
|
180
|
-
// knows to navigate to the hash.
|
181
|
-
var hash = window.location.hash.toString()
|
182
|
-
if ( hash !== '' ) {
|
183
|
-
window.location.href = hash
|
184
|
-
}
|
185
|
-
|
186
|
-
// Invoke their success handler if they gave us one.
|
187
|
-
success.apply(this, arguments)
|
188
|
-
}
|
189
|
-
|
190
|
-
// Cancel the current request if we're already pjaxing
|
191
|
-
var xhr = pjax.xhr
|
192
|
-
if ( xhr && xhr.readyState < 4) {
|
193
|
-
xhr.onreadystatechange = $.noop
|
194
|
-
xhr.abort()
|
195
|
-
}
|
196
|
-
|
197
|
-
pjax.options = options
|
198
|
-
pjax.xhr = $.ajax(options)
|
199
|
-
$(document).trigger('pjax', [pjax.xhr, options])
|
200
|
-
|
201
|
-
return pjax.xhr
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
// Internal: Build options Object for arguments.
|
206
|
-
//
|
207
|
-
// For convenience the first parameter can be either the container or
|
208
|
-
// the options object.
|
209
|
-
//
|
210
|
-
// Examples
|
211
|
-
//
|
212
|
-
// optionsFor('#container')
|
213
|
-
// // => {container: '#container'}
|
214
|
-
//
|
215
|
-
// optionsFor('#container', {push: true})
|
216
|
-
// // => {container: '#container', push: true}
|
217
|
-
//
|
218
|
-
// optionsFor({container: '#container', push: true})
|
219
|
-
// // => {container: '#container', push: true}
|
220
|
-
//
|
221
|
-
// Returns options Object.
|
222
|
-
function optionsFor(container, options) {
|
223
|
-
// Both container and options
|
224
|
-
if ( container && options )
|
225
|
-
options.container = container
|
226
|
-
|
227
|
-
// First argument is options Object
|
228
|
-
else if ( $.isPlainObject(container) )
|
229
|
-
options = container
|
230
|
-
|
231
|
-
// Only container
|
232
|
-
else
|
233
|
-
options = {container: container}
|
234
|
-
|
235
|
-
// Find and validate container
|
236
|
-
if (options.container)
|
237
|
-
options.container = findContainerFor(options.container)
|
238
|
-
|
239
|
-
return options
|
240
|
-
}
|
241
|
-
|
242
|
-
// Internal: Find container element for a variety of inputs.
|
243
|
-
//
|
244
|
-
// Because we can't persist elements using the history API, we must be
|
245
|
-
// able to find a String selector that will consistently find the Element.
|
246
|
-
//
|
247
|
-
// container - A selector String, jQuery object, or DOM Element.
|
248
|
-
//
|
249
|
-
// Returns a jQuery object whose context is `document` and has a selector.
|
250
|
-
function findContainerFor(container) {
|
251
|
-
container = $(container)
|
252
|
-
|
253
|
-
if ( !container.length ) {
|
254
|
-
throw "no pjax container for " + container.selector
|
255
|
-
} else if ( container.selector !== '' && container.context === document ) {
|
256
|
-
return container
|
257
|
-
} else if ( container.attr('id') ) {
|
258
|
-
return $('#' + container.attr('id'))
|
259
|
-
} else {
|
260
|
-
throw "cant get selector for pjax container!"
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
|
265
|
-
var timeoutTimer = null
|
266
|
-
|
267
|
-
pjax.defaults = {
|
268
|
-
timeout: 650,
|
269
|
-
push: true,
|
270
|
-
replace: false,
|
271
|
-
// We want the browser to maintain two separate internal caches: one for
|
272
|
-
// pjax'd partial page loads and one for normal page loads. Without
|
273
|
-
// adding this secret parameter, some browsers will often confuse the two.
|
274
|
-
data: { _pjax: true },
|
275
|
-
type: 'GET',
|
276
|
-
dataType: 'html',
|
277
|
-
beforeSend: function(xhr, settings){
|
278
|
-
var context = this
|
279
|
-
|
280
|
-
if (settings.async && settings.timeout > 0) {
|
281
|
-
timeoutTimer = setTimeout(function() {
|
282
|
-
var event = $.Event('pjax:timeout')
|
283
|
-
context.trigger(event, [xhr, pjax.options])
|
284
|
-
if (event.result !== false)
|
285
|
-
xhr.abort('timeout')
|
286
|
-
}, settings.timeout)
|
287
|
-
|
288
|
-
// Clear timeout setting so jquerys internal timeout isn't invoked
|
289
|
-
settings.timeout = 0
|
290
|
-
}
|
291
|
-
|
292
|
-
this.trigger('pjax:start', [xhr, pjax.options])
|
293
|
-
// start.pjax is deprecated
|
294
|
-
this.trigger('start.pjax', [xhr, pjax.options])
|
295
|
-
xhr.setRequestHeader('X-PJAX', 'true')
|
296
|
-
},
|
297
|
-
error: function(xhr, textStatus, errorThrown){
|
298
|
-
if ( textStatus !== 'abort' )
|
299
|
-
window.location = pjax.options.url
|
300
|
-
},
|
301
|
-
complete: function(xhr){
|
302
|
-
if (timeoutTimer)
|
303
|
-
clearTimeout(timeoutTimer)
|
304
|
-
|
305
|
-
this.trigger('pjax:end', [xhr, pjax.options])
|
306
|
-
// end.pjax is deprecated
|
307
|
-
this.trigger('end.pjax', [xhr, pjax.options])
|
308
|
-
}
|
309
|
-
}
|
310
|
-
|
311
|
-
// Export $.pjax.click
|
312
|
-
pjax.click = handleClick
|
313
|
-
|
314
|
-
|
315
|
-
// Used to detect initial (useless) popstate.
|
316
|
-
// If history.state exists, assume browser isn't going to fire initial popstate.
|
317
|
-
var popped = ('state' in window.history), initialURL = location.href
|
318
|
-
|
319
|
-
|
320
|
-
// popstate handler takes care of the back and forward buttons
|
321
|
-
//
|
322
|
-
// You probably shouldn't use pjax on pages with other pushState
|
323
|
-
// stuff yet.
|
324
|
-
$(window).bind('popstate', function(event){
|
325
|
-
// Ignore inital popstate that some browsers fire on page load
|
326
|
-
var initialPop = !popped && location.href == initialURL
|
327
|
-
popped = true
|
328
|
-
if ( initialPop ) return
|
329
|
-
|
330
|
-
var state = event.state
|
331
|
-
|
332
|
-
if ( state && state.pjax ) {
|
333
|
-
var container = state.pjax
|
334
|
-
if ( $(container+'').length )
|
335
|
-
$.pjax({
|
336
|
-
url: state.url || location.href,
|
337
|
-
fragment: state.fragment,
|
338
|
-
container: container,
|
339
|
-
push: false,
|
340
|
-
timeout: state.timeout
|
341
|
-
})
|
342
|
-
else
|
343
|
-
window.location = location.href
|
344
|
-
}
|
345
|
-
})
|
346
|
-
|
347
|
-
|
348
|
-
// Add the state property to jQuery's event object so we can use it in
|
349
|
-
// $(window).bind('popstate')
|
350
|
-
if ( $.inArray('state', $.event.props) < 0 )
|
351
|
-
$.event.props.push('state')
|
352
|
-
|
353
|
-
|
354
|
-
// Is pjax supported by this browser?
|
355
|
-
$.support.pjax =
|
356
|
-
window.history && window.history.pushState && window.history.replaceState
|
357
|
-
// pushState isn't reliable on iOS until 5.
|
358
|
-
&& !navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]|WebApps\/.+CFNetwork)/)
|
359
|
-
|
360
|
-
|
361
|
-
// Fall back to normalcy for older browsers.
|
362
|
-
if ( !$.support.pjax ) {
|
363
|
-
$.pjax = function( options ) {
|
364
|
-
window.location = $.isFunction(options.url) ? options.url() : options.url
|
365
|
-
}
|
366
|
-
$.pjax.click = $.noop
|
367
|
-
$.fn.pjax = function() { return this }
|
368
|
-
}
|
369
|
-
|
370
|
-
})(jQuery);
|