Mercurial > hg > orthanc
annotate OrthancExplorer/libs/jquery-file-upload/js/cors/jquery.postmessage-transport.js @ 3066:5713952f60c0 update-jquery
upgraded jquery, jquery-mobile, jquery-file-upload. Everything seems to be working as before. Theme has changed !
author | am@osimis.io |
---|---|
date | Wed, 26 Dec 2018 16:58:21 +0100 |
parents | 4bc019d2f969 |
children |
rev | line source |
---|---|
0 | 1 /* |
3066
5713952f60c0
upgraded jquery, jquery-mobile, jquery-file-upload. Everything seems to be working as before. Theme has changed !
am@osimis.io
parents:
57
diff
changeset
|
2 * jQuery postMessage Transport Plugin 1.1.1 |
0 | 3 * https://github.com/blueimp/jQuery-File-Upload |
4 * | |
5 * Copyright 2011, Sebastian Tschan | |
6 * https://blueimp.net | |
7 * | |
8 * Licensed under the MIT license: | |
9 * http://www.opensource.org/licenses/MIT | |
10 */ | |
11 | |
12 /*jslint unparam: true, nomen: true */ | |
13 /*global define, window, document */ | |
14 | |
15 (function (factory) { | |
16 'use strict'; | |
17 if (typeof define === 'function' && define.amd) { | |
18 // Register as an anonymous AMD module: | |
19 define(['jquery'], factory); | |
20 } else { | |
21 // Browser globals: | |
22 factory(window.jQuery); | |
23 } | |
24 }(function ($) { | |
25 'use strict'; | |
26 | |
27 var counter = 0, | |
28 names = [ | |
29 'accepts', | |
30 'cache', | |
31 'contents', | |
32 'contentType', | |
33 'crossDomain', | |
34 'data', | |
35 'dataType', | |
36 'headers', | |
37 'ifModified', | |
38 'mimeType', | |
39 'password', | |
40 'processData', | |
41 'timeout', | |
42 'traditional', | |
43 'type', | |
44 'url', | |
45 'username' | |
46 ], | |
47 convert = function (p) { | |
48 return p; | |
49 }; | |
50 | |
51 $.ajaxSetup({ | |
52 converters: { | |
53 'postmessage text': convert, | |
54 'postmessage json': convert, | |
55 'postmessage html': convert | |
56 } | |
57 }); | |
58 | |
59 $.ajaxTransport('postmessage', function (options) { | |
60 if (options.postMessage && window.postMessage) { | |
61 var iframe, | |
62 loc = $('<a>').prop('href', options.postMessage)[0], | |
63 target = loc.protocol + '//' + loc.host, | |
64 xhrUpload = options.xhr().upload; | |
65 return { | |
66 send: function (_, completeCallback) { | |
3066
5713952f60c0
upgraded jquery, jquery-mobile, jquery-file-upload. Everything seems to be working as before. Theme has changed !
am@osimis.io
parents:
57
diff
changeset
|
67 counter += 1; |
0 | 68 var message = { |
3066
5713952f60c0
upgraded jquery, jquery-mobile, jquery-file-upload. Everything seems to be working as before. Theme has changed !
am@osimis.io
parents:
57
diff
changeset
|
69 id: 'postmessage-transport-' + counter |
0 | 70 }, |
71 eventName = 'message.' + message.id; | |
72 iframe = $( | |
73 '<iframe style="display:none;" src="' + | |
74 options.postMessage + '" name="' + | |
75 message.id + '"></iframe>' | |
76 ).bind('load', function () { | |
77 $.each(names, function (i, name) { | |
78 message[name] = options[name]; | |
79 }); | |
80 message.dataType = message.dataType.replace('postmessage ', ''); | |
81 $(window).bind(eventName, function (e) { | |
82 e = e.originalEvent; | |
83 var data = e.data, | |
84 ev; | |
85 if (e.origin === target && data.id === message.id) { | |
86 if (data.type === 'progress') { | |
87 ev = document.createEvent('Event'); | |
88 ev.initEvent(data.type, false, true); | |
89 $.extend(ev, data); | |
90 xhrUpload.dispatchEvent(ev); | |
91 } else { | |
92 completeCallback( | |
93 data.status, | |
94 data.statusText, | |
95 {postmessage: data.result}, | |
96 data.headers | |
97 ); | |
98 iframe.remove(); | |
99 $(window).unbind(eventName); | |
100 } | |
101 } | |
102 }); | |
103 iframe[0].contentWindow.postMessage( | |
104 message, | |
105 target | |
106 ); | |
107 }).appendTo(document.body); | |
108 }, | |
109 abort: function () { | |
110 if (iframe) { | |
111 iframe.remove(); | |
112 } | |
113 } | |
114 }; | |
115 } | |
116 }); | |
117 | |
118 })); |