diff options
author | Barak Korren <[email protected]> | 2013-04-02 20:38:07 +0300 |
---|---|---|
committer | Barak Korren <[email protected]> | 2013-04-02 20:38:07 +0300 |
commit | 58a2577d48790c79adfd44bcfd662c980ce6cfe4 (patch) | |
tree | 523d814ea0b7b6f617fe515b186099c6e83fed72 /lib/dojo/request/util.js.uncompressed.js | |
parent | e470a273cf09562fb2f9c0c899002303f19c8d16 (diff) | |
parent | cc332603431102a682feda22b9cf0093a29f0176 (diff) |
Merge branch 'master' of https://github.com/gothfox/Tiny-Tiny-RSS.git
Diffstat (limited to 'lib/dojo/request/util.js.uncompressed.js')
-rw-r--r-- | lib/dojo/request/util.js.uncompressed.js | 145 |
1 files changed, 0 insertions, 145 deletions
diff --git a/lib/dojo/request/util.js.uncompressed.js b/lib/dojo/request/util.js.uncompressed.js deleted file mode 100644 index 988eb6746..000000000 --- a/lib/dojo/request/util.js.uncompressed.js +++ /dev/null @@ -1,145 +0,0 @@ -define("dojo/request/util", [ - 'exports', - '../errors/RequestError', - '../errors/CancelError', - '../Deferred', - '../io-query', - '../_base/array', - '../_base/lang' -], function(exports, RequestError, CancelError, Deferred, ioQuery, array, lang){ - exports.deepCopy = function deepCopy(target, source){ - for(var name in source){ - var tval = target[name], - sval = source[name]; - if(tval !== sval){ - if(tval && typeof tval === 'object' && sval && typeof sval === 'object'){ - exports.deepCopy(tval, sval); - }else{ - target[name] = sval; - } - } - } - return target; - }; - - exports.deepCreate = function deepCreate(source, properties){ - properties = properties || {}; - var target = lang.delegate(source), - name, value; - - for(name in source){ - value = source[name]; - - if(value && typeof value === 'object'){ - target[name] = exports.deepCreate(value, properties[name]); - } - } - return exports.deepCopy(target, properties); - }; - - var freeze = Object.freeze || function(obj){ return obj; }; - function okHandler(response){ - return freeze(response); - } - - exports.deferred = function deferred(response, cancel, isValid, isReady, handleResponse, last){ - var def = new Deferred(function(reason){ - cancel && cancel(def, response); - - if(!reason || !(reason instanceof RequestError) && !(reason instanceof CancelError)){ - return new CancelError('Request canceled', response); - } - return reason; - }); - - def.response = response; - def.isValid = isValid; - def.isReady = isReady; - def.handleResponse = handleResponse; - - function errHandler(error){ - error.response = response; - throw error; - } - var responsePromise = def.then(okHandler).otherwise(errHandler); - - if(exports.notify){ - responsePromise.then( - lang.hitch(exports.notify, 'emit', 'load'), - lang.hitch(exports.notify, 'emit', 'error') - ); - } - - var dataPromise = responsePromise.then(function(response){ - return response.data || response.text; - }); - - var promise = freeze(lang.delegate(dataPromise, { - response: responsePromise - })); - - - if(last){ - def.then(function(response){ - last.call(def, response); - }, function(error){ - last.call(def, response, error); - }); - } - - def.promise = promise; - def.then = promise.then; - - return def; - }; - - exports.addCommonMethods = function addCommonMethods(provider, methods){ - array.forEach(methods||['GET', 'POST', 'PUT', 'DELETE'], function(method){ - provider[(method === 'DELETE' ? 'DEL' : method).toLowerCase()] = function(url, options){ - options = lang.delegate(options||{}); - options.method = method; - return provider(url, options); - }; - }); - }; - - exports.parseArgs = function parseArgs(url, options, skipData){ - var data = options.data, - query = options.query; - - if(data && !skipData){ - if(typeof data === 'object'){ - options.data = ioQuery.objectToQuery(data); - } - } - - if(query){ - if(typeof query === 'object'){ - query = ioQuery.objectToQuery(query); - } - if(options.preventCache){ - query += (query ? '&' : '') + 'request.preventCache=' + (+(new Date)); - } - }else if(options.preventCache){ - query = 'request.preventCache=' + (+(new Date)); - } - - if(url && query){ - url += (~url.indexOf('?') ? '&' : '?') + query; - } - - return { - url: url, - options: options, - getHeader: function(headerName){ return null; } - }; - }; - - exports.checkStatus = function(stat){ - stat = stat || 0; - return (stat >= 200 && stat < 300) || // allow any 2XX response code - stat === 304 || // or, get it out of the cache - stat === 1223 || // or, Internet Explorer mangled the status code - !stat; // or, we're Titanium/browser chrome/chrome extension requesting a local file - }; -}); |