]>
git.immae.eu Git - perso/Immae/Config/Nix.git/blob - pkgs/webapps/etherpad-lite/modules/ep_immae_buttons/static/js/main.js
07f7b9c932085ee541652a06500d13f267760e9b
1 exports
.postAceInit = function(hook
, context
){
2 $(document
).ready(function () {
3 $('.clearFormatting').click(function(){
4 context
.ace
.callWithAce(function(ace
){
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..
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
17 },'clearFormatting' , true);
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);
32 function findAndReplace(searchText
, replacement
, searchNode
) {
33 if (!searchText
|| typeof replacement
=== 'undefined') {
34 // Throw error here if you want...
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"];
44 var currentNode
= childNodes
[cnLength
];
45 if (currentNode
.nodeType
=== 1){
46 if(excludes
.indexOf(currentNode
.nodeName
.toLowerCase() === -1)){
47 arguments
.callee(searchText
, replacement
, currentNode
);
50 if (currentNode
.nodeType
!== 3 || !regex
.test(currentNode
.data
) ) {
53 var parent
= currentNode
.parentNode
,
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
);
64 parent
.insertBefore(frag
, currentNode
);
65 parent
.removeChild(currentNode
);