/*Admin side script */ (function ($) { jQuery.fn.wpMediaModal = function (options) { options = $.extend({ preview: false, ids: false, multiSelect: false, modalTitle: "Select Image", modalButton: "Select", attachment_ids: "" }, options); var make = function () { var slideshow_frame; var $ids = jQuery('#' + options.ids); var $preview = jQuery('#' + options.preview); // Uploading files jQuery(this).live('click', function (event) { event.preventDefault(); // If the media frame already exists, reopen it. if (slideshow_frame) { slideshow_frame.open(); return; } // Create the media frame. slideshow_frame = wp.media.frames.downloadable_file = wp.media({ title: options.modalTitle, button: { text: options.modalButton, }, multiple: options.multiSelect }); options.attachment_ids = $ids.val(); // When an image is selected, run a callback. slideshow_frame.on('select', function () { options.attachment_ids = $ids.val(); var selection = slideshow_frame.state().get('selection'); selection.map(function (attachment) { attachment = attachment.toJSON(); if (attachment.id) { if (options.multiSelect) { options.attachment_ids = options.attachment_ids ? options.attachment_ids + "," + attachment.id : attachment.id; } else { options.attachment_ids = attachment.id; $preview.children('li.image').remove(); } ; $preview.append('\