Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/hintgroup.dart, revision 1.2

1.1       damieng     1: /*
                      2:   This file is part of LONCAPA-Daxe.
                      3: 
                      4:   LONCAPA-Daxe is free software: you can redistribute it and/or modify
                      5:   it under the terms of the GNU General Public License as published by
                      6:   the Free Software Foundation, either version 3 of the License, or
                      7:   (at your option) any later version.
                      8: 
                      9:   LONCAPA-Daxe is distributed in the hope that it will be useful,
                     10:   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     12:   GNU General Public License for more details.
                     13: 
                     14:   You should have received a copy of the GNU General Public License
                     15:   along with Daxe.  If not, see <http://www.gnu.org/licenses/>.
                     16: */
                     17: 
                     18: part of loncapa_daxe;
                     19: 
                     20: /**
                     21:  * This is used by RadioResponse for simple UI.
                     22:  */
                     23: class Hintgroup extends LCDBlock {
                     24:   
                     25:   Hintgroup.fromRef(x.Element elementRef) : super.fromRef(elementRef) {
                     26:   }
                     27:   
                     28:   Hintgroup.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent) {
                     29:     if (parent is LCDBlock && (parent as LCDBlock).simpleUI)
                     30:       simpleUI = true;
                     31:   }
                     32:   
1.2     ! damieng    33:   @override
1.1       damieng    34:   bool simpleUIPossible() {
                     35:     if (attributes.length != 0)
                     36:       return false;
                     37:     // check if there is a single hintpart with on="default" and simple content inside
                     38:     bool hintpartok = false;
                     39:     bool othernode = false;
                     40:     for (DaxeNode dn in childNodes) {
                     41:       if (dn.nodeType == DaxeNode.ELEMENT_NODE && dn.nodeName == 'hintpart' &&
                     42:           dn.getAttribute('on') == 'default' && dn.attributes.length == 1 &&
                     43:           SimpleUIText.checkNodeContents(dn))
                     44:         hintpartok = true;
                     45:       else if (dn.nodeType != DaxeNode.TEXT_NODE || dn.nodeValue.trim() != '')
                     46:         othernode = true;
                     47:     }
                     48:     if (hintpartok && !othernode)
                     49:       return true;
                     50:     // otherwise just check the contents
                     51:     return SimpleUIText.checkNodeContents(this);
                     52:   }
                     53:   
1.2     ! damieng    54:   @override
        !            55:   h.Element html() {
        !            56:     simpleUI = parent is LCDBlock && (parent as LCDBlock).simpleUI;
        !            57:     if (!simpleUI)
        !            58:       return super.html();
        !            59:     setupRestrictions();
        !            60:     h.DivElement div = new h.DivElement();
        !            61:     div.id = id;
        !            62:     h.SpanElement titleSpan = new h.SpanElement();
        !            63:     titleSpan.appendText(LCDStrings.get('hint') + ' ');
        !            64:     div.append(titleSpan);
        !            65:     h.SpanElement contentsSpan = new h.SpanElement();
        !            66:     for (DaxeNode dn=firstChild; dn!= null; dn=dn.nextSibling) {
        !            67:       contentsSpan.append(dn.html());
        !            68:     }
        !            69:     div.append(contentsSpan);
        !            70:     return div;
        !            71:   }
        !            72:   
        !            73:   @override
        !            74:   h.Element getHTMLContentsNode() {
        !            75:     if (!simpleUI)
        !            76:       return super.getHTMLContentsNode();
        !            77:     return(getHTMLNode().nodes[1]);
        !            78:   }
        !            79:   
        !            80:   void setupRestrictions() {
        !            81:     if (restrictedInserts == null)
        !            82:       restrictedInserts = SimpleUIText.possibleDescendants;
        !            83:   }
        !            84:   
        !            85:   @override
        !            86:   void setupSimpleUI() {
        !            87:     simpleUI = true;
        !            88:     setupRestrictions();
        !            89:     fixChildrenForSimpleUI();
        !            90:   }
        !            91:   
        !            92:   void fixChildrenForSimpleUI() {
1.1       damieng    93:     // remove hintpart (but keep its content)
                     94:     for (DaxeNode dn in childNodes) {
                     95:       if (dn.nodeType == DaxeNode.ELEMENT_NODE && dn.nodeName == 'hintpart') {
                     96:         removeChild(dn);
                     97:         // remove spaces inside this node
                     98:         normalize();
                     99:         if (firstChild is DNText && firstChild.nodeValue.trim() == '' &&
                    100:             firstChild.nextSibling == null)
                    101:           removeChild(firstChild);
                    102:         // remove left and right spaces inside hintpart
                    103:         if (dn.firstChild.nodeType == DaxeNode.TEXT_NODE) {
                    104:           if (dn.firstChild.nodeValue.trim() == '')
                    105:             dn.removeChild(dn.firstChild);
                    106:           else
                    107:             dn.firstChild.nodeValue = dn.firstChild.nodeValue.trimLeft();
                    108:         }
                    109:         if (dn.lastChild.nodeType == DaxeNode.TEXT_NODE) {
                    110:           if (dn.lastChild.nodeValue.trim() == '')
                    111:             dn.removeChild(dn.lastChild);
                    112:           else
                    113:             dn.lastChild.nodeValue = dn.lastChild.nodeValue.trimRight();
                    114:         }
                    115:         // append hintpart content
                    116:         for (DaxeNode dn2=dn.firstChild; dn2!=null; dn2=dn.firstChild) {
                    117:           dn.removeChild(dn2);
                    118:           appendChild(dn2);
                    119:         }
                    120:         break;
                    121:       }
                    122:     }
                    123:   }
                    124:   
                    125: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>