4 * @class Roo.htmleditor.BlockFigure
5 * Block that has an image and a figcaption
6 * @cfg {String} image_src the url for the image
7 * @cfg {String} align (left|right) alignment for the block default left
8 * @cfg {String} caption the text to appear below (and in the alt tag)
9 * @cfg {String} caption_display (block|none) display or not the caption
10 * @cfg {String|number} image_width the width of the image number or %?
11 * @cfg {String|number} image_height the height of the image number or %?
14 * Create a new Filter.
15 * @param {Object} config Configuration options
18 Roo.htmleditor.BlockFigure = function(cfg)
21 this.readElement(cfg.node);
22 this.updateElement(cfg.node);
26 Roo.extend(Roo.htmleditor.BlockFigure, Roo.htmleditor.Block, {
33 caption_display : 'block',
39 // margin: '2%', not used
41 text_align: 'left', // (left|right) alignment for the text caption default left. - not used at present
44 // used by context menu
45 friendly_name : 'Image with caption',
46 deleteTitle : "Delete Image and Caption",
48 contextMenu : function(toolbar)
51 var block = function() {
52 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
56 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
58 var syncValue = toolbar.editorcore.syncValue;
66 xns : rooui.Toolbar //Boostrap?
70 text: 'Change Image URL',
73 click: function (btn, state)
78 title : "Image Source URL",
79 msg : "Enter the url for the image",
80 buttons: Roo.MessageBox.OKCANCEL,
81 fn: function(btn, val){
88 toolbar.editorcore.onEditorEvent();
92 //multiline: multiline,
103 text: 'Change Link URL',
106 click: function (btn, state)
110 Roo.MessageBox.show({
112 msg : "Enter the url for the link - leave blank to have no link",
113 buttons: Roo.MessageBox.OKCANCEL,
114 fn: function(btn, val){
121 toolbar.editorcore.onEditorEvent();
125 //multiline: multiline,
135 text: 'Show Video URL',
138 click: function (btn, state)
140 Roo.MessageBox.alert("Video URL",
141 block().video_url == '' ? 'This image is not linked ot a video' :
142 'The image is linked to: <a target="_new" href="' + block().video_url + '">' + block().video_url + '</a>');
152 xns : rooui.Toolbar //Boostrap?
157 displayField : 'val',
160 triggerAction : 'all',
166 select : function (combo, r, index)
168 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
170 b.width = r.get('val');
173 toolbar.editorcore.onEditorEvent();
178 xtype : 'SimpleStore',
191 xns : rooui.Toolbar //Boostrap?
196 displayField : 'val',
199 triggerAction : 'all',
205 select : function (combo, r, index)
207 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
209 b.align = r.get('val');
212 toolbar.editorcore.onEditorEvent();
217 xtype : 'SimpleStore',
231 text: 'Hide Caption',
232 name : 'caption_display',
235 setValue : function(v) {
236 this.toggle(v == 'block' ? false : true);
239 toggle: function (btn, state)
242 b.caption_display = b.caption_display == 'block' ? 'none' : 'block';
243 this.setText(b.caption_display == 'block' ? "Hide Caption" : "Show Caption");
246 toolbar.editorcore.selectNode(toolbar.tb.selectedNode);
247 toolbar.editorcore.onEditorEvent();
256 * create a DomHelper friendly object - for use with
257 * Roo.DomHelper.markup / overwrite / etc..
259 toObject : function()
261 var d = document.createElement('div');
262 d.innerHTML = this.caption;
264 var m = this.width == '50%' && this.align == 'center' ? '0 auto' : 0;
268 contenteditable : 'false',
269 src : this.image_src,
270 alt : d.innerText.replace(/\n/g, " ").replace(/\s+/g, ' ').trim(), // removeHTML and reduce spaces..
280 '<div class="{0}" width="420" height="315" src="{1}" frameborder="0" allowfullscreen>' +
282 '<img class="{0}-thumbnail" src="{3}/Images/{4}/{5}#image-{4}" />' +
287 if (this.href.length > 0) {
291 contenteditable : 'true',
299 if (this.video_url.length > 0) {
304 allowfullscreen : true,
305 width : 420, // these are for video tricks - that we replace the outer
307 src : this.video_url,
313 // we remove caption totally if its hidden... - will delete data.. but otherwise we end up with fake caption
314 var captionhtml = this.caption_display == 'hidden' ? '' : (this.caption.length ? this.caption : "Caption");
318 'data-block' : 'Figure',
319 contenteditable : 'false',
324 'max-width': this.width,
340 'text-align': 'left',
341 'margin-top' : '16px',
342 'font-size' : '16px',
343 'line-height' : '24px',
344 display : this.caption_display
346 cls : this.cls.length > 0 ? (this.cls + '-thumbnail' ) : '',
349 // we can not rely on yahoo syndication to use CSS elements - so have to use '<i>' to encase stuff.
351 contenteditable : true,
362 readElement : function(node)
364 // this should not really come from the link...
365 this.video_url = this.getVal(node, 'div', 'src');
366 this.cls = this.getVal(node, 'div', 'class');
367 this.href = this.getVal(node, 'a', 'href');
370 this.image_src = this.getVal(node, 'img', 'src');
372 this.align = this.getVal(node, 'figure', 'align');
373 this.caption = this.getVal(node, 'figcaption', 'html');
375 if (this.caption.trim().match(/^<i[^>]*>/i)) {
376 this.caption = this.caption.trim().replace(/^<i[^>]*>/i, '').replace(/^<\/i>$/i, '');
378 this.caption_display = this.getVal(node, 'figcaption', 'style', 'display');
379 //this.text_align = this.getVal(node, 'figcaption', 'style','text-align');
380 this.width = this.getVal(node, 'figure', 'style', 'max-width');
381 //this.margin = this.getVal(node, 'figure', 'style', 'margin');
384 removeNode : function()