1 /** 2 * @fileoverview A tag-name UI component used by xrx.richxml. 3 */ 4 goog.provide('xrx.richxml.tagname'); 5 6 7 8 goog.require('goog.dom'); 9 goog.require('goog.style'); 10 goog.require('xrx.i18n'); 11 goog.require('xrx.richxml'); 12 13 14 15 /** 16 * Constructs a tag-name UI component.s 17 * The tag-name is shown when the cursor moves near to a 18 * tag in a xrx.richxml component. 19 * @constructor 20 */ 21 xrx.richxml.tagname = function(element) { 22 23 24 25 this.element_ = element; 26 27 28 29 this.createDom(); 30 }; 31 32 33 34 /** 35 * Lazy creation. We first search for a element with 36 * id 'xrx-tagname'. If not found, we create a DIV and 37 * append it to HTML BODY. 38 */ 39 xrx.richxml.tagname.prototype.createDom = function() { 40 41 if (!this.element_) { 42 this.element_ = goog.dom.getElement('xrx-tagname'); 43 } 44 if (!this.element_) { 45 this.element_ = goog.dom.createElement('div'); 46 goog.dom.append(goog.dom.getElementsByTagNameAndClass('body')[0], 47 this.element_); 48 } 49 }; 50 51 52 53 /** 54 * Shows the tag-name control. 55 * @param {!xrx.node.Element} 56 */ 57 xrx.richxml.tagname.prototype.show = function(node) { 58 var span = goog.dom.createElement('span'); 59 var text = xrx.i18n.translate(node); 60 goog.dom.setTextContent(span, text); 61 62 this.hide(); 63 goog.dom.append(this.element_, span); 64 }; 65 66 67 68 /** 69 * Hides the tag-name control. 70 */ 71 xrx.richxml.tagname.prototype.hide = function() { 72 goog.dom.removeChildren(this.element_); 73 }; 74