Mercurial > hg > extraction-interface
comparison develop/views/Extractapp/taggingtext.php @ 6:63e08b98032f
rewrite extraction interface into PHP MVC architecture.
(Although js hasn't been rewritten into MVC, it's fitted into the current PHP MVC architecture.)
- The root of the new PHP MVC is at 'develop/'.
- extraction interface is called "Extractapp" with several action, eg TaggingText, EditWordlist, EditTaglist, ExportTable.
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 05 Feb 2015 16:07:53 +0100 |
parents | |
children | da10158c6d0a |
comparison
equal
deleted
inserted
replaced
5:cbbb7ef22394 | 6:63e08b98032f |
---|---|
1 <?php | |
2 // --- initialize config file and input text --- | |
3 $stringInput = $viewmodel['stringInput']; | |
4 $wordlistArray = $viewmodel['wordlistArray']; | |
5 $taglistArray = $viewmodel['taglistArray']; | |
6 $section_id = $viewmodel['section_id']; | |
7 | |
8 ?> | |
9 | |
10 <html> | |
11 <head> | |
12 <title></title> | |
13 | |
14 <style> | |
15 dynasty | |
16 { | |
17 color:red; | |
18 } | |
19 nianhao | |
20 { | |
21 color:blue; | |
22 } | |
23 name | |
24 { | |
25 color:orange; | |
26 } | |
27 #editable-area { | |
28 line-height:160%; | |
29 letter-spacing:1.5px; | |
30 font-size:21px; | |
31 } | |
32 | |
33 | |
34 <?php | |
35 // color on the tags | |
36 foreach ( $taglistArray as $taglistValue ) { | |
37 echo $taglistValue[2]."\n{\ncolor:".$taglistValue[3]."\n}\n"; | |
38 | |
39 echo ".span_".$taglistValue[2]."\n{\nbackground-color:".$taglistValue[3]."\n}\n"; | |
40 } | |
41 | |
42 ?> | |
43 </style> | |
44 | |
45 | |
46 </head> | |
47 | |
48 <body> | |
49 | |
50 <script type="text/javascript"> | |
51 | |
52 <?php | |
53 foreach ( $taglistArray as $taglistValue ) { | |
54 echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n"; | |
55 echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n"; | |
56 echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n"; | |
57 echo "\tremoveTagNewDiv( e, \"".$taglistValue[2]."\", $(this) );\n"; | |
58 echo "});\n"; | |
59 } | |
60 ?> | |
61 | |
62 $(document).ready(function(){ | |
63 //run once | |
64 var el=$('#follow-scroll'); | |
65 var originalelpos=el.offset().top; // take it where it originally is on the page | |
66 | |
67 //run on scroll | |
68 $(window).scroll(function(){ | |
69 var el = $('#follow-scroll'); // important! (local) | |
70 var elpos = el.offset().top; // take current situation | |
71 var windowpos = $(window).scrollTop(); | |
72 var finaldestination = windowpos+originalelpos; | |
73 el.stop().animate({'top':finaldestination},500); | |
74 }); | |
75 }); | |
76 $(document).on("click", "name", function (e) { | |
77 | |
78 if ( $("#editTextId").html() != "Edit the text" ) return 0; | |
79 if ( $(this).prop("tagName").toLowerCase() != "name" ) return 0; | |
80 | |
81 removeTagNewDiv( e, "name", $(this) ); | |
82 }); | |
83 | |
84 $(document).on("mouseup", '#editable-area', function (e) { | |
85 $('.questionMarkClass').remove(); | |
86 $('.tagItemDivClass').remove(); | |
87 | |
88 if ( $("#editTextId").html() != "Edit the text" ) return 0; | |
89 | |
90 var selection = getSelected(); | |
91 range = getSelected().getRangeAt(0); | |
92 | |
93 container = document.createElement("div"); | |
94 container.appendChild(selection.getRangeAt(0).cloneContents()); | |
95 | |
96 if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) { | |
97 | |
98 var newdiv = document.createElement("div"); | |
99 newdiv.id = "tagItemDivId"; | |
100 newdiv.setAttribute("class", "tagItemDivClass"); | |
101 newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; | |
102 | |
103 //console.log(selection.getRangeAt(0).cloneContents()); | |
104 if ( container.innerHTML.indexOf( "br" ) != -1 ) { | |
105 var newselect = document.createElement("select"); | |
106 newselect.id = "TitletagType"; | |
107 <?php | |
108 foreach ( $taglistArray as $taglistValue ) { | |
109 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n"; | |
110 } | |
111 ?> | |
112 newdiv.appendChild(newselect); | |
113 | |
114 //matchValue = .match(); | |
115 myRegexp = new RegExp("〈(.*?)〉", "g") | |
116 matchValue = myRegexp.exec(String(selection)); | |
117 | |
118 if ( matchValue != null ) { | |
119 newdiv.innerHTML += "<input id=\"TitletagName\" value=\""+ matchValue[1] +"\"></br>"; | |
120 } else { | |
121 newdiv.innerHTML += "<input id=\"TitletagName\" value=\"\"></br>"; | |
122 } | |
123 newdiv.innerHTML += "<button onclick=\"addTagTitle( range, container )\">Add Title Tag To Each Line</button></br>"; | |
124 | |
125 newdiv.innerHTML += "<button onclick=\"exportTable( range, container )\">Export As A Table</button></br></br>"; | |
126 | |
127 var newselect = document.createElement("select"); | |
128 newselect.id = "RemoveTitletagType"; | |
129 <?php | |
130 foreach ( $taglistArray as $taglistValue ) { | |
131 echo "newselect.innerHTML += \"<option value='".$taglistValue[2]."'>".$taglistValue[1]."</option>\";\n"; | |
132 } | |
133 ?> | |
134 newdiv.appendChild(newselect); | |
135 | |
136 newdiv.innerHTML += "<input id=\"RemoveTitletagName\" value=\"\"></br>"; | |
137 newdiv.innerHTML += "<button onclick=\"removeTagTitle( range, container )\">Remove</button></br>"; | |
138 } else { | |
139 newdiv.innerHTML = "Tag: "+String(selection)+"<br>"; | |
140 | |
141 newdiv.innerHTML += "<button accesskey=\"2\" onclick=\"tagwithtitle( range, '"+String(selection)+"' )\">Tag As Title</button></br>"; | |
142 | |
143 <?php | |
144 foreach ( $taglistArray as $taglistValue ) { | |
145 if ( $taglistValue[2] == "person") { | |
146 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(No BR)</button>\";\n"; | |
147 echo "newdiv.innerHTML += \"<button accesskey=\\\"1\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."2' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
148 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
149 } else if ($taglistValue[2] == "post_time") { | |
150 echo "newdiv.innerHTML += \"<button accesskey=\\\"3\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
151 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
152 } else if ($taglistValue[2] == "office") { | |
153 echo "newdiv.innerHTML += \"<button accesskey=\\\"4\\\" onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
154 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
155 } else { | |
156 echo "newdiv.innerHTML += \"<button onclick=\\\"tagwithOnlytag( range, '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."</button>\";\n"; | |
157 echo "newdiv.innerHTML += \"<button onclick=\\\"tagStringWithTag( '\"+String(selection)+\"', '".$taglistValue[2]."' )\\\">Tag as:".$taglistValue[1]."(ALL)</button></br>\";\n"; | |
158 } | |
159 } | |
160 ?> | |
161 } | |
162 $('body').append(newdiv); | |
163 | |
164 $('#TitletagType').val(lastAddTag); | |
165 } | |
166 //e.stopPropagation(); | |
167 }); | |
168 | |
169 | |
170 | |
171 function replaceSmartRegex() { | |
172 saveUndoText(); | |
173 var startPage = $('#regexPageStart2').val(); | |
174 var endPage = $('#regexPageEnd2').val(); | |
175 | |
176 var el = document.getElementById("editable-area"); | |
177 var regexText=document.getElementById("regexText").value; | |
178 | |
179 <?php | |
180 foreach ( $wordlistArray as $wordlistValue ) { | |
181 echo "\tvar regexText1=\"List ".$wordlistValue[1]."\";\n"; | |
182 echo "\tregexText1 = preg_quote(regexText1);\n"; | |
183 echo "\tvar replaceText1=\"".$wordlistValue[2]."\";\n"; | |
184 echo "\tregexText = regexText.replace(new RegExp(regexText1, \"g\"), replaceText1);\n\n"; | |
185 } | |
186 ?> | |
187 | |
188 var replaceText=document.getElementById("replaceText").value; | |
189 var str="" + el.innerHTML; | |
190 | |
191 if ( startPage == "" ) { | |
192 alert( "Tagged "+str.match(new RegExp(regexText, "g")).length+" entities!" ); | |
193 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); | |
194 } else { | |
195 var regexText2="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】"; | |
196 var partString = ""+str.match(new RegExp(regexText2, "g")); | |
197 alert(partString); | |
198 | |
199 alert( "Tagged "+partString.match(new RegExp(regexText, "g")).length+" entities!" ); | |
200 var resultString = partString.replace(new RegExp(regexText, "g"), replaceText); | |
201 | |
202 str="" + el.innerHTML; | |
203 el.innerHTML = str.replace(new RegExp(regexText2, "g"), resultString); | |
204 } | |
205 //document.styleSheets[0].addRule("tag001", "color:green;") | |
206 } | |
207 | |
208 | |
209 | |
210 | |
211 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) { | |
212 <?php | |
213 foreach ( $wordlistArray as $wordlistValue ) { | |
214 echo "if ( $('#smartRegexPopUpSelectWord').val() == \"".$wordlistValue[0]."\") {"; | |
215 echo "$('#smartRegexPopUpText').val(\"".$wordlistValue[2]."\");"; | |
216 echo "}"; | |
217 } | |
218 ?> | |
219 }); | |
220 | |
221 | |
222 </script> | |
223 | |
224 <table width="1250" border="1"> | |
225 <tr> | |
226 <td width="980"> | |
227 <div id="editable-area" class="area" style="max-width: 980"><?php echo $stringInput; ?></div> | |
228 </td> | |
229 <td width="270" valign="top"> | |
230 <div id="follow-scroll" style="position:absolute; width: 220" width="220"> | |
231 <div id="load_regex_div" style="position: absolute; display: none"></div> | |
232 <div id="smartRegexPopUpDiv" style="position: absolute; display: none"> | |
233 Name: <input id="smartRegexPopUpName"></input><br><br> | |
234 Word List: | |
235 <select id="smartRegexPopUpSelectWord"> | |
236 <option value="NULL" selected>無</option> | |
237 <?php | |
238 foreach ( $wordlistArray as $wordlistValue ) { | |
239 echo "<option value=\"".$wordlistValue[0]."\">".$wordlistValue[1]."</option>\n"; | |
240 } | |
241 ?> | |
242 </select> | |
243 <br> | |
244 OR (USE "|" TO SEPARATE WORDS):<br> | |
245 <TEXTAREA id="smartRegexPopUpText" COLS=30 ROWS=4></TEXTAREA><br><br> | |
246 Tag: | |
247 <select id="smartRegexPopUpSelectTag"> | |
248 <?php | |
249 foreach ( $taglistArray as $taglistValue ) { | |
250 echo "<option value=\"".$taglistValue[2]."\">".$taglistValue[1]."</option>\n"; | |
251 } | |
252 echo "<option value=\"title\">Title</option>\n"; | |
253 ?> | |
254 <option value="NOTAG">不標記</option> | |
255 </select><br> | |
256 <button id="smartRegexPopUpAdd" onclick="replaceSmartAdd()" style="height: 30px; width: 50px">Add</button> | |
257 <button id="smartRegexPopUpEdit" onclick="replaceSmartEdit()" style="height: 30px; width: 50px">Edit</button> | |
258 <button id="smartRegexPopUpDel" onclick="replaceSmartDel()" style="height: 30px; width: 50px">Delete</button> | |
259 <button id="smartRegexPopUpBack" onclick="replaceSmartBack()" style="height: 30px; width: 50px"><<</button> | |
260 <button id="smartRegexPopUpFor" onclick="replaceSmartFor()" style="height: 30px; width: 50px">>></button> | |
261 <button onclick="replaceSmartClose()" style="height: 30px; width: 50px">Close</button> | |
262 </div> | |
263 <form action="javascript:void(0);"> | |
264 <fieldset> | |
265 <legend>Replace By <i><b>Smart Regex</b></i>©:</legend> | |
266 <div id="smartRegexShowDiv"></div><br> | |
267 <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br> | |
268 Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br> | |
269 <button onclick="replaceSmartRun()" style="height: 30px; width: 220px">Run</button></br> | |
270 <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br> | |
271 <button onclick="smartRegexSave()" style="height: 30px; width: 70px">Save</button> | |
272 <button onclick="smartRegexLoad(<?php echo $section_id;?>)" style="height: 30px; width: 70px">Load</button> | |
273 <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br> | |
274 </fieldset> | |
275 | |
276 <fieldset> | |
277 <legend>Tag by rule:</legend> | |
278 <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br> | |
279 <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br> | |
280 <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>--> | |
281 <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>--> | |
282 <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button> | |
283 </fieldset> | |
284 | |
285 <fieldset> | |
286 <legend>Edit:</legend> | |
287 <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>--> | |
288 <button onclick="saveText(<?php echo $section_id; ?>)" style="height: 30px; width: 220px">Save the text</button></br> | |
289 <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br> | |
290 </br> | |
291 <button onclick="window.open('../EditWordlist/<?php echo $section_id;?>')" style="height: 30px; width: 220px">Manage Word List</button></br> | |
292 <button onclick="window.open('../EditTaglist/<?php echo $section_id;?>')" style="height: 30px; width: 220px">Manage Tag List</button></br> | |
293 </fieldset> | |
294 | |
295 <fieldset> | |
296 <legend>Export:</legend> | |
297 Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br> | |
298 <button onclick="exportPage()" style="height: 30px; width: 220px">Export</button></br> | |
299 <button onclick="exportAll(<?php echo $section_id;?>)" style="height: 30px; width: 220px">Export All</button></br> | |
300 </fieldset> | |
301 | |
302 <fieldset> | |
303 <legend>Replace By <i><b>Regex</b></i>:</legend> | |
304 Range: <input type="text" size="5" id="regexPageStart2">to<input type="text" size="5" id="regexPageEnd2"><br> | |
305 Regex: <input type="text" size="30" id="regexText"></br> | |
306 Replace: <input type="text" size="30" id="replaceText"><br> | |
307 <button onclick="replaceSmartRegex()">Replace!</button> | |
308 </fieldset> | |
309 </form> | |
310 </div> | |
311 </td> | |
312 </tr> | |
313 </table> | |
314 </body> | |
315 </html> |