-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmce-plgn.js
53 lines (51 loc) · 1.59 KB
/
tmce-plgn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Buttons tmce plugin file
* @package pootle buttons
* @since 0.7
* @developer http://wpdevelopment.me <[email protected]>
*/
(function($) {
/* Register the buttons */
tinymce.create('tinymce.plugins.MyButtons', {
init : function(ed, url) {
var ass_url = pbtn.ass_url = url + '/assets/';
/**
* Adds HTML tag to selected content
*/
ed.addButton( 'pbtn_add_btn', {
title : 'Insert Button',
image : ass_url + 'icon.png',
cmd: 'pbtn_add_btn_cmd'
});
ed.addCommand( 'pbtn_add_btn_cmd', function() {
var selected_text = ed.selection.getContent();
ed.windowManager.open( {
title: 'Insert Button',
url : pbtn.dialogUrl + '&assets_url=' + ass_url + '&text=' + selected_text,
width : 500,
height : 500
}, { plugin_url : pbtn.ass_url, editor : ed } );
});
ed.on( "dblClick", function ( e ) {
var btn = $( e.target );
if ( btn.hasClass( "pbtn" ) ) {
var href = btn.attr( 'href' ) ? btn.attr( 'href' ) : '',
icon = btn.find('i').length ? encodeURIComponent( btn.find('i').prop( 'outerHTML' ) ) : '';
ed.selection.select( btn[0] );
ed.windowManager.open( {
title: 'Edit Button',
url : pbtn.dialogUrl + '&edit_button=1&assets_url=' + ass_url + '&text=' + btn.text() +
'&icon=' + icon + '&url=' + href,
width : 500,
height : 500
}, { plugin_url : pbtn.ass_url, editor : ed, button : btn } );
}
} );
},
createControl : function(n, cm) {
return null;
}
});
/* Start the buttons */
tinymce.PluginManager.add( 'pbtn_script', tinymce.plugins.MyButtons );
})(jQuery);