Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/nodes/h1.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: * Used for section's h1 (as first child).
! 22: * As the first child in a section, display the class icon and the title in bold.
! 23: */
! 24: class H1 extends LCDBlock {
! 25:
! 26: H1.fromRef(x.Element elementRef) : super.fromRef(elementRef);
! 27:
! 28: H1.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent);
! 29:
! 30: @override
! 31: bool simpleUIPossible() {
! 32: if (previousSibling != null)
! 33: return false;
! 34: if (attributes.length != 0)
! 35: return false;
! 36: if (firstChild != null && firstChild is! DNText)
! 37: return false;
! 38: if (firstChild != null && firstChild.nextSibling != null)
! 39: return false;
! 40: return true;
! 41: }
! 42:
! 43: @override
! 44: h.Element html() {
! 45: simpleUI = parent is Section && (parent as Section).simpleUI && previousSibling == null;
! 46: if (!simpleUI)
! 47: return super.html();
! 48: setupRestrictions();
! 49:
! 50: h.DivElement div = new h.DivElement();
! 51: div.id = "$id";
! 52: div.classes.add('dn');
! 53: if (!valid)
! 54: div.classes.add('invalid');
! 55: div.classes.add('section-title');
! 56: setStyle(div);
! 57: String cl = parent.getAttribute('class');
! 58: if (cl != null && cl.startsWith('role-')) {
! 59: //TODO: provide a way to change the role
! 60: String role = cl.substring(5);
! 61: div.style.backgroundImage = 'url("images/section_icons/$role.png")';
! 62: div.style.backgroundRepeat = 'no-repeat';
! 63: }
! 64: if (firstChild == null) {
! 65: div.style.position = 'relative';
! 66: h.SpanElement span = new h.SpanElement();
! 67: span.style.position = 'absolute';
! 68: span.style.color = '#CCC';
! 69: span.appendText(LCDStrings.get('section_title'));
! 70: div.append(span);
! 71: }
! 72: DaxeNode dn = firstChild;
! 73: while (dn != null) {
! 74: div.append(dn.html());
! 75: dn = dn.nextSibling;
! 76: }
! 77: if (lastChild == null || lastChild.nodeType == DaxeNode.TEXT_NODE)
! 78: div.appendText('\n');
! 79: return(div);
! 80: }
! 81:
! 82: @override
! 83: h.Element getHTMLContentsNode() {
! 84: if (!simpleUI)
! 85: return super.getHTMLContentsNode();
! 86: return getHTMLNode();
! 87: }
! 88:
! 89: @override
! 90: void updateHTMLAfterChildrenChange(List<DaxeNode> changed) {
! 91: if (!simpleUI)
! 92: super.updateHTMLAfterChildrenChange(changed);
! 93: updateHTML();
! 94: }
! 95:
! 96: void setupRestrictions() {
! 97: attRefs = [];
! 98: restrictedInserts = ['m','lm','chem','num','i','sup','sub'];
! 99: }
! 100:
! 101: @override
! 102: void setupSimpleUI() {
! 103: simpleUI = true;
! 104: setupRestrictions();
! 105: }
! 106:
! 107: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>