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 Roo.htmleditor.Block.factory = function(node)
22 var id = Roo.get(node).id;
23 if (typeof(Roo.htmleditor.Block.cache[id]) != 'undefined') {
24 Roo.htmleditor.Block.cache[id].readElement();
25 return Roo.htmleditor.Block.cache[id];
28 var cls = Roo.htmleditor['Block' + node.getAttribute('data-block')];
29 if (typeof(cls) == 'undefined') {
30 Roo.log("OOps missing block : " + 'Block' + node.getAttribute('data-block'));
33 Roo.htmleditor.Block.cache[id] = new cls({ node: node });
34 return Roo.htmleditor.Block.cache[id]; /// should trigger update element
36 // question goes here... do we need to clear out this cache sometimes?
37 // or show we make it relivant to the htmleditor.
38 Roo.htmleditor.Block.cache = {};
40 Roo.htmleditor.Block.prototype = {
44 // used by context menu
45 friendly_name : 'Image with caption',
49 * Update a node with values from this object
50 * @param {DomElement} node
52 updateElement : function(node)
54 Roo.DomHelper.update(node === undefined ? this.node : node, this.toObject());
57 * convert to plain HTML for calling insertAtCursor..
61 return Roo.DomHelper.markup(this.toObject());
64 * used by readEleemnt to extract data from a node
65 * may need improving as it's pretty basic
67 * @param {DomElement} node
68 * @param {String} tag - tag to find, eg. IMG ?? might be better to use DomQuery ?
69 * @param {String} attribute (use html - for contents, or style for using next param as style)
70 * @param {String} style the style property - eg. text-align
72 getVal : function(node, tag, attr, style)
75 if (tag !== true && n.tagName != tag.toUpperCase()) {
76 // in theory we could do figure[3] << 3rd figure? or some more complex search..?
78 n = node.getElementsByTagName(tag).item(0);
83 if (attr == 'style') {
87 return Roo.get(n).attr(attr);
91 * create a DomHelper friendly object - for use with
92 * Roo.DomHelper.markup / overwrite / etc..
100 * Read a node that has a 'data-block' property - and extract the values from it.
101 * @param {DomElement} node - the node
103 readElement : function(node)