File: /var/www/html/wp-content/plugins/hover_effects_pack/js/hover_effects_plugin.js
"use strict";
(function() {
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
jQuery('.add_media').on('click', function() {
_custom_media = false;
});
tinymce.PluginManager.add('hover_pack', function(editor, url) {
editor.addButton('hover_pack_button', {
image: wphp_params.wphp_plugin_url + 'icon.png',
onclick: function() {
var width = jQuery(window).width(),
H = jQuery(window).height(),
W = (753 < width) ? 753 : width;
H = H - 120;
tb_show('Hover Image Shortcode', wphp_params.wphp_plugin_url + 'hp_popup.html?width=' + W + '&height=' + H);
setTimeout(wphp_modal_open, 500);
setTimeout(wphp_add_insert_listener, 500);
setTimeout(wphp_add_colorpicker, 500);
}
});
});
jQuery(function() {
// Select File
var file_upload;
var attachment;
jQuery('.image-upload').on('click', function(event) {
event.preventDefault();
if (file_upload) {
file_upload.open();
return;
}
// Create the media frame.
file_upload = wp.media.frames.file_upload = wp.media({
title: jQuery(this).data('uploader_title'),
library: {
type: 'image'
},
button: {
text: jQuery(this).data('uploader_button_text'),
},
multiple: false
});
file_upload.on('select', function() {
attachment = file_upload.state().get('selection').first().toJSON();
var insert_image_url = '';
var insert_image_width = '';
var insert_image_height = '';
if(wphp_params.wphp_thumb_size == 'md') {
if(typeof attachment.sizes.medium === 'undefined'){
if(typeof attachment.sizes.thumbnail === 'undefined'){
insert_image_url = attachment.url;
insert_image_width = attachment.width;
insert_image_height = attachment.height;
} else {
insert_image_url = attachment.sizes.thumbnail.url;
insert_image_width = attachment.sizes.thumbnail.width;
insert_image_height = attachment.sizes.thumbnail.height;
}
} else {
insert_image_url = attachment.sizes.medium.url;
insert_image_width = attachment.sizes.medium.width;
insert_image_height = attachment.sizes.medium.height;
}
}
if(wphp_params.wphp_thumb_size == 'th') {
if (typeof attachment.sizes.thumbnail === 'undefined') {
insert_image_url = attachment.url;
insert_image_width = attachment.width;
insert_image_height = attachment.height;
} else {
insert_image_url = attachment.sizes.thumbnail.url;
insert_image_width = attachment.sizes.thumbnail.width;
insert_image_height = attachment.sizes.thumbnail.height;
}
}
if(wphp_params.wphp_thumb_size == 'og') {
insert_image_url = attachment.url;
insert_image_width = attachment.width;
insert_image_height = attachment.height;
}
jQuery('#hover-image-img').val(insert_image_url);
jQuery('#hover-image-link').val(attachment.url);
jQuery('#hover-image-width').val(insert_image_width);
jQuery('#hover-image-height').val(insert_image_height);
// SiteOrigin support
jQuery('.hpso-image').val(insert_image_url);
jQuery('.hpso-image-link').val(attachment.url);
jQuery('.hpso-image-width').val(insert_image_width);
jQuery('.hpso-image-height').val(insert_image_height);
});
file_upload.open();
});
var form = jQuery('#hover-image-form');
var table = form.find('table');
form.appendTo('body').hide();
});
})();
function wphp_add_insert_listener() {
jQuery('#hover-image-submit').on('click', function() {
var options = {
'img': '',
'link': '',
'link_tab': '',
'img_title': '',
'img_alt': '',
'disable_popup': '',
'width': '',
'height': '',
'class': '',
'radius': '',
'effect': 'fade',
'inverse_effect': '',
'color': '',
'opacity': '100',
'title': '',
'title_visible': '',
'title_delay': '',
'title_slide': '',
'title_rotation': '',
'title_scale': '',
'title_fade': '',
'text': '',
'text_visible': '',
'text_delay': '',
'text_slide': '',
'text_rotation': '',
'text_scale': '',
'text_fade': ''
};
var shortcode = '[hover_pack';
for (var index in options) {
var value = jQuery('#hover-image-' + index).val();
// attaches the attribute to the shortcode only if it's different from the default value
if (value !== options[index]) value = jQuery('<div/>').text(value).html();
if (value != 'on') {
shortcode += ' ' + index + '="' + value + '"';
}
if (jQuery('#hover-image-' + index + ':checked')[0] !== undefined) {
shortcode += ' ' + index + '="1"';
}
}
shortcode += ']';
// inserts the shortcode into the active editor
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
tb_remove();
});
}
function wphp_modal_open() {
var file_upload;
var attachment;
jQuery('.image-upload').on('click', function(event) {
event.preventDefault();
if (file_upload) {
file_upload.open();
return;
}
// Create the media frame.
file_upload = wp.media.frames.file_upload = wp.media({
title: jQuery(this).data('uploader_title'),
library: {
type: 'image'
},
button: {
text: jQuery(this).data('uploader_button_text'),
},
multiple: false
});
file_upload.on('select', function() {
attachment = file_upload.state().get('selection').first().toJSON();
var insert_image_url = '';
var insert_image_width = '';
var insert_image_height = '';
if(wphp_params.wphp_thumb_size == 'md') {
if(typeof attachment.sizes.medium === 'undefined'){
if(typeof attachment.sizes.thumbnail === 'undefined'){
insert_image_url = attachment.url;
insert_image_width = attachment.width;
insert_image_height = attachment.height;
} else {
insert_image_url = attachment.sizes.thumbnail.url;
insert_image_width = attachment.sizes.thumbnail.width;
insert_image_height = attachment.sizes.thumbnail.height;
}
} else {
insert_image_url = attachment.sizes.medium.url;
insert_image_width = attachment.sizes.medium.width;
insert_image_height = attachment.sizes.medium.height;
}
}
if(wphp_params.wphp_thumb_size == 'th') {
if (typeof attachment.sizes.thumbnail === 'undefined') {
insert_image_url = attachment.url;
insert_image_width = attachment.width;
insert_image_height = attachment.height;
} else {
insert_image_url = attachment.sizes.thumbnail.url;
insert_image_width = attachment.sizes.thumbnail.width;
insert_image_height = attachment.sizes.thumbnail.height;
}
}
if(wphp_params.wphp_thumb_size == 'og') {
insert_image_url = attachment.url;
insert_image_width = attachment.width;
insert_image_height = attachment.height;
}
jQuery('#hover-image-img').val(insert_image_url);
jQuery('#hover-image-link').val(attachment.url);
jQuery('#hover-image-width').val(insert_image_width);
jQuery('#hover-image-height').val(insert_image_height);
// SiteOrigin support
jQuery('.hpso-image').val(insert_image_url);
jQuery('.hpso-image-link').val(attachment.url);
jQuery('.hpso-image-width').val(insert_image_width);
jQuery('.hpso-image-height').val(insert_image_height);
});
file_upload.open();
});
}
function wphp_add_colorpicker() {
jQuery('#hover-image-color').wpColorPicker();
}