1/* 2 * jQuery.upload v1.0.2 3 * 4 * Copyright (c) 2010 lagos 5 * Dual licensed under the MIT and GPL licenses. 6 * 7 * http://lagoscript.org 8 * 9 * work_log 10 * jQuery3対å¿ã§loadãonã«æ¸ãæã 2017/08/22 kawakami 11 * 弿° json ãJSON.parseã«å¤æ´ 2019/12/26 kawakami 12 */ 13(function($) { 14 15 var uuid = 0; 16 17 $.fn.upload = function(url, data, callback, type) { 18 var self = this, inputs, checkbox, checked, 19 iframeName = 'jquery_upload' + ++uuid, 20 iframe = $('<iframe name="' + iframeName + '" style="position:absolute;top:-9999px" />').appendTo('body'), 21 form = '<form target="' + iframeName + '" method="post" enctype="multipart/form-data" />'; 22 23 if ($.isFunction(data)) { 24 type = callback; 25 callback = data; 26 data = {}; 27 } 28 29 checkbox = $('input:checkbox', this); 30 checked = $('input:checked', this); 31 form = self.wrapAll(form).parent('form').attr('action', url); 32 33 // Make sure radios and checkboxes keep original values 34 // (IE resets checkd attributes when appending) 35 checkbox.removeAttr('checked'); 36 checked.attr('checked', true); 37 38 inputs = createInputs(data); 39 inputs = inputs ? $(inputs).appendTo(form) : null; 40 41 form.submit(function() { 42 iframe.on('load', function() { 43 var data = handleData(this, type), 44 checked = $('input:checked', self); 45 46 form.after(self).remove(); 47 checkbox.removeAttr('checked'); 48 checked.attr('checked', true); 49 if (inputs) { 50 inputs.remove(); 51 } 52 53 setTimeout(function() { 54 iframe.remove(); 55 if (type === 'script') { 56 $.globalEval(data); 57 } 58 if (callback) { 59 callback.call(self, data); 60 } 61 }, 0); 62 }); 63 }).submit(); 64 65 return this; 66 }; 67 68 function createInputs(data) { 69 return $.map(param(data), function(param) { 70 return '<input type="hidden" name="' + param.name + '" value="' + param.value + '"/>'; 71 }).join(''); 72 } 73 74 function param(data) { 75 if ($.isArray(data)) { 76 return data; 77 } 78 var params = []; 79 80 function add(name, value) { 81 params.push({name:name, value:value}); 82 } 83 84 if (typeof data === 'object') { 85 $.each(data, function(name) { 86 if ($.isArray(this)) { 87 $.each(this, function() { 88 add(name, this); 89 }); 90 } else { 91 add(name, $.isFunction(this) ? this() : this); 92 } 93 }); 94 } else if (typeof data === 'string') { 95 $.each(data.split('&'), function() { 96 var param = $.map(this.split('='), function(v) { 97 return decodeURIComponent(v.replace(/\+/g, ' ')); 98 }); 99 100 add(param[0], param[1]); 101 }); 102 } 103 104 return params; 105 } 106 107 function handleData(iframe, type) { 108 var data, contents = $(iframe).contents().get(0); 109 110 if ($.isXMLDoc(contents) || contents.XMLDocument) { 111 return contents.XMLDocument || contents; 112 } 113 data = $(contents).find('body').html(); 114 115 switch (type) { 116 case 'xml': 117 data = parseXml(data); 118 break; 119 case 'json': 120 //data = window.eval('(' + data + ')'); 121 data = JSON.parse($(contents).find('body').text()); 122 break; 123 } 124 return data; 125 } 126 127 function parseXml(text) { 128 if (window.DOMParser) { 129 return new DOMParser().parseFromString(text, 'application/xml'); 130 } else { 131 var xml = new ActiveXObject('Microsoft.XMLDOM'); 132 xml.async = false; 133 xml.loadXML(text); 134 return xml; 135 } 136 } 137 138})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.