3 * @class Roo.bootstrap.form.HtmlEditorToolbar.Standard
4 * @parent Roo.bootstrap.form.HtmlEditor
5 * @extends Roo.bootstrap.nav.Simplebar
11 new Roo.bootstrap.form.HtmlEditor({
14 new Roo.bootstrap.form.HtmlEditorToolbar.Standard({
15 disable : { fonts: 1 , format: 1, ..., ... , ...],
21 * @cfg {Object} disable List of elements to disable..
22 * @cfg {Array} btns List of additional buttons.
26 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
29 Roo.bootstrap.form.HtmlEditorToolbar.Standard = function(config)
32 Roo.apply(this, config);
34 // default disabled, based on 'good practice'..
35 this.disable = this.disable || {};
36 Roo.applyIf(this.disable, {
39 specialElements : true
41 Roo.bootstrap.form.HtmlEditorToolbar.Standard.superclass.constructor.call(this, config);
43 this.editor = config.editor;
44 this.editorcore = config.editor.editorcore;
46 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.btnid; });
48 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
49 // dont call parent... till later.
51 Roo.extend(Roo.bootstrap.form.HtmlEditorToolbar.Standard, Roo.bootstrap.nav.Simplebar, {
61 "h1","h2","h3","h4","h5","h6",
63 "abbr", "acronym", "address", "cite", "samp", "var",
70 onRender : function(ct, position)
72 // Roo.log("Call onRender: " + this.xtype);
74 Roo.bootstrap.form.HtmlEditorToolbar.Standard.superclass.onRender.call(this, ct, position);
76 this.el.dom.style.marginBottom = '0';
78 var editorcore = this.editorcore;
79 var editor= this.editor;
82 var btn = function(id, cmd , toggle, handler, html){
84 var event = toggle ? 'toggle' : 'click';
93 cmd : cmd, // why id || cmd
94 enableToggle: toggle !== false,
96 pressed : toggle ? false : null,
99 a.listeners[toggle ? 'toggle' : 'click'] = function() {
100 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
106 // var cb_box = function...
120 Roo.each(this.formats, function(f) {
121 style.menu.items.push({
124 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
129 editorcore.insertTag(this.tagname);
136 children.push(style);
138 btn('bold', false,true);
139 btn('italic', false,true);
140 btn('align-left', 'justifyleft',true);
141 btn('align-center', 'justifycenter',true);
142 btn('align-right' , 'justifyright',true);
143 btn('link', false, true, function(btn) {
144 var url = this.selectedNode && this.selectedNode.tagName.toUpperCase() == 'A' ?
145 this.selectedNode.getAttribute('href') : '';
147 Roo.bootstrap.MessageBox.show({
148 title : "Add / Edit Link URL",
149 msg : "Enter the URL for the link",
150 buttons: Roo.bootstrap.MessageBox.OKCANCEL,
157 fn: function(pressed, newurl) {
158 if (pressed != 'ok') {
162 this.selectedNode.setAttribute('href', newurl);
165 if(newurl && newurl .match(/http(s):\/\/.+/)) {
166 this.editorcore.relayCmd('createlink', newurl);
171 btn('list','insertunorderedlist',true);
172 btn('list-ol','insertorderedlist',true);
174 btn('pencil', false,true, function(btn){
176 this.toggleSourceEdit(btn.pressed);
179 if (this.editor.btns.length > 0) {
180 for (var i = 0; i<this.editor.btns.length; i++) {
181 children.push(this.editor.btns[i]);
187 this.xtype = 'NavSimplebar'; // why?
189 for(var i=0;i< children.length;i++) {
191 this.buttons.add(this.addxtypeChild(children[i]));
194 this.buildToolbarDelete();
196 editor.on('editorevent', this.updateToolbar, this);
199 buildToolbarDelete : function()
202 /* this.addxtypeChild({
205 cls : 'roo-htmleditor-fill'
208 this.deleteBtn = this.addxtypeChild({
214 click : this.onDelete.createDelegate(this)
217 this.deleteBtn.hide();
222 onBtnClick : function(id)
224 this.editorcore.relayCmd(id);
225 this.editorcore.focus();
229 * Protected method that will not generally be called directly. It triggers
230 * a toolbar update by reading the markup state of the current selection in the editor.
232 updateToolbar: function(editor ,ev, sel){
234 if(!this.editorcore.activated){
235 this.editor.onFirstFocus(); // is this neeed?
239 var btns = this.buttons;
240 var doc = this.editorcore.doc;
241 var hasToggle = false;
242 btns.each(function(e) {
243 if (e.enableToggle && e.cmd) {
244 hasToggle = hasToggle || (['align-left', 'align-right', 'align-center'].indexOf(e.btnid) < 0 && doc.queryCommandState(e.cmd));
245 e.setActive(doc.queryCommandState(e.cmd));
251 (ev.type == 'mouseup' || ev.type == 'click' ) &&
252 ev.target && ev.target.tagName != 'BODY' ) { // && ev.target.tagName == 'IMG') {
253 // they have click on an image...
254 // let's see if we can change the selection...
259 var ans = this.editorcore.getAllAncestors();
261 sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editorcore.doc.body;
262 sel = sel ? sel : this.editorcore.doc.body;
263 sel = sel.tagName.length ? sel : this.editorcore.doc.body;
267 var lastSel = this.selectedNode;
268 this.selectedNode = sel;
270 // ok see if we are editing a block?
273 // you are not actually selecting the block.
274 if (sel && sel.hasAttribute('data-block')) {
276 } else if (sel && sel.closest('[data-block]')) {
277 db = sel.closest('[data-block]');
282 if (db && this.editorcore.enableBlocks) {
283 block = Roo.htmleditor.Block.factory(db);
286 db.className = (db.classList.length > 0 ? db.className + ' ' : '') +
288 sel = this.selectedNode = db;
292 // highlight the 'a'..
293 var tn = sel && sel.tagName.toUpperCase() || '';
294 if (!block && sel && tn != 'A') {
295 var asel = sel.closest('A');
301 btns.get('link').setActive(tn == 'A' && this.selectedNode.hasAttribute('href'));
303 Roo.bootstrap.menu.Manager.hideAll();
306 Array.from(this.editorcore.doc.body.querySelectorAll('.roo-ed-selection')).forEach(function(e) {
307 e.classList.remove('roo-ed-selection');
311 // handle delete button..
312 if (hasToggle || (tn.length && tn == 'BODY')) {
313 this.deleteBtn.hide();
317 this.deleteBtn.show();
321 //this.editorsyncValue();
323 onFirstFocus: function() {
324 this.buttons.each(function(item){
329 onDelete : function()
331 var range = this.editorcore.createRange();
332 var selection = this.editorcore.getSelection();
333 var sn = this.selectedNode;
334 range.setStart(sn,0);
338 if (sn.hasAttribute('data-block')) {
339 var block = Roo.htmleditor.Block.factory(this.selectedNode);
341 sn = block.removeNode();
342 sn.parentNode.removeChild(sn);
343 selection.removeAllRanges();
344 selection.addRange(range);
345 this.updateToolbar(null, null, null);
346 this.editorcore.fireEditorEvent(false);
352 return; // should not really happen..
354 if (sn && sn.tagName == 'BODY') {
357 var stn = sn.childNodes[0] || sn.nextSibling || sn.previousSibling || sn.parentNode;
359 // remove and keep parents.
360 a = new Roo.htmleditor.FilterKeepChildren({tag : false});
363 selection.removeAllRanges();
364 selection.addRange(range);
365 this.editorcore.fireEditorEvent(false);
371 toggleSourceEdit : function(sourceEditMode){
375 Roo.log("disabling buttons");
376 this.buttons.each( function(item){
377 if(item.cmd != 'pencil'){
383 Roo.log("enabling buttons");
384 if(this.editorcore.initialized){
385 this.buttons.each( function(item){
391 Roo.log("calling toggole on editor");
392 // tell the editor that it's been pressed..
393 this.editor.toggleSourceEdit(sourceEditMode);