diff options
author | friendica <info@friendica.com> | 2014-01-19 14:08:21 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-01-19 14:08:21 -0800 |
commit | f3a7bf913f3bb03c1601b105271daf77df4e3bbb (patch) | |
tree | b7a2c2ddcf1440f2df61c5bace571a76e13e3e18 /library/jqupload/js/cors | |
parent | 724ad4505628d493b43b4f585512d67dc0b4ee76 (diff) | |
download | volse-hubzilla-f3a7bf913f3bb03c1601b105271daf77df4e3bbb.tar.gz volse-hubzilla-f3a7bf913f3bb03c1601b105271daf77df4e3bbb.tar.bz2 volse-hubzilla-f3a7bf913f3bb03c1601b105271daf77df4e3bbb.zip |
add the jquery file uploader. Have been suggesting this as a replacement for the valum uploaders for quite some time - as there is client resize ability and no license incompatibilities. It still requires integration.
Diffstat (limited to 'library/jqupload/js/cors')
-rw-r--r-- | library/jqupload/js/cors/jquery.postmessage-transport.js | 117 | ||||
-rw-r--r-- | library/jqupload/js/cors/jquery.xdr-transport.js | 86 |
2 files changed, 203 insertions, 0 deletions
diff --git a/library/jqupload/js/cors/jquery.postmessage-transport.js b/library/jqupload/js/cors/jquery.postmessage-transport.js new file mode 100644 index 000000000..2b4851e67 --- /dev/null +++ b/library/jqupload/js/cors/jquery.postmessage-transport.js @@ -0,0 +1,117 @@ +/* + * jQuery postMessage Transport Plugin 1.1.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2011, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/* global define, window, document */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['jquery'], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + var counter = 0, + names = [ + 'accepts', + 'cache', + 'contents', + 'contentType', + 'crossDomain', + 'data', + 'dataType', + 'headers', + 'ifModified', + 'mimeType', + 'password', + 'processData', + 'timeout', + 'traditional', + 'type', + 'url', + 'username' + ], + convert = function (p) { + return p; + }; + + $.ajaxSetup({ + converters: { + 'postmessage text': convert, + 'postmessage json': convert, + 'postmessage html': convert + } + }); + + $.ajaxTransport('postmessage', function (options) { + if (options.postMessage && window.postMessage) { + var iframe, + loc = $('<a>').prop('href', options.postMessage)[0], + target = loc.protocol + '//' + loc.host, + xhrUpload = options.xhr().upload; + return { + send: function (_, completeCallback) { + counter += 1; + var message = { + id: 'postmessage-transport-' + counter + }, + eventName = 'message.' + message.id; + iframe = $( + '<iframe style="display:none;" src="' + + options.postMessage + '" name="' + + message.id + '"></iframe>' + ).bind('load', function () { + $.each(names, function (i, name) { + message[name] = options[name]; + }); + message.dataType = message.dataType.replace('postmessage ', ''); + $(window).bind(eventName, function (e) { + e = e.originalEvent; + var data = e.data, + ev; + if (e.origin === target && data.id === message.id) { + if (data.type === 'progress') { + ev = document.createEvent('Event'); + ev.initEvent(data.type, false, true); + $.extend(ev, data); + xhrUpload.dispatchEvent(ev); + } else { + completeCallback( + data.status, + data.statusText, + {postmessage: data.result}, + data.headers + ); + iframe.remove(); + $(window).unbind(eventName); + } + } + }); + iframe[0].contentWindow.postMessage( + message, + target + ); + }).appendTo(document.body); + }, + abort: function () { + if (iframe) { + iframe.remove(); + } + } + }; + } + }); + +})); diff --git a/library/jqupload/js/cors/jquery.xdr-transport.js b/library/jqupload/js/cors/jquery.xdr-transport.js new file mode 100644 index 000000000..0044cc2d5 --- /dev/null +++ b/library/jqupload/js/cors/jquery.xdr-transport.js @@ -0,0 +1,86 @@ +/* + * jQuery XDomainRequest Transport Plugin 1.1.3 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2011, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + * + * Based on Julian Aubourg's ajaxHooks xdr.js: + * https://github.com/jaubourg/ajaxHooks/ + */ + +/* global define, window, XDomainRequest */ + +(function (factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { + // Register as an anonymous AMD module: + define(['jquery'], factory); + } else { + // Browser globals: + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + if (window.XDomainRequest && !$.support.cors) { + $.ajaxTransport(function (s) { + if (s.crossDomain && s.async) { + if (s.timeout) { + s.xdrTimeout = s.timeout; + delete s.timeout; + } + var xdr; + return { + send: function (headers, completeCallback) { + var addParamChar = /\?/.test(s.url) ? '&' : '?'; + function callback(status, statusText, responses, responseHeaders) { + xdr.onload = xdr.onerror = xdr.ontimeout = $.noop; + xdr = null; + completeCallback(status, statusText, responses, responseHeaders); + } + xdr = new XDomainRequest(); + // XDomainRequest only supports GET and POST: + if (s.type === 'DELETE') { + s.url = s.url + addParamChar + '_method=DELETE'; + s.type = 'POST'; + } else if (s.type === 'PUT') { + s.url = s.url + addParamChar + '_method=PUT'; + s.type = 'POST'; + } else if (s.type === 'PATCH') { + s.url = s.url + addParamChar + '_method=PATCH'; + s.type = 'POST'; + } + xdr.open(s.type, s.url); + xdr.onload = function () { + callback( + 200, + 'OK', + {text: xdr.responseText}, + 'Content-Type: ' + xdr.contentType + ); + }; + xdr.onerror = function () { + callback(404, 'Not Found'); + }; + if (s.xdrTimeout) { + xdr.ontimeout = function () { + callback(0, 'timeout'); + }; + xdr.timeout = s.xdrTimeout; + } + xdr.send((s.hasContent && s.data) || null); + }, + abort: function () { + if (xdr) { + xdr.onerror = $.noop(); + xdr.abort(); + } + } + }; + } + }); + } +})); |