Fix some js errors, see diff
set sophia_after_dark_enable_top_header always to false, as it would a a bar to the top of the page below the admin bar also did some general fixing on php :)
This commit is contained in:
@@ -1,73 +1,59 @@
|
||||
/**
|
||||
* Image up-loader functions
|
||||
* Image uploader functions
|
||||
*/
|
||||
var mtSelector;
|
||||
function upload_media_image(mtSelector){
|
||||
// ADD IMAGE LINK
|
||||
jQuery('body').on( 'click', mtSelector , function( event ){
|
||||
event.preventDefault();
|
||||
|
||||
var imgContainer = jQuery(this).closest('.attachment-media-view').find( '.thumbnail-image'),
|
||||
placeholder = jQuery(this).closest('.attachment-media-view').find( '.placeholder'),
|
||||
imgIdInput = jQuery(this).siblings('.upload-id');
|
||||
const initUploadMediaImage = (selector) => {
|
||||
jQuery('body').on('click', selector, function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Create a new media frame
|
||||
frame = wp.media({
|
||||
title: 'Select or Upload Image',
|
||||
button: {
|
||||
text: 'Use Image'
|
||||
},
|
||||
multiple: false // Set to true to allow multiple files to be selected
|
||||
const $button = jQuery(this);
|
||||
const $mediaView = $button.closest('.attachment-media-view');
|
||||
const $imgContainer = $mediaView.find('.thumbnail-image');
|
||||
const $placeholder = $mediaView.find('.placeholder');
|
||||
const $input = $button.siblings('.upload-id');
|
||||
|
||||
const frame = wp.media({
|
||||
title: 'Select or Upload Image',
|
||||
button: {
|
||||
text: 'Use Image'
|
||||
},
|
||||
multiple: false
|
||||
});
|
||||
|
||||
frame.on('select', () => {
|
||||
const attachment = frame.state().get('selection').first().toJSON();
|
||||
$imgContainer.html(`<img src="${attachment.url}" style="max-width:100%;" />`);
|
||||
$placeholder.addClass('hidden');
|
||||
$input.val(attachment.url).trigger('change');
|
||||
});
|
||||
|
||||
frame.open();
|
||||
});
|
||||
};
|
||||
|
||||
// When an image is selected in the media frame...
|
||||
frame.on( 'select', function() {
|
||||
const initDeleteMediaImage = (selector) => {
|
||||
jQuery('body').on('click', selector, function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Get media attachment details from the frame state
|
||||
var attachment = frame.state().get('selection').first().toJSON();
|
||||
const $button = jQuery(this);
|
||||
const $mediaView = $button.closest('.attachment-media-view');
|
||||
const $imgContainer = $mediaView.find('.thumbnail-image');
|
||||
const $placeholder = $mediaView.find('.placeholder');
|
||||
const $input = $button.siblings('.upload-id');
|
||||
|
||||
// Send the attachment URL to our custom image input field.
|
||||
imgContainer.html( '<img src="'+attachment.url+'" style="max-width:100%;"/>' );
|
||||
placeholder.addClass('hidden');
|
||||
imgIdInput.val( attachment.url ).trigger('change');
|
||||
$imgContainer.find('img').remove();
|
||||
$placeholder.removeClass('hidden');
|
||||
$input.val('').trigger('change');
|
||||
});
|
||||
};
|
||||
|
||||
// Finally, open the modal on click
|
||||
frame.open();
|
||||
|
||||
});
|
||||
}
|
||||
jQuery(($) => {
|
||||
'use strict';
|
||||
|
||||
function delete_media_image(mtSelector){
|
||||
// DELETE IMAGE LINK
|
||||
jQuery('body').on( 'click', mtSelector, function( event ){
|
||||
// Initialize jQuery UI buttonset for radio image controls
|
||||
$('.mt-meta-options-wrap .buttonset').buttonset();
|
||||
|
||||
event.preventDefault();
|
||||
var imgContainer = jQuery(this).closest('.attachment-media-view').find( '.thumbnail-image'),
|
||||
placeholder = jQuery(this).closest('.attachment-media-view').find( '.placeholder'),
|
||||
imgIdInput = jQuery(this).siblings('.upload-id');
|
||||
|
||||
// Clear out the preview image
|
||||
imgContainer.find('img').remove();
|
||||
placeholder.removeClass('hidden');
|
||||
|
||||
// Delete the image id from the hidden input
|
||||
imgIdInput.val( '' ).trigger('change');
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(document).ready(function($){
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Radio Image control in metabox
|
||||
*/
|
||||
$( '.mt-meta-options-wrap .buttonset' ).buttonset();
|
||||
|
||||
/**
|
||||
* Image up-loader
|
||||
*/
|
||||
upload_media_image('.mt-upload-button');
|
||||
delete_media_image('.mt-delete-button');
|
||||
// Initialize image upload/delete functionality
|
||||
initUploadMediaImage('.mt-upload-button');
|
||||
initDeleteMediaImage('.mt-delete-button');
|
||||
});
|
||||
Reference in New Issue
Block a user