Skip to content

Commit 6b64496

Browse files
committed
New way to generate random names, without the need of an ajax call
1 parent 3da73ca commit 6b64496

6 files changed

Lines changed: 16 additions & 25 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*~
22
counter.txt
3+
.gitignore

counter.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

editor_plugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor_plugin_src.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,9 @@
3434
: "400";
3535

3636
ed.addCommand('mceEtherPadLite', function() {
37-
var xmlhttp;
38-
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
39-
xmlhttp = new XMLHttpRequest();
40-
} else { // code for IE6, IE5
41-
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
42-
}
43-
xmlhttp.onreadystatechange = function() {
44-
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
45-
var padName = xmlhttp.responseText;
46-
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>";
47-
ed.execCommand('mceInsertContent', false, iframe);
48-
}
49-
};
50-
xmlhttp.open("GET", url+"/etherpad_name_generator.php?padPrefix="+padPrefix, true);
51-
xmlhttp.send();
37+
var padName = padPrefix + '.' + randomPadName();
38+
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>";
39+
ed.execCommand('mceInsertContent', false, iframe);
5240
});
5341

5442
ed.addButton('etherpadlite', {title : 'etherpadlite.desc', cmd : 'mceEtherPadLite', image : url + '/img/etherpadlite.gif'});
@@ -64,6 +52,17 @@
6452
};
6553
}
6654
});
55+
56+
function randomPadName() {
57+
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
58+
var string_length = 10;
59+
var randomstring = '';
60+
for (var i = 0; i < string_length; i++) {
61+
var rnum = Math.floor(Math.random() * chars.length);
62+
randomstring += chars.substring(rnum, rnum + 1);
63+
}
64+
return randomstring;
65+
}
6766

6867

6968
// Register plugin

etherpad_name_generator.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

img/etherpadlite.gif

-510 Bytes
Loading

0 commit comments

Comments
 (0)