-
Notifications
You must be signed in to change notification settings - Fork 1
/
editor_plugin_src.js
70 lines (60 loc) · 2.47 KB
/
editor_plugin_src.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
/**
* Etherpad Lite plug-in for TinyMCE version 3.x
* @author Daniel Tygel
* @version $Rev: 1.0 $
* @package etherpadlite
* @link https://github.com/dtygel/tinymce-etherpadlite-embed
* EtherPad plugin for TinyMCE
* AFFERO LICENSE
*/
(function() {
tinymce.PluginManager.requireLangPack('etherpadlite');
tinymce.create('tinymce.plugins.EtherPadLitePlugin', {
init : function(ed, url) {
var t = this;
t.editor = ed;
//If the person who activated the plugin didn't put a Pad Server URL, the plugin will be disabled
if (!ed.getParam("plugin_etherpadlite_padServerUrl")) {
alert(etherpadlite.error);
return null;
}
var padUrl = ed.getParam("plugin_etherpadlite_padServerUrl");
var padPrefix = (ed.getParam("plugin_etherpadlite_padNamesPrefix"))
? ed.getParam("plugin_etherpadlite_padNamesPrefix")
: "";
var padWidth = (ed.getParam("plugin_etherpadlite_padWidth"))
? ed.getParam("plugin_etherpadlite_padWidth")
: "100%";
var padHeight = (ed.getParam("plugin_etherpadlite_padHeight"))
? ed.getParam("plugin_etherpadlite_padHeight")
: "400";
ed.addCommand('mceEtherPadLite', function() {
var padName = padPrefix + '.' + randomPadName();
var iframe = "<iframe name='embed_readwrite' src='" + padUrl + padName + "?showControls=true&showChat=true&&alwaysShowChat=true&lang=pt&showLineNumbers=true&useMonospaceFont=false' width='" + padWidth + "' height='" + padHeight + "'></iframe>";
ed.execCommand('mceInsertContent', false, iframe);
});
ed.addButton('etherpadlite', {title : 'etherpadlite.desc', cmd : 'mceEtherPadLite', image : url + '/img/etherpadlite.gif'});
},
getInfo : function() {
return {
longname : 'Insert a collaborative text with Etherpad Lite',
author : 'Daniel Tygel',
authorurl : 'http://cirandas.net/dtygel',
infourl : 'https://github.com/dtygel/tinymce-etherpadlite-embed',
version : tinymce.majorVersion + "." + tinymce.minorVersion
};
}
});
function randomPadName() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var string_length = 10;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
return randomstring;
}
// Register plugin
tinymce.PluginManager.add('etherpadlite', tinymce.plugins.EtherPadLitePlugin);
})();