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