Ubuntu
/**
* Marketing Button JS
*/
var MarketingButton = (function () {
var _privateMethod = function () {};
var inbound_buttons_loaded = false;
var Public = {
init: function () {
// add listeners to iframes
this.waitForEditorLoad();
this.attachHandlers();
},
attachHandlers: function(){
this.closePopupHandler();
this.triggerPopupHandler();
this.insertShortcodeHandler();
this.launchShortcodeWindow();
this.backButtonHandler();
},
triggerPopupHandler: function() {
var that = this;
jQuery("body").on('click', '.open-marketing-button-popup', function (e) {
e.preventDefault();
var id = jQuery(this).attr('data-editor');
jQuery('#iframe-target').attr('current-editor', id);
if(document.getElementById(id) && document.getElementById(id).parentNode.parentNode.parentNode.style.display !== "none") {
console.log('iframe display');
} else {
id = id.replace("_ifr", "");
jQuery('#iframe-target').attr('current-editor', id);
console.log('textarea display');
}
console.log('editor id', id);
/*var pos = that.getCursorPosition(iframeTarget);*/
/* Run popup here */
jQuery.magnificPopup.open({
items: {
src: '#inbound-marketing-popup', // can be a HTML string, jQuery object, or CSS selector
type: 'inline',
callbacks: {
open: function() {
jQuery('.inbound-short-list').show();
},
close: function() {
jQuery("#iframe-target").html('');
}
}
}
});
});
// on marketing button click, grab ID to insert to
},
waitForEditorLoad: function() {
var that = this;
jQuery(".acf_postbox .field_type-wysiwyg iframe")
.waitUntilExists(function(){
console.log('wait');
if(!inbound_buttons_loaded) {
// do stuff with editor
that.addButtonsToACFNormal();
inbound_buttons_loaded = true;
}
});
},
launchShortcodeWindow: function(){
jQuery(".launch-marketing-shortcode").on('click', function (e) {
var $this = jQuery(this);
var type = $this.attr('data-launch-sc');
var url = inbound_load.image_dir + 'popup.php?popup=' + type + '&width=' + 900 + "&path=" + encodeURIComponent(inbound_load.image_dir);
//$('shortcode-frame').attr('href', url);
// hide list
jQuery('.inbound-short-list').hide();
var iframe = "