| 1 |
(function($) { |
| 2 |
"use strict"; |
| 3 |
if ( typeof bws_shortcode_button != 'undefined' ) { |
| 4 |
var win; |
| 5 |
|
| 6 |
tinymce.create( |
| 7 |
'tinymce.plugins.BWSButton', |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Initializes the plugin, this will be executed after the plugin has been created. |
| 11 |
* This call is done before the editor instance has finished it's initialization so use the onInit event |
| 12 |
* of the editor instance to intercept that event. |
| 13 |
* |
| 14 |
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. |
| 15 |
* @param {string} url Absolute URL to where the plugin is located. |
| 16 |
*/ |
| 17 |
init : function( ed, url ) { |
| 18 |
ed.addButton( |
| 19 |
'add_bws_shortcode', |
| 20 |
{ |
| 21 |
title : bws_shortcode_button.title, |
| 22 |
classes: 'bws_shortcode_button widget btn', |
| 23 |
icon: 'icon bwsicons bwsicons-shortcode', |
| 24 |
text: bws_shortcode_button.label, |
| 25 |
onclick: function() { |
| 26 |
|
| 27 |
win = ed.windowManager.open( |
| 28 |
{ |
| 29 |
width: 400, |
| 30 |
height: 400, |
| 31 |
inline: true, |
| 32 |
title: bws_shortcode_button.title, |
| 33 |
body: { |
| 34 |
id : 'bws-shortcode-content', |
| 35 |
type: 'container', |
| 36 |
classes: 'bws-shortcode', |
| 37 |
html: $( '#bws_shortcode_popup' ).html() |
| 38 |
}, |
| 39 |
buttons: [{ |
| 40 |
text: 'Insert', |
| 41 |
classes: 'button-primary primary bws_shortcode_insert', |
| 42 |
onclick: function( e ) { |
| 43 |
var shortcode = $( '.mce-container-body #bws_shortcode_display' ).text(); |
| 44 |
if ( '' != shortcode ) { |
| 45 |
/* insert shortcode to tinymce */ |
| 46 |
ed.insertContent( shortcode ); |
| 47 |
} |
| 48 |
ed.windowManager.close(); |
| 49 |
}, |
| 50 |
}, |
| 51 |
{ |
| 52 |
text: 'Cancel', |
| 53 |
onclick: 'close' |
| 54 |
}], |
| 55 |
|
| 56 |
} |
| 57 |
); |
| 58 |
var current_object = '.mce-container-body'; |
| 59 |
var select_count = $( current_object + ' select#bws_shortcode_select option' ).length; |
| 60 |
if ( 1 == select_count ) { |
| 61 |
$( current_object + ' #bws_shortcode_select_plugin' ).hide(); |
| 62 |
} |
| 63 |
|
| 64 |
var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
| 65 |
$( current_object + ' #bws_shortcode_content > div' ).hide(); |
| 66 |
$( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
| 67 |
|
| 68 |
if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
| 69 |
$( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
| 70 |
} |
| 71 |
|
| 72 |
$( current_object + ' #bws_shortcode_select' ).on( |
| 73 |
'change', |
| 74 |
function() { |
| 75 |
var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
| 76 |
$( current_object + ' #bws_shortcode_content > div' ).hide(); |
| 77 |
$( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
| 78 |
if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
| 79 |
$( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
| 80 |
} else { |
| 81 |
$( current_object + ' #bws_shortcode_display' ).text( '' ); |
| 82 |
} |
| 83 |
} |
| 84 |
); |
| 85 |
|
| 86 |
$.each( |
| 87 |
bws_shortcode_button.function_name, |
| 88 |
function( index, value ) { |
| 89 |
eval( value + '();' ); |
| 90 |
} |
| 91 |
); |
| 92 |
} |
| 93 |
} |
| 94 |
); |
| 95 |
}, |
| 96 |
|
| 97 |
/** |
| 98 |
* Creates control instances based in the incomming name. This method is normally not |
| 99 |
* needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons |
| 100 |
* but you sometimes need to create more complex controls like listboxes, split buttons etc then this |
| 101 |
* method can be used to create those. |
| 102 |
* |
| 103 |
* @param {String} n Name of the control to create. |
| 104 |
* @param {tinymce.ControlManager} cm Control manager to use inorder to create new control. |
| 105 |
* @return {tinymce.ui.Control} New control instance or null if no control was created. |
| 106 |
*/ |
| 107 |
createControl : function(n, cm) { |
| 108 |
return null; |
| 109 |
}, |
| 110 |
|
| 111 |
/** |
| 112 |
* Returns information about the plugin as a name/value array. |
| 113 |
* The current keys are longname, author, authorurl, infourl and version. |
| 114 |
* |
| 115 |
* @return {Object} Name/value array containing information about the plugin. |
| 116 |
*/ |
| 117 |
getInfo : function() { |
| 118 |
return { |
| 119 |
longname : 'BWS Shortcode Buttons', |
| 120 |
author : 'BWS', |
| 121 |
authorurl : 'https://bestwebsoft.com', |
| 122 |
infourl : '', |
| 123 |
version : "0.1" |
| 124 |
}; |
| 125 |
} |
| 126 |
} |
| 127 |
); |
| 128 |
|
| 129 |
/* Register plugin */ |
| 130 |
tinymce.PluginManager.add( 'add_bws_shortcode', tinymce.plugins.BWSButton ); |
| 131 |
} |
| 132 |
})( jQuery ); |
| 133 |
|