author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 7 | cf61fcea0001 |
child 19 | 3d72ae0968f4 |
permissions | -rwxr-xr-x |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
(function($) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
if ( typeof bws_shortcode_button != 'undefined' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
var win; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
tinymce.create( 'tinymce.plugins.BWSButton', { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
* Initializes the plugin, this will be executed after the plugin has been created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
* This call is done before the editor instance has finished it's initialization so use the onInit event |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
* of the editor instance to intercept that event. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
* @param {string} url Absolute URL to where the plugin is located. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
init : function( ed, url ) { |
16 | 15 |
ed.addButton( 'add_bws_shortcode', { |
16 |
title : bws_shortcode_button.title, |
|
17 |
classes: 'bws_shortcode_button widget btn', |
|
18 |
icon: 'icon bwsicons bwsicons-shortcode', |
|
19 |
text: bws_shortcode_button.label, |
|
20 |
onclick: function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
|
16 | 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() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
var plugin = $( current_object + ' #bws_shortcode_select option:selected' ).val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
$( current_object + ' #bws_shortcode_content > div' ).hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
$( current_object + ' #bws_shortcode_content > #' + plugin ).show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
if ( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
$( current_object + ' #bws_shortcode_display' ).text( $( current_object + ' #bws_shortcode_content > #' + plugin + ' .bws_default_shortcode' ).val() ); |
16 | 71 |
} else { |
72 |
$( current_object + ' #bws_shortcode_display' ).text( '' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
} |
16 | 74 |
}); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
|
16 | 76 |
$.each( bws_shortcode_button.function_name, function( index, value ) { |
77 |
eval( value + '();' ); |
|
78 |
}); |
|
79 |
} |
|
80 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
* Creates control instances based in the incomming name. This method is normally not |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
* needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
* but you sometimes need to create more complex controls like listboxes, split buttons etc then this |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
87 |
* method can be used to create those. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
* @param {String} n Name of the control to create. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
* @param {tinymce.ControlManager} cm Control manager to use inorder to create new control. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
* @return {tinymce.ui.Control} New control instance or null if no control was created. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
createControl : function(n, cm) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
return null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
* Returns information about the plugin as a name/value array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
* The current keys are longname, author, authorurl, infourl and version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
* @return {Object} Name/value array containing information about the plugin. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
103 |
getInfo : function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
104 |
return { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
longname : 'BWS Shortcode Buttons', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
author : 'BWS', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
authorurl : 'https://bestwebsoft.com', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
108 |
infourl : '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
109 |
version : "0.1" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
114 |
/* Register plugin */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
115 |
tinymce.PluginManager.add( 'add_bws_shortcode', tinymce.plugins.BWSButton ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
116 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
117 |
})(jQuery); |