3 * @class Roo.bootstrap.form.HtmlEditorToolbar.Context
4 * @parent Roo.bootstrap.form.HtmlEditor
5 * @extends Roo.bootstrap.nav.Simplebar
11 new Roo.bootstrap.form.HtmlEditor({
16 disable : { fonts: 1 , format: 1, ..., ... , ...],
29 Roo.bootstrap.form.HtmlEditorToolbar.Context = function(config)
32 Roo.apply(this, config);
35 Roo.bootstrap.form.HtmlEditorToolbar.Context.superclass.constructor.call(this, config);
37 this.editor = config.editor;
38 this.editorcore = config.editor.editorcore;
40 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
44 Roo.bootstrap.form.HtmlEditorToolbar.Context.types = {
59 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
149 name : 'selectoptions',
155 // should we really allow this??
156 // should this just be
173 Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Context, Roo.bootstrap.nav.Simplebar, {
179 button_groups : false, // subtoolbars... - buttson?
180 active_group : false,
182 selectedNode : false,
184 onRender : function(ct, position)
186 // Roo.log("Call onRender: " + this.xtype);
188 this.constructor.superclass.onRender.call(this, ct, position);
194 // disable everything...
195 var ty = this.constructor.superclass.types;
196 this.button_groups = {};
197 // block toolbars are built in updateToolbar when needed.
199 this.button_groups[i] = this.buildToolbar(ty[i],i);
201 this.buildToolbarDelete();
204 this.editor.on('editorevent', this.updateToolbar, this);
207 onFirstFocus: function() {
212 buildToolbarGroup: function(tlist, key )
214 var editor = this.editor;
215 var editorcore = this.editorcore;
220 for (var i = 0; i < tlist.length; i++) {
222 // newer versions will use xtype cfg to create menus.
223 if (typeof(tlist[i].xtype) != 'undefined') {
224 tb[typeof(tlist[i].name)== 'undefined' ? 'add' : 'addField'](Roo.factory(tlist[i]));
233 cls : 'roo-htmleditor-context-label-' + key + '-' + item.name,
238 // add a text entry!?
242 xns : Roo.bootstrap.form,
243 cls : 'roo-htmleditor-context-entry-' + key + '-' + item.name,
244 name: '-roo-edit-' + item.name,
249 'change' : function(f, nv, ov) {
250 tb.selectedNode.setAttribute(f.attrname, nv);
251 editorcore.syncValue();
259 ret.forEach(function(e) {
266 buildToolbarDelete : function()
272 cls : 'roo-htmleditor-fill'
275 this.deleteBtn = this.addxtypeChild({
281 click : this.onDelete.createDelegate(this)
284 this.deleteBtn.hide();
289 onDelete : function()
291 var range = editorcore.createRange();
292 var selection = this.editorcore.getSelection();
293 range.setStart(stn,0);
296 var sn = this.selectedNode;
297 if (sn.hasAttribute('data-block')) {
298 var block = Roo.htmleditor.Block.factory(tb.selectedNode)
301 selection.removeAllRanges();
302 selection.addRange(range);
303 this.updateToolbar(null, null, null);
308 return; // should not really happen..
310 if (sn && sn.tagName == 'BODY') {
313 var stn = sn.childNodes[0] || sn.nextSibling || sn.previousSibling || sn.parentNode;
315 // remove and keep parents.
316 a = new Roo.htmleditor.FilterKeepChildren({tag : false});
319 selection.removeAllRanges();
320 selection.addRange(range);
321 this.updateToolbar(null, null, null);
326 * Protected method that will not generally be called directly. It triggers
327 * a toolbar update by reading the markup state of the current selection in the editor.
329 * Note you can force an update by calling on('editorevent', scope, false)
331 updateToolbar: function(editor ,ev, sel)
333 var ty = this.constructor.superclass.types;
337 ev.stopEvent(); // se if we can stop this looping with mutiple events.
341 // capture mouse up - this is handy for selecting images..
342 // perhaps should go somewhere else...
343 if(!this.editorcore.activated){
344 this.editor.onFirstFocus();
347 //Roo.log(ev ? ev.target : 'NOTARGET');
350 // http://developer.yahoo.com/yui/docs/simple-editor.js.html
351 // selectNode - might want to handle IE?
354 (ev.type == 'mouseup' || ev.type == 'click' ) &&
355 ev.target && ev.target.tagName != 'BODY' ) { // && ev.target.tagName == 'IMG') {
356 // they have click on an image...
357 // let's see if we can change the selection...
360 // this triggers looping?
361 //this.editorcore.selectNode(sel);
365 // this forces an id..
366 Array.from(this.editorcore.doc.body.querySelectorAll('.roo-ed-selection')).forEach(function(e) {
367 e.classList.remove('roo-ed-selection');
370 var ans = this.editorcore.getAllAncestors();
374 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editorcore.doc.body;
375 sel = sel ? sel : this.editorcore.doc.body;
376 sel = sel.tagName.length ? sel : this.editorcore.doc.body;
380 var tn = sel.tagName.toUpperCase();
381 var lastSel = this.selectedNode;
382 this.selectedNode = sel;
385 // ok see if we are editing a block?
388 // you are not actually selecting the block.
389 if (sel && sel.hasAttribute('data-block')) {
391 } else if (sel && sel.closest('[data-block]')) {
393 db = sel.closest('[data-block]');
399 if (db && this.editorcore.enableBlocks) {
400 block = Roo.htmleditor.Block.factory(db);
405 db.classList.length > 0 ? db.className + ' ' : ''
406 ) + 'roo-ed-selection';
408 // since we removed it earlier... its not there..
409 tn = 'BLOCK.' + db.getAttribute('data-block');
411 //this.editorcore.selectNode(db);
412 if (typeof(this.button_groups[tn]) == 'undefined') {
413 this.button_groups[tn] = this.buildBlockToolbar( block );
415 this.selectedNode = db;
416 left_label = block.friendly_name;
417 ans = this.editorcore.getAllAncestors();
424 if (this.active_group.name == tn && lastSel == this.selectedNode && ev !== false) {
425 return; // no change?
428 if (this.active_group) {
429 this.hideActiveGroup();
431 this.showActiveGroup(tn);
434 hideActiveGroup : function()
436 if (this.active_group === false) {
439 this.active_group.forEach(function(e) {
442 this.active_group = false;
444 showActiveGroup : function(tn)
446 if (typeof(this.button_groups[tn]) == 'undefined') {
450 this.active_group = this.button_groups[tn];
453 if (this.selectedNode.hasAttribute('data-block') ) {
454 var block = Roo.htmleditor.Block.factory(this.selectedNode);
455 this.active_group.forEach(function(e) {
456 e.setValue(this.selectedNode.getAttribute(block[e.name]));
462 // based on attributes...
463 this.active_group.forEach(function(e) {
464 e.setValue(this.selectedNode.getAttribute(e.attrname));