jQuery(document).ready(function($) { // In some rare cases the globally loaded LS_MCE_l10n // variable might not be available due to plugins making // changes in the WP script queue. The below makes sure // that we can at least avoid undef JS errors. if( typeof LS_MCE_l10n === 'undefined' ) { LS_MCE_l10n = {}; } tinymce.create('tinymce.plugins.layerslider_plugin', { init : function(ed, url) { // Close event $(document).on('click', '.mce-layerslider-overlay', $.proxy(function() { this.closePopup(); }, this)); $(document).on('click', '.mce-layerslider-window .close-modal', $.proxy(function(e) { e.preventDefault(); this.closePopup(); }, this)); $(document).on('keydown', $.proxy(function(e) { if( e.which === 27 ) { this.closePopup(); } }, this)).on('keyup', $.proxy(function(e) { })); // Select slider $(document).on('click', '.mce-layerslider-window .slider-item', $.proxy(function(e) { this.selectSlider( e, $(e.currentTarget) ); }, this)); // Insert slider $(document).on('click', '.mce-layerslider-insert-button', $.proxy(function(e) { this.insertSlider(); this.closePopup(); }, this)); // Button props ed.addButton('layerslider_button', { title : LS_MCE_l10n.MCEAddLayerSlider, cmd : 'layerslider_insert_shortcode', onClick : $.proxy(this.openPopup, this) }); }, openPopup : function(e) { // Get the popup var $modal = $('.mce-layerslider-window'); // If the popup isn't already open, create it and load its content using ajax if( ! $('.mce-layerslider-window').length ) { var modalMarkup = '
\ \

'+LS_MCE_l10n.MCEInsertSlider+'

\
\ \
'; // Prepend modal $modal = $( modalMarkup ).prependTo('body'); var $inner = $('.inner', $modal); // Set focus on the window to allow keyboard shortcuts setTimeout(function() { $modal.focus(); }, 100); // Add overlay $('
', { 'class' : 'mce-layerslider-overlay'}).prependTo('body'); var itemMarkup = '
\
\
\
\
'+LS_MCE_l10n.MCENoPreview+'
\ '+LS_MCE_l10n.MCENoPreviewText+'\
\
\
\
\
\
\
\ \
\
'; // Get sliders $.getJSON(ajaxurl, { action : 'ls_get_mce_sliders' }, function(data) { $.each(data, function(index, item) { var $item = $(itemMarkup); $item.data({ 'id': item.id, 'slug': item.slug }); if( item.preview ) { $('.preview', $item).empty().css({ 'background-image': 'url('+item.preview+')' }); } $('.name', $item).html( item.name ); $item.appendTo( $inner ); }); }); } }, searchSlider : function() { }, selectSlider : function( event, $item ) { // Add to multi-select if( event.ctrlKey || event.metaKey ) { $item.toggleClass('selected'); // Single select } else { $item.addClass('selected').siblings().removeClass('selected'); } // Enable insert button $('.mce-layerslider-insert-button').attr('disabled', false); }, insertSlider: function() { // Get modal window var $modal = $('.mce-layerslider-window'); // Get selected element $('.slider-item.selected', $modal).each(function() { // Get options var $item = $(this), sliderId = $item.data('id'), sliderSlug = $item.data('slug'), embedId = sliderSlug ? sliderSlug : sliderId, firstSlide = $('input[data-option="firstslide"]', $modal).val(); if( firstSlide ) { firstSlide = ' firstslide="'+firstSlide+'"'; } tinymce.execCommand('mceInsertContent', false, '[layerslider id="'+embedId+'"'+firstSlide+']'); }); }, closePopup : function() { if($('.mce-layerslider-window').length) { $('.mce-layerslider-overlay').remove(); $('.mce-layerslider-window').remove(); } } }); // Add button tinymce.PluginManager.add('layerslider_button', tinymce.plugins.layerslider_plugin); }); x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586