Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/hintgroup.dart, revision 1.1
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:
! 33: /**
! 34: * Returns true if the given node can be displayed with a simple UI.
! 35: */
! 36: bool simpleUIPossible() {
! 37: if (attributes.length != 0)
! 38: return false;
! 39: // check if there is a single hintpart with on="default" and simple content inside
! 40: bool hintpartok = false;
! 41: bool othernode = false;
! 42: for (DaxeNode dn in childNodes) {
! 43: if (dn.nodeType == DaxeNode.ELEMENT_NODE && dn.nodeName == 'hintpart' &&
! 44: dn.getAttribute('on') == 'default' && dn.attributes.length == 1 &&
! 45: SimpleUIText.checkNodeContents(dn))
! 46: hintpartok = true;
! 47: else if (dn.nodeType != DaxeNode.TEXT_NODE || dn.nodeValue.trim() != '')
! 48: othernode = true;
! 49: }
! 50: if (hintpartok && !othernode)
! 51: return true;
! 52: // otherwise just check the contents
! 53: return SimpleUIText.checkNodeContents(this);
! 54: }
! 55:
! 56: void fixStructureForSimpleUI() {
! 57: // remove hintpart (but keep its content)
! 58: for (DaxeNode dn in childNodes) {
! 59: if (dn.nodeType == DaxeNode.ELEMENT_NODE && dn.nodeName == 'hintpart') {
! 60: removeChild(dn);
! 61: // remove spaces inside this node
! 62: normalize();
! 63: if (firstChild is DNText && firstChild.nodeValue.trim() == '' &&
! 64: firstChild.nextSibling == null)
! 65: removeChild(firstChild);
! 66: // remove left and right spaces inside hintpart
! 67: if (dn.firstChild.nodeType == DaxeNode.TEXT_NODE) {
! 68: if (dn.firstChild.nodeValue.trim() == '')
! 69: dn.removeChild(dn.firstChild);
! 70: else
! 71: dn.firstChild.nodeValue = dn.firstChild.nodeValue.trimLeft();
! 72: }
! 73: if (dn.lastChild.nodeType == DaxeNode.TEXT_NODE) {
! 74: if (dn.lastChild.nodeValue.trim() == '')
! 75: dn.removeChild(dn.lastChild);
! 76: else
! 77: dn.lastChild.nodeValue = dn.lastChild.nodeValue.trimRight();
! 78: }
! 79: // append hintpart content
! 80: for (DaxeNode dn2=dn.firstChild; dn2!=null; dn2=dn.firstChild) {
! 81: dn.removeChild(dn2);
! 82: appendChild(dn2);
! 83: }
! 84: break;
! 85: }
! 86: }
! 87: }
! 88:
! 89: @override
! 90: h.Element html() {
! 91: simpleUI = parent is LCDBlock && (parent as LCDBlock).simpleUI;
! 92: if (!simpleUI)
! 93: return super.html();
! 94: h.DivElement div = new h.DivElement();
! 95: div.id = id;
! 96: h.SpanElement titleSpan = new h.SpanElement();
! 97: titleSpan.appendText(LCDStrings.get('hint') + ' ');
! 98: div.append(titleSpan);
! 99: h.SpanElement contentsSpan = new h.SpanElement();
! 100: for (DaxeNode dn=firstChild; dn!= null; dn=dn.nextSibling) {
! 101: contentsSpan.append(dn.html());
! 102: }
! 103: div.append(contentsSpan);
! 104: return div;
! 105: }
! 106:
! 107: @override
! 108: h.Element getHTMLContentsNode() {
! 109: if (!simpleUI)
! 110: return super.getHTMLContentsNode();
! 111: return(getHTMLNode().nodes[1]);
! 112: }
! 113:
! 114: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>