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