| 1 |
(function ($) { |
| 2 |
"use strict"; |
| 3 |
|
| 4 |
/** |
| 5 |
* All of the code for your admin-facing JavaScript source |
| 6 |
* should reside in this file. |
| 7 |
* |
| 8 |
* Note: It has been assumed you will write jQuery code here, so the |
| 9 |
* $ function reference has been prepared for usage within the scope |
| 10 |
* of this function. |
| 11 |
* |
| 12 |
* This enables you to define handlers, for when the DOM is ready: |
| 13 |
* |
| 14 |
* $(function() { |
| 15 |
* |
| 16 |
* }); |
| 17 |
* |
| 18 |
* When the window is loaded: |
| 19 |
* |
| 20 |
* $( window ).load(function() { |
| 21 |
* |
| 22 |
* }); |
| 23 |
* |
| 24 |
* ...and/or other possibilities. |
| 25 |
* |
| 26 |
* Ideally, it is not considered best practise to attach more than a |
| 27 |
* single DOM-ready or window-load handler for a particular page. |
| 28 |
* Although scripts in the WordPress core, Plugins and Themes may be |
| 29 |
* practising this, we should strive to set a better example in our own work. |
| 30 |
*/ |
| 31 |
jQuery(document).ready(function ($) { |
| 32 |
$(document).on("click", ".upload-media-button", function (e) { |
| 33 |
e.preventDefault(); |
| 34 |
var $button = $(this); |
| 35 |
|
| 36 |
// Create the media frame. |
| 37 |
var file_frame = (wp.media.frames.file_frame = wp.media({ |
| 38 |
title: "Select or upload media", |
| 39 |
button: { |
| 40 |
text: "Select", |
| 41 |
}, |
| 42 |
multiple: false, // Set to true to allow multiple files to be selected |
| 43 |
})); |
| 44 |
|
| 45 |
// When an image is selected, run a callback. |
| 46 |
file_frame.on("select", function () { |
| 47 |
// We set multiple to false so only get one image from the uploader |
| 48 |
|
| 49 |
var attachment = file_frame.state().get("selection").first().toJSON(); |
| 50 |
|
| 51 |
$button.siblings("input").val(attachment.url); |
| 52 |
$button |
| 53 |
.siblings("span.image-holder") |
| 54 |
.html('<img src="' + attachment.url + '">'); |
| 55 |
}); |
| 56 |
|
| 57 |
// Finally, open the modal |
| 58 |
file_frame.open(); |
| 59 |
}); |
| 60 |
|
| 61 |
$(".image-url").each(function () { |
| 62 |
$(this).on("keyup", function () { |
| 63 |
$(this) |
| 64 |
.siblings("span.image-holder") |
| 65 |
.html('<img src="' + $(this).val() + '">'); |
| 66 |
}); |
| 67 |
}); |
| 68 |
|
| 69 |
/* Show More event */ |
| 70 |
$(".ect-toggle-btn").on("click", function () { |
| 71 |
$(this).next("div.advanced-section").toggle(); |
| 72 |
$(".ect-toggle-btn").toggleClass("more"); |
| 73 |
}); |
| 74 |
|
| 75 |
|
| 76 |
$(document).on("widget-added widget-updated", function (e, widget) { |
| 77 |
/* Show More event */ |
| 78 |
$(".ect-toggle-btn").on("click", function () { |
| 79 |
$(this).next("div.advanced-section").toggle(); |
| 80 |
$(".ect-toggle-btn").toggleClass("more"); |
| 81 |
}); |
| 82 |
|
| 83 |
}); |
| 84 |
}); |
| 85 |
})(jQuery); |
| 86 |
|