changeset 54:f9e7119339b2 extractapp

bug fixed: when addTagTitle, removing self-closing tag which causes error in coloring tag
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 30 Mar 2015 15:34:47 +0200
parents f9594c240826
children e930eb88b547
files js/taggingtext.js models/extractapp.php views/Extractapp/TaggingText.php
diffstat 3 files changed, 52 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/js/taggingtext.js	Thu Mar 26 17:25:46 2015 +0100
+++ b/js/taggingtext.js	Mon Mar 30 15:34:47 2015 +0200
@@ -122,6 +122,24 @@
     tagObject.append(newdiv);
 }
 
+function removeEmptyNodes( node ) {
+    if (node.hasChildNodes()) {
+        var children = node.childNodes;
+        for (var i = 0; i < children.length; i++) {
+            if (children[i].textContent == "" && children[i].innerHTML == "" && children[i].nodeName != "BR") {
+                //console.log("removing child: "+children[i].nodeName+", its parent: "+node.nodeName);
+                node.removeChild(children[i]);
+            } else {
+                //console.log("recursive to "+children[i].nodeName+"("+children[i].textContent+")")
+                removeEmptyNodes(children[i]);  // recursive
+            }
+
+        };
+    } else {
+        //console.log(node.nodeName+" ("+node.textContent+") has no childNodes.");
+    }
+
+}
 
 
 function removeTagTitle( range, container ) {
@@ -168,22 +186,28 @@
 }
 
 function addTagTitle( range, container ) {
+    // TODO: bug: here generate self-closing tag when the end of text with tag on it
+
     saveUndoText();
+
+    var el = document.getElementById("editable-area");
+    
     lastAddTag = $('#TitletagType').val();
     var tag = "<"+$('#TitletagType').val()+">〈"+$('#TitletagName').val()+"〉</"+$('#TitletagType').val()+">";
-    range.deleteContents();
+
+    range.deleteContents(); // may causes self-closing tag
+
     var stringtemp = container.innerHTML;
 
     var regexText=/<br>/g;
     var replaceText="<br>"+tag;
     stringtemp = stringtemp.replace(regexText, replaceText);
-    
+  
     var newdiv = document.createElement("aaaa");
     newdiv.innerHTML = tag+stringtemp;
+
     range.insertNode(newdiv);
-    
-    var el = document.getElementById("editable-area");
-    
+   
 
     var regexText=/<aaaa>/gi;
     var replaceText='';
@@ -194,6 +218,9 @@
     el.innerHTML = el.innerHTML.replace(regexText, replaceText);
     
     $('.tagItemDivClass').remove();
+
+    removeEmptyNodes(el);   // removing self-closing tags
+
 }
 
 function cleanUpTextArea() {
@@ -323,15 +350,16 @@
 
 //Tagging Items
 function getSelected() {
-    if(window.getSelection) {
+    if(window.getSelection) {   // all browsers, except IE before version 9
         return window.getSelection();
     } else if (document.getSelection) { 
         return document.getSelection(); 
-    } else {
+    } else {    // IE
         var selection = document.selection && document.selection.createRange();
         if(selection.text) {
             return selection.text;
         }
+
         return false;
     }
     return false;
--- a/models/extractapp.php	Thu Mar 26 17:25:46 2015 +0100
+++ b/models/extractapp.php	Mon Mar 30 15:34:47 2015 +0200
@@ -88,6 +88,7 @@
 
     public function GetTextFromLocal($_id){
         $this->section_id = $_id;
+        $this->branch_id = 1;   // local test sets branch_id to 1
         $this->messages .= "DEBUG: from my local"."<br>";
         $this->lg_text = $this->GetSectionContent();
 
@@ -403,7 +404,7 @@
             if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) {
                 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt");
                 //saving in my local machine in developing phrase
-                //file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile);
+                file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile);
             }
             
             if (get_magic_quotes_gpc()) {
@@ -412,11 +413,16 @@
                 $require = $_postdata['text'];
             }
  
+            echo "Debug: (full text before) ". $require;
+
             $require = preg_replace("/【<a(.*?)>(.*?)<\/a>】/u", "【\\2】", $require);
             $require = preg_replace('/&amp;/u', "&", $require); 
             $require = preg_replace("/○/u", " ", $require); 
             $require = preg_replace("/<br>/u", "\n", $require);
             //$require = preg_replace("/<br>/u", "\n", $require);
+            
+            echo "----------------------------------<br>";
+            echo "Debug: (full text after) ". $require;
 
             if ($_postdata['branchId'] == 0) {
                 // -- new branch case
@@ -425,7 +431,7 @@
             $require = $this->AppendMetaData($require);
                 
             //saving in my local machine in developing phrase
-            //file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
+            file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
         } 
 
         // ------
@@ -473,7 +479,7 @@
 
         // execute the request
         // **** commended to DEBUG ***
-        $output = curl_exec($ch);
+        //$output = curl_exec($ch);
         // *****
 
         // output the profile information - includes the header
@@ -1243,7 +1249,8 @@
 
         // echo $taglist->name.", ".$taglist->tag."," .$taglist->color;
         // --- detect if the taglist set is up-to-date or not ---
-        $contentString = (string)$xml->text_content->asXML();
+
+        $contentString = (string)($xml->text_content->asXML());
         //$removed_str = array("<text_content>","</text_content>");
         //$new_contentString = str_replace($removed_str, "", $contentString);
 
@@ -1298,7 +1305,6 @@
 
         $this->book_meta = $book_meta;
 
-
         return $stringInput;
     }
     
--- a/views/Extractapp/TaggingText.php	Thu Mar 26 17:25:46 2015 +0100
+++ b/views/Extractapp/TaggingText.php	Mon Mar 30 15:34:47 2015 +0200
@@ -281,7 +281,8 @@
    
     if ( $("#editTextId").html() != "Edit the text" ) return 0;
     var selection = getSelected();
-    range = getSelected().getRangeAt(0);
+
+    range = selection.getRangeAt(0);
     
     container = document.createElement("div");
     container.appendChild(selection.getRangeAt(0).cloneContents());
@@ -300,9 +301,7 @@
         if ( container.innerHTML.indexOf( "br" ) != -1 ) {
             var newselect = document.createElement("select");
             newselect.id = "TitletagType";
-            
-
-            console.log(JSON.parse('<?php echo json_encode($taglistArray) ?>'));
+            //console.log(JSON.parse('<?php echo json_encode($taglistArray) ?>'));
 
             <?php 
                 foreach ( $taglistArray as $taglistValue ) {
@@ -321,7 +320,6 @@
                 newdiv.innerHTML += "<input id=\"TitletagName\" value=\"\"></br>";
             }
 
-            console.log(" container innerHTML: "+ container.innerHTML );
 
             newdiv.innerHTML += "<button onclick=\"addTagTitle( range, container )\">Add Title Tag To Each Line</button></br>";
             
@@ -396,6 +394,7 @@
         $('#TitletagType').val(lastAddTag);
 
     }
+
     //e.stopPropagation();
 });
 
@@ -670,6 +669,7 @@
 
 function saveTextToLGService() {
 
+    // -------------
     var info = JSON.parse('<?php echo json_encode($info) ?>');
     var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
 
@@ -687,7 +687,7 @@
         if(mm<10) {
             mm='0'+mm
         } 
-        today = dd+'/'+mm+'/'+yyyy;
+        today = dd+'.'+mm+'.'+yyyy;
         var label = prompt("Please enter your label for this new branch", today);
         while (label == null) {
             alert("You haven't saved your editing.");