comparison js/taggingtext.js @ 63:3395385476d1 extractapp

bug fixed: popup tag window is closed automatically when saving text file
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 01 Apr 2015 15:10:35 +0200
parents f9e7119339b2
children ca6bf3532830
comparison
equal deleted inserted replaced
62:3fb9e3884401 63:3395385476d1
43 matchedCount += str.match(regexText).length; 43 matchedCount += str.match(regexText).length;
44 el.innerHTML = str.replace(regexText, replaceText); 44 el.innerHTML = str.replace(regexText, replaceText);
45 45
46 alert( "Tagged "+matchedCount+" entities!" ); 46 alert( "Tagged "+matchedCount+" entities!" );
47 } 47 }
48
49 function removeTagNewDiv( eventObject, tagName, tagObject ) {
50 saveUndoText();
51 var newdiv = document.createElement("div");
52 newdiv.id = "questionMarkId";
53 newdiv.setAttribute("class", "questionMarkClass");
54 newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px';
55 newdiv.innerHTML = "Tag: "+tagName+"<br>Value: "+tagObject.text()+"<br>";
56
57
58 var newbutton = $('<button>Remove this</button>').mouseup(function (e2) {
59 var textKeep = $(this).parent().parent().html();
60 var regexText=/<div(.*?)<\/div>/g;
61 var replaceText="";
62 textKeep = textKeep.replace(regexText, replaceText);
63
64 $(this).parent().parent().replaceWith( textKeep );
65 });
66 newbutton.appendTo(newdiv);
67
68 var newbutton = $('<button>Remove this(with newline)</button>').mouseup(function (e2) {
69 var textKeep = $(this).parent().parent().html();
70 var regexText=/<div(.*?)<\/div>/g;
71 var replaceText="";
72 textKeep = textKeep.replace(regexText, replaceText);
73
74 var newLineBefore = $(this).parent().parent().prev();
75 if ( newLineBefore.prop("tagName") == "BR" ) {
76 $(this).parent().parent().prev().replaceWith( );
77 }
78 $(this).parent().parent().replaceWith( textKeep );
79 });
80 newbutton.appendTo(newdiv);
81
82 var newbutton = $('<button>Remove all</button>').mouseup(function (e2) {
83 var textKeep = $(this).parent().parent().html();
84 var regexText=/<div(.*?)<\/div>/g;
85 var replaceText="";
86 textKeep = textKeep.replace(regexText, replaceText);
87
88 $(this).parent().parent().replaceWith( textKeep );
89
90 var el = document.getElementById("editable-area");
91 var regexText=new RegExp("<"+tagName+">("+textKeep+")</"+tagName+">", "g");
92 var replaceText="$1";
93 var str="" + el.innerHTML;
94
95 if ( str.match(regexText)==null ) {
96 alert( "Removed 1 entity!" );
97 } else {
98 alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" );
99 }
100 el.innerHTML = str.replace(regexText, replaceText);
101 });
102 newbutton.appendTo(newdiv);
103
104 var newbutton = $('<button>Remove all(with newline)</button>').mouseup(function (e2) {
105 var textKeep = $(this).parent().parent().html();
106 var regexText=/<div(.*?)<\/div>/g;
107 var replaceText="";
108 textKeep = textKeep.replace(regexText, replaceText);
109
110 $(this).parent().remove();
111
112 var el = document.getElementById("editable-area");
113 var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "g");
114 var replaceText="$1";
115 var str="" + el.innerHTML;
116
117 alert( "Removed "+str.match(regexText).length+" entities!" );
118 el.innerHTML = str.replace(regexText, replaceText);
119 });
120 newbutton.appendTo(newdiv);
121
122 tagObject.append(newdiv);
123 }
124
125 function removeEmptyNodes( node ) { 48 function removeEmptyNodes( node ) {
126 if (node.hasChildNodes()) { 49 if (node.hasChildNodes()) {
127 var children = node.childNodes; 50 var children = node.childNodes;
128 for (var i = 0; i < children.length; i++) { 51 for (var i = 0; i < children.length; i++) {
129 if (children[i].textContent == "" && children[i].innerHTML == "" && children[i].nodeName != "BR") { 52 if (children[i].textContent == "" && children[i].innerHTML == "" && children[i].nodeName != "BR") {
276 $("button").attr("disabled", false); 199 $("button").attr("disabled", false);
277 $("#editTextId").html("Edit the text"); 200 $("#editTextId").html("Edit the text");
278 } 201 }
279 } 202 }
280 203
204
205 function removeTagNewDiv( eventObject, tagName, tagObject ) {
206 saveUndoText();
207 var newdiv = document.createElement("div");
208 newdiv.id = "questionMarkId";
209 newdiv.setAttribute("class", "questionMarkClass");
210
211 newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px; z-index:4';
212 newdiv.innerHTML = "Tag: "+tagName+"<br>Value: "+tagObject.text()+"<br>";
213
214 var newbutton = $('<button>Remove this</button>').mouseup(function (e2) {
215 var textKeep = $(this).parent().parent().html();
216 var regexText=/<div(.*?)<\/div>/g;
217 var replaceText="";
218 textKeep = textKeep.replace(regexText, replaceText);
219
220 $(this).parent().parent().replaceWith( textKeep );
221 });
222 newbutton.appendTo(newdiv);
223
224 var newbutton = $('<button>Remove this(with newline)</button>').mouseup(function (e2) {
225 var textKeep = $(this).parent().parent().html();
226 var regexText=/<div(.*?)<\/div>/g;
227 var replaceText="";
228 textKeep = textKeep.replace(regexText, replaceText);
229
230 var newLineBefore = $(this).parent().parent().prev();
231 if ( newLineBefore.prop("tagName") == "BR" ) {
232 $(this).parent().parent().prev().replaceWith( );
233 }
234 $(this).parent().parent().replaceWith( textKeep );
235 });
236 newbutton.appendTo(newdiv);
237
238 var newbutton = $('<button>Remove all</button>').mouseup(function (e2) {
239 var textKeep = $(this).parent().parent().html();
240 var regexText=/<div(.*?)<\/div>/g;
241 var replaceText="";
242 textKeep = textKeep.replace(regexText, replaceText);
243
244 $(this).parent().parent().replaceWith( textKeep );
245
246 var el = document.getElementById("editable-area");
247 var regexText=new RegExp("<"+tagName+">("+textKeep+")</"+tagName+">", "g");
248 var replaceText="$1";
249 var str="" + el.innerHTML;
250
251 if ( str.match(regexText)==null ) {
252 alert( "Removed 1 entity!" );
253 } else {
254 alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" );
255 }
256 el.innerHTML = str.replace(regexText, replaceText);
257 });
258 newbutton.appendTo(newdiv);
259
260 var newbutton = $('<button>Remove all(with newline)</button>').mouseup(function (e2) {
261 var textKeep = $(this).parent().parent().html();
262 var regexText=/<div(.*?)<\/div>/g;
263 var replaceText="";
264 textKeep = textKeep.replace(regexText, replaceText);
265
266 $(this).parent().remove();
267
268 var el = document.getElementById("editable-area");
269 var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "g");
270 var replaceText="$1";
271 var str="" + el.innerHTML;
272
273 alert( "Removed "+str.match(regexText).length+" entities!" );
274 el.innerHTML = str.replace(regexText, replaceText);
275 });
276 newbutton.appendTo(newdiv);
277
278 tagObject.append(newdiv);
279 }
281 280
282 function saveText(section_id) { 281 function saveText(section_id) {
283 var el = document.getElementById("editable-area"); 282 var el = document.getElementById("editable-area");
284 $.ajax({ 283 $.ajax({
285 url : './'+section_id, 284 url : './'+section_id,