jQuery(document).ready(function(){ rx_portfolio_admin = new RxPortfolioAdmin(); }); function RxPortfolioAdmin(){ var post_meta = jQuery('#featured_images_rx_portfolio').attr('data-post_meta'); initSortableFeaturedImages(); function initSortableFeaturedImages(){ jQuery("#featuredImagesUI").sortable({ placeholder: "ui-state-highlight", stop: function( event, ui ){ } }); jQuery("#featuredImagesUI").disableSelection(); jQuery("#featuredImagesUI").children().each(function(indx){ thumbsHoverAction(jQuery(this).find('.featuredThumbOverlay')); jQuery(this).find('.thumbOverlayRemove').click(function(e){ e.preventDefault(); if(confirm('Are you sure you want to remove this image?')){ jQuery(this).parent().parent().parent().remove(); checkChildrens(); } }); }); } function checkChildrens(){ var dummyData = ''; var children = jQuery("#featuredImagesUI").children(); if(children.length==0){ removeDummyFeaturedData(); jQuery(dummyData).appendTo(jQuery('#featuresThumbsContainer')); }else{ removeDummyFeaturedData(); } } function removeDummyFeaturedData(){ try{ jQuery('#dummyFeaturedImagesDATA').remove(); }catch(e){} } //add featured images handleFeaturedImagesUpload(); function handleFeaturedImagesUpload(){ jQuery('#removeAllFeaturedImagesBTN').click(function(e){ e.preventDefault(); try{ var children = jQuery("#featuredImagesUI").children(); if(children.length==0){ alert('There are no featured images'); return; } if(confirm('Are you sure you want to remove all images?')){ jQuery("#featuredImagesUI").empty(); checkChildrens(); } }catch(e){} }); jQuery('#addFeaturedImagesBTN').click(function(e){ e.preventDefault(); var send_attachment_bkp = wp.media.editor.send.attachment; var frame = wp.media({ title: "Select Images", multiple: true, library: { type: 'image' }, button : { text : 'add image' } }); frame.on('close',function() { var selection = frame.state().get('selection'); selection.each(function(attachment) { var iconUrl = 'http://placehold.it/150x150'; if(attachment.attributes.sizes.thumbnail!=undefined){ iconUrl = (attachment.attributes.sizes.thumbnail.url!='')?attachment.attributes.sizes.thumbnail.url:iconUrl; } featuredImageHTML = '