jQuery(document).ready(function($) { var modal = $('#aesop-generator-wrap'); // start new $('.aesop-add-story-component').click(function(e){ e.preventDefault(); if ( typeof window.aiactive !== 'undefined' ) { alert('Nesting components within the visual interface is not supported.'); } else if ( typeof window.ailocked !== 'undefined' ) { alert('Please click on the editor and set your cursor location first.'); } else { jQuery('body').toggleClass('modal-open'); jQuery(modal).toggleClass('aesop-generator-open'); } }); var settingsHeight = function(){ var height = $(window).height() - 60; var width = $(window).width(); var buttonHeight = 71; // .aesop-buttoninsert-wrap doesn't exist on initial function call if ( width < 782 ) { var genLeftHeight = $('.aesop-generator-left').outerHeight(); } else { var genLeftHeight = 0; } if ( width < 480 ) { height = $(window).height() - 40; // 30 + 10, line 64 in responsive.less } $('#aesop-generator-settings-outer').css({'height':height - genLeftHeight - buttonHeight}); if ( height < 700 && width > 782 ) { $('.aesop-generator-left').addClass('aesop-generator-small-height'); } else { $('.aesop-generator-left').removeClass('aesop-generator-small-height'); } } var destroyModal = function(){ if ( typeof tinyMCE !== 'undefined' && tinyMCE.activeEditor ) { var editing = tinyMCE.activeEditor.dom.select('#aesop-generator-editing'); if(editing != ''){ editing[0].removeAttribute('id'); } } $(modal).removeClass('aesop-generator-open'); $('body').removeClass('modal-open'); $('body').removeClass('modal-updating'); } settingsHeight(); $(window).resize(function(){ settingsHeight(); }); // close modals on escape $(document).keyup(function(e) { if (e.keyCode == 27) { destroyModal(); } }); $('.aesop-close-modal').click(function(e){ e.preventDefault(); destroyModal(); }); $('.post-type-ai_galleries .insert-media').html(' Add Gallery'); // end new $('.aesop-generator').dropkick({ change: function () { var queried_shortcode = $('#aesop-generator-select').find(':selected').val(); $('#aesop-generator-settings').html(aesopshortcodes[queried_shortcode]); // conditionally load the map marker shortcode // since 1.3 $('.aesop-map-sticky #aesop-generator-attr-sticky').on('change',function(){ var selectedValue = $(this).val(); if( 'off' == selectedValue ) { $('#aesop-generator-wrap li.map_marker').fadeOut(); } else { $('#aesop-generator-wrap li.map_marker').fadeIn().css('display','inline-block'); } }); //// // conditional loading //// /* var hiddenClass = $('aesop-option-hidden'), openClass = $('aesop-option-open'), hiddenQuoteOpts = $('.aesop-quote-speed, .aesop-quote-offset, .aesop-quote-direction'), hiddenParallaxOpts = $('.aesop-parallax-floatermedia, .aesop-parallax-floaterposition, .aesop-parallax-floateroffset, .aesop-parallax-floaterdirection'), hiddenVideoOpts = $('.aesop-video-hosted, .aesop-video-loop, .aesop-video-autoplay, .aesop-video-controls, .aesop-video-viewstart, .aesop-video-viewend'); // quote component $('.aesop-quote-parallax #aesop-generator-attr-parallax').on('change',function(){ var selectedValue = $(this).val(); if( 'on' === selectedValue ) { $(hiddenQuoteOpts).removeClass('aesop-option-hidden').addClass('aesop-option-open'); $.cookie('aesop-quote-parallax-options', 'visible', { expires: 7 }); } else { $(hiddenQuoteOpts).removeClass('aesop-option-open').addClass('aesop-option-hidden'); $.cookie('aesop-quote-parallax-options', 'hidden', { expires: 7 }); } }); // parallax component $('.aesop-parallax-floater #aesop-generator-attr-floater').on('change',function(){ var selectedValue = $(this).val(); if( 'on' === selectedValue ) { $(hiddenParallaxOpts).addClass('aesop-option-open'); $.cookie('aesop-parallax-options', 'visible', { expires: 7 }); } else { $(hiddenParallaxOpts).removeClass('aesop-option-open').addClass('aesop-option-hidden'); $.cookie('aesop-parallax-options', 'hidden', { expires: 7 }); } }); // video component $('.aesop-video-src #aesop-generator-attr-src').on('change',function(){ var selectedValue = $(this).val(); if( 'self' === selectedValue ) { $(hiddenVideoOpts).addClass('aesop-option-open'); $('.aesop-video-id').removeClass('aesop-option-open').addClass('aesop-option-hidden'); $.cookie('aesop-video-options', 'visible', { expires: 7 }); } else { $(hiddenVideoOpts).removeClass('aesop-option-open').addClass('aesop-option-hidden'); $('.aesop-video-id').addClass('aesop-option-open'); $.cookie('aesop-video-options', 'hidden', { expires: 7 }); } }); //// // set cookies for remembered states // @todo - need to account for multiple components in editor //// // set quote cookie if ( 'visible' == $.cookie('aesop-quote-parallax-options') ) { $(hiddenQuoteOpts).addClass('aesop-option-open'); } else if ( 'hidden' == $.cookie('aesop-quote-parallax-options') ) { $(hiddenQuoteOpts).addClass('aesop-option-hidden'); } // set paralalx cookie if ( 'visible' == $.cookie('aesop-parallax-options') ) { $(hiddenParallaxOpts).addClass('aesop-option-open'); } else if ( 'hidden' == $.cookie('aesop-parallax-options') ) { $(hiddenParallaxOpts).addClass('aesop-option-hidden'); } // set paralalx cookie if ( 'visible' == $.cookie('aesop-video-options') ) { $(hiddenVideoOpts).addClass('aesop-option-open'); } else if ( 'hidden' == $.cookie('aesop-video-options') ) { $(hiddenVideoOpts).addClass('aesop-option-hidden'); } */ } }); function SpecialCharEncode(s) { if ((typeof s) != "string") return s; var tagsToReplace = { '<': '<', '>': '>', '[':'[', ']':']', '"': '"' }; return s.replace(/[\[\]<>\"]/g, function(tag) { return tagsToReplace[tag] || tag; }); //return s.replace(/\[/g, "[").replace(/\]/g, "]").replace(/\"/g, "'"); //return s.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { return '&#'+i.charCodeAt(0)+';'; }); } // Insert shortcode //$('#aesop-generator-insert,.aesop-generator').live('click', function() { jQuery(document).on('click', '#aesop-generator-insert,.aesop-generator', function(e){ $('.aesop-generator-empty').hide(); var queried_shortcode = $('.aesop-generator').find(':selected').val(); var aesop_compatibility_mode_prefix = $('#aesop-compatibility-mode-prefix').val(); $('#aesop-generator-result').val('[' + aesop_compatibility_mode_prefix + queried_shortcode); $('#aesop-generator-settings .aesop-generator-attr').each(function() { if ( $(this).val() !== '' ) { var val = $(this).val(); if ($(this).attr('name') != "floatermedia" && $(this).attr('name') != "overlay_content") { // encode special chars so we don't break html val = SpecialCharEncode(val); } else { // just replace brackets and quotes val = val.replace(/\[/g, "[").replace(/\]/g, "]").replace(/\"/g, "'"); } $('#aesop-generator-result').val( $('#aesop-generator-result').val() + ' ' + $(this).attr('name') + '="' + val + '"' ); } }); $('#aesop-generator-result').val($('#aesop-generator-result').val() + ']'); // wrap shortcode if ( $('#aesop-generator-content').val() != 'false' ) { $('#aesop-generator-result').val($('#aesop-generator-result').val() + $('#aesop-generator-content').val() + '[/' + aesop_compatibility_mode_prefix + queried_shortcode + ']'); } if ( typeof tinyMCE !== 'undefined' && tinyMCE.activeEditor ) { var editing = tinyMCE.activeEditor.dom.select('#aesop-generator-editing'); $(editing).replaceWith('

'); } window.send_to_editor(jQuery('#aesop-generator-result').val()); // start new destroyModal(); // end new return false; }); }); // media uploader var file_frame; var className; jQuery(document).on('click', '#aesop-upload-img', function( e ){ e.preventDefault(); className = e.currentTarget.parentElement.className; // If the media frame already exists, reopen it. if ( file_frame ) { file_frame.open(); return; } // Create the media frame. file_frame = wp.media.frames.file_frame = wp.media({ title: jQuery( this ).data( 'uploader_title' ), button: { text: jQuery( this ).data( 'uploader_button_text' ), }, multiple: false // Set to true to allow multiple files to be selected }); // When an image is selected, run a callback. file_frame.on( 'select', function() { var attachment = file_frame.state().get('selection').first().toJSON(); jQuery('.' + className + ' .aesop-generator-attr-media_upload').val(attachment.url); }); // Finally, open the modal file_frame.open(); }); /** * DropKick * * Highly customizable element that gets dropkicked lists = [], // Convenience keys for keyboard navigation keyMap = { 'left' : 37, 'up' : 38, 'right' : 39, 'down' : 40, 'enter' : 13 }, // HTML template for the dropdowns dropdownTemplate = [ '
', '', '{{ label }}', '', '
', '', '
', '
' ].join(''), // HTML template for dropdown options optionTemplate = '
  • {{ text }}
  • ', // Some nice default values defaults = { startSpeed : 1000, // I recommend a high value here, I feel it makes the changes less noticeable to the user theme : false, change : false }, // Make sure we only bind keydown on the document once keysBound = false ; // Called by using $('foo').dropkick(); methods.init = function (settings) { settings = $.extend({}, defaults, settings); return this.each(function () { var // The current list and place our new one in front of it $select.before($dk); // Update the reference to $dk $dk = $('#dk_container_' + id).fadeIn(settings.startSpeed); // Save the current theme theme = settings.theme ? settings.theme : 'default'; $dk.addClass('dk_theme_' + theme); data.theme = theme; // Save the updated $dk reference into our data object data.$dk = $dk; // Save the dropkick data onto the