1/* globals ywgc_field_data, wp, yith */ 2( function ( $ ) { 3 4 /** 5 * File field. 6 */ 7 ( function () { 8 /** 9 * Get the wrapper of the file field. 10 * @param element JQuery element or dom element. 11 * @returns {*} 12 */ 13 function getWrapper( element ) { 14 return $( element ).closest( '.yith-plugin-fw-file' ); 15 } 16 17 function onDragOver() { 18 getWrapper( this ).addClass( 'yith-plugin-fw--is-dragging' ); 19 } 20 21 function onDragLeave() { 22 getWrapper( this ).addClass( 'yith-plugin-fw--is-dragging' ); 23 } 24 25 function onChange() { 26 var wrapper = getWrapper( this ), 27 name = wrapper.find( '.yith-plugin-fw-file__preview__name' ), 28 file = this.files.length ? this.files[ 0 ] : false; 29 30 wrapper.removeClass( 'yith-plugin-fw--is-dragging' ); 31 32 var ext = file.name.split( '.' ).pop().toLowerCase(); 33 34 if ($.inArray( ext, ['png', 'jpg', 'jpeg'] ) == -1 ) { 35 $( "div.yith-plugin-fw-file__message" ).append( 36 '<br><span class="ywgc-picture-error">' + 37 ywgc_data.invalid_image_extension + '</span>' 38 ); 39 return; 40 } 41 42 if ( file.size > ywgc_data.custom_image_max_size * 1024 * 1024 && ywgc_data.custom_image_max_size > 0) { 43 $( "div.yith-plugin-fw-file__message" ).append( 44 '<br><span class="ywgc-picture-error">' + 45 ywgc_data.invalid_image_size + '</span>' 46 ); 47 return; 48 } 49 50 if ( file ) { 51 var oFReader = new FileReader(); 52 oFReader.readAsDataURL( file ); 53 54 oFReader.onload = function(oFREvent) { 55 var image_base64 = oFREvent.target.result; 56 57 var html_miniature = '<img src="' + image_base64 + '" class="attachment-thumbnail size-thumbnail custom-selected-image selected_design_image" ' + 58 'alt="" ' + 59 'srcset="' + image_base64 + ' 150w, ' + 60 '' + image_base64 + ' 250w, ' + 61 '' + image_base64 + ' 100w" ' + 62 'sizes="(max-width: 150px) 85vw, 150px" width="150" height="150">'; 63 64 $( '.yith-ywgc-preview-image' ).html( html_miniature ); 65 }; 66 67 name.html( file.name ); 68 $( '.yith-ywgc-drag-drop-icon-modal' ).hide(); 69 wrapper.addClass( 'yith-plugin-fw--filled' ); 70 } else { 71 wrapper.removeClass( 'yith-plugin-fw--filled' ); 72 } 73 } 74 75 $( document ) 76 .on( 'dragover', '.yith-plugin-fw-file', onDragOver ) 77 .on( 'dragleave', '.yith-plugin-fw-file', onDragLeave ) 78 .on( 'change', '.yith-plugin-fw-file__field', onChange ); 79 80 } )(); 81 82 83} )( 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.