-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor_plugin.js
75 lines (62 loc) · 1.61 KB
/
editor_plugin.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* editor_plugin.js
*
* @package tabindent
* @since 1.1
*
* Pieced together from several sources, notably:
* http://tinymce.moxiecode.com/forum/viewtopic.php?pid=77144#p77144
*
* Copyright 2011 Boone B Gorges
* License: GPLv3
*/
(function() {
tinymce.create('tinymce.plugins.TabIndent', {
init : function(ed, url) {
var t = this;
t.editor = ed;
// Catch the Tab button event
ed.onKeyPress.add(function(inst,e) {
// In later versions of FF, you need to populate the event manually
if ( !e )
var e = window.event;
if ( e.keyCode )
code = e.keyCode; // Non-FF
else if ( e.which )
code = e.which; // FF
if ( code == 9 && !e.altKey && !e.ctrlKey ) {
t.doTabIndent();
// prevent tab key from leaving editor in some browsers
if ( e.preventDefault ) {
e.preventDefault();
}
return false;
}
});
// Attach the indent action to the editor button
ed.addCommand('mcePreview', function() {
t.doTabIndent();
});
// Register the editor button
ed.addButton('tabindent', {
title : 'tabindent.button_hover',
cmd : 'mcePreview',
image : url + '/img/tab_button.gif'
} );
},
doTabIndent : function() {
tinyMCE.activeEditor.selection.setContent(" ");
},
getInfo : function() {
return {
longname : 'Tab Indent',
author : 'Boone B Gorges',
authorurl : 'http://boonebgorges.com',
infourl : 'http://github.com/boonebgorges/tabindent',
version : '1.0'
};
}
});
// Register plugin
tinymce.PluginManager.add('tabindent', tinymce.plugins.TabIndent);
})();