1jQuery(function($){ 2// Set all variables to be used in scope 3 var frame, 4 selection, 5 multiple_image= true, 6 metaBox = $('#atbdp_gallery'), // meta box id here 7 addImgLink = metaBox.find('#directorist-listing-gallery-btn'), 8 delImgLink = metaBox.find( '#directorist-gallery-remove'), 9 imgContainer = metaBox.find( '.directorist-listing-gallery-container'), 10 active_mi_ext = atbdp_font_data.active_mi_ext; 11 12 /*if the multiple image extension is active then set the multiple image parameter to true*/ 13 if(1 === active_mi_ext){ multiple_image = true } 14 15// ADD IMAGE LINK 16 addImgLink.on( 'click', function( event ){ 17 18 event.preventDefault(); 19 20 // If the media frame already exists, reopen it. 21 if ( frame ) { 22 frame.open(); 23 return; 24 } 25 26 // Create a new media frame 27 frame = wp.media({ 28 title: atbdp_font_data.i18n_text.upload_image, 29 button: { 30 text: atbdp_font_data.i18n_text.choose_image 31 }, 32 library : { type : 'image'}, // only allow image upload only 33 multiple: multiple_image // Set to true to allow multiple files to be selected. it will be set based on the availability of Multiple Image extension 34 }); 35 36 37 // When an image is selected in the media frame... 38 frame.on( 'select', function() { 39 /*get the image collection array if the MI extension is active*/ 40 /*One little hints: a constant can not be defined inside the if block*/ 41 if (multiple_image){ 42 selection = frame.state().get( 'selection' ).toJSON(); 43 }else { 44 selection = frame.state().get( 'selection' ).first().toJSON(); 45 } 46 var data = ''; // create a placeholder to save all our image from the selection of media uploader 47 48 // if no image exist then remove the place holder image before appending new image 49 if ($('.directorist-listing-gallery-single').length === 0) { 50 imgContainer.html(''); 51 } 52 53 54 //handle multiple image uploading....... 55 if ( multiple_image ){ 56 $(selection).each(function () { 57 // here el === this 58 // append the selected element if it is an image 59 if ('image' === this.type) { 60 // we have got an image attachment so lets proceed. 61 // target the input field and then assign the current id of the attachment to an array. 62 data += '<div class="directorist-listing-gallery-single">'; 63 data += '<input class="directorist-listing-gallery-single__attatchment" name="gallery_img[]" type="hidden" value="'+this.id+'">'; 64 data += '<img style="width: 100%; height: 100%;" src="'+this.url+'" alt="Listing Image" /> <span class="directorist-listing-gallery-single__remove fa fa-times" title="Remove it"></span></div>'; 65 } 66 67 }); 68 }else{ 69 // Handle single image uploading 70 71 // add the id to the input field of the image uploader and then save the ids in the database as a post meta 72 // so check if the attachment is really an image and reject other types 73 if ('image' === selection.type){ 74 // we have got an image attachment so lets proceed. 75 // target the input field and then assign the current id of the attachment to an array. 76 data += '<div class="directorist-listing-gallery-single">'; 77 data += '<input class="directorist-listing-gallery-single__attatchment" name="gallery_img[]" type="hidden" value="'+selection.id+'">'; 78 data += '<img style="width: 100%; height: 100%;" src="' + selection.url + '" alt="Listing Image" /> <span class="directorist-listing-gallery-single__remove fa fa-times" title="Remove it"></span></div>'; 79 } 80 } 81 82 // If MI extension is active then append images to the listing, else only add one image replacing previous upload 83 if(multiple_image){ 84 imgContainer.append(data); 85 }else { 86 imgContainer.html(data); 87 } 88 89 // Un-hide the remove image link 90 delImgLink.removeClass( 'hidden' ); 91 }); 92 // Finally, open the modal on click 93 frame.open(); 94 }); 95 96 97// DELETE ALL IMAGES LINK 98 delImgLink.on( 'click', function( event ){ 99 event.preventDefault(); 100 // Clear out the preview image and set no image as placeholder 101 imgContainer.html( '<img src="' + atbdp_font_data.AdminAssetPath + 'images/no-image.png" alt="Listing Image" />' ); 102 // Hide the delete image link 103 delImgLink.addClass( 'hidden' ); 104 105 106 }); 107 108 /*REMOVE SINGLE IMAGE*/ 109 $(document).on('click', '.directorist-listing-gallery-single__remove', function (e) { 110 e.preventDefault(); 111 $(this).parent().remove(); 112 // if no image exist then add placeholder and hide remove image button 113 if ($('.directorist-listing-gallery-single').length === 0) { 114 115 imgContainer.html( '<img src="'+atbdp_font_data.AdminAssetPath+'images/no-image.png" alt="Listing Image" /><p>No images</p> ' + 116 '<small>(allowed formats jpeg. png. gif)</small>' ); 117 delImgLink.addClass( 'hidden' ); 118 119 } 120 }); 121 122 //magnific popup 123 if ($(".directorist-gallery-grid-two .directorist-grid-item").length) { 124 $(".directorist-gallery-grid-two .directorist-grid-item").magnificPopup({ 125 type: "image", 126 delegate: "a", 127 gallery: { 128 enabled: true 129 } 130 }); 131 132 } 133 134 135 136 137});
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.