zepto_rails 1.0
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 +8 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +91 -0
- data/MIT-LICENSE +20 -0
- data/README.md +46 -0
- data/Rakefile +27 -0
- data/lib/zepto/rails.rb +2 -0
- data/lib/zepto/rails/engine.rb +6 -0
- data/lib/zepto/rails/version.rb +5 -0
- data/lib/zepto_rails.rb +1 -0
- data/vendor/assets/javascripts/zepto.js +7 -0
- data/vendor/assets/javascripts/zepto/ajax.js +314 -0
- data/vendor/assets/javascripts/zepto/all.js +14 -0
- data/vendor/assets/javascripts/zepto/assets.js +21 -0
- data/vendor/assets/javascripts/zepto/data.js +67 -0
- data/vendor/assets/javascripts/zepto/detect.js +55 -0
- data/vendor/assets/javascripts/zepto/event.js +248 -0
- data/vendor/assets/javascripts/zepto/form.js +40 -0
- data/vendor/assets/javascripts/zepto/fx.js +102 -0
- data/vendor/assets/javascripts/zepto/fx_methods.js +71 -0
- data/vendor/assets/javascripts/zepto/gesture.js +35 -0
- data/vendor/assets/javascripts/zepto/polyfill.js +36 -0
- data/vendor/assets/javascripts/zepto/selector.js +81 -0
- data/vendor/assets/javascripts/zepto/stack.js +22 -0
- data/vendor/assets/javascripts/zepto/touch.js +115 -0
- data/vendor/assets/javascripts/zepto/zepto.js +790 -0
- data/zepto_rails.gemspec +21 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in zepto-rails.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zepto-rails (1.0.0)
|
5
|
+
rails (>= 3.2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.2.3)
|
11
|
+
actionpack (= 3.2.3)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.3)
|
14
|
+
activemodel (= 3.2.3)
|
15
|
+
activesupport (= 3.2.3)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.1)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.1.2)
|
23
|
+
activemodel (3.2.3)
|
24
|
+
activesupport (= 3.2.3)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.3)
|
27
|
+
activemodel (= 3.2.3)
|
28
|
+
activesupport (= 3.2.3)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.3)
|
32
|
+
activemodel (= 3.2.3)
|
33
|
+
activesupport (= 3.2.3)
|
34
|
+
activesupport (3.2.3)
|
35
|
+
i18n (~> 0.6)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.0)
|
39
|
+
erubis (2.7.0)
|
40
|
+
hike (1.2.1)
|
41
|
+
i18n (0.6.0)
|
42
|
+
journey (1.0.3)
|
43
|
+
json (1.6.6)
|
44
|
+
mail (2.4.4)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.18)
|
49
|
+
multi_json (1.3.2)
|
50
|
+
polyglot (0.3.3)
|
51
|
+
rack (1.4.1)
|
52
|
+
rack-cache (1.2)
|
53
|
+
rack (>= 0.4)
|
54
|
+
rack-ssl (1.3.2)
|
55
|
+
rack
|
56
|
+
rack-test (0.6.1)
|
57
|
+
rack (>= 1.0)
|
58
|
+
rails (3.2.3)
|
59
|
+
actionmailer (= 3.2.3)
|
60
|
+
actionpack (= 3.2.3)
|
61
|
+
activerecord (= 3.2.3)
|
62
|
+
activeresource (= 3.2.3)
|
63
|
+
activesupport (= 3.2.3)
|
64
|
+
bundler (~> 1.0)
|
65
|
+
railties (= 3.2.3)
|
66
|
+
railties (3.2.3)
|
67
|
+
actionpack (= 3.2.3)
|
68
|
+
activesupport (= 3.2.3)
|
69
|
+
rack-ssl (~> 1.3.2)
|
70
|
+
rake (>= 0.8.7)
|
71
|
+
rdoc (~> 3.4)
|
72
|
+
thor (~> 0.14.6)
|
73
|
+
rake (0.9.2.2)
|
74
|
+
rdoc (3.12)
|
75
|
+
json (~> 1.4)
|
76
|
+
sprockets (2.1.3)
|
77
|
+
hike (~> 1.2)
|
78
|
+
rack (~> 1.0)
|
79
|
+
tilt (~> 1.1, != 1.3.0)
|
80
|
+
thor (0.14.6)
|
81
|
+
tilt (1.3.3)
|
82
|
+
treetop (1.4.10)
|
83
|
+
polyglot
|
84
|
+
polyglot (>= 0.3.1)
|
85
|
+
tzinfo (0.3.33)
|
86
|
+
|
87
|
+
PLATFORMS
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
zepto-rails!
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Jason T. Carrell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# zepto-rails
|
2
|
+
|
3
|
+
Zepto for the Rails asset pipeline.
|
4
|
+
|
5
|
+
This gem provides Zepto 1.0.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add zepto-rails to the Gemfile.
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'zepto_rails'
|
13
|
+
```
|
14
|
+
|
15
|
+
And run `bundle install`.
|
16
|
+
|
17
|
+
Then add this lines to your `app/assets/javascripts/application.js`:
|
18
|
+
|
19
|
+
```
|
20
|
+
// require zepto
|
21
|
+
```
|
22
|
+
|
23
|
+
If you only want to include some of the modules in zepto you can add them individually. The available modules are:
|
24
|
+
|
25
|
+
```
|
26
|
+
//= require zepto/polyfill
|
27
|
+
//= require zepto/zepto
|
28
|
+
//= require zepto/event
|
29
|
+
//= require zepto/detect
|
30
|
+
//= require zepto/fx
|
31
|
+
//= require zepto/fx_methods
|
32
|
+
//= require zepto/ajax
|
33
|
+
//= require zepto/form
|
34
|
+
//= require zepto/assets
|
35
|
+
//= require zepto/data
|
36
|
+
//= require zepto/selector
|
37
|
+
//= require zepto/touch
|
38
|
+
//= require zepto/gesture
|
39
|
+
//= require zepto/stack
|
40
|
+
```
|
41
|
+
|
42
|
+
Or if you want to include all of the modules add this line to your `app/assets/javascripts/application.js`:
|
43
|
+
|
44
|
+
```
|
45
|
+
// require zepto/all
|
46
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ZeptoRails'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
data/lib/zepto/rails.rb
ADDED
data/lib/zepto_rails.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'zepto/rails'
|
@@ -0,0 +1,314 @@
|
|
1
|
+
// Zepto.js
|
2
|
+
// (c) 2010-2012 Thomas Fuchs
|
3
|
+
// Zepto.js may be freely distributed under the MIT license.
|
4
|
+
|
5
|
+
;(function($){
|
6
|
+
var jsonpID = 0,
|
7
|
+
document = window.document,
|
8
|
+
key,
|
9
|
+
name,
|
10
|
+
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
11
|
+
scriptTypeRE = /^(?:text|application)\/javascript/i,
|
12
|
+
xmlTypeRE = /^(?:text|application)\/xml/i,
|
13
|
+
jsonType = 'application/json',
|
14
|
+
htmlType = 'text/html',
|
15
|
+
blankRE = /^\s*$/
|
16
|
+
|
17
|
+
// trigger a custom event and return false if it was cancelled
|
18
|
+
function triggerAndReturn(context, eventName, data) {
|
19
|
+
var event = $.Event(eventName)
|
20
|
+
$(context).trigger(event, data)
|
21
|
+
return !event.defaultPrevented
|
22
|
+
}
|
23
|
+
|
24
|
+
// trigger an Ajax "global" event
|
25
|
+
function triggerGlobal(settings, context, eventName, data) {
|
26
|
+
if (settings.global) return triggerAndReturn(context || document, eventName, data)
|
27
|
+
}
|
28
|
+
|
29
|
+
// Number of active Ajax requests
|
30
|
+
$.active = 0
|
31
|
+
|
32
|
+
function ajaxStart(settings) {
|
33
|
+
if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart')
|
34
|
+
}
|
35
|
+
function ajaxStop(settings) {
|
36
|
+
if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop')
|
37
|
+
}
|
38
|
+
|
39
|
+
// triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
|
40
|
+
function ajaxBeforeSend(xhr, settings) {
|
41
|
+
var context = settings.context
|
42
|
+
if (settings.beforeSend.call(context, xhr, settings) === false ||
|
43
|
+
triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
|
44
|
+
return false
|
45
|
+
|
46
|
+
triggerGlobal(settings, context, 'ajaxSend', [xhr, settings])
|
47
|
+
}
|
48
|
+
function ajaxSuccess(data, xhr, settings) {
|
49
|
+
var context = settings.context, status = 'success'
|
50
|
+
settings.success.call(context, data, status, xhr)
|
51
|
+
triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data])
|
52
|
+
ajaxComplete(status, xhr, settings)
|
53
|
+
}
|
54
|
+
// type: "timeout", "error", "abort", "parsererror"
|
55
|
+
function ajaxError(error, type, xhr, settings) {
|
56
|
+
var context = settings.context
|
57
|
+
settings.error.call(context, xhr, type, error)
|
58
|
+
triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error])
|
59
|
+
ajaxComplete(type, xhr, settings)
|
60
|
+
}
|
61
|
+
// status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
|
62
|
+
function ajaxComplete(status, xhr, settings) {
|
63
|
+
var context = settings.context
|
64
|
+
settings.complete.call(context, xhr, status)
|
65
|
+
triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings])
|
66
|
+
ajaxStop(settings)
|
67
|
+
}
|
68
|
+
|
69
|
+
// Empty function, used as default callback
|
70
|
+
function empty() {}
|
71
|
+
|
72
|
+
$.ajaxJSONP = function(options){
|
73
|
+
if (!('type' in options)) return $.ajax(options)
|
74
|
+
|
75
|
+
var callbackName = 'jsonp' + (++jsonpID),
|
76
|
+
script = document.createElement('script'),
|
77
|
+
cleanup = function() {
|
78
|
+
clearTimeout(abortTimeout)
|
79
|
+
$(script).remove()
|
80
|
+
delete window[callbackName]
|
81
|
+
},
|
82
|
+
abort = function(type){
|
83
|
+
cleanup()
|
84
|
+
// In case of manual abort or timeout, keep an empty function as callback
|
85
|
+
// so that the SCRIPT tag that eventually loads won't result in an error.
|
86
|
+
if (!type || type == 'timeout') window[callbackName] = empty
|
87
|
+
ajaxError(null, type || 'abort', xhr, options)
|
88
|
+
},
|
89
|
+
xhr = { abort: abort }, abortTimeout
|
90
|
+
|
91
|
+
if (ajaxBeforeSend(xhr, options) === false) {
|
92
|
+
abort('abort')
|
93
|
+
return false
|
94
|
+
}
|
95
|
+
|
96
|
+
window[callbackName] = function(data){
|
97
|
+
cleanup()
|
98
|
+
ajaxSuccess(data, xhr, options)
|
99
|
+
}
|
100
|
+
|
101
|
+
script.onerror = function() { abort('error') }
|
102
|
+
|
103
|
+
script.src = options.url.replace(/=\?/, '=' + callbackName)
|
104
|
+
$('head').append(script)
|
105
|
+
|
106
|
+
if (options.timeout > 0) abortTimeout = setTimeout(function(){
|
107
|
+
abort('timeout')
|
108
|
+
}, options.timeout)
|
109
|
+
|
110
|
+
return xhr
|
111
|
+
}
|
112
|
+
|
113
|
+
$.ajaxSettings = {
|
114
|
+
// Default type of request
|
115
|
+
type: 'GET',
|
116
|
+
// Callback that is executed before request
|
117
|
+
beforeSend: empty,
|
118
|
+
// Callback that is executed if the request succeeds
|
119
|
+
success: empty,
|
120
|
+
// Callback that is executed the the server drops error
|
121
|
+
error: empty,
|
122
|
+
// Callback that is executed on request complete (both: error and success)
|
123
|
+
complete: empty,
|
124
|
+
// The context for the callbacks
|
125
|
+
context: null,
|
126
|
+
// Whether to trigger "global" Ajax events
|
127
|
+
global: true,
|
128
|
+
// Transport
|
129
|
+
xhr: function () {
|
130
|
+
return new window.XMLHttpRequest()
|
131
|
+
},
|
132
|
+
// MIME types mapping
|
133
|
+
accepts: {
|
134
|
+
script: 'text/javascript, application/javascript',
|
135
|
+
json: jsonType,
|
136
|
+
xml: 'application/xml, text/xml',
|
137
|
+
html: htmlType,
|
138
|
+
text: 'text/plain'
|
139
|
+
},
|
140
|
+
// Whether the request is to another domain
|
141
|
+
crossDomain: false,
|
142
|
+
// Default timeout
|
143
|
+
timeout: 0,
|
144
|
+
// Whether data should be serialized to string
|
145
|
+
processData: true,
|
146
|
+
// Whether the browser should be allowed to cache GET responses
|
147
|
+
cache: true
|
148
|
+
}
|
149
|
+
|
150
|
+
function mimeToDataType(mime) {
|
151
|
+
if (mime) mime = mime.split(';', 2)[0]
|
152
|
+
return mime && ( mime == htmlType ? 'html' :
|
153
|
+
mime == jsonType ? 'json' :
|
154
|
+
scriptTypeRE.test(mime) ? 'script' :
|
155
|
+
xmlTypeRE.test(mime) && 'xml' ) || 'text'
|
156
|
+
}
|
157
|
+
|
158
|
+
function appendQuery(url, query) {
|
159
|
+
return (url + '&' + query).replace(/[&?]{1,2}/, '?')
|
160
|
+
}
|
161
|
+
|
162
|
+
// serialize payload and append it to the URL for GET requests
|
163
|
+
function serializeData(options) {
|
164
|
+
if (options.processData && options.data && $.type(options.data) != "string")
|
165
|
+
options.data = $.param(options.data, options.traditional)
|
166
|
+
if (options.data && (!options.type || options.type.toUpperCase() == 'GET'))
|
167
|
+
options.url = appendQuery(options.url, options.data)
|
168
|
+
}
|
169
|
+
|
170
|
+
$.ajax = function(options){
|
171
|
+
var settings = $.extend({}, options || {})
|
172
|
+
for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key]
|
173
|
+
|
174
|
+
ajaxStart(settings)
|
175
|
+
|
176
|
+
if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) &&
|
177
|
+
RegExp.$2 != window.location.host
|
178
|
+
|
179
|
+
if (!settings.url) settings.url = window.location.toString()
|
180
|
+
serializeData(settings)
|
181
|
+
if (settings.cache === false) settings.url = appendQuery(settings.url, '_=' + Date.now())
|
182
|
+
|
183
|
+
var dataType = settings.dataType, hasPlaceholder = /=\?/.test(settings.url)
|
184
|
+
if (dataType == 'jsonp' || hasPlaceholder) {
|
185
|
+
if (!hasPlaceholder) settings.url = appendQuery(settings.url, 'callback=?')
|
186
|
+
return $.ajaxJSONP(settings)
|
187
|
+
}
|
188
|
+
|
189
|
+
var mime = settings.accepts[dataType],
|
190
|
+
baseHeaders = { },
|
191
|
+
protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
|
192
|
+
xhr = settings.xhr(), abortTimeout
|
193
|
+
|
194
|
+
if (!settings.crossDomain) baseHeaders['X-Requested-With'] = 'XMLHttpRequest'
|
195
|
+
if (mime) {
|
196
|
+
baseHeaders['Accept'] = mime
|
197
|
+
if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0]
|
198
|
+
xhr.overrideMimeType && xhr.overrideMimeType(mime)
|
199
|
+
}
|
200
|
+
if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET'))
|
201
|
+
baseHeaders['Content-Type'] = (settings.contentType || 'application/x-www-form-urlencoded')
|
202
|
+
settings.headers = $.extend(baseHeaders, settings.headers || {})
|
203
|
+
|
204
|
+
xhr.onreadystatechange = function(){
|
205
|
+
if (xhr.readyState == 4) {
|
206
|
+
xhr.onreadystatechange = empty;
|
207
|
+
clearTimeout(abortTimeout)
|
208
|
+
var result, error = false
|
209
|
+
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
|
210
|
+
dataType = dataType || mimeToDataType(xhr.getResponseHeader('content-type'))
|
211
|
+
result = xhr.responseText
|
212
|
+
|
213
|
+
try {
|
214
|
+
// http://perfectionkills.com/global-eval-what-are-the-options/
|
215
|
+
if (dataType == 'script') (1,eval)(result)
|
216
|
+
else if (dataType == 'xml') result = xhr.responseXML
|
217
|
+
else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result)
|
218
|
+
} catch (e) { error = e }
|
219
|
+
|
220
|
+
if (error) ajaxError(error, 'parsererror', xhr, settings)
|
221
|
+
else ajaxSuccess(result, xhr, settings)
|
222
|
+
} else {
|
223
|
+
ajaxError(null, xhr.status ? 'error' : 'abort', xhr, settings)
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
var async = 'async' in settings ? settings.async : true
|
229
|
+
xhr.open(settings.type, settings.url, async)
|
230
|
+
|
231
|
+
for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name])
|
232
|
+
|
233
|
+
if (ajaxBeforeSend(xhr, settings) === false) {
|
234
|
+
xhr.abort()
|
235
|
+
return false
|
236
|
+
}
|
237
|
+
|
238
|
+
if (settings.timeout > 0) abortTimeout = setTimeout(function(){
|
239
|
+
xhr.onreadystatechange = empty
|
240
|
+
xhr.abort()
|
241
|
+
ajaxError(null, 'timeout', xhr, settings)
|
242
|
+
}, settings.timeout)
|
243
|
+
|
244
|
+
// avoid sending empty string (#319)
|
245
|
+
xhr.send(settings.data ? settings.data : null)
|
246
|
+
return xhr
|
247
|
+
}
|
248
|
+
|
249
|
+
// handle optional data/success arguments
|
250
|
+
function parseArguments(url, data, success, dataType) {
|
251
|
+
var hasData = !$.isFunction(data)
|
252
|
+
return {
|
253
|
+
url: url,
|
254
|
+
data: hasData ? data : undefined,
|
255
|
+
success: !hasData ? data : $.isFunction(success) ? success : undefined,
|
256
|
+
dataType: hasData ? dataType || success : success
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
$.get = function(url, data, success, dataType){
|
261
|
+
return $.ajax(parseArguments.apply(null, arguments))
|
262
|
+
}
|
263
|
+
|
264
|
+
$.post = function(url, data, success, dataType){
|
265
|
+
var options = parseArguments.apply(null, arguments)
|
266
|
+
options.type = 'POST'
|
267
|
+
return $.ajax(options)
|
268
|
+
}
|
269
|
+
|
270
|
+
$.getJSON = function(url, data, success){
|
271
|
+
var options = parseArguments.apply(null, arguments)
|
272
|
+
options.dataType = 'json'
|
273
|
+
return $.ajax(options)
|
274
|
+
}
|
275
|
+
|
276
|
+
$.fn.load = function(url, data, success){
|
277
|
+
if (!this.length) return this
|
278
|
+
var self = this, parts = url.split(/\s/), selector,
|
279
|
+
options = parseArguments(url, data, success),
|
280
|
+
callback = options.success
|
281
|
+
if (parts.length > 1) options.url = parts[0], selector = parts[1]
|
282
|
+
options.success = function(response){
|
283
|
+
self.html(selector ?
|
284
|
+
$('<div>').html(response.replace(rscript, "")).find(selector)
|
285
|
+
: response)
|
286
|
+
callback && callback.apply(self, arguments)
|
287
|
+
}
|
288
|
+
$.ajax(options)
|
289
|
+
return this
|
290
|
+
}
|
291
|
+
|
292
|
+
var escape = encodeURIComponent
|
293
|
+
|
294
|
+
function serialize(params, obj, traditional, scope){
|
295
|
+
var type, array = $.isArray(obj)
|
296
|
+
$.each(obj, function(key, value) {
|
297
|
+
type = $.type(value)
|
298
|
+
if (scope) key = traditional ? scope : scope + '[' + (array ? '' : key) + ']'
|
299
|
+
// handle data in serializeArray() format
|
300
|
+
if (!scope && array) params.add(value.name, value.value)
|
301
|
+
// recurse into nested objects
|
302
|
+
else if (type == "array" || (!traditional && type == "object"))
|
303
|
+
serialize(params, value, traditional, key)
|
304
|
+
else params.add(key, value)
|
305
|
+
})
|
306
|
+
}
|
307
|
+
|
308
|
+
$.param = function(obj, traditional){
|
309
|
+
var params = []
|
310
|
+
params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) }
|
311
|
+
serialize(params, obj, traditional)
|
312
|
+
return params.join('&').replace(/%20/g, '+')
|
313
|
+
}
|
314
|
+
})(Zepto)
|