Mercurial > hg > extraction-interface
comparison interface/tagging_text.php @ 0:b12c99b7c3f0
commit for previous development
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 19 Jan 2015 17:13:49 +0100 |
parents | |
children | 63e08b98032f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b12c99b7c3f0 |
---|---|
1 <?php | |
2 header("Content-Type: text/html;charset=utf-8"); | |
3 | |
4 if (isset($_GET['id'])) { | |
5 $section_id = $_GET['id']; | |
6 } else { | |
7 $get_book_id = $_GET['book']; | |
8 $get_start = $_GET['start']; | |
9 $get_end = $_GET['end']; | |
10 } | |
11 | |
12 include_once('Lib_mb_utf8.php'); | |
13 include_once('config.php'); | |
14 | |
15 set_time_limit(0); | |
16 ini_set('memory_limit', '-1'); | |
17 | |
18 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
19 mysql_query("SET NAMES utf8"); | |
20 | |
21 if (!$link_mysql) { | |
22 die('Could not connect: ' . mysql_error()); | |
23 } | |
24 | |
25 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
26 if (!$db_selected) { | |
27 die ('Can\'t use foo : ' . mysql_error()); | |
28 } | |
29 | |
30 if (!function_exists("GetSQLValueString")) { | |
31 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") | |
32 { | |
33 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; | |
34 | |
35 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); | |
36 | |
37 switch ($theType) { | |
38 case "text": | |
39 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
40 break; | |
41 case "long": | |
42 case "int": | |
43 $theValue = ($theValue != "") ? intval($theValue) : "NULL"; | |
44 break; | |
45 case "double": | |
46 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; | |
47 break; | |
48 case "date": | |
49 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
50 break; | |
51 case "defined": | |
52 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; | |
53 break; | |
54 } | |
55 return $theValue; | |
56 } | |
57 } | |
58 | |
59 $query = sprintf("SELECT * FROM `sections` WHERE `id`=\"%s\"", $section_id); | |
60 $result = mysql_query($query); | |
61 while ($row = mysql_fetch_assoc($result)) { | |
62 $bookId=$row['books_id']; | |
63 $startPage=$row['start_page']; | |
64 $endPage=$row['end_page']; | |
65 } | |
66 | |
67 $contentString=""; | |
68 if ( file_exists("parsing_files/".$section_id.".txt") ) { | |
69 $contentString=file_get_contents("parsing_files/".$section_id.".txt"); | |
70 $stringInput = $contentString; | |
71 $stringInput = preg_replace("/ /u", "○", $stringInput); | |
72 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | |
73 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); | |
74 } else { | |
75 $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage); | |
76 $result = mysql_query($query); | |
77 while ($row = mysql_fetch_assoc($result)) { | |
78 $contentString.="【".$row['line']."】".$row['content']."\n"; | |
79 } | |
80 $stringInput = $contentString; | |
81 $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); | |
82 $stringInput = preg_replace("/ /u", "○", $stringInput); | |
83 $stringInput = preg_replace("/\n/u", "<br>", $stringInput); | |
84 $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); | |
85 } | |
86 | |
87 | |
88 $taglistArray=""; | |
89 $query = sprintf("SELECT * FROM `taglist` WHERE `systemName`='%s' ORDER BY `tag` ASC", $systemNAME); | |
90 $result = mysql_query($query); | |
91 while ($row = mysql_fetch_assoc($result)) { | |
92 $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); | |
93 } | |
94 | |
95 function sortFunction($a,$b) { | |
96 return strlen($b)-strlen($a); | |
97 } | |
98 | |
99 $wordlistArray=""; | |
100 $query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $systemNAME); | |
101 $result = mysql_query($query); | |
102 while ($row = mysql_fetch_assoc($result)) { | |
103 $listString = file_get_contents("wordlist/".$row['id'].".txt"); | |
104 $listString = preg_replace("/<div>/u", "\n", $listString); | |
105 $listString = preg_replace("/<\/div>/u", "", $listString); | |
106 $listString = preg_replace("/<span(.*?)>/u", "", $listString); | |
107 $listString = preg_replace("/<\/span>/u", "", $listString); | |
108 //$listString = preg_replace("/\n/u", "|", $listString); | |
109 | |
110 $wordlistArray2 = explode( "\n", $listString ); | |
111 usort($wordlistArray2,'sortFunction'); | |
112 foreach ( $wordlistArray2 as $index=>$value ) { | |
113 $wordlistArray2[$index] = implode("○?", preg_split("/(?<!^)(?!$)/u", $value)); | |
114 } | |
115 foreach ( $wordlistArray2 as $index=>$value ) { | |
116 if ($value=="") unset($wordlistArray2[$index]); | |
117 | |
118 } | |
119 $listString = implode("|", $wordlistArray2); | |
120 | |
121 if ( $listString[0]=="|" ) $listString = substr($listString, 1); | |
122 $wordlistArray[] = array( $row['id'], $row['name'], $listString ); | |
123 } | |
124 | |
125 ?> | |
126 | |
127 <html> | |
128 <head> | |
129 <title></title> | |
130 <script src="./jquery-1.10.2.min.js"></script> | |
131 <style> | |
132 dynasty | |
133 { | |
134 color:red; | |
135 } | |
136 nianhao | |
137 { | |
138 color:blue; | |
139 } | |
140 name | |
141 { | |
142 color:orange; | |
143 } | |
144 #editable-area { | |
145 line-height:160%; | |
146 letter-spacing:1.5px; | |
147 font-size:21px; | |
148 } | |
149 <?php | |
150 foreach ( $taglistArray as $taglistValue ) { | |
151 echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n"; | |
152 | |
153 echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n"; | |
154 } | |
155 ?> | |
156 </style> | |
157 <script type="text/javascript"> | |
158 var stringBeforeChange=""; | |
159 var stringBeforeChangeStack = []; | |
160 var lastAddTag=""; | |
161 | |
162 window.onbeforeunload = function() { | |
163 return "Are you sure?"; | |
164 }; | |
165 | |
166 $(document).ready(function(){ | |
167 //run once | |
168 var el=$('#follow-scroll'); | |
169 var originalelpos=el.offset().top; // take it where it originally is on the page | |
170 | |
171 //run on scroll | |
172 $(window).scroll(function(){ | |
173 var el = $('#follow-scroll'); // important! (local) | |
174 var elpos = el.offset().top; // take current situation | |
175 var windowpos = $(window).scrollTop(); | |
176 var finaldestination = windowpos+originalelpos; | |
177 el.stop().animate({'top':finaldestination},500); | |
178 }); | |
179 }); | |
180 | |
181 /* | |
182 $(document).on("mouseup", function (e) { | |
183 e.stopPropagation(); | |
184 $('.questionMarkClass').remove(); | |
185 $('.tagItemDivClass').remove(); | |
186 alert("Remove"); | |
187 }); | |
188 | |
189 | |
190 $(document).on("click", '.questionMarkClass', function (e) { | |
191 e.stopPropagation(); | |
192 }); | |
193 */ | |
194 | |
195 function removeTagNewDiv( eventObject, tagName, tagObject ) { | |
196 saveUndoText(); | |
197 var newdiv = document.createElement("div"); | |
198 newdiv.id = "questionMarkId"; | |
199 newdiv.setAttribute("class", "questionMarkClass"); | |
200 newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; | |
201 newdiv.innerHTML = "Tag: "+tagName+"<br>Value: "+tagObject.text()+"<br>"; | |
202 | |
203 | |
204 var newbutton = $('<button>Remove this</button>').mouseup(function (e2) { | |
205 var textKeep = $(this).parent().parent().html(); | |
206 var regexText=/<div(.*?)<\/div>/g; | |
207 var replaceText=""; | |
208 textKeep = textKeep.replace(regexText, replaceText); | |
209 | |
210 $(this).parent().parent().replaceWith( textKeep ); | |
211 }); | |
212 newbutton.appendTo(newdiv); | |
213 | |
214 var newbutton = $('<button>Remove this(with newline)</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 var newLineBefore = $(this).parent().parent().prev(); | |
221 if ( newLineBefore.prop("tagName") == "BR" ) { | |
222 $(this).parent().parent().prev().replaceWith( ); | |
223 } | |
224 $(this).parent().parent().replaceWith( textKeep ); | |
225 }); | |
226 newbutton.appendTo(newdiv); | |
227 | |
228 var newbutton = $('<button>Remove all</button>').mouseup(function (e2) { | |
229 var textKeep = $(this).parent().parent().html(); | |
230 var regexText=/<div(.*?)<\/div>/g; | |
231 var replaceText=""; | |
232 textKeep = textKeep.replace(regexText, replaceText); | |
233 | |
234 $(this).parent().parent().replaceWith( textKeep ); | |
235 | |
236 var el = document.getElementById("editable-area"); | |
237 var regexText=new RegExp("<"+tagName+">("+textKeep+")</"+tagName+">", "g"); | |
238 var replaceText="$1"; | |
239 var str="" + el.innerHTML; | |
240 | |
241 if ( str.match(regexText)==null ) { | |
242 alert( "Removed 1 entity!" ); | |
243 } else { | |
244 alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" ); | |
245 } | |
246 el.innerHTML = str.replace(regexText, replaceText); | |
247 }); | |
248 newbutton.appendTo(newdiv); | |
249 | |
250 var newbutton = $('<button>Remove all(with newline)</button>').mouseup(function (e2) { | |
251 var textKeep = $(this).parent().parent().html(); | |
252 var regexText=/<div(.*?)<\/div>/g; | |
253 var replaceText=""; | |
254 textKeep = textKeep.replace(regexText, replaceText); | |
255 | |
256 $(this).parent().remove(); | |
257 | |
258 var el = document.getElementById("editable-area"); | |
259 var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "g"); | |
260 var replaceText="$1"; | |
261 var str="" + el.innerHTML; | |
262 | |
263 alert( "Removed "+str.match(regexText).length+" entities!" ); | |
264 el.innerHTML = str.replace(regexText, replaceText); | |
265 }); | |
266 newbutton.appendTo(newdiv); | |
267 | |
268 tagObject.append(newdiv); | |
269 } | |
270 | |
271 | |
272 <?php | |
273 foreach ( $taglistArray as $taglistValue ) { | |
274 echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n"; | |
275 echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n"; | |
276 echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n"; | |
277 echo "\tremoveTagNewDiv( e, \"".$taglistValue[2]."\", $(this) );\n"; | |
278 echo "});\n"; | |
279 } | |
280 ?> | |
281 $(document).on("click", "name", function (e) { | |
282 if ( $("#editTextId").html() != "Edit the text" ) return 0; | |
283 if ( $(this).prop("tagName").toLowerCase() != "name" ) return 0; | |
284 removeTagNewDiv( e, "name", $(this) ); | |
285 }); | |
286 | |
287 $(document).on("mouseup", '#editable-area', function (e) { | |
288 $('.questionMarkClass').remove(); | |
289 $('.tagItemDivClass').remove(); | |
290 | |
291 if ( $("#editTextId").html() != "Edit the text" ) return 0; | |
292 var selection = getSelected(); | |
293 range = getSelected().getRangeAt(0); | |
294 | |
295 container = document.createElement("div"); | |
296 container.appendChild(selection.getRangeAt(0).cloneContents()); | |
297 | |
298 if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) { | |
299 | |
300 var newdiv = document.createElement("div"); | |
301 newdiv.id = "tagItemDivId"; | |
302 newdiv.setAttribute("class", "tagItemDivClass"); | |
303 newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; | |
304 | |
305 //console.log(selection.getRangeAt(0).cloneContents()); | |
306 if ( container.innerHTML.indexOf( "br" ) != -1 ) { | |
307 var newselect = document.createElement("select"); | |
308 newselect.id = "TitletagType"; | |
309 <?php | |
310 foreach ( $taglistArray as $taglistValue ) { | |
311 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n"; | |
312 } | |
313 ?> | |
314 newdiv.appendChild(newselect); | |
315 | |
316 //matchValue = .match(); | |
317 myRegexp = new RegExp("〈(.*?)〉", "g") | |
318 matchValue = myRegexp.exec(String(selection)); | |
319 | |
320 if ( matchValue != null ) { | |
321 newdiv.innerHTML += "<input id=\"TitletagName\" value=\""+ matchValue[1] +"\"></br>"; | |
322 } else { | |
323 newdiv.innerHTML += "<input id=\"TitletagName\" value=\"\"></br>"; | |
324 } | |
325 newdiv.innerHTML += "<button onclick=\"addTagTitle( range, container )\">Add Title Tag To Each Line</button></br>"; | |
326 | |
327 newdiv.innerHTML += "<button onclick=\"exportTable( range, container )\">Export As A Table</button></br></br>"; | |
328 | |
329 var newselect = document.createElement("select"); | |
330 newselect.id = "RemoveTitletagType"; | |
331 <?php | |
332 foreach ( $taglistArray as $taglistValue ) { | |
333 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n"; | |
334 } | |
335 ?> | |
336 newdiv.appendChild(newselect); | |
337 | |
338 newdiv.innerHTML += "<input id=\"RemoveTitletagName\" value=\"\"></br>"; | |
339 newdiv.innerHTML += "<button onclick=\"removeTagTitle( range, container )\">Remove</button></br>"; | |
340 } else { | |
341 newdiv.innerHTML = "Tag: "+String(selection)+"<br>"; | |
342 | |
343 newdiv.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>"; | |
344 | |
345 <?php | |
346 foreach ( $taglistArray as $taglistValue ) { | |
347 if ( $taglistValue[2] == "person") { | |
348 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n"; | |
349 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
350 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
351 } else if ($taglistValue[2] == "post_time") { | |
352 echo "newdiv.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
353 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
354 } else if ($taglistValue[2] == "office") { | |
355 echo "newdiv.innerHTML += \"<button accesskey=\\\"4\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
356 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
357 } else { | |
358 echo "newdiv.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
359 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
360 } | |
361 } | |
362 ?> | |
363 } | |
364 $('body').append(newdiv); | |
365 | |
366 $('#TitletagType').val(lastAddTag); | |
367 } | |
368 //e.stopPropagation(); | |
369 }); | |
370 | |
371 function removeTagTitle( range, container ) { | |
372 saveUndoText(); | |
373 range.deleteContents(); | |
374 | |
375 lastAddTag = $('#RemoveTitletagType').val(); | |
376 | |
377 var stringtemp = container.innerHTML; | |
378 | |
379 if ( $('#RemoveTitletagName').val() == "" ) { | |
380 var regexText="<"+lastAddTag+">〈(.*?)〉</"+lastAddTag+">"; | |
381 var replaceText=""; | |
382 stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); | |
383 | |
384 var regexText="<"+lastAddTag+">(.*?)</"+lastAddTag+">"; | |
385 var replaceText="$1"; | |
386 stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); | |
387 } else { | |
388 var regexText="<"+lastAddTag+">〈"+$('#RemoveTitletagName').val()+"〉</"+lastAddTag+">"; | |
389 var replaceText=""; | |
390 stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); | |
391 | |
392 var regexText="<"+lastAddTag+">("+$('#RemoveTitletagName').val()+")</"+lastAddTag+">"; | |
393 var replaceText="$1"; | |
394 stringtemp = stringtemp.replace(new RegExp(regexText, "g"), replaceText); | |
395 } | |
396 | |
397 var newdiv = document.createElement("aaaa"); | |
398 newdiv.innerHTML = stringtemp; | |
399 range.insertNode(newdiv); | |
400 | |
401 var el = document.getElementById("editable-area"); | |
402 | |
403 var regexText=/<aaaa>/gi; | |
404 var replaceText=''; | |
405 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
406 | |
407 var regexText=/<\/aaaa>/gi; | |
408 var replaceText=''; | |
409 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
410 | |
411 $('.tagItemDivClass').remove(); | |
412 } | |
413 | |
414 function addTagTitle( range, container ) { | |
415 saveUndoText(); | |
416 lastAddTag = $('#TitletagType').val(); | |
417 tag = "<"+$('#TitletagType').val()+">〈"+$('#TitletagName').val()+"〉</"+$('#TitletagType').val()+">"; | |
418 range.deleteContents(); | |
419 var stringtemp = container.innerHTML; | |
420 var regexText=/<br>/g; | |
421 var replaceText="<br>"+tag; | |
422 stringtemp = stringtemp.replace(regexText, replaceText); | |
423 | |
424 var newdiv = document.createElement("aaaa"); | |
425 newdiv.innerHTML = tag+stringtemp; | |
426 range.insertNode(newdiv); | |
427 | |
428 var el = document.getElementById("editable-area"); | |
429 | |
430 var regexText=/<aaaa>/gi; | |
431 var replaceText=''; | |
432 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
433 | |
434 var regexText=/<\/aaaa>/gi; | |
435 var replaceText=''; | |
436 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
437 | |
438 $('.tagItemDivClass').remove(); | |
439 } | |
440 | |
441 function exportTable( range, container ) { | |
442 //MsgBox("enter function"); | |
443 var form = document.createElement("form"); | |
444 form.setAttribute("method", "post"); | |
445 form.setAttribute("action", "exportTable.php"); | |
446 form.setAttribute("target", "_blank"); | |
447 | |
448 var hiddenField = document.createElement("input"); | |
449 hiddenField.setAttribute("name", "content"); | |
450 hiddenField.setAttribute("value", container.innerHTML); | |
451 form.appendChild(hiddenField); | |
452 | |
453 var hiddenField = document.createElement("input"); | |
454 hiddenField.setAttribute("name", "sectionid"); | |
455 hiddenField.setAttribute("value", "<?php echo $section_id; ?>"); | |
456 form.appendChild(hiddenField); | |
457 | |
458 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { | |
459 document.body.appendChild(form); | |
460 form.submit(); | |
461 } else { | |
462 form.submit(); // works under IE and Chrome, but not FF | |
463 } | |
464 } | |
465 | |
466 function exportPage() { | |
467 var startPage = $('#exportPageStart').val(); | |
468 var endPage = $('#exportPageEnd').val(); | |
469 | |
470 var el = document.getElementById("editable-area"); | |
471 var str="" + el.innerHTML; | |
472 | |
473 var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; | |
474 | |
475 var form = document.createElement("form"); | |
476 form.setAttribute("method", "post"); | |
477 form.setAttribute("action", "exportTable.php"); | |
478 form.setAttribute("target", "_blank"); | |
479 | |
480 var hiddenField = document.createElement("input"); | |
481 hiddenField.setAttribute("name", "content"); | |
482 hiddenField.setAttribute("value", str.match(new RegExp(regexText, "g"))); | |
483 form.appendChild(hiddenField); | |
484 | |
485 var hiddenField = document.createElement("input"); | |
486 hiddenField.setAttribute("name", "sectionid"); | |
487 hiddenField.setAttribute("value", "<?php echo $section_id; ?>"); | |
488 form.appendChild(hiddenField); | |
489 | |
490 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { | |
491 document.body.appendChild(form); | |
492 form.submit(); | |
493 } else { | |
494 form.submit(); // works under IE and Chrome, but not FF | |
495 } | |
496 } | |
497 | |
498 function exportAll() { | |
499 var el = document.getElementById("editable-area"); | |
500 var str="" + el.innerHTML; | |
501 | |
502 var form = document.createElement("form"); | |
503 form.setAttribute("method", "post"); | |
504 form.setAttribute("action", "exportTable.php"); | |
505 form.setAttribute("target", "_blank"); | |
506 | |
507 var hiddenField = document.createElement("input"); | |
508 hiddenField.setAttribute("name", "content"); | |
509 hiddenField.setAttribute("value", str); | |
510 form.appendChild(hiddenField); | |
511 | |
512 var hiddenField = document.createElement("input"); | |
513 hiddenField.setAttribute("name", "sectionid"); | |
514 hiddenField.setAttribute("value", "<?php echo $section_id; ?>"); | |
515 form.appendChild(hiddenField); | |
516 | |
517 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { | |
518 document.body.appendChild(form); | |
519 form.submit(); | |
520 } else { | |
521 form.submit(); // works under IE and Chrome, but not FF | |
522 } | |
523 } | |
524 | |
525 function cleanUpTextArea() { | |
526 var el = document.getElementById("editable-area"); | |
527 | |
528 var regexText=/<div>/gi; | |
529 var replaceText='<br>'; | |
530 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
531 | |
532 var regexText=/<\/div>/gi; | |
533 var replaceText=''; | |
534 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
535 | |
536 | |
537 var regexText=/<span style="(.*?)">/gi; | |
538 var replaceText=''; | |
539 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
540 | |
541 var regexText=/<\/span>/gi; | |
542 var replaceText=''; | |
543 el.innerHTML = el.innerHTML.replace(regexText, replaceText); | |
544 } | |
545 | |
546 function Undo() { | |
547 if ( stringBeforeChangeStack.length > 0 ) { | |
548 var el = document.getElementById("editable-area"); | |
549 el.innerHTML = stringBeforeChangeStack.pop(); | |
550 } else { | |
551 var el = document.getElementById("buttonUndo"); | |
552 el.disabled = true; | |
553 } | |
554 } | |
555 | |
556 function saveUndoText() { | |
557 var el = document.getElementById("editable-area"); | |
558 //stringBeforeChange = el.innerHTML; | |
559 stringBeforeChangeStack.push(el.innerHTML); | |
560 var el = document.getElementById("buttonUndo"); | |
561 el.disabled = false; | |
562 } | |
563 | |
564 function editText() { | |
565 var el = document.getElementById("editable-area"); | |
566 if ( $("#editTextId").html() == "Edit the text" ) { | |
567 saveUndoText(); | |
568 el.contentEditable = true; | |
569 $("button").attr("disabled", true); | |
570 $("#editTextId").attr("disabled", false); | |
571 $("#editTextId").html("Edit completed!"); | |
572 } else { | |
573 el.contentEditable = false; | |
574 cleanUpTextArea(); | |
575 $("button").attr("disabled", false); | |
576 $("#editTextId").html("Edit the text"); | |
577 } | |
578 } | |
579 | |
580 function saveText() { | |
581 var el = document.getElementById("editable-area"); | |
582 | |
583 $.ajax({ | |
584 url : 'save_full_text.php', | |
585 async : false, | |
586 type : 'POST', | |
587 data : 'text='+encodeURIComponent(el.innerHTML)+'&filename=<?php echo $section_id; ?>' | |
588 }).done(function(result) { | |
589 alert("Saved!"); | |
590 }); | |
591 | |
592 } | |
593 | |
594 function preg_quote (str, delimiter) { | |
595 // http://kevin.vanzonneveld.net | |
596 // + original by: booeyOH | |
597 // + improved by: Ates Goral (http://magnetiq.com) | |
598 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
599 // + bugfixed by: Onno Marsman | |
600 // + improved by: Brett Zamir (http://brett-zamir.me) | |
601 // * example 1: preg_quote("$40"); | |
602 // * returns 1: '\$40' | |
603 // * example 2: preg_quote("*RRRING* Hello?"); | |
604 // * returns 2: '\*RRRING\* Hello\?' | |
605 // * example 3: preg_quote("\\.+*?[^]$(){}=!<>|:"); | |
606 // * returns 3: '\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:' | |
607 return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&'); | |
608 } | |
609 | |
610 function replaceRegex() { | |
611 saveUndoText(); | |
612 | |
613 var startPage = $('#regexPageStart2').val(); | |
614 var endPage = $('#regexPageEnd2').val(); | |
615 var el = document.getElementById("editable-area"); | |
616 var str="" + el.innerHTML; | |
617 | |
618 var regexText=document.getElementById("regexText").value; | |
619 var replaceText=document.getElementById("replaceText").value; | |
620 var str="" + el.innerHTML; | |
621 | |
622 if ( startPage == "" ) { | |
623 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); | |
624 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); | |
625 } else { | |
626 var regexText2="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; | |
627 var partString = ""+str.match(new RegExp(regexText2, "g")); | |
628 alert(partString); | |
629 | |
630 alert( "Tagged "+partString.match(new RegExp(regexText, "g")).length+" entities!" ); | |
631 var resultString = partString.replace(new RegExp(regexText, "g"), replaceText); | |
632 | |
633 str="" + el.innerHTML; | |
634 el.innerHTML = str.replace(new RegExp(regexText, "g"), resultString); | |
635 } | |
636 | |
637 //document.styleSheets[0].addRule("tag001", "color:green;") | |
638 } | |
639 | |
640 function replaceSmartRegex() { | |
641 saveUndoText(); | |
642 var startPage = $('#regexPageStart2').val(); | |
643 var endPage = $('#regexPageEnd2').val(); | |
644 | |
645 var el = document.getElementById("editable-area"); | |
646 var regexText=document.getElementById("regexText").value; | |
647 | |
648 <?php | |
649 foreach ( $wordlistArray as $wordlistValue ) { | |
650 echo "\tvar regexText1=\"List ".$wordlistValue[1]."\";\n"; | |
651 echo "\tregexText1 = preg_quote(regexText1);\n"; | |
652 echo "\tvar replaceText1=\"".$wordlistValue[2]."\";\n"; | |
653 echo "\tregexText = regexText.replace(new RegExp(regexText1, \"g\"), replaceText1);\n\n"; | |
654 } | |
655 ?> | |
656 | |
657 var replaceText=document.getElementById("replaceText").value; | |
658 var str="" + el.innerHTML; | |
659 | |
660 if ( startPage == "" ) { | |
661 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); | |
662 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); | |
663 } else { | |
664 var regexText2="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; | |
665 var partString = ""+str.match(new RegExp(regexText2, "g")); | |
666 alert(partString); | |
667 | |
668 alert( "Tagged "+partString.match(new RegExp(regexText, "g")).length+" entities!" ); | |
669 var resultString = partString.replace(new RegExp(regexText, "g"), replaceText); | |
670 | |
671 str="" + el.innerHTML; | |
672 el.innerHTML = str.replace(new RegExp(regexText2, "g"), resultString); | |
673 } | |
674 //document.styleSheets[0].addRule("tag001", "color:green;") | |
675 } | |
676 | |
677 //Tagging Items | |
678 function getSelected() { | |
679 if(window.getSelection) { | |
680 return window.getSelection(); | |
681 } else if (document.getSelection) { | |
682 return document.getSelection(); | |
683 } else { | |
684 var selection = document.selection && document.selection.createRange(); | |
685 if(selection.text) { | |
686 return selection.text; | |
687 } | |
688 return false; | |
689 } | |
690 return false; | |
691 } | |
692 | |
693 function tagStringWithTag( stringValue, tag ) { | |
694 saveUndoText(); | |
695 var el = document.getElementById("editable-area"); | |
696 var regexText="("+String(stringValue)+")"; | |
697 if ( tag=="person") { | |
698 var replaceText="<br><"+tag+">$1</"+tag+">"; | |
699 } else { | |
700 var replaceText="<"+tag+">$1</"+tag+">"; | |
701 } | |
702 var str="" + el.innerHTML; | |
703 | |
704 $('.tagItemDivClass').remove(); | |
705 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); | |
706 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); | |
707 } | |
708 | |
709 | |
710 function tagwithtitle( range, stringSelection ) { | |
711 saveUndoText(); | |
712 range.deleteContents(); | |
713 //var newdiv = document.createElement("br"); | |
714 //range.insertNode(newdiv); | |
715 range.insertNode(document.createTextNode("〈"+stringSelection+"〉")); | |
716 var newdiv = document.createElement("br"); | |
717 range.insertNode(newdiv); | |
718 | |
719 $('.tagItemDivClass').remove(); | |
720 } | |
721 | |
722 function tagwithOnlytag( range, stringSelection, tag ) { | |
723 saveUndoText(); | |
724 | |
725 range.deleteContents(); | |
726 if ( tag=="person2") { | |
727 var newdiv = document.createElement("person"); | |
728 newdiv.innerHTML = stringSelection; | |
729 range.insertNode(newdiv); | |
730 var newdiv = document.createElement("br"); | |
731 range.insertNode(newdiv); | |
732 } else { | |
733 var newdiv = document.createElement(tag); | |
734 newdiv.innerHTML = stringSelection; | |
735 range.insertNode(newdiv); | |
736 } | |
737 $('.tagItemDivClass').remove(); | |
738 } | |
739 | |
740 function tagNameWithLastName() { | |
741 saveUndoText(); | |
742 var el = document.getElementById("editable-area"); | |
743 var regexText=/(○|】|^)(王|李|張|趙|劉|陳|楊|吳|黃|黄|朱|孫|郭|胡|呂|高|宋|徐|程|林|鄭|范|何|韓|曹|馬|許|田|馮|杜|周|曾|汪|蘇|董|方|蔡|梁|石|謝|賈|薛|彭|崔|唐|潘|鄧|史|錢|侯|魏|羅|葉|沈|孟|姚|傅|丁|章|蕭|蔣|盧|陸|袁|晁|譚|邵|歐陽|孔|詹|俞|尹|廖|閻|洪|夏|雷|葛|文|柳|陶|毛|丘|龔|蒲|邢|郝|龐|安|裴|折|施|游|金|鄒|湯|虞|嚴|鍾)([^○(舉人|縣人|歲貢|間任)]{1,3}|○[^○])(?=(○|$))/g; | |
744 var replaceText="$1<br><person>$2$3</person>$4"; | |
745 var str="" + el.innerHTML; | |
746 | |
747 alert( "Tagged "+str.match(regexText).length+" entities!" ); | |
748 el.innerHTML = str.replace(regexText, replaceText); | |
749 } | |
750 | |
751 function tagNameWithLastName2() { | |
752 saveUndoText(); | |
753 var el = document.getElementById("editable-area"); | |
754 var regexText="(○|】|^)("+$('#surname').val()+")([^○(舉人|縣人|歲貢|間任)]{1,3}|○[^○])(?=(○|$))"; | |
755 var replaceText="$1<br><person>$2$3</person>$4"; | |
756 var str="" + el.innerHTML; | |
757 | |
758 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); | |
759 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); | |
760 } | |
761 | |
762 function tagTime() { | |
763 saveUndoText(); | |
764 var el = document.getElementById("editable-area"); | |
765 var str="" + el.innerHTML; | |
766 | |
767 var regexText=/(<?php echo $wordlistArray[0][2]; ?>)(○?)(一|二|三|四|五|六|七|八|九)?(○?)(十)?(○?)(一|二|三|四|五|六|七|八|九|元|十)(○?)(年)/g; | |
768 var replaceText="<time>$1$2$3$4$5$6$7$8$9</time>"; | |
769 var matchedCount = str.match(regexText).length; | |
770 str = str.replace(regexText, replaceText); | |
771 | |
772 var regexText=/(?!(>))(<?php echo $wordlistArray[0][2]; ?>)/g; | |
773 var replaceText="<time>$1$2</time>"; | |
774 matchedCount += str.match(regexText).length; | |
775 el.innerHTML = str.replace(regexText, replaceText); | |
776 | |
777 var regexText=/(一|二|三|四|五|六|七|八|九)?(○?)(十)?(○?)(一|二|三|四|五|六|七|八|九|元|十)(○?)(年)(?!(<))/g; | |
778 var replaceText="<time>$1$2$3$4$5$6$7</time>"; | |
779 matchedCount += str.match(regexText).length; | |
780 el.innerHTML = str.replace(regexText, replaceText); | |
781 | |
782 alert( "Tagged "+matchedCount+" entities!" ); | |
783 } | |
784 | |
785 function tagBiogAddr() { | |
786 saveUndoText(); | |
787 var el = document.getElementById("editable-area"); | |
788 var str="" + el.innerHTML; | |
789 | |
790 var regexText=/(○)([^○]{1,6})(○?)(人)/g; | |
791 var replaceText="$1<biog_addr>$2</biog_addr>$3$4"; | |
792 el.innerHTML = str.replace(regexText, replaceText); | |
793 | |
794 alert( "Tagged "+str.match(regexText).length+" entities!" ); | |
795 } | |
796 | |
797 function smartRegexNew() { | |
798 $('#smartRegexPopUpDiv').css("display", "block"); | |
799 $('#smartRegexPopUpDiv').css("background-color", "White"); | |
800 $('#smartRegexPopUpDiv').css("width", "400px"); | |
801 $('#smartRegexPopUpDiv').css("height", "300px"); | |
802 $('#smartRegexPopUpDiv').css("top", "100px"); | |
803 $('#smartRegexPopUpDiv').css("left", "-200px"); | |
804 $('#smartRegexPopUpDiv').css("border", "1px solid black"); | |
805 $('#smartRegexPopUpDiv').css("padding", "5px"); | |
806 | |
807 $('#smartRegexPopUpAdd').attr("disabled", false); | |
808 $('#smartRegexPopUpEdit').attr("disabled", "disabled"); | |
809 $('#smartRegexPopUpDel').attr("disabled", "disabled"); | |
810 $('#smartRegexPopUpBack').attr("disabled", "disabled"); | |
811 $('#smartRegexPopUpFor').attr("disabled", "disabled"); | |
812 } | |
813 | |
814 function replaceSmartClose() { | |
815 $('#smartRegexPopUpDiv').css("display", "none"); | |
816 $("#smartRegexPopUpSelectWord").val("NULL"); | |
817 $("#smartRegexPopUpText").val(""); | |
818 $("#smartRegexPopUpName").val(""); | |
819 } | |
820 | |
821 function replaceSmartEdit(){ | |
822 thisObject = $('#smartRegexPopUpDiv').attr("editID"); | |
823 | |
824 $('#smartRegexShowDiv > #'+thisObject).attr("class", "span_"+$("#smartRegexPopUpSelectTag").val()); | |
825 $('#smartRegexShowDiv > #'+thisObject).attr("regexText", $("#smartRegexPopUpText").val()); | |
826 $('#smartRegexShowDiv > #'+thisObject).attr("regexReplace", $("#smartRegexPopUpSelectTag").val()); | |
827 } | |
828 | |
829 function replaceSmartDel() { | |
830 thisObject = $('#smartRegexPopUpDiv').attr("editID"); | |
831 $('#smartRegexShowDiv > #'+thisObject).remove(); | |
832 } | |
833 | |
834 function replaceSmartFor() { | |
835 thisObject = $('#smartRegexPopUpDiv').attr("editID"); | |
836 //var wahaha = $('#'+thisObject).clone(); | |
837 //var hahawa = $('#'+thisObject).next(); | |
838 //$('#'+thisObject).remove(); | |
839 //wahaha.insertAfter(hahawa); | |
840 $('#smartRegexShowDiv > #'+thisObject).insertAfter( $('#'+thisObject).next() ); | |
841 } | |
842 | |
843 function replaceSmartBack() { | |
844 thisObject = $('#smartRegexPopUpDiv').attr("editID"); | |
845 //var wahaha = $('#'+thisObject).clone(); | |
846 //var hahawa = $('#'+thisObject).prev(); | |
847 //$('#'+thisObject).remove(); | |
848 //wahaha.insertBefore(hahawa); | |
849 $('#smartRegexShowDiv > #'+thisObject).insertBefore( $('#'+thisObject).prev() ); | |
850 } | |
851 | |
852 function replaceSmartAdd() { | |
853 var newdiv = document.createElement("span"); | |
854 newdiv.innerHTML = " "+$("#smartRegexPopUpName").val()+" "; | |
855 $(newdiv).css("border", "1px solid black"); | |
856 $(newdiv).css("width", "100px"); | |
857 | |
858 $(newdiv).attr("class", "span_"+$("#smartRegexPopUpSelectTag").val()); | |
859 $(newdiv).attr("id", "span_"+$("#smartRegexPopUpName").val()); | |
860 $(newdiv).attr("regexText", $("#smartRegexPopUpText").val()); | |
861 $(newdiv).attr("regexReplace", $("#smartRegexPopUpSelectTag").val()); | |
862 | |
863 $('#smartRegexShowDiv').append(newdiv); | |
864 | |
865 replaceSmartClose(); | |
866 } | |
867 | |
868 $(document).on("click", '#smartRegexShowDiv > span', function (e) { | |
869 $('#smartRegexPopUpDiv').css("display", "block"); | |
870 $('#smartRegexPopUpDiv').css("background-color", "White"); | |
871 $('#smartRegexPopUpDiv').css("width", "400px"); | |
872 $('#smartRegexPopUpDiv').css("height", "300px"); | |
873 $('#smartRegexPopUpDiv').css("top", "100px"); | |
874 $('#smartRegexPopUpDiv').css("left", "-200px"); | |
875 $('#smartRegexPopUpDiv').css("border", "1px solid black"); | |
876 $('#smartRegexPopUpDiv').css("padding", "5px"); | |
877 | |
878 $('#smartRegexPopUpDiv').attr("editID", $(this).attr("id")); | |
879 | |
880 $('#smartRegexPopUpName').val($(this).html()); | |
881 $('#smartRegexPopUpText').val($(this).attr("regexText")); | |
882 $('#smartRegexPopUpSelectTag').val($(this).attr("regexReplace")); | |
883 | |
884 $('#smartRegexPopUpAdd').attr("disabled", "disabled"); | |
885 $('#smartRegexPopUpEdit').attr("disabled", false); | |
886 $('#smartRegexPopUpDel').attr("disabled", false); | |
887 $('#smartRegexPopUpBack').attr("disabled", false); | |
888 $('#smartRegexPopUpFor').attr("disabled", false); | |
889 }); | |
890 | |
891 function smartRegexEmpty() { | |
892 $('#smartRegexShowDiv').html(""); | |
893 } | |
894 | |
895 function replaceSmartRun() { | |
896 | |
897 var replaceSmartRegexString = ""; | |
898 var replaceSmartReplaceString = ""; | |
899 var count=1; | |
900 | |
901 saveUndoText(); | |
902 | |
903 $('#smartRegexShowDiv').children('span').each(function () { | |
904 replaceSmartRegexString += "(" + $(this).attr("regexText") + ")"; | |
905 if ( $(this).attr("regexReplace") == "notag" ) { | |
906 replaceSmartReplaceString += "$" + count; | |
907 } else if ( $(this).attr("regexReplace") == "title" ) { | |
908 replaceSmartReplaceString += "<br>〈" + "$" + count + "〉<br>"; | |
909 } else { | |
910 replaceSmartReplaceString += "<" + $(this).attr("regexReplace") + ">" + "$" + count + "</"+ $(this).attr("regexReplace") +">"; | |
911 } | |
912 count++; | |
913 }); | |
914 | |
915 | |
916 var startPage = $('#regexPageStart').val(); | |
917 var endPage = $('#regexPageEnd').val(); | |
918 var el = document.getElementById("editable-area"); | |
919 var str="" + el.innerHTML; | |
920 | |
921 if ( startPage == "" ) { | |
922 alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); | |
923 el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); | |
924 } else { | |
925 var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; | |
926 var partString = ""+str.match(new RegExp(regexText, "g")); | |
927 alert(partString); | |
928 | |
929 alert( "Tagged "+partString.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); | |
930 var resultString = partString.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); | |
931 | |
932 str="" + el.innerHTML; | |
933 el.innerHTML = str.replace(new RegExp(regexText, "g"), resultString); | |
934 } | |
935 } | |
936 | |
937 function replaceSmartRunSpace() { | |
938 | |
939 var replaceSmartRegexString = ""; | |
940 var replaceSmartReplaceString = ""; | |
941 var count=1; | |
942 saveUndoText(); | |
943 | |
944 $('#smartRegexShowDiv').children('span').each(function () { | |
945 //alert($(this).attr("regexText")); | |
946 replaceSmartRegexString += "(" + $(this).attr("regexText") + ")(○*)"; | |
947 if ( $(this).attr("regexReplace") == "notag" ) { | |
948 replaceSmartReplaceString += "$" + count; | |
949 } else if ( $(this).attr("regexReplace") == "title" ) { | |
950 replaceSmartReplaceString += "<br>〈" + "$" + count + "〉<br>"; | |
951 } else { | |
952 replaceSmartReplaceString += "<" + $(this).attr("regexReplace") + ">" + "$" + count + "</"+ $(this).attr("regexReplace") +">"; | |
953 } | |
954 count++; | |
955 replaceSmartReplaceString += "$" + count; | |
956 count++; | |
957 }); | |
958 | |
959 var startPage = $('#regexPageStart').val(); | |
960 var endPage = $('#regexPageEnd').val(); | |
961 var el = document.getElementById("editable-area"); | |
962 var str="" + el.innerHTML; | |
963 | |
964 if ( startPage == "" ) { | |
965 alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); | |
966 el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); | |
967 } else { | |
968 var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; | |
969 var partString = ""+str.match(new RegExp(regexText, "g")); | |
970 alert(partString); | |
971 | |
972 alert( "Tagged "+partString.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); | |
973 var resultString = partString.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); | |
974 | |
975 str="" + el.innerHTML; | |
976 el.innerHTML = str.replace(new RegExp(regexText, "g"), resultString); | |
977 } | |
978 | |
979 //alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" ); | |
980 //el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString); | |
981 } | |
982 | |
983 function smartRegexSave() { | |
984 var x; | |
985 var name=prompt("Please enter this Regex name",RegexLoadedName); | |
986 if (name!=null){ | |
987 $.ajax({ | |
988 url : 'save_regex.php', | |
989 async : false, | |
990 type : 'POST', | |
991 data : 'text='+encodeURIComponent($('#smartRegexShowDiv').html())+'&filename='+name | |
992 }).done(function(result) { | |
993 alert("Saved!"); | |
994 }); | |
995 } | |
996 } | |
997 | |
998 function smartRegexLoad() { | |
999 | |
1000 | |
1001 $('#load_regex_div').html(""); | |
1002 $('#load_regex_div').css("display", "block"); | |
1003 $('#load_regex_div').css("border", "1px solid black"); | |
1004 $('#load_regex_div').css("background-color", "White"); | |
1005 $('#load_regex_div').css("width", "200px"); | |
1006 $('#load_regex_div').css("height", "150px"); | |
1007 $('#load_regex_div').css("top", "100px"); | |
1008 $('#load_regex_div').css("left", "-200px"); | |
1009 | |
1010 var newselect = document.createElement("select"); | |
1011 newselect.id = "loadRegexSelect"; | |
1012 | |
1013 $.ajax({ | |
1014 type: 'GET', | |
1015 url: 'load_regex.php', | |
1016 dataType: 'json', | |
1017 cache: false, | |
1018 success: function (data) { | |
1019 $.each(data, function(index, element) { | |
1020 newselect.innerHTML += "<option value=\""+index+"\">"+index+"</option>\n"; | |
1021 //alert(index); | |
1022 //alert(element); | |
1023 var newdiv = document.createElement("div"); | |
1024 $(newdiv).css("display", "none"); | |
1025 $(newdiv).html(element); | |
1026 $(newdiv).attr("id", "div_"+index); | |
1027 $('#load_regex_div').append(newdiv); | |
1028 }); | |
1029 } | |
1030 }); | |
1031 | |
1032 $('#load_regex_div').append(newselect); | |
1033 var newbutton = document.createElement("button"); | |
1034 $(newbutton).html("Load"); | |
1035 $(newbutton).attr("onclick", "loadRegexAdd()"); | |
1036 $('#load_regex_div').append(newbutton); | |
1037 var newbutton = document.createElement("button"); | |
1038 $(newbutton).html("Close"); | |
1039 $(newbutton).attr("onclick", "$('#load_regex_div').css(\"display\", \"none\");"); | |
1040 $('#load_regex_div').append(newbutton); | |
1041 } | |
1042 | |
1043 var RegexLoadedName = ""; | |
1044 function loadRegexAdd() { | |
1045 RegexLoadedName = $('#loadRegexSelect').val(); | |
1046 var divName = "div_"+$('#loadRegexSelect').val(); | |
1047 $('#smartRegexShowDiv').html( $('#'+divName).html() ); | |
1048 $('#load_regex_div').css("display", "none"); | |
1049 } | |
1050 | |
1051 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) { | |
1052 <?php | |
1053 foreach ( $wordlistArray as $wordlistValue ) { | |
1054 echo "if ( $('#smartRegexPopUpSelectWord').val() == \"".$wordlistValue[0]."\") {"; | |
1055 echo "$('#smartRegexPopUpText').val(\"".$wordlistValue[2]."\");"; | |
1056 echo "}"; | |
1057 } | |
1058 ?> | |
1059 }); | |
1060 | |
1061 </script> | |
1062 </head> | |
1063 <body> | |
1064 <table width="1250" border="1"> | |
1065 <tr> | |
1066 <td width="980"> | |
1067 <div id="editable-area" class="area" style="max-width: 980"><?php echo $stringInput; ?></div> | |
1068 </td> | |
1069 <td width="270" valign="top"> | |
1070 <div id="follow-scroll" style="position:absolute; width: 220" width="220"> | |
1071 <div id="load_regex_div" style="position: absolute; display: none"></div> | |
1072 <div id="smartRegexPopUpDiv" style="position: absolute; display: none"> | |
1073 Name: <input id="smartRegexPopUpName"></input><br><br> | |
1074 Word List: | |
1075 <select id="smartRegexPopUpSelectWord"> | |
1076 <option value="NULL" selected>無</option> | |
1077 <?php | |
1078 foreach ( $wordlistArray as $wordlistValue ) { | |
1079 echo "<option value=\"".$wordlistValue[0]."\">".$wordlistValue[1]."</option>\n"; | |
1080 } | |
1081 ?> | |
1082 </select> | |
1083 <br> | |
1084 OR (USE "|" TO SEPARATE WORDS):<br> | |
1085 <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br> | |
1086 Tag: | |
1087 <select id="smartRegexPopUpSelectTag"> | |
1088 <?php | |
1089 foreach ( $taglistArray as $taglistValue ) { | |
1090 echo "<option value=\"".$taglistValue[2]."\">".$taglistValue[1]."</option>\n"; | |
1091 } | |
1092 echo "<option value=\"title\">Title</option>\n"; | |
1093 ?> | |
1094 <option value="NOTAG">不標記</option> | |
1095 </select><br> | |
1096 <button id="smartRegexPopUpAdd" onclick="replaceSmartAdd()" style="height: 30px; width: 50px">Add</button> | |
1097 <button id="smartRegexPopUpEdit" onclick="replaceSmartEdit()" style="height: 30px; width: 50px">Edit</button> | |
1098 <button id="smartRegexPopUpDel" onclick="replaceSmartDel()" style="height: 30px; width: 50px">Delete</button> | |
1099 <button id="smartRegexPopUpBack" onclick="replaceSmartBack()" style="height: 30px; width: 50px"><<</button> | |
1100 <button id="smartRegexPopUpFor" onclick="replaceSmartFor()" style="height: 30px; width: 50px">>></button> | |
1101 <button onclick="replaceSmartClose()" style="height: 30px; width: 50px">Close</button> | |
1102 </div> | |
1103 <form action="javascript:void(0);"> | |
1104 <fieldset> | |
1105 <legend>Replace By <i><b>Smart Regex</b></i>©:</legend> | |
1106 <div id="smartRegexShowDiv"></div><br> | |
1107 <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br> | |
1108 Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br> | |
1109 <button onclick="replaceSmartRun()" style="height: 30px; width: 220px">Run</button></br> | |
1110 <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br> | |
1111 <button onclick="smartRegexSave()" style="height: 30px; width: 70px">Save</button> | |
1112 <button onclick="smartRegexLoad()" style="height: 30px; width: 70px">Load</button> | |
1113 <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br> | |
1114 </fieldset> | |
1115 | |
1116 <fieldset> | |
1117 <legend>Tag by rule:</legend> | |
1118 <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br> | |
1119 <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br> | |
1120 <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>--> | |
1121 <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>--> | |
1122 <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button> | |
1123 </fieldset> | |
1124 | |
1125 <fieldset> | |
1126 <legend>Edit:</legend> | |
1127 <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>--> | |
1128 <button onclick="saveText()" style="height: 30px; width: 220px">Save the text</button></br> | |
1129 <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br> | |
1130 </br> | |
1131 <button onclick="window.open('edit_wordlist.php')" style="height: 30px; width: 220px">Manage Word List</button></br> | |
1132 <button onclick="window.open('edit_taglist.php')" style="height: 30px; width: 220px">Manage Tag List</button></br> | |
1133 </fieldset> | |
1134 | |
1135 <fieldset> | |
1136 <legend>Export:</legend> | |
1137 Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br> | |
1138 <button onclick="exportPage()" style="height: 30px; width: 220px">Export</button></br> | |
1139 <button onclick="exportAll()" style="height: 30px; width: 220px">Export All</button></br> | |
1140 </fieldset> | |
1141 | |
1142 <fieldset> | |
1143 <legend>Replace By <i><b>Regex</b></i>:</legend> | |
1144 Range: <input type="text" size="5" id="regexPageStart2">to<input type="text" size="5" id="regexPageEnd2"><br> | |
1145 Regex: <input type="text" size="30" id="regexText"></br> | |
1146 Replace: <input type="text" size="30" id="replaceText"><br> | |
1147 <button onclick="replaceSmartRegex()">Replace!</button> | |
1148 </fieldset> | |
1149 </form> | |
1150 </div> | |
1151 </td> | |
1152 </tr> | |
1153 </table> | |
1154 </body> | |
1155 </html> |