# HG changeset patch # User Zoe Hong # Date 1427722487 -7200 # Node ID f9e7119339b2b2544448e904e005ce429ba17177 # Parent f9594c240826a679f8eece381e711e4b4bba0a77 bug fixed: when addTagTitle, removing self-closing tag which causes error in coloring tag diff -r f9594c240826 -r f9e7119339b2 js/taggingtext.js --- 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()+"〉"; - range.deleteContents(); + + range.deleteContents(); // may causes self-closing tag + var stringtemp = container.innerHTML; var regexText=/
/g; var replaceText="
"+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=//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; diff -r f9594c240826 -r f9e7119339b2 models/extractapp.php --- 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"."
"; $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>】/u", "【\\2】", $require); $require = preg_replace('/&/u', "&", $require); $require = preg_replace("/○/u", " ", $require); $require = preg_replace("/
/u", "\n", $require); //$require = preg_replace("/
/u", "\n", $require); + + echo "----------------------------------
"; + 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("",""); //$new_contentString = str_replace($removed_str, "", $contentString); @@ -1298,7 +1305,6 @@ $this->book_meta = $book_meta; - return $stringInput; } diff -r f9594c240826 -r f9e7119339b2 views/Extractapp/TaggingText.php --- 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('')); + //console.log(JSON.parse(''));
"; } - console.log(" container innerHTML: "+ container.innerHTML ); newdiv.innerHTML += "
"; @@ -396,6 +394,7 @@ $('#TitletagType').val(lastAddTag); } + //e.stopPropagation(); }); @@ -670,6 +669,7 @@ function saveTextToLGService() { + // ------------- var info = JSON.parse(''); var topic_id = JSON.parse(''); @@ -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.");