1/** Image Uploader - v1.2.3 - 26/11/2019 2 * Copyright (c) 2019 Christian Bayer; Licensed MIT 3 * 4 * @package image uploaded min. 5 */ 6 7! (function (e) { 8 e.fn.imageUploader = function (t) { 9 let n, 10 i = { 11 preloaded: [], 12 imagesInputName: "images", 13 preloadedInputName: "preloaded", 14 label: "Drag & Drop files here or click to browse", 15 extensions: [".jpg", ".jpeg", ".png", ".gif", ".svg", ".pdf"], 16 mimes: ["image/jpeg", "image/png", "image/gif", "image/svg+xml", "application/pdf"], 17 maxSize: void 0, 18 maxFiles: void 0, 19 }, 20 a = this, 21 s = new DataTransfer(); 22 (a.settings = {}), 23 (a.init = function () { 24 (a.settings = e.extend( a.settings, i, t )), 25 a.each( 26 function (t, n) { 27 let i = o(); 28 if ((e( n ).append( i ), i.on( "dragover", r.bind( i ) ), i.on( "dragleave", r.bind( i ) ), i.on( "drop", p.bind( i ) ), a.settings.preloaded.length)) { 29 i.addClass( "has-files" ); 30 let e = i.find( ".uploaded" ); 31 let len = a.settings.preloaded.length; 32 for (let t = 0; t < len; t++) { 33 e.append( l( a.settings.preloaded[t].src, a.settings.preloaded[t].id, ! 0 ) ); 34 } 35 } 36 } 37 ); 38 }); 39 let o = function () { 40 let t = e( "<div>", { class: "image-uploader" } ); 41 n = e( "<input>", { type: "file", id: a.settings.imagesInputName + "-" + h(), name: a.settings.imagesInputName + "[]", accept: a.settings.extensions.join( "," ), multiple: "" } ).appendTo( t ); 42 e( "<div>", { class: "uploaded" } ).appendTo( t ); 43 let i = e( "<div>", { class: "upload-text" } ).appendTo( t ); 44 e( "<i>", { class: "iui-cloud-upload" } ).appendTo( i ), e( "<span>", { text: a.settings.label } ).appendTo( i ); 45 return ( 46 t.on( 47 "click", 48 function (e) { 49 d( e ), n.trigger( "click" ); 50 } 51 ), 52 n.on( 53 "click", 54 function (e) { 55 e.stopPropagation(); 56 } 57 ), 58 n.on( "change", p.bind( t ) ), 59 t 60 ); 61 }, 62 d = function (e) { 63 e.preventDefault(), e.stopPropagation(); 64 }, 65 l = function (t, i, o) { 66 var rand = ''; 67 var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 68 var charactersLength = characters.length; 69 for ( var inc = 0; inc < 5; inc++ ) { 70 rand += characters.charAt( Math.floor( Math.random() * charactersLength ) ); 71 } 72 73 var image = new Image(); 74 image.src = t; 75 image.onload = function() { 76 if (this.width > 0) { 77 console.log( 'valid' ); 78 } 79 } 80 image.onerror = function() { 81 var brokReplace = document.getElementById( rand ); 82 brokReplace.src = woocommerce_help_scout_form_params.hs_plugin_url + 'img/blank.png'; 83 console.log( 'invalid' ); 84 } 85 86 let l = e( "<div>", { class: "uploaded-image" } ), 87 r = (e( "<img >", { src: t, id: rand } ).appendTo( l ), e( "<button>", { class: "delete-image" } ).appendTo( l )); 88 e( "<i>", { class: "iui-close" } ).appendTo( r ); 89 90 if (o) { 91 l.attr( "data-preloaded", ! 0 ); 92 e( "<input>", { type: "hidden", name: a.settings.preloadedInputName + "[]", value: i } ).appendTo( l ); 93 } else { 94 l.attr( "data-index", i ); 95 } 96 return ( 97 l.on( 98 "click", 99 function (e) { 100 d( e ); 101 } 102 ), 103 r.on( 104 "click", 105 function (t) { 106 d( t ); 107 let o = l.parent(); 108 if ( ! 0 === l.data( "preloaded" )) { 109 a.settings.preloaded = a.settings.preloaded.filter( 110 function (e) { 111 return e.id !== i; 112 } 113 ); 114 } else { 115 let t = parseInt( l.data( "index" ) ); 116 o.find( ".uploaded-image[data-index]" ).each( 117 function (n, i) { 118 n > t && e( i ).attr( "data-index", n - 1 ); 119 } 120 ), 121 s.items.remove( t ), 122 n.prop( "files", s.files ); 123 } 124 l.remove(), o.children().length || o.parent().removeClass( "has-files" ); 125 } 126 ), 127 l 128 ); 129 }, 130 r = function (t) { 131 d( t ), "dragover" === t.type ? e( this ).addClass( "drag-over" ) : e( this ).removeClass( "drag-over" ); 132 }, 133 p = function (t) { 134 d( t ); 135 let i = e( this ), 136 o = Array.from( t.target.files || t.originalEvent.dataTransfer.files ), 137 l = []; 138 e( o ).each( 139 function (e, t) { 140 (a.settings.extensions && ! g( t )) || (a.settings.mimes && ! c( t )) || (a.settings.maxSize && ! f( t )) || (a.settings.maxFiles && ! m
140( l.length, t )) || l.push( t ); 141 } 142 ), 143 l.length ? (i.removeClass( "drag-over" ), u( i, l )) : n.prop( "files", s.files ); 144 }, 145 g = function (e) { 146 return ! (a.settings.extensions.indexOf( e.name.replace( new RegExp( "^.*\\." ), "." ) ) < 0) || (alert( `The file "${e.name}" does not match with the accepted file extensions: "${a.settings.extensions.join('", "')}"` ), ! 1); 147 }, 148 c = function (e) { 149 return ! (a.settings.mimes.indexOf( e.type ) < 0) || (alert( `The file "${e.name}" does not match with the accepted mime types: "${a.settings.mimes.join('", "')}"` ), ! 1); 150 }, 151 f = function (e) { 152 return ! (e.size > a.settings.maxSize) || (alert( `The file "${e.name}" exceeds the maximum size of ${a.settings.maxSize / 1024 / 1024}Mb` ), ! 1); 153 }, 154 m = function (e, t) { 155 return ! (e + s.items.length + a.settings.preloaded.length >= a.settings.maxFiles) || (alert( `The file "${t.name}" could not be added because the limit of ${a.settings.maxFiles} files was reached` ), ! 1); 156 }, 157 u = function (t, n) { 158 t.addClass( "has-files" ); 159 let i = t.find( ".uploaded" ), 160 a = t.find( 'input[type="file"]' ); 161 e( n ).each( 162 function (e, t) { 163 s.items.add( t ), i.append( l( URL.createObjectURL( t ), s.items.length - 1 ), ! 1 ); 164 } 165 ), 166 a.prop( "files", s.files ); 167 }, 168 h = function () { 169 return Date.now() + Math.floor( 100 * Math.random() + 1 ); 170 }; 171 return this.init(), this; 172 }; 173 174})( 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.