wpa_cli_web 0.0.5 → 0.0.6
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/.bowerrc +3 -0
- data/lib/wpa_cli_web.rb +19 -31
- data/lib/wpa_cli_web/public/bower_components/house-style/.bower.json +14 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/.bowerrc +3 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/.gitignore +2 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/Gemfile +6 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/Gruntfile.js +99 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/Guardfile +19 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/bower.json +7 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/bower_components/normalize-css/LICENSE.md +19 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/bower_components/normalize-css/README.md +49 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/bower_components/normalize-css/bower.json +23 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/bower_components/normalize-css/normalize.css +396 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/house-style.css +860 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/house-style.min.css +1 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/base/base.css +37 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/button/button.css +26 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/grid/grid.css +151 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/grid/grid.png +0 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/grid/images.html +208 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/grid/index.html +141 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/loading/index.html +22 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/loading/loading.css +41 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/loading/spinner.svg +11 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/masthead/bbc-blocks-white.png +0 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/masthead/index.html +20 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/masthead/masthead.css +23 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/panel/panel.css +71 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/project-header/index.html +22 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/project-header/project-header.css +37 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/table/index.html +26 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/table/table.css +6 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/modules/transitions/transitions.css +11 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/package.json +21 -0
- data/lib/wpa_cli_web/public/bower_components/house-style/vendor/prefixfree.min.js +5 -0
- data/lib/wpa_cli_web/public/bower_components/normalize-css/.bower.json +21 -0
- data/lib/wpa_cli_web/public/bower_components/normalize-css/LICENSE.md +19 -0
- data/lib/wpa_cli_web/public/bower_components/normalize-css/README.md +49 -0
- data/lib/wpa_cli_web/public/bower_components/normalize-css/bower.json +12 -0
- data/lib/wpa_cli_web/public/bower_components/normalize-css/normalize.css +396 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/.bower.json +14 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/.gitignore +3 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/.travis.yml +10 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/LICENSE +7 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/Makefile +6 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/README.md +167 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/config/smoosh.json +35 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/integration/ender.js +1033 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/integration/integration.html +26 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/mobile/ender.js +62 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/mobile/package.json +14 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/mobile/qwery-mobile.js +79 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/mobile/qwery-mobile.min.js +7 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/mobile/src/mobile.js +72 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/package.json +25 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/pseudos/package.json +17 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/pseudos/qwery-pseudos.js +106 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/pseudos/qwery-pseudos.min.js +7 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/pseudos/src/pseudos.js +99 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/qwery.js +369 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/qwery.min.js +7 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/src/copyright.js +6 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/src/ender.js +62 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/src/qwery.js +362 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/W3C-Selector-tests.html +1372 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/benchmarks.html +220 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/index.html +132 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/mobile.html +58 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/phantom.js +43 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/test-env.js +25 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/tests/tests.js +533 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/vendor/nw.js +1680 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/vendor/sink.css +79 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/vendor/sink.js +181 -0
- data/lib/wpa_cli_web/public/bower_components/qwery/vendor/sizzle.js +1400 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/.bower.json +14 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/.gitignore +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/.jshintrc +61 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/Makefile +8 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/README.md +308 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/build.json +74 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/make/tests.js +89 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/package.json +27 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/reqwest.js +565 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/reqwest.min.js +7 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/src/copyright.js +6 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/src/ender.js +26 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/src/reqwest.js +559 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/ender.js +117 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/badfixtures.xml +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures.html +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures.js +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures.json +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures.xml +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_jsonp.jsonp +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_jsonp2.jsonp +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_jsonp3.jsonp +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_jsonp_multi.jsonp +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_jsonp_multi_b.jsonp +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_jsonp_multi_c.jsonp +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/fixtures_with_prefix.json +1 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/fixtures/invalidJSON.json +5 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/tests.html +105 -0
- data/lib/wpa_cli_web/public/bower_components/reqwest/tests/tests.js +1723 -0
- data/lib/wpa_cli_web/views/access_points.erb +5 -0
- data/lib/wpa_cli_web/views/access_points_list.erb +19 -0
- data/lib/wpa_cli_web/views/layout.erb +141 -0
- data/lib/wpa_cli_web/views/networks_edit.erb +15 -0
- data/lib/wpa_cli_web/views/restart.erb +7 -0
- data/lib/wpa_cli_web/views/restarting.erb +14 -0
- data/wpa_cli_web.gemspec +1 -1
- metadata +111 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var exec = require('child_process').exec
|
|
2
|
+
, fs = require('fs')
|
|
3
|
+
, Connect = require('connect')
|
|
4
|
+
, dispatch = require('dispatch')
|
|
5
|
+
, mime = require('mime')
|
|
6
|
+
, DelayedStream = require('delayed-stream')
|
|
7
|
+
|
|
8
|
+
, getMime = function(ext) {
|
|
9
|
+
return mime.lookup(ext == 'jsonp' ? 'js' : ext)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var routes = {
|
|
13
|
+
'/': function (req, res) {
|
|
14
|
+
res.write(fs.readFileSync('./tests/tests.html', 'utf8'))
|
|
15
|
+
res.end()
|
|
16
|
+
},
|
|
17
|
+
'/tests/timeout$': function (req, res) {
|
|
18
|
+
var delayed = DelayedStream.create(req)
|
|
19
|
+
setTimeout(function() {
|
|
20
|
+
res.writeHead(200, {
|
|
21
|
+
'Expires': 0
|
|
22
|
+
, 'Cache-Control': 'max-age=0, no-cache, no-store'
|
|
23
|
+
})
|
|
24
|
+
req.query.callback && res.write(req.query.callback + '(')
|
|
25
|
+
res.write(JSON.stringify({ method: req.method, query: req.query, headers: req.headers }))
|
|
26
|
+
req.query.callback && res.write(');')
|
|
27
|
+
delayed.pipe(res)
|
|
28
|
+
}, 2000)
|
|
29
|
+
},
|
|
30
|
+
'(([\\w\\-\\/\\.]+)\\.(css|js|json|jsonp|html|xml)$)': function (req, res, next, uri, file, ext) {
|
|
31
|
+
res.writeHead(200, {
|
|
32
|
+
'Expires': 0
|
|
33
|
+
, 'Cache-Control': 'max-age=0, no-cache, no-store'
|
|
34
|
+
, 'Content-Type': getMime(ext)
|
|
35
|
+
})
|
|
36
|
+
if (req.query.echo !== undefined) {
|
|
37
|
+
ext == 'jsonp' && res.write((req.query.callback || req.query.testCallback || 'echoCallback') + '(')
|
|
38
|
+
res.write(JSON.stringify({ method: req.method, query: req.query, headers: req.headers }))
|
|
39
|
+
ext == 'jsonp' && res.write(');')
|
|
40
|
+
} else {
|
|
41
|
+
res.write(fs.readFileSync('./' + file + '.' + ext))
|
|
42
|
+
}
|
|
43
|
+
res.end()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Connect.createServer(Connect.query(), dispatch(routes)).listen(1234)
|
|
48
|
+
|
|
49
|
+
var otherOriginRoutes = {
|
|
50
|
+
'/get-value': function (req, res) {
|
|
51
|
+
res.writeHead(200, {
|
|
52
|
+
'Access-Control-Allow-Origin': req.headers.origin,
|
|
53
|
+
'Content-Type': 'text/plain'
|
|
54
|
+
})
|
|
55
|
+
res.end('hello')
|
|
56
|
+
},
|
|
57
|
+
'/set-cookie': function (req, res) {
|
|
58
|
+
res.writeHead(200, {
|
|
59
|
+
'Access-Control-Allow-Origin': req.headers.origin,
|
|
60
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
61
|
+
'Content-Type': 'text/plain',
|
|
62
|
+
'Set-Cookie': 'cookie=hello'
|
|
63
|
+
})
|
|
64
|
+
res.end('Set a cookie!')
|
|
65
|
+
},
|
|
66
|
+
'/get-cookie-value': function (req, res) {
|
|
67
|
+
var cookies = {}
|
|
68
|
+
, value
|
|
69
|
+
|
|
70
|
+
req.headers.cookie && req.headers.cookie.split(';').forEach(function( cookie ) {
|
|
71
|
+
var parts = cookie.split('=')
|
|
72
|
+
cookies[ parts[ 0 ].trim() ] = ( parts[ 1 ] || '' ).trim()
|
|
73
|
+
})
|
|
74
|
+
value = cookies.cookie
|
|
75
|
+
|
|
76
|
+
res.writeHead(200, {
|
|
77
|
+
'Access-Control-Allow-Origin': req.headers.origin,
|
|
78
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
79
|
+
'Content-Type': 'text/plain'
|
|
80
|
+
})
|
|
81
|
+
res.end(value)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Connect.createServer(Connect.query(), dispatch(otherOriginRoutes)).listen(5678)
|
|
86
|
+
|
|
87
|
+
exec('open http://localhost:1234', function () {
|
|
88
|
+
console.log('opening tests at http://localhost:1234')
|
|
89
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reqwest"
|
|
3
|
+
, "description": "A wrapper for asynchronous http requests"
|
|
4
|
+
, "keywords": ["ender", "ajax", "xhr", "connection", "web 2.0", "async", "sync"]
|
|
5
|
+
, "version": "0.8.3"
|
|
6
|
+
, "homepage": "https://github.com/ded/reqwest"
|
|
7
|
+
, "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
|
|
8
|
+
, "repository": {
|
|
9
|
+
"type": "git"
|
|
10
|
+
, "url": "https://github.com/ded/reqwest.git"
|
|
11
|
+
}
|
|
12
|
+
, "main": "./reqwest.js"
|
|
13
|
+
, "ender": "./src/ender.js"
|
|
14
|
+
, "devDependencies": {
|
|
15
|
+
"connect": "1.8.x"
|
|
16
|
+
, "mime": "1.x.x"
|
|
17
|
+
, "sink-test": ">=0.1.2"
|
|
18
|
+
, "dispatch": "0.x.x"
|
|
19
|
+
, "valentine": ">=1.4.7"
|
|
20
|
+
, "smoosh": "0.4.0"
|
|
21
|
+
, "delayed-stream" : "0.0.5"
|
|
22
|
+
}
|
|
23
|
+
, "scripts": {
|
|
24
|
+
"boosh": "smoosh make ./build.json"
|
|
25
|
+
, "test": "node make/tests.js"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Reqwest! A general purpose XHR connection manager
|
|
3
|
+
* (c) Dustin Diaz 2013
|
|
4
|
+
* https://github.com/ded/reqwest
|
|
5
|
+
* license MIT
|
|
6
|
+
*/
|
|
7
|
+
!function (name, context, definition) {
|
|
8
|
+
if (typeof module != 'undefined' && module.exports) module.exports = definition()
|
|
9
|
+
else if (typeof define == 'function' && define.amd) define(definition)
|
|
10
|
+
else context[name] = definition()
|
|
11
|
+
}('reqwest', this, function () {
|
|
12
|
+
|
|
13
|
+
var win = window
|
|
14
|
+
, doc = document
|
|
15
|
+
, twoHundo = /^20\d$/
|
|
16
|
+
, byTag = 'getElementsByTagName'
|
|
17
|
+
, readyState = 'readyState'
|
|
18
|
+
, contentType = 'Content-Type'
|
|
19
|
+
, requestedWith = 'X-Requested-With'
|
|
20
|
+
, head = doc[byTag]('head')[0]
|
|
21
|
+
, uniqid = 0
|
|
22
|
+
, callbackPrefix = 'reqwest_' + (+new Date())
|
|
23
|
+
, lastValue // data stored by the most recent JSONP callback
|
|
24
|
+
, xmlHttpRequest = 'XMLHttpRequest'
|
|
25
|
+
, noop = function () {}
|
|
26
|
+
|
|
27
|
+
, isArray = typeof Array.isArray == 'function'
|
|
28
|
+
? Array.isArray
|
|
29
|
+
: function (a) {
|
|
30
|
+
return a instanceof Array
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
, defaultHeaders = {
|
|
34
|
+
contentType: 'application/x-www-form-urlencoded'
|
|
35
|
+
, requestedWith: xmlHttpRequest
|
|
36
|
+
, accept: {
|
|
37
|
+
'*': 'text/javascript, text/html, application/xml, text/xml, */*'
|
|
38
|
+
, xml: 'application/xml, text/xml'
|
|
39
|
+
, html: 'text/html'
|
|
40
|
+
, text: 'text/plain'
|
|
41
|
+
, json: 'application/json, text/javascript'
|
|
42
|
+
, js: 'application/javascript, text/javascript'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
, xhr = win[xmlHttpRequest]
|
|
47
|
+
? function () {
|
|
48
|
+
return new XMLHttpRequest()
|
|
49
|
+
}
|
|
50
|
+
: function () {
|
|
51
|
+
return new ActiveXObject('Microsoft.XMLHTTP')
|
|
52
|
+
}
|
|
53
|
+
, globalSetupOptions = {
|
|
54
|
+
dataFilter: function (data) {
|
|
55
|
+
return data
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleReadyState(r, success, error) {
|
|
60
|
+
return function () {
|
|
61
|
+
// use _aborted to mitigate against IE err c00c023f
|
|
62
|
+
// (can't read props on aborted request objects)
|
|
63
|
+
if (r._aborted) return error(r.request)
|
|
64
|
+
if (r.request && r.request[readyState] == 4) {
|
|
65
|
+
r.request.onreadystatechange = noop
|
|
66
|
+
if (twoHundo.test(r.request.status))
|
|
67
|
+
success(r.request)
|
|
68
|
+
else
|
|
69
|
+
error(r.request)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function setHeaders(http, o) {
|
|
75
|
+
var headers = o.headers || {}
|
|
76
|
+
, h
|
|
77
|
+
|
|
78
|
+
headers.Accept = headers.Accept
|
|
79
|
+
|| defaultHeaders.accept[o.type]
|
|
80
|
+
|| defaultHeaders.accept['*']
|
|
81
|
+
|
|
82
|
+
// breaks cross-origin requests with legacy browsers
|
|
83
|
+
if (!o.crossOrigin && !headers[requestedWith]) headers[requestedWith] = defaultHeaders.requestedWith
|
|
84
|
+
if (!headers[contentType]) headers[contentType] = o.contentType || defaultHeaders.contentType
|
|
85
|
+
for (h in headers)
|
|
86
|
+
headers.hasOwnProperty(h) && http.setRequestHeader(h, headers[h])
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function setCredentials(http, o) {
|
|
90
|
+
if (typeof o.withCredentials !== 'undefined' && typeof http.withCredentials !== 'undefined') {
|
|
91
|
+
http.withCredentials = !!o.withCredentials
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function generalCallback(data) {
|
|
96
|
+
lastValue = data
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function urlappend (url, s) {
|
|
100
|
+
return url + (/\?/.test(url) ? '&' : '?') + s
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleJsonp(o, fn, err, url) {
|
|
104
|
+
var reqId = uniqid++
|
|
105
|
+
, cbkey = o.jsonpCallback || 'callback' // the 'callback' key
|
|
106
|
+
, cbval = o.jsonpCallbackName || reqwest.getcallbackPrefix(reqId)
|
|
107
|
+
// , cbval = o.jsonpCallbackName || ('reqwest_' + reqId) // the 'callback' value
|
|
108
|
+
, cbreg = new RegExp('((^|\\?|&)' + cbkey + ')=([^&]+)')
|
|
109
|
+
, match = url.match(cbreg)
|
|
110
|
+
, script = doc.createElement('script')
|
|
111
|
+
, loaded = 0
|
|
112
|
+
, isIE10 = navigator.userAgent.indexOf('MSIE 10.0') !== -1
|
|
113
|
+
|
|
114
|
+
if (match) {
|
|
115
|
+
if (match[3] === '?') {
|
|
116
|
+
url = url.replace(cbreg, '$1=' + cbval) // wildcard callback func name
|
|
117
|
+
} else {
|
|
118
|
+
cbval = match[3] // provided callback func name
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
url = urlappend(url, cbkey + '=' + cbval) // no callback details, add 'em
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
win[cbval] = generalCallback
|
|
125
|
+
|
|
126
|
+
script.type = 'text/javascript'
|
|
127
|
+
script.src = url
|
|
128
|
+
script.async = true
|
|
129
|
+
if (typeof script.onreadystatechange !== 'undefined' && !isIE10) {
|
|
130
|
+
// need this for IE due to out-of-order onreadystatechange(), binding script
|
|
131
|
+
// execution to an event listener gives us control over when the script
|
|
132
|
+
// is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
|
|
133
|
+
//
|
|
134
|
+
// if this hack is used in IE10 jsonp callback are never called
|
|
135
|
+
script.event = 'onclick'
|
|
136
|
+
script.htmlFor = script.id = '_reqwest_' + reqId
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
script.onload = script.onreadystatechange = function () {
|
|
140
|
+
if ((script[readyState] && script[readyState] !== 'complete' && script[readyState] !== 'loaded') || loaded) {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
script.onload = script.onreadystatechange = null
|
|
144
|
+
script.onclick && script.onclick()
|
|
145
|
+
// Call the user callback with the last value stored and clean up values and scripts.
|
|
146
|
+
fn(lastValue)
|
|
147
|
+
lastValue = undefined
|
|
148
|
+
head.removeChild(script)
|
|
149
|
+
loaded = 1
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Add the script to the DOM head
|
|
153
|
+
head.appendChild(script)
|
|
154
|
+
|
|
155
|
+
// Enable JSONP timeout
|
|
156
|
+
return {
|
|
157
|
+
abort: function () {
|
|
158
|
+
script.onload = script.onreadystatechange = null
|
|
159
|
+
err({}, 'Request is aborted: timeout', {})
|
|
160
|
+
lastValue = undefined
|
|
161
|
+
head.removeChild(script)
|
|
162
|
+
loaded = 1
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function getRequest(fn, err) {
|
|
168
|
+
var o = this.o
|
|
169
|
+
, method = (o.method || 'GET').toUpperCase()
|
|
170
|
+
, url = typeof o === 'string' ? o : o.url
|
|
171
|
+
// convert non-string objects to query-string form unless o.processData is false
|
|
172
|
+
, data = (o.processData !== false && o.data && typeof o.data !== 'string')
|
|
173
|
+
? reqwest.toQueryString(o.data)
|
|
174
|
+
: (o.data || null)
|
|
175
|
+
, http
|
|
176
|
+
|
|
177
|
+
// if we're working on a GET request and we have data then we should append
|
|
178
|
+
// query string to end of URL and not post data
|
|
179
|
+
if ((o.type == 'jsonp' || method == 'GET') && data) {
|
|
180
|
+
url = urlappend(url, data)
|
|
181
|
+
data = null
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (o.type == 'jsonp') return handleJsonp(o, fn, err, url)
|
|
185
|
+
|
|
186
|
+
http = xhr()
|
|
187
|
+
http.open(method, url, o.async === false ? false : true)
|
|
188
|
+
setHeaders(http, o)
|
|
189
|
+
setCredentials(http, o)
|
|
190
|
+
http.onreadystatechange = handleReadyState(this, fn, err)
|
|
191
|
+
o.before && o.before(http)
|
|
192
|
+
http.send(data)
|
|
193
|
+
return http
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function Reqwest(o, fn) {
|
|
197
|
+
this.o = o
|
|
198
|
+
this.fn = fn
|
|
199
|
+
|
|
200
|
+
init.apply(this, arguments)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function setType(url) {
|
|
204
|
+
var m = url.match(/\.(json|jsonp|html|xml)(\?|$)/)
|
|
205
|
+
return m ? m[1] : 'js'
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function init(o, fn) {
|
|
209
|
+
|
|
210
|
+
this.url = typeof o == 'string' ? o : o.url
|
|
211
|
+
this.timeout = null
|
|
212
|
+
|
|
213
|
+
// whether request has been fulfilled for purpose
|
|
214
|
+
// of tracking the Promises
|
|
215
|
+
this._fulfilled = false
|
|
216
|
+
// success handlers
|
|
217
|
+
this._fulfillmentHandlers = []
|
|
218
|
+
// error handlers
|
|
219
|
+
this._errorHandlers = []
|
|
220
|
+
// complete (both success and fail) handlers
|
|
221
|
+
this._completeHandlers = []
|
|
222
|
+
this._erred = false
|
|
223
|
+
this._responseArgs = {}
|
|
224
|
+
|
|
225
|
+
var self = this
|
|
226
|
+
, type = o.type || setType(this.url)
|
|
227
|
+
|
|
228
|
+
fn = fn || function () {}
|
|
229
|
+
|
|
230
|
+
if (o.timeout) {
|
|
231
|
+
this.timeout = setTimeout(function () {
|
|
232
|
+
self.abort()
|
|
233
|
+
}, o.timeout)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (o.success) {
|
|
237
|
+
this._fulfillmentHandlers.push(function () {
|
|
238
|
+
o.success.apply(o, arguments)
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (o.error) {
|
|
243
|
+
this._errorHandlers.push(function () {
|
|
244
|
+
o.error.apply(o, arguments)
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (o.complete) {
|
|
249
|
+
this._completeHandlers.push(function () {
|
|
250
|
+
o.complete.apply(o, arguments)
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function complete (resp) {
|
|
255
|
+
o.timeout && clearTimeout(self.timeout)
|
|
256
|
+
self.timeout = null
|
|
257
|
+
while (self._completeHandlers.length > 0) {
|
|
258
|
+
self._completeHandlers.shift()(resp)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function success (resp) {
|
|
263
|
+
// use global data filter on response text
|
|
264
|
+
var filteredResponse = globalSetupOptions.dataFilter(resp.responseText, type)
|
|
265
|
+
, r = filteredResponse
|
|
266
|
+
try {
|
|
267
|
+
resp.responseText = r
|
|
268
|
+
} catch (e) {
|
|
269
|
+
// can't assign this in IE<=8, just ignore
|
|
270
|
+
}
|
|
271
|
+
if (r) {
|
|
272
|
+
switch (type) {
|
|
273
|
+
case 'json':
|
|
274
|
+
try {
|
|
275
|
+
resp = win.JSON ? win.JSON.parse(r) : eval('(' + r + ')')
|
|
276
|
+
} catch (err) {
|
|
277
|
+
return error(resp, 'Could not parse JSON in response', err)
|
|
278
|
+
}
|
|
279
|
+
break
|
|
280
|
+
case 'js':
|
|
281
|
+
resp = eval(r)
|
|
282
|
+
break
|
|
283
|
+
case 'html':
|
|
284
|
+
resp = r
|
|
285
|
+
break
|
|
286
|
+
case 'xml':
|
|
287
|
+
resp = resp.responseXML
|
|
288
|
+
&& resp.responseXML.parseError // IE trololo
|
|
289
|
+
&& resp.responseXML.parseError.errorCode
|
|
290
|
+
&& resp.responseXML.parseError.reason
|
|
291
|
+
? null
|
|
292
|
+
: resp.responseXML
|
|
293
|
+
break
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
self._responseArgs.resp = resp
|
|
298
|
+
self._fulfilled = true
|
|
299
|
+
fn(resp)
|
|
300
|
+
while (self._fulfillmentHandlers.length > 0) {
|
|
301
|
+
self._fulfillmentHandlers.shift()(resp)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
complete(resp)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function error(resp, msg, t) {
|
|
308
|
+
self._responseArgs.resp = resp
|
|
309
|
+
self._responseArgs.msg = msg
|
|
310
|
+
self._responseArgs.t = t
|
|
311
|
+
self._erred = true
|
|
312
|
+
while (self._errorHandlers.length > 0) {
|
|
313
|
+
self._errorHandlers.shift()(resp, msg, t)
|
|
314
|
+
}
|
|
315
|
+
complete(resp)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
this.request = getRequest.call(this, success, error)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
Reqwest.prototype = {
|
|
322
|
+
abort: function () {
|
|
323
|
+
this._aborted = true
|
|
324
|
+
this.request.abort()
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
, retry: function () {
|
|
328
|
+
init.call(this, this.o, this.fn)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Small deviation from the Promises A CommonJs specification
|
|
333
|
+
* http://wiki.commonjs.org/wiki/Promises/A
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* `then` will execute upon successful requests
|
|
338
|
+
*/
|
|
339
|
+
, then: function (success, fail) {
|
|
340
|
+
success = success || function () {}
|
|
341
|
+
fail = fail || function () {}
|
|
342
|
+
if (this._fulfilled) {
|
|
343
|
+
success(this._responseArgs.resp)
|
|
344
|
+
} else if (this._erred) {
|
|
345
|
+
fail(this._responseArgs.resp, this._responseArgs.msg, this._responseArgs.t)
|
|
346
|
+
} else {
|
|
347
|
+
this._fulfillmentHandlers.push(success)
|
|
348
|
+
this._errorHandlers.push(fail)
|
|
349
|
+
}
|
|
350
|
+
return this
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* `always` will execute whether the request succeeds or fails
|
|
355
|
+
*/
|
|
356
|
+
, always: function (fn) {
|
|
357
|
+
if (this._fulfilled || this._erred) {
|
|
358
|
+
fn(this._responseArgs.resp)
|
|
359
|
+
} else {
|
|
360
|
+
this._completeHandlers.push(fn)
|
|
361
|
+
}
|
|
362
|
+
return this
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* `fail` will execute when the request fails
|
|
367
|
+
*/
|
|
368
|
+
, fail: function (fn) {
|
|
369
|
+
if (this._erred) {
|
|
370
|
+
fn(this._responseArgs.resp, this._responseArgs.msg, this._responseArgs.t)
|
|
371
|
+
} else {
|
|
372
|
+
this._errorHandlers.push(fn)
|
|
373
|
+
}
|
|
374
|
+
return this
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function reqwest(o, fn) {
|
|
379
|
+
return new Reqwest(o, fn)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// normalize newline variants according to spec -> CRLF
|
|
383
|
+
function normalize(s) {
|
|
384
|
+
return s ? s.replace(/\r?\n/g, '\r\n') : ''
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function serial(el, cb) {
|
|
388
|
+
var n = el.name
|
|
389
|
+
, t = el.tagName.toLowerCase()
|
|
390
|
+
, optCb = function (o) {
|
|
391
|
+
// IE gives value="" even where there is no value attribute
|
|
392
|
+
// 'specified' ref: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-862529273
|
|
393
|
+
if (o && !o.disabled)
|
|
394
|
+
cb(n, normalize(o.attributes.value && o.attributes.value.specified ? o.value : o.text))
|
|
395
|
+
}
|
|
396
|
+
, ch, ra, val, i
|
|
397
|
+
|
|
398
|
+
// don't serialize elements that are disabled or without a name
|
|
399
|
+
if (el.disabled || !n) return
|
|
400
|
+
|
|
401
|
+
switch (t) {
|
|
402
|
+
case 'input':
|
|
403
|
+
if (!/reset|button|image|file/i.test(el.type)) {
|
|
404
|
+
ch = /checkbox/i.test(el.type)
|
|
405
|
+
ra = /radio/i.test(el.type)
|
|
406
|
+
val = el.value
|
|
407
|
+
// WebKit gives us "" instead of "on" if a checkbox has no value, so correct it here
|
|
408
|
+
;(!(ch || ra) || el.checked) && cb(n, normalize(ch && val === '' ? 'on' : val))
|
|
409
|
+
}
|
|
410
|
+
break
|
|
411
|
+
case 'textarea':
|
|
412
|
+
cb(n, normalize(el.value))
|
|
413
|
+
break
|
|
414
|
+
case 'select':
|
|
415
|
+
if (el.type.toLowerCase() === 'select-one') {
|
|
416
|
+
optCb(el.selectedIndex >= 0 ? el.options[el.selectedIndex] : null)
|
|
417
|
+
} else {
|
|
418
|
+
for (i = 0; el.length && i < el.length; i++) {
|
|
419
|
+
el.options[i].selected && optCb(el.options[i])
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
break
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// collect up all form elements found from the passed argument elements all
|
|
427
|
+
// the way down to child elements; pass a '<form>' or form fields.
|
|
428
|
+
// called with 'this'=callback to use for serial() on each element
|
|
429
|
+
function eachFormElement() {
|
|
430
|
+
var cb = this
|
|
431
|
+
, e, i
|
|
432
|
+
, serializeSubtags = function (e, tags) {
|
|
433
|
+
var i, j, fa
|
|
434
|
+
for (i = 0; i < tags.length; i++) {
|
|
435
|
+
fa = e[byTag](tags[i])
|
|
436
|
+
for (j = 0; j < fa.length; j++) serial(fa[j], cb)
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
for (i = 0; i < arguments.length; i++) {
|
|
441
|
+
e = arguments[i]
|
|
442
|
+
if (/input|select|textarea/i.test(e.tagName)) serial(e, cb)
|
|
443
|
+
serializeSubtags(e, [ 'input', 'select', 'textarea' ])
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// standard query string style serialization
|
|
448
|
+
function serializeQueryString() {
|
|
449
|
+
return reqwest.toQueryString(reqwest.serializeArray.apply(null, arguments))
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// { 'name': 'value', ... } style serialization
|
|
453
|
+
function serializeHash() {
|
|
454
|
+
var hash = {}
|
|
455
|
+
eachFormElement.apply(function (name, value) {
|
|
456
|
+
if (name in hash) {
|
|
457
|
+
hash[name] && !isArray(hash[name]) && (hash[name] = [hash[name]])
|
|
458
|
+
hash[name].push(value)
|
|
459
|
+
} else hash[name] = value
|
|
460
|
+
}, arguments)
|
|
461
|
+
return hash
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// [ { name: 'name', value: 'value' }, ... ] style serialization
|
|
465
|
+
reqwest.serializeArray = function () {
|
|
466
|
+
var arr = []
|
|
467
|
+
eachFormElement.apply(function (name, value) {
|
|
468
|
+
arr.push({name: name, value: value})
|
|
469
|
+
}, arguments)
|
|
470
|
+
return arr
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
reqwest.serialize = function () {
|
|
474
|
+
if (arguments.length === 0) return ''
|
|
475
|
+
var opt, fn
|
|
476
|
+
, args = Array.prototype.slice.call(arguments, 0)
|
|
477
|
+
|
|
478
|
+
opt = args.pop()
|
|
479
|
+
opt && opt.nodeType && args.push(opt) && (opt = null)
|
|
480
|
+
opt && (opt = opt.type)
|
|
481
|
+
|
|
482
|
+
if (opt == 'map') fn = serializeHash
|
|
483
|
+
else if (opt == 'array') fn = reqwest.serializeArray
|
|
484
|
+
else fn = serializeQueryString
|
|
485
|
+
|
|
486
|
+
return fn.apply(null, args)
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
reqwest.toQueryString = function (o, trad) {
|
|
490
|
+
var prefix, i
|
|
491
|
+
, traditional = trad || false
|
|
492
|
+
, s = []
|
|
493
|
+
, enc = encodeURIComponent
|
|
494
|
+
, add = function (key, value) {
|
|
495
|
+
// If value is a function, invoke it and return its value
|
|
496
|
+
value = ('function' === typeof value) ? value() : (value == null ? '' : value)
|
|
497
|
+
s[s.length] = enc(key) + '=' + enc(value)
|
|
498
|
+
}
|
|
499
|
+
// If an array was passed in, assume that it is an array of form elements.
|
|
500
|
+
if (isArray(o)) {
|
|
501
|
+
for (i = 0; o && i < o.length; i++) add(o[i].name, o[i].value)
|
|
502
|
+
} else {
|
|
503
|
+
// If traditional, encode the "old" way (the way 1.3.2 or older
|
|
504
|
+
// did it), otherwise encode params recursively.
|
|
505
|
+
for (prefix in o) {
|
|
506
|
+
buildParams(prefix, o[prefix], traditional, add)
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// spaces should be + according to spec
|
|
511
|
+
return s.join('&').replace(/%20/g, '+')
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function buildParams(prefix, obj, traditional, add) {
|
|
515
|
+
var name, i, v
|
|
516
|
+
, rbracket = /\[\]$/
|
|
517
|
+
|
|
518
|
+
if (isArray(obj)) {
|
|
519
|
+
// Serialize array item.
|
|
520
|
+
for (i = 0; obj && i < obj.length; i++) {
|
|
521
|
+
v = obj[i]
|
|
522
|
+
if (traditional || rbracket.test(prefix)) {
|
|
523
|
+
// Treat each array item as a scalar.
|
|
524
|
+
add(prefix, v)
|
|
525
|
+
} else {
|
|
526
|
+
buildParams(prefix + '[' + (typeof v === 'object' ? i : '') + ']', v, traditional, add)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
} else if (obj && obj.toString() === '[object Object]') {
|
|
530
|
+
// Serialize object item.
|
|
531
|
+
for (name in obj) {
|
|
532
|
+
buildParams(prefix + '[' + name + ']', obj[name], traditional, add)
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
} else {
|
|
536
|
+
// Serialize scalar item.
|
|
537
|
+
add(prefix, obj)
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
reqwest.getcallbackPrefix = function () {
|
|
542
|
+
return callbackPrefix
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// jQuery and Zepto compatibility, differences can be remapped here so you can call
|
|
546
|
+
// .ajax.compat(options, callback)
|
|
547
|
+
reqwest.compat = function (o, fn) {
|
|
548
|
+
if (o) {
|
|
549
|
+
o.type && (o.method = o.type) && delete o.type
|
|
550
|
+
o.dataType && (o.type = o.dataType)
|
|
551
|
+
o.jsonpCallback && (o.jsonpCallbackName = o.jsonpCallback) && delete o.jsonpCallback
|
|
552
|
+
o.jsonp && (o.jsonpCallback = o.jsonp)
|
|
553
|
+
}
|
|
554
|
+
return new Reqwest(o, fn)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
reqwest.ajaxSetup = function (options) {
|
|
558
|
+
options = options || {}
|
|
559
|
+
for (var k in options) {
|
|
560
|
+
globalSetupOptions[k] = options[k]
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return reqwest
|
|
565
|
+
});
|