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