3 * @class Roo.htmleditor.Block
4 * Base class for html editor blocks - do not use it directly .. extend it..
5 * @cfg {DomElement} node The node to apply stuff to.
6 * @cfg {String} friendly_name the name that appears in the context bar about this block
7 * @cfg {Object} Context menu - see Roo.form.HtmlEditor.ToolbarContext
10 * Create a new Filter.
11 * @param {Object} config Configuration options
14 Roo.htmleditor.Block = function(cfg)
16 // do nothing .. should not be called really.
19 * factory method to get the block from an element (using cache if necessary)
21 * @param {HtmlElement} the dom element
23 Roo.htmleditor.Block.factory = function(node)
25 var cc = Roo.htmleditor.Block.cache;
26 var id = Roo.get(node).id;
27 if (typeof(cc[id]) != 'undefined' && (!cc[id].node || cc[id].node.closest('body'))) {
28 Roo.htmleditor.Block.cache[id].readElement(node);
29 return Roo.htmleditor.Block.cache[id];
31 var db = node.getAttribute('data-block');
33 db = node.nodeName.toLowerCase().toUpperCaseFirst();
35 var cls = Roo.htmleditor['Block' + db];
36 if (typeof(cls) == 'undefined') {
37 //Roo.log(node.getAttribute('data-block'));
38 Roo.log("OOps missing block : " + 'Block' + db);
41 Roo.htmleditor.Block.cache[id] = new cls({ node: node });
42 return Roo.htmleditor.Block.cache[id]; /// should trigger update element
46 * initalize all Elements from content that are 'blockable'
48 * @param the body element
50 Roo.htmleditor.Block.initAll = function(body, type)
52 if (typeof(type) == 'undefined') {
53 var ia = Roo.htmleditor.Block.initAll;
59 Roo.each(Roo.get(body).query(type), function(e) {
60 Roo.htmleditor.Block.factory(e);
63 // question goes here... do we need to clear out this cache sometimes?
64 // or show we make it relivant to the htmleditor.
65 Roo.htmleditor.Block.cache = {};
67 Roo.htmleditor.Block.prototype = {
71 // used by context menu
72 friendly_name : 'Based Block',
74 // text for button to delete this element
79 * Update a node with values from this object
80 * @param {DomElement} node
82 updateElement : function(node)
84 Roo.DomHelper.update(node === undefined ? this.node : node, this.toObject());
87 * convert to plain HTML for calling insertAtCursor..
91 return Roo.DomHelper.markup(this.toObject());
94 * used by readEleemnt to extract data from a node
95 * may need improving as it's pretty basic
97 * @param {DomElement} node
98 * @param {String} tag - tag to find, eg. IMG ?? might be better to use DomQuery ?
99 * @param {String} attribute (use html - for contents, style for using next param as style, or false to return the node)
100 * @param {String} style the style property - eg. text-align
102 getVal : function(node, tag, attr, style)
105 if (tag !== true && n.tagName != tag.toUpperCase()) {
106 // in theory we could do figure[3] << 3rd figure? or some more complex search..?
108 n = node.getElementsByTagName(tag).item(0);
113 if (attr === false) {
116 if (attr == 'html') {
119 if (attr == 'style') {
120 return n.style[style];
123 return n.hasAttribute(attr) ? n.getAttribute(attr) : '';
127 * create a DomHelper friendly object - for use with
128 * Roo.DomHelper.markup / overwrite / etc..
131 toObject : function()
136 * Read a node that has a 'data-block' property - and extract the values from it.
137 * @param {DomElement} node - the node
139 readElement : function(node)