wpa_cli_web 0.0.5 → 0.0.6

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