File:  [LON-CAPA] / modules / damieng / graphical_editor / loncapa_daxe / web / nodes / h1.dart
Revision 1.5: download - view: text, annotated - select for diffs
Tue Dec 22 20:52:15 2015 UTC (8 years, 5 months ago) by damieng
Branches: MAIN
CVS tags: HEAD
fixed section role menu display on Firefox

/*
  This file is part of LONCAPA-Daxe.

  LONCAPA-Daxe is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  LONCAPA-Daxe is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Daxe.  If not, see <http://www.gnu.org/licenses/>.
*/

part of loncapa_daxe;

/**
 * Used for section's h1 (as first child).
 * As the first child in a section, display the class icon and the title in bold.
 */
class H1 extends LCDBlockNoNewline {
  
  H1.fromRef(x.Element elementRef) : super.fromRef(elementRef);
  
  H1.fromNode(x.Node node, DaxeNode parent) : super.fromNode(node, parent);
  
  @override
  bool simpleUIPossible() {
    if (previousSibling != null)
      return false;
    if (attributes.length != 0)
      return false;
    if (firstChild != null && firstChild is! DNText)
      return false;
    if (firstChild != null && firstChild.nextSibling != null)
      return false;
    return true;
  }
  
  @override
  h.Element html() {
    simpleUI = parent is Section && (parent as Section).simpleUI && previousSibling == null;
    if (!simpleUI)
      return super.html();
    setupRestrictions();
    
    h.DivElement div = new h.DivElement();
    div.id = "$id";
    div.classes.add('dn');
    if (!valid)
      div.classes.add('invalid');
    div.classes.add('section-title');
    setStyle(div);
    String cl = parent.getAttribute('class');
    if (cl != null && cl.startsWith('role-')) {
      h.ImageElement roleImg = new h.ImageElement();
      String role = cl.substring(5);
      roleImg.src = "images/section_icons/$role.png";
      roleImg.width = 35;
      roleImg.height = 35;
      roleImg.onMouseDown.listen((h.MouseEvent e) {
        (parent as Section).showRolesMenu(e.client);
        e.preventDefault();
      });
      div.append(roleImg);
    } else if (cl == null) {
      h.SelectElement select = new h.SelectElement();
      (parent as Section).fillSelectWithRoles(select);
      div.append(select);
    }
    if (firstChild == null) {
      div.style.position = 'relative';
      h.SpanElement span = new h.SpanElement();
      span.style.position = 'absolute';
      span.style.color = '#CCC';
      span.appendText(LCDStrings.get('section_title'));
      div.append(span);
    }
    DaxeNode dn = firstChild;
    while (dn != null) {
      div.append(dn.html());
      dn = dn.nextSibling;
    }
    if (lastChild == null || lastChild.nodeType == DaxeNode.TEXT_NODE)
      div.appendText('\n');
    return(div);
  }
  
  @override
  h.Element getHTMLContentsNode() {
    if (!simpleUI)
      return super.getHTMLContentsNode();
    h.Element he = getHTMLNode();
    if (he.nodes.first is h.ImageElement || he.nodes.first is h.SelectElement)
      return he.nodes[1];
    else
      return he.nodes.first;
  }
  
  @override
  void updateHTMLAfterChildrenChange(List<DaxeNode> changed) {
    if (!simpleUI)
      super.updateHTMLAfterChildrenChange(changed);
    updateHTML();
  }
  
  void setupRestrictions() {
    attRefs = [];
    restrictedInserts = ['m','lm','chem','num','i','sup','sub'];
  }
  
  @override
  void setupSimpleUI() {
    simpleUI = true;
    setupRestrictions();
  }
  
  @override
  void attributeDialog([ActionFunction okfct]) {
    // this is called by the contextual menu
    if (simpleUI) {
      AttributeDialog dlg = new AttributeDialog(this, okfct);
      dlg.show();
    } else {
      super.attributeDialog(okfct);
    }
  }
  
  @override
  void updateAttributes() {
    if (!simpleUI)
      super.updateAttributes();
    // currently changing the attributes (even the style attribute)
    // has no effect with simple UI
  }
}

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