aboutsummaryrefslogtreecommitdiff
path: root/flakes/etherpad-lite/modules/ep_immae_buttons
diff options
context:
space:
mode:
Diffstat (limited to 'flakes/etherpad-lite/modules/ep_immae_buttons')
-rw-r--r--flakes/etherpad-lite/modules/ep_immae_buttons/ep.json13
-rw-r--r--flakes/etherpad-lite/modules/ep_immae_buttons/hooks.js6
-rw-r--r--flakes/etherpad-lite/modules/ep_immae_buttons/node-packages.nix22
-rw-r--r--flakes/etherpad-lite/modules/ep_immae_buttons/package.json10
-rw-r--r--flakes/etherpad-lite/modules/ep_immae_buttons/static/js/main.js67
-rw-r--r--flakes/etherpad-lite/modules/ep_immae_buttons/templates/editbarButtons.ejs12
6 files changed, 130 insertions, 0 deletions
diff --git a/flakes/etherpad-lite/modules/ep_immae_buttons/ep.json b/flakes/etherpad-lite/modules/ep_immae_buttons/ep.json
new file mode 100644
index 0000000..10db4ef
--- /dev/null
+++ b/flakes/etherpad-lite/modules/ep_immae_buttons/ep.json
@@ -0,0 +1,13 @@
1{
2 "parts": [
3 {
4 "name": "immae_buttons",
5 "hooks": {
6 "eejsBlock_editbarMenuLeft": "ep_immae_buttons/hooks:eejsBlock_editbarMenuLeft"
7 },
8 "client_hooks": {
9 "postAceInit": "ep_immae_buttons/static/js/main:postAceInit"
10 }
11 }
12 ]
13}
diff --git a/flakes/etherpad-lite/modules/ep_immae_buttons/hooks.js b/flakes/etherpad-lite/modules/ep_immae_buttons/hooks.js
new file mode 100644
index 0000000..dcf7782
--- /dev/null
+++ b/flakes/etherpad-lite/modules/ep_immae_buttons/hooks.js
@@ -0,0 +1,6 @@
1var eejs = require('ep_etherpad-lite/node/eejs/');
2
3exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {
4 args.content = args.content + eejs.require("ep_immae_buttons/templates/editbarButtons.ejs");
5 return cb();
6}
diff --git a/flakes/etherpad-lite/modules/ep_immae_buttons/node-packages.nix b/flakes/etherpad-lite/modules/ep_immae_buttons/node-packages.nix
new file mode 100644
index 0000000..d7045df
--- /dev/null
+++ b/flakes/etherpad-lite/modules/ep_immae_buttons/node-packages.nix
@@ -0,0 +1,22 @@
1# This file has been generated by node2nix 1.8.0. Do not edit!
2
3{nodeEnv, fetchurl, fetchgit, globalBuildInputs ? []}:
4
5let
6 sources = {};
7in
8{
9 ep_immae_buttons = nodeEnv.buildNodePackage {
10 name = "ep_immae_buttons";
11 packageName = "ep_immae_buttons";
12 version = "0.1.0";
13 src = ./.;
14 buildInputs = globalBuildInputs;
15 meta = {
16 description = "Additional buttons (replacing clear_formatting and copy_paste_select_all)";
17 };
18 production = true;
19 bypassCache = true;
20 reconstructLock = true;
21 };
22}
diff --git a/flakes/etherpad-lite/modules/ep_immae_buttons/package.json b/flakes/etherpad-lite/modules/ep_immae_buttons/package.json
new file mode 100644
index 0000000..39bb0a8
--- /dev/null
+++ b/flakes/etherpad-lite/modules/ep_immae_buttons/package.json
@@ -0,0 +1,10 @@
1{
2 "name": "ep_immae_buttons",
3 "description": "Additional buttons (replacing clear_formatting and copy_paste_select_all)",
4 "version": "0.1.0",
5 "author": "Immae",
6 "contributors": [],
7 "dependencies": { },
8 "repository" : { "type" : "git", "url" : "" },
9 "engines": { "node": "*" }
10}
diff --git a/flakes/etherpad-lite/modules/ep_immae_buttons/static/js/main.js b/flakes/etherpad-lite/modules/ep_immae_buttons/static/js/main.js
new file mode 100644
index 0000000..07f7b9c
--- /dev/null
+++ b/flakes/etherpad-lite/modules/ep_immae_buttons/static/js/main.js
@@ -0,0 +1,67 @@
1exports.postAceInit = function(hook, context){
2 $(document).ready(function () {
3 $('.clearFormatting').click(function(){
4 context.ace.callWithAce(function(ace){
5
6 var rep = ace.ace_getRep(); // get the current user selection
7 var isSelection = (rep.selStart[0] !== rep.selEnd[0] || rep.selStart[1] !== rep.selEnd[1]);
8 if(!isSelection) return false; // No point proceeding if no selection..
9
10 var attrs = rep.apool.attribToNum; // get the attributes on this document
11 $.each(attrs, function(k, v){ // for each attribute
12 var attr = k.split(",")[0]; // get the name of the attribute
13 if(attr !== "author"){ // if its not an author attribute
14 ace.ace_setAttributeOnSelection(attr, false); // set the attribute to false
15 }
16 });
17 },'clearFormatting' , true);
18 });
19
20 $('.findAndReplace').click(function(){
21 var from = prompt("Search for...");
22 var to = prompt("Replace with...");
23 var HTMLLines = $('iframe[name="ace_outer"]').contents().find('iframe').contents().find("#innerdocbody").children("div");
24 $(HTMLLines).each(function(){ // For each line
25 findAndReplace(from, to, this);
26 });
27 });
28
29 });
30}
31
32function findAndReplace(searchText, replacement, searchNode) {
33 if (!searchText || typeof replacement === 'undefined') {
34 // Throw error here if you want...
35 return;
36 }
37 var regex = typeof searchText === 'string' ?
38 new RegExp(searchText, 'gi') : searchText,
39 childNodes = (searchNode || document.body).childNodes,
40 cnLength = childNodes.length,
41 excludes = ["html","head","style","title","meta","script","object","iframe","link"];
42
43 while (cnLength--) {
44 var currentNode = childNodes[cnLength];
45 if (currentNode.nodeType === 1){
46 if(excludes.indexOf(currentNode.nodeName.toLowerCase() === -1)){
47 arguments.callee(searchText, replacement, currentNode);
48 }
49 }
50 if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
51 continue;
52 }
53 var parent = currentNode.parentNode,
54 frag = (function(){
55 var html = currentNode.data.replace(regex, replacement),
56 wrap = document.createElement('div'),
57 frag = document.createDocumentFragment();
58 wrap.innerHTML = html;
59 while (wrap.firstChild) {
60 frag.appendChild(wrap.firstChild);
61 }
62 return frag;
63 })();
64 parent.insertBefore(frag, currentNode);
65 parent.removeChild(currentNode);
66 }
67}
diff --git a/flakes/etherpad-lite/modules/ep_immae_buttons/templates/editbarButtons.ejs b/flakes/etherpad-lite/modules/ep_immae_buttons/templates/editbarButtons.ejs
new file mode 100644
index 0000000..339ae3d
--- /dev/null
+++ b/flakes/etherpad-lite/modules/ep_immae_buttons/templates/editbarButtons.ejs
@@ -0,0 +1,12 @@
1<li class="separator"></li>
2<li class="clearFormatting">
3 <a title="Clear Formatting">
4 <span class="buttonicon buttonicon-clear-formatting">Clear</span>
5 </a>
6</li>
7<li class="separator"></li>
8<li class="findAndReplace">
9 <a title="Find and replace">
10 <span class="buttonicon buttonicon-find-replace">Find</span>
11 </a>
12</li>