10 * |
10 * |
11 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. |
11 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. |
12 * @param {string} url Absolute URL to where the plugin is located. |
12 * @param {string} url Absolute URL to where the plugin is located. |
13 */ |
13 */ |
14 init : function( ed, url ) { |
14 init : function( ed, url ) { |
15 if ( bws_shortcode_button.wp_version < '3.9' ) { |
15 ed.addButton( 'add_bws_shortcode', { |
16 ed.addButton( 'add_bws_shortcode', { |
16 title : bws_shortcode_button.title, |
17 title : bws_shortcode_button.title, |
17 classes: 'bws_shortcode_button widget btn', |
18 classes: 'bws_shortcode_button widget btn', |
18 icon: 'icon bwsicons bwsicons-shortcode', |
19 image : bws_shortcode_button.icon_url, |
19 text: bws_shortcode_button.label, |
20 onclick: function() { |
20 onclick: function() { |
21 /* triggers the thickbox */ |
|
22 var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; |
|
23 W = W - 80; |
|
24 H = H - 84; |
|
25 tb_show( bws_shortcode_button.title, '#TB_inline?width=' + W + '&height=' + H + '&inlineId=bws_shortcode_popup' ); |
|
26 |
|
27 var current_object = '#TB_ajaxContent'; |
|
28 |
|
29 var select_count = $( current_object + ' select#bws_shortcode_select option').length; |
|
30 if ( 1 == select_count ) { |
|
31 $( current_object + ' #bws_shortcode_select_plugin' ).hide(); |
|
32 } |
|
33 |
21 |
|
22 win = ed.windowManager.open( { |
|
23 width: 400, |
|
24 height: 400, |
|
25 inline: true, |
|
26 title: bws_shortcode_button.title, |
|
27 body: { |
|
28 id : 'bws-shortcode-content', |
|
29 type: 'container', |
|
30 classes: 'bws-shortcode', |
|
31 html: $( '#bws_shortcode_popup' ).html() |
|
32 }, |
|
33 buttons: [{ |
|
34 text: 'Insert', |
|
35 classes: 'button-primary primary bws_shortcode_insert', |
|
36 onclick: function( e ) { |
|
37 var shortcode = $( '.mce-container-body #bws_shortcode_display' ).text(); |
|
38 if ( '' != shortcode ) { |
|
39 /* insert shortcode to tinymce */ |
|
40 ed.insertContent( shortcode ); |
|
41 } |
|
42 ed.windowManager.close(); |
|
43 }, |
|
44 }, |
|
45 { |
|
46 text: 'Cancel', |
|
47 onclick: 'close' |
|
48 }], |
|
49 |
|
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 |
|
57 var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
|
58 $( current_object + ' #bws_shortcode_content > div' ).hide(); |
|
59 $( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
|
60 |
|
61 if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
|
62 $( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
|
63 } |
|
64 |
|
65 $( current_object + ' #bws_shortcode_select' ).on( 'change',function() { |
34 var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
66 var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
35 $( current_object + ' #bws_shortcode_content > div' ).hide(); |
67 $( current_object + ' #bws_shortcode_content > div' ).hide(); |
36 $( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
68 $( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
37 |
|
38 if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
69 if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
39 $( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
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( '' ); |
40 } |
73 } |
|
74 }); |
41 |
75 |
42 $( current_object + ' #bws_shortcode_select' ).on( 'change',function() { |
76 $.each( bws_shortcode_button.function_name, function( index, value ) { |
43 var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
77 eval( value + '();' ); |
44 $( current_object + ' #bws_shortcode_content > div' ).hide(); |
78 }); |
45 $( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
79 } |
46 if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
80 }); |
47 $( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
|
48 } else { |
|
49 $( current_object + ' #bws_shortcode_display' ).text( '' ); |
|
50 } |
|
51 }); |
|
52 |
|
53 $.each( bws_shortcode_button.function_name, function( index, value ) { |
|
54 eval( value + '();' ); |
|
55 }); |
|
56 } |
|
57 }); |
|
58 } else { |
|
59 ed.addButton( 'add_bws_shortcode', { |
|
60 title : bws_shortcode_button.title, |
|
61 classes: 'bws_shortcode_button widget btn', |
|
62 icon: 'icon bwsicons bwsicons-shortcode', |
|
63 text: bws_shortcode_button.label, |
|
64 onclick: function() { |
|
65 |
|
66 win = ed.windowManager.open( { |
|
67 width: 400, |
|
68 height: 400, |
|
69 inline: true, |
|
70 title: bws_shortcode_button.title, |
|
71 body: { |
|
72 id : 'bws-shortcode-content', |
|
73 type: 'container', |
|
74 classes: 'bws-shortcode', |
|
75 html: $( '#bws_shortcode_popup' ).html() |
|
76 }, |
|
77 buttons: [{ |
|
78 text: 'Insert', |
|
79 classes: 'button-primary primary bws_shortcode_insert', |
|
80 onclick: function( e ) { |
|
81 var shortcode = $( '.mce-container-body #bws_shortcode_display' ).text(); |
|
82 if ( '' != shortcode ) { |
|
83 /* insert shortcode to tinymce */ |
|
84 ed.insertContent( shortcode ); |
|
85 } |
|
86 ed.windowManager.close(); |
|
87 }, |
|
88 }, |
|
89 { |
|
90 text: 'Cancel', |
|
91 onclick: 'close' |
|
92 }], |
|
93 |
|
94 }); |
|
95 var current_object = '.mce-container-body'; |
|
96 var select_count = $( current_object + ' select#bws_shortcode_select option').length; |
|
97 if ( 1 == select_count ) { |
|
98 $( current_object + ' #bws_shortcode_select_plugin' ).hide(); |
|
99 } |
|
100 |
|
101 var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
|
102 $( current_object + ' #bws_shortcode_content > div' ).hide(); |
|
103 $( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
|
104 |
|
105 if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
|
106 $( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
|
107 } |
|
108 |
|
109 $( current_object + ' #bws_shortcode_select' ).on( 'change',function() { |
|
110 var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
|
111 $( current_object + ' #bws_shortcode_content > div' ).hide(); |
|
112 $( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
|
113 if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
|
114 $( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
|
115 } else { |
|
116 $( current_object + ' #bws_shortcode_display' ).text( '' ); |
|
117 } |
|
118 }); |
|
119 |
|
120 $.each( bws_shortcode_button.function_name, function( index, value ) { |
|
121 eval( value + '();' ); |
|
122 }); |
|
123 } |
|
124 }); |
|
125 } |
|
126 }, |
81 }, |
127 |
82 |
128 /** |
83 /** |
129 * Creates control instances based in the incomming name. This method is normally not |
84 * Creates control instances based in the incomming name. This method is normally not |
130 * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons |
85 * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons |