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