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) {
145 Roo.bootstrap.MessageBox.prompt(
146 "Add / Edit Link URL",
147 "Enter the URL for the link",
148 function(pressed, url) {
149 if (pressed != 'ok') {
153 if(url && url.match(/http(s):\/\/.+/)) {
154 this.editorcore.relayCmd('createlink', url);
159 btn('list','insertunorderedlist',true);
160 btn('list-ol','insertorderedlist',true);
162 btn('pencil', false,true, function(btn){
164 this.toggleSourceEdit(btn.pressed);
167 if (this.editor.btns.length > 0) {
168 for (var i = 0; i<this.editor.btns.length; i++) {
169 children.push(this.editor.btns[i]);
175 this.xtype = 'NavSimplebar'; // why?
177 for(var i=0;i< children.length;i++) {
179 this.buttons.add(this.addxtypeChild(children[i]));
182 this.buildToolbarDelete();
184 editor.on('editorevent', this.updateToolbar, this);
187 buildToolbarDelete : function()
190 /* this.addxtypeChild({
193 cls : 'roo-htmleditor-fill'
196 this.deleteBtn = this.addxtypeChild({
202 click : this.onDelete.createDelegate(this)
205 this.deleteBtn.hide();
210 onBtnClick : function(id)
212 this.editorcore.relayCmd(id);
213 this.editorcore.focus();
217 * Protected method that will not generally be called directly. It triggers
218 * a toolbar update by reading the markup state of the current selection in the editor.
220 updateToolbar: function(editor ,ev, sel){
222 if(!this.editorcore.activated){
223 this.editor.onFirstFocus(); // is this neeed?
227 var btns = this.buttons;
228 var doc = this.editorcore.doc;
229 var hasToggle = false;
230 btns.each(function(e) {
231 if (e.enableToggle && e.cmd) {
232 hasToggle = hasToggle || doc.queryCommandState(e.cmd);
233 e.setActive(doc.queryCommandState(e.cmd));
239 (ev.type == 'mouseup' || ev.type == 'click' ) &&
240 ev.target && ev.target.tagName != 'BODY' ) { // && ev.target.tagName == 'IMG') {
241 // they have click on an image...
242 // let's see if we can change the selection...
246 var tn = sel && sel.tagName.toUpperCase() || '';
247 if (sel && tn != 'A') {
248 var asel = sel.closest('A');
254 btns.get('link').setActive(tn == 'A');
256 Roo.bootstrap.menu.Manager.hideAll();
260 Array.from(this.editorcore.doc.body.querySelectorAll('.roo-ed-selection')).forEach(function(e) {
261 e.classList.remove('roo-ed-selection');
265 // handle delete button..
266 if (hasToggle || (tn.length && tn == 'BODY')) {
267 this.deleteBtn.hide();
271 this.deleteBtn.show();
275 //this.editorsyncValue();
277 onFirstFocus: function() {
278 this.buttons.each(function(item){
283 onDelete : function()
285 var range = this.editorcore.createRange();
286 var selection = this.editorcore.getSelection();
287 var sn = this.selectedNode;
288 range.setStart(sn,0);
292 if (sn.hasAttribute('data-block')) {
293 var block = Roo.htmleditor.Block.factory(tb.selectedNode);
296 selection.removeAllRanges();
297 selection.addRange(range);
298 this.updateToolbar(null, null, null);
303 return; // should not really happen..
305 if (sn && sn.tagName == 'BODY') {
308 var stn = sn.childNodes[0] || sn.nextSibling || sn.previousSibling || sn.parentNode;
310 // remove and keep parents.
311 a = new Roo.htmleditor.FilterKeepChildren({tag : false});
314 selection.removeAllRanges();
315 selection.addRange(range);
316 this.editorcore.fireEditorEvent(false);
322 toggleSourceEdit : function(sourceEditMode){
326 Roo.log("disabling buttons");
327 this.buttons.each( function(item){
328 if(item.cmd != 'pencil'){
334 Roo.log("enabling buttons");
335 if(this.editorcore.initialized){
336 this.buttons.each( function(item){
342 Roo.log("calling toggole on editor");
343 // tell the editor that it's been pressed..
344 this.editor.toggleSourceEdit(sourceEditMode);