1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- var $ = jQuery;
- $(document).ready(function() {
- //$("***").ttt();
- console.log("OKOKOKO K plugin");
- var mediaUploader;
- $('#upload_image_button').click(function(e) {
- e.preventDefault();
- if (mediaUploader) {
- mediaUploader.open();
- return;
- }
- mediaUploader = wp.media.frames.file_frame = wp.media({
- title: 'Choose Image',
- button: {
- text: 'Choose Image'
- },
- multiple: false
- });
- mediaUploader.on('select', function() {
- var attachment = mediaUploader.state().get('selection').first().toJSON();
- console.log("LLLL",attachment);
- $('#background_image').attr("src",attachment.url);
- });
- mediaUploader.open();
- });
- /*
- $('#upload_image_button').click(function() {
- console.log("UPLLOADDD");
- formfield = $('#link_image').attr('name');
- tb_show('', 'media-upload.php?type=image&TB_iframe=true');
- return false;
- });
- window.send_to_editor = function(html) {
- imgurl = $('img',html).attr('src');
- imgsrc = '<img src="'+imgurl+'">';
- $('#link_image').val(imgurl); // this populates a text field with the image url
- //$('#my-link-img').html(imgsrc); // this prints the image into a div
- tb_remove();
- }
- */
- $('.custom_media').each(function() {
- var self = $(this);
- $('.custom_media_upload', self).click(function() {
- var send_attachment_bkp = wp.media.editor.send.attachment;
- wp.media.editor.send.attachment = function(props, attachment) {
- $('.custom_media_image', self).attr('src', attachment.url);
- var path = "/" + attachment.url.split("/").splice(3).join("/");
- $('.custom_media_url', self).val(path);
- $('.custom_media_id', self).val(attachment.id);
- wp.media.editor.send.attachment = send_attachment_bkp;
- }
- wp.media.editor.open();
- return false;
- });
- });
- });
|