flexa_lib 0.1.3 → 0.1.5
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/lib/flexa_lib/version.rb +1 -1
- data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/images/glyphicons-halflings.png +0 -0
- data/vendor/assets/javascripts/bootstrap-alert.js +94 -0
- data/vendor/assets/javascripts/bootstrap-button.js +98 -0
- data/vendor/assets/javascripts/bootstrap-carousel.js +157 -0
- data/vendor/assets/javascripts/bootstrap-collapse.js +136 -0
- data/vendor/assets/javascripts/bootstrap-dropdown.js +92 -0
- data/vendor/assets/javascripts/bootstrap-modal.js +210 -0
- data/vendor/assets/javascripts/bootstrap-popover.js +95 -0
- data/vendor/assets/javascripts/bootstrap-scrollspy.js +125 -0
- data/vendor/assets/javascripts/bootstrap-tab.js +130 -0
- data/vendor/assets/javascripts/bootstrap-tooltip.js +270 -0
- data/vendor/assets/javascripts/bootstrap-transition.js +51 -0
- data/vendor/assets/javascripts/bootstrap-typeahead.js +271 -0
- data/vendor/assets/javascripts/bootstrap.js +12 -0
- data/vendor/assets/javascripts/flexa-themejs.js +94 -0
- data/vendor/assets/javascripts/jquery.cookie.js +96 -0
- data/vendor/assets/javascripts/jquery.pjax.js +460 -0
- data/vendor/assets/javascripts/populate.js +272 -0
- data/vendor/assets/stylesheets/_bootstrap-responsive.scss +318 -0
- data/vendor/assets/stylesheets/_bootstrap.scss +63 -0
- data/vendor/assets/stylesheets/bootstrap/_accordion.scss +28 -0
- data/vendor/assets/stylesheets/bootstrap/_alerts.scss +62 -0
- data/vendor/assets/stylesheets/bootstrap/_breadcrumbs.scss +22 -0
- data/vendor/assets/stylesheets/bootstrap/_button-groups.scss +136 -0
- data/vendor/assets/stylesheets/bootstrap/_buttons.scss +163 -0
- data/vendor/assets/stylesheets/bootstrap/_carousel.scss +116 -0
- data/vendor/assets/stylesheets/bootstrap/_close.scss +18 -0
- data/vendor/assets/stylesheets/bootstrap/_code.scss +56 -0
- data/vendor/assets/stylesheets/bootstrap/_component-animations.scss +18 -0
- data/vendor/assets/stylesheets/bootstrap/_dropdowns.scss +126 -0
- data/vendor/assets/stylesheets/bootstrap/_forms.scss +463 -0
- data/vendor/assets/stylesheets/bootstrap/_grid.scss +8 -0
- data/vendor/assets/stylesheets/bootstrap/_hero-unit.scss +20 -0
- data/vendor/assets/stylesheets/bootstrap/_labels.scss +32 -0
- data/vendor/assets/stylesheets/bootstrap/_layouts.scss +17 -0
- data/vendor/assets/stylesheets/bootstrap/_mixins.scss +530 -0
- data/vendor/assets/stylesheets/bootstrap/_modals.scss +83 -0
- data/vendor/assets/stylesheets/bootstrap/_navbar.scss +288 -0
- data/vendor/assets/stylesheets/bootstrap/_navs.scss +329 -0
- data/vendor/assets/stylesheets/bootstrap/_pager.scss +30 -0
- data/vendor/assets/stylesheets/bootstrap/_pagination.scss +53 -0
- data/vendor/assets/stylesheets/bootstrap/_popovers.scss +49 -0
- data/vendor/assets/stylesheets/bootstrap/_progress-bars.scss +95 -0
- data/vendor/assets/stylesheets/bootstrap/_reset.scss +105 -0
- data/vendor/assets/stylesheets/bootstrap/_scaffolding.scss +29 -0
- data/vendor/assets/stylesheets/bootstrap/_sprites.scss +157 -0
- data/vendor/assets/stylesheets/bootstrap/_tables.scss +126 -0
- data/vendor/assets/stylesheets/bootstrap/_thumbnails.scss +35 -0
- data/vendor/assets/stylesheets/bootstrap/_tooltip.scss +35 -0
- data/vendor/assets/stylesheets/bootstrap/_type.scss +209 -0
- data/vendor/assets/stylesheets/bootstrap/_utilities.scss +23 -0
- data/vendor/assets/stylesheets/bootstrap/_variables.scss +103 -0
- data/vendor/assets/stylesheets/bootstrap/_wells.scss +17 -0
- data/vendor/assets/stylesheets/docs.css.scss +790 -0
- data/vendor/assets/stylesheets/flexa-theme.css.scss +32 -0
- data/vendor/assets/stylesheets/override.css.scss +77 -0
- metadata +60 -3
@@ -0,0 +1,96 @@
|
|
1
|
+
/**
|
2
|
+
* Cookie plugin
|
3
|
+
*
|
4
|
+
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
|
5
|
+
* Dual licensed under the MIT and GPL licenses:
|
6
|
+
* http://www.opensource.org/licenses/mit-license.php
|
7
|
+
* http://www.gnu.org/licenses/gpl.html
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Create a cookie with the given name and value and other optional parameters.
|
13
|
+
*
|
14
|
+
* @example $.cookie('the_cookie', 'the_value');
|
15
|
+
* @desc Set the value of a cookie.
|
16
|
+
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
|
17
|
+
* @desc Create a cookie with all available options.
|
18
|
+
* @example $.cookie('the_cookie', 'the_value');
|
19
|
+
* @desc Create a session cookie.
|
20
|
+
* @example $.cookie('the_cookie', null);
|
21
|
+
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
|
22
|
+
* used when the cookie was set.
|
23
|
+
*
|
24
|
+
* @param String name The name of the cookie.
|
25
|
+
* @param String value The value of the cookie.
|
26
|
+
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
|
27
|
+
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
|
28
|
+
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
|
29
|
+
* If set to null or omitted, the cookie will be a session cookie and will not be retained
|
30
|
+
* when the the browser exits.
|
31
|
+
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
|
32
|
+
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
|
33
|
+
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
|
34
|
+
* require a secure protocol (like HTTPS).
|
35
|
+
* @type undefined
|
36
|
+
*
|
37
|
+
* @name $.cookie
|
38
|
+
* @cat Plugins/Cookie
|
39
|
+
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
40
|
+
*/
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Get the value of a cookie with the given name.
|
44
|
+
*
|
45
|
+
* @example $.cookie('the_cookie');
|
46
|
+
* @desc Get the value of a cookie.
|
47
|
+
*
|
48
|
+
* @param String name The name of the cookie.
|
49
|
+
* @return The value of the cookie.
|
50
|
+
* @type String
|
51
|
+
*
|
52
|
+
* @name $.cookie
|
53
|
+
* @cat Plugins/Cookie
|
54
|
+
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
55
|
+
*/
|
56
|
+
jQuery.cookie = function(name, value, options) {
|
57
|
+
if (typeof value != 'undefined') { // name and value given, set cookie
|
58
|
+
options = options || {};
|
59
|
+
if (value === null) {
|
60
|
+
value = '';
|
61
|
+
options.expires = -1;
|
62
|
+
}
|
63
|
+
var expires = '';
|
64
|
+
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
65
|
+
var date;
|
66
|
+
if (typeof options.expires == 'number') {
|
67
|
+
date = new Date();
|
68
|
+
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
69
|
+
} else {
|
70
|
+
date = options.expires;
|
71
|
+
}
|
72
|
+
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
|
73
|
+
}
|
74
|
+
// CAUTION: Needed to parenthesize options.path and options.domain
|
75
|
+
// in the following expressions, otherwise they evaluate to undefined
|
76
|
+
// in the packed version for some reason...
|
77
|
+
var path = options.path ? '; path=' + (options.path) : '';
|
78
|
+
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
79
|
+
var secure = options.secure ? '; secure' : '';
|
80
|
+
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
81
|
+
} else { // only name given, get cookie
|
82
|
+
var cookieValue = null;
|
83
|
+
if (document.cookie && document.cookie != '') {
|
84
|
+
var cookies = document.cookie.split(';');
|
85
|
+
for (var i = 0; i < cookies.length; i++) {
|
86
|
+
var cookie = jQuery.trim(cookies[i]);
|
87
|
+
// Does this cookie string begin with the name we want?
|
88
|
+
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
89
|
+
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return cookieValue;
|
95
|
+
}
|
96
|
+
};
|
@@ -0,0 +1,460 @@
|
|
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
|
+
// Internal: Strips _pjax=true param from url
|
85
|
+
//
|
86
|
+
// url - String
|
87
|
+
//
|
88
|
+
// Returns String.
|
89
|
+
function stripPjaxParam(url) {
|
90
|
+
return url
|
91
|
+
.replace(/\?_pjax=true&?/, '?')
|
92
|
+
.replace(/_pjax=true&?/, '')
|
93
|
+
.replace(/\?$/, '')
|
94
|
+
}
|
95
|
+
|
96
|
+
// Internal: Parse URL components and returns a Locationish object.
|
97
|
+
//
|
98
|
+
// url - String URL
|
99
|
+
//
|
100
|
+
// Returns HTMLAnchorElement that acts like Location.
|
101
|
+
function parseURL(url) {
|
102
|
+
var a = document.createElement('a')
|
103
|
+
a.href = url
|
104
|
+
return a
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
// Loads a URL with ajax, puts the response body inside a container,
|
109
|
+
// then pushState()'s the loaded URL.
|
110
|
+
//
|
111
|
+
// Works just like $.ajax in that it accepts a jQuery ajax
|
112
|
+
// settings object (with keys like url, type, data, etc).
|
113
|
+
//
|
114
|
+
// Accepts these extra keys:
|
115
|
+
//
|
116
|
+
// container - Where to stick the response body.
|
117
|
+
// $(container).html(xhr.responseBody)
|
118
|
+
// push - Whether to pushState the URL. Defaults to true (of course).
|
119
|
+
// replace - Want to use replaceState instead? That's cool.
|
120
|
+
//
|
121
|
+
// Use it just like $.ajax:
|
122
|
+
//
|
123
|
+
// var xhr = $.pjax({ url: this.href, container: '#main' })
|
124
|
+
// console.log( xhr.readyState )
|
125
|
+
//
|
126
|
+
// Returns whatever $.ajax returns.
|
127
|
+
var pjax = $.pjax = function( options ) {
|
128
|
+
options = $.extend(true, {}, $.ajaxSettings, pjax.defaults, options)
|
129
|
+
|
130
|
+
if ($.isFunction(options.url)) {
|
131
|
+
options.url = options.url()
|
132
|
+
}
|
133
|
+
|
134
|
+
var url = options.url
|
135
|
+
var hash = parseURL(url).hash
|
136
|
+
|
137
|
+
// DEPRECATED: Save references to original event callbacks. However,
|
138
|
+
// listening for custom pjax:* events is prefered.
|
139
|
+
var oldBeforeSend = options.beforeSend,
|
140
|
+
oldComplete = options.complete,
|
141
|
+
oldSuccess = options.success,
|
142
|
+
oldError = options.error
|
143
|
+
|
144
|
+
options.context = findContainerFor(options.container)
|
145
|
+
|
146
|
+
var timeoutTimer
|
147
|
+
|
148
|
+
options.beforeSend = function(xhr, settings) {
|
149
|
+
var context = this
|
150
|
+
|
151
|
+
url = stripPjaxParam(settings.url)
|
152
|
+
|
153
|
+
if (settings.timeout > 0) {
|
154
|
+
timeoutTimer = setTimeout(function() {
|
155
|
+
var event = $.Event('pjax:timeout')
|
156
|
+
context.trigger(event, [xhr, options])
|
157
|
+
if (event.result !== false)
|
158
|
+
xhr.abort('timeout')
|
159
|
+
}, settings.timeout)
|
160
|
+
|
161
|
+
// Clear timeout setting so jquerys internal timeout isn't invoked
|
162
|
+
settings.timeout = 0
|
163
|
+
}
|
164
|
+
|
165
|
+
xhr.setRequestHeader('X-PJAX', 'true')
|
166
|
+
|
167
|
+
var result
|
168
|
+
|
169
|
+
// DEPRECATED: Invoke original `beforeSend` handler
|
170
|
+
if (oldBeforeSend) {
|
171
|
+
result = oldBeforeSend.apply(this, arguments)
|
172
|
+
if (result === false) return false
|
173
|
+
}
|
174
|
+
|
175
|
+
var event = $.Event('pjax:beforeSend')
|
176
|
+
this.trigger(event, [xhr, settings])
|
177
|
+
result = event.result
|
178
|
+
if (result === false) return false
|
179
|
+
|
180
|
+
this.trigger('pjax:start', [xhr, options])
|
181
|
+
// start.pjax is deprecated
|
182
|
+
this.trigger('start.pjax', [xhr, options])
|
183
|
+
}
|
184
|
+
|
185
|
+
options.complete = function(xhr, textStatus) {
|
186
|
+
if (timeoutTimer)
|
187
|
+
clearTimeout(timeoutTimer)
|
188
|
+
|
189
|
+
// DEPRECATED: Invoke original `complete` handler
|
190
|
+
if (oldComplete) oldComplete.apply(this, arguments)
|
191
|
+
|
192
|
+
this.trigger('pjax:complete', [xhr, textStatus, options])
|
193
|
+
|
194
|
+
this.trigger('pjax:end', [xhr, options])
|
195
|
+
// end.pjax is deprecated
|
196
|
+
this.trigger('end.pjax', [xhr, options])
|
197
|
+
}
|
198
|
+
|
199
|
+
options.error = function(xhr, textStatus, errorThrown) {
|
200
|
+
var respUrl = xhr.getResponseHeader('X-PJAX-URL')
|
201
|
+
if (respUrl) url = stripPjaxParam(respUrl)
|
202
|
+
|
203
|
+
// DEPRECATED: Invoke original `error` handler
|
204
|
+
if (oldError) oldError.apply(this, arguments)
|
205
|
+
|
206
|
+
var event = $.Event('pjax:error')
|
207
|
+
this.trigger(event, [xhr, textStatus, errorThrown, options])
|
208
|
+
if (textStatus !== 'abort' && event.result !== false)
|
209
|
+
window.location = url
|
210
|
+
}
|
211
|
+
|
212
|
+
options.success = function(data, status, xhr) {
|
213
|
+
var respUrl = xhr.getResponseHeader('X-PJAX-URL')
|
214
|
+
if (respUrl) url = stripPjaxParam(respUrl)
|
215
|
+
|
216
|
+
var title, oldTitle = document.title
|
217
|
+
|
218
|
+
if ( options.fragment ) {
|
219
|
+
// If they specified a fragment, look for it in the response
|
220
|
+
// and pull it out.
|
221
|
+
var html = $('<html>').html(data)
|
222
|
+
var $fragment = html.find(options.fragment)
|
223
|
+
if ( $fragment.length ) {
|
224
|
+
this.html($fragment.contents())
|
225
|
+
|
226
|
+
// If there's a <title> tag in the response, use it as
|
227
|
+
// the page's title. Otherwise, look for data-title and title attributes.
|
228
|
+
title = html.find('title').text() || $fragment.attr('title') || $fragment.data('title')
|
229
|
+
} else {
|
230
|
+
return window.location = url
|
231
|
+
}
|
232
|
+
} else {
|
233
|
+
// If we got no data or an entire web page, go directly
|
234
|
+
// to the page and let normal error handling happen.
|
235
|
+
if ( !$.trim(data) || /<html/i.test(data) )
|
236
|
+
return window.location = url
|
237
|
+
|
238
|
+
this.html(data)
|
239
|
+
|
240
|
+
// If there's a <title> tag in the response, use it as
|
241
|
+
// the page's title.
|
242
|
+
title = this.find('title').remove().text()
|
243
|
+
}
|
244
|
+
|
245
|
+
if ( title ) document.title = $.trim(title)
|
246
|
+
|
247
|
+
var state = {
|
248
|
+
url: url,
|
249
|
+
pjax: this.selector,
|
250
|
+
fragment: options.fragment,
|
251
|
+
timeout: options.timeout
|
252
|
+
}
|
253
|
+
|
254
|
+
if ( options.replace ) {
|
255
|
+
pjax.active = true
|
256
|
+
window.history.replaceState(state, document.title, url)
|
257
|
+
} else if ( options.push ) {
|
258
|
+
// this extra replaceState before first push ensures good back
|
259
|
+
// button behavior
|
260
|
+
if ( !pjax.active ) {
|
261
|
+
window.history.replaceState($.extend({}, state, {url:null}), oldTitle)
|
262
|
+
pjax.active = true
|
263
|
+
}
|
264
|
+
|
265
|
+
window.history.pushState(state, document.title, url)
|
266
|
+
}
|
267
|
+
|
268
|
+
// Google Analytics support
|
269
|
+
if ( (options.replace || options.push) && window._gaq )
|
270
|
+
_gaq.push(['_trackPageview'])
|
271
|
+
|
272
|
+
// If the URL has a hash in it, make sure the browser
|
273
|
+
// knows to navigate to the hash.
|
274
|
+
if ( hash !== '' ) {
|
275
|
+
window.location.href = hash
|
276
|
+
}
|
277
|
+
|
278
|
+
// DEPRECATED: Invoke original `success` handler
|
279
|
+
if (oldSuccess) oldSuccess.apply(this, arguments)
|
280
|
+
|
281
|
+
this.trigger('pjax:success', [data, status, xhr, options])
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
// Cancel the current request if we're already pjaxing
|
286
|
+
var xhr = pjax.xhr
|
287
|
+
if ( xhr && xhr.readyState < 4) {
|
288
|
+
xhr.onreadystatechange = $.noop
|
289
|
+
xhr.abort()
|
290
|
+
}
|
291
|
+
|
292
|
+
pjax.options = options
|
293
|
+
pjax.xhr = $.ajax(options)
|
294
|
+
$(document).trigger('pjax', [pjax.xhr, options])
|
295
|
+
|
296
|
+
return pjax.xhr
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
// Internal: Build options Object for arguments.
|
301
|
+
//
|
302
|
+
// For convenience the first parameter can be either the container or
|
303
|
+
// the options object.
|
304
|
+
//
|
305
|
+
// Examples
|
306
|
+
//
|
307
|
+
// optionsFor('#container')
|
308
|
+
// // => {container: '#container'}
|
309
|
+
//
|
310
|
+
// optionsFor('#container', {push: true})
|
311
|
+
// // => {container: '#container', push: true}
|
312
|
+
//
|
313
|
+
// optionsFor({container: '#container', push: true})
|
314
|
+
// // => {container: '#container', push: true}
|
315
|
+
//
|
316
|
+
// Returns options Object.
|
317
|
+
function optionsFor(container, options) {
|
318
|
+
// Both container and options
|
319
|
+
if ( container && options )
|
320
|
+
options.container = container
|
321
|
+
|
322
|
+
// First argument is options Object
|
323
|
+
else if ( $.isPlainObject(container) )
|
324
|
+
options = container
|
325
|
+
|
326
|
+
// Only container
|
327
|
+
else
|
328
|
+
options = {container: container}
|
329
|
+
|
330
|
+
// Find and validate container
|
331
|
+
if (options.container)
|
332
|
+
options.container = findContainerFor(options.container)
|
333
|
+
|
334
|
+
return options
|
335
|
+
}
|
336
|
+
|
337
|
+
// Internal: Find container element for a variety of inputs.
|
338
|
+
//
|
339
|
+
// Because we can't persist elements using the history API, we must be
|
340
|
+
// able to find a String selector that will consistently find the Element.
|
341
|
+
//
|
342
|
+
// container - A selector String, jQuery object, or DOM Element.
|
343
|
+
//
|
344
|
+
// Returns a jQuery object whose context is `document` and has a selector.
|
345
|
+
function findContainerFor(container) {
|
346
|
+
container = $(container)
|
347
|
+
|
348
|
+
if ( !container.length ) {
|
349
|
+
throw "no pjax container for " + container.selector
|
350
|
+
} else if ( container.selector !== '' && container.context === document ) {
|
351
|
+
return container
|
352
|
+
} else if ( container.attr('id') ) {
|
353
|
+
return $('#' + container.attr('id'))
|
354
|
+
} else {
|
355
|
+
throw "cant get selector for pjax container!"
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
pjax.defaults = {
|
361
|
+
timeout: 650,
|
362
|
+
push: true,
|
363
|
+
replace: false,
|
364
|
+
// We want the browser to maintain two separate internal caches: one for
|
365
|
+
// pjax'd partial page loads and one for normal page loads. Without
|
366
|
+
// adding this secret parameter, some browsers will often confuse the two.
|
367
|
+
data: { _pjax: true },
|
368
|
+
type: 'GET',
|
369
|
+
dataType: 'html'
|
370
|
+
}
|
371
|
+
|
372
|
+
// Export $.pjax.click
|
373
|
+
pjax.click = handleClick
|
374
|
+
|
375
|
+
|
376
|
+
// Used to detect initial (useless) popstate.
|
377
|
+
// If history.state exists, assume browser isn't going to fire initial popstate.
|
378
|
+
var popped = ('state' in window.history), initialURL = location.href
|
379
|
+
|
380
|
+
|
381
|
+
// popstate handler takes care of the back and forward buttons
|
382
|
+
//
|
383
|
+
// You probably shouldn't use pjax on pages with other pushState
|
384
|
+
// stuff yet.
|
385
|
+
$(window).bind('popstate', function(event){
|
386
|
+
// Ignore inital popstate that some browsers fire on page load
|
387
|
+
var initialPop = !popped && location.href == initialURL
|
388
|
+
popped = true
|
389
|
+
if ( initialPop ) return
|
390
|
+
|
391
|
+
var state = event.state
|
392
|
+
|
393
|
+
if ( state && state.pjax ) {
|
394
|
+
var container = state.pjax
|
395
|
+
if ( $(container+'').length )
|
396
|
+
$.pjax({
|
397
|
+
url: state.url || location.href,
|
398
|
+
fragment: state.fragment,
|
399
|
+
container: container,
|
400
|
+
push: false,
|
401
|
+
timeout: state.timeout
|
402
|
+
})
|
403
|
+
else
|
404
|
+
window.location = location.href
|
405
|
+
}
|
406
|
+
})
|
407
|
+
|
408
|
+
|
409
|
+
// Add the state property to jQuery's event object so we can use it in
|
410
|
+
// $(window).bind('popstate')
|
411
|
+
if ( $.inArray('state', $.event.props) < 0 )
|
412
|
+
$.event.props.push('state')
|
413
|
+
|
414
|
+
|
415
|
+
// Is pjax supported by this browser?
|
416
|
+
$.support.pjax =
|
417
|
+
window.history && window.history.pushState && window.history.replaceState
|
418
|
+
// pushState isn't reliable on iOS until 5.
|
419
|
+
&& !navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]|WebApps\/.+CFNetwork)/)
|
420
|
+
|
421
|
+
|
422
|
+
// Fall back to normalcy for older browsers.
|
423
|
+
if ( !$.support.pjax ) {
|
424
|
+
$.pjax = function( options ) {
|
425
|
+
var url = $.isFunction(options.url) ? options.url() : options.url,
|
426
|
+
method = options.type ? options.type.toUpperCase() : 'GET'
|
427
|
+
|
428
|
+
var form = $('<form>', {
|
429
|
+
method: method === 'GET' ? 'GET' : 'POST',
|
430
|
+
action: url,
|
431
|
+
style: 'display:none'
|
432
|
+
})
|
433
|
+
|
434
|
+
if (method !== 'GET' && method !== 'POST') {
|
435
|
+
form.append($('<input>', {
|
436
|
+
type: 'hidden',
|
437
|
+
name: '_method',
|
438
|
+
value: method.toLowerCase()
|
439
|
+
}))
|
440
|
+
}
|
441
|
+
|
442
|
+
var data = options.data
|
443
|
+
if (typeof data === 'string') {
|
444
|
+
$.each(data.split('&'), function(index, value) {
|
445
|
+
var pair = value.split('=')
|
446
|
+
form.append($('<input>', {type: 'hidden', name: pair[0], value: pair[1]}))
|
447
|
+
})
|
448
|
+
} else if (typeof data === 'object') {
|
449
|
+
for (key in data)
|
450
|
+
form.append($('<input>', {type: 'hidden', name: key, value: data[key]}))
|
451
|
+
}
|
452
|
+
|
453
|
+
$(document.body).append(form)
|
454
|
+
form.submit()
|
455
|
+
}
|
456
|
+
$.pjax.click = $.noop
|
457
|
+
$.fn.pjax = function() { return this }
|
458
|
+
}
|
459
|
+
|
460
|
+
})(jQuery);
|