4 * @class Roo.bootstrap.HtmlEditorToolbar1
9 new Roo.bootstrap.HtmlEditor({
12 new Roo.bootstrap.HtmlEditorToolbar1({
13 disable : { fonts: 1 , format: 1, ..., ... , ...],
19 * @cfg {Object} disable List of elements to disable..
20 * @cfg {Array} btns List of additional buttons.
24 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
27 Roo.bootstrap.HtmlEditor.ToolbarStandard = function(config)
30 Roo.apply(this, config);
32 // default disabled, based on 'good practice'..
33 this.disable = this.disable || {};
34 Roo.applyIf(this.disable, {
37 specialElements : true
39 Roo.bootstrap.HtmlEditor.ToolbarStandard.superclass.constructor.call(this, config);
41 this.editor = config.editor;
42 this.editorcore = config.editor.editorcore;
44 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
46 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
47 // dont call parent... till later.
49 Roo.extend(Roo.bootstrap.HtmlEditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
60 "h1","h2","h3","h4","h5","h6",
62 "abbr", "acronym", "address", "cite", "samp", "var",
66 onRender : function(ct, position)
68 // Roo.log("Call onRender: " + this.xtype);
70 Roo.bootstrap.HtmlEditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
72 this.el.dom.style.marginBottom = '0';
74 var editorcore = this.editorcore;
75 var editor= this.editor;
78 var btn = function(id,cmd , toggle, handler){
80 var event = toggle ? 'toggle' : 'click';
88 enableToggle:toggle !== false,
90 pressed : toggle ? false : null,
93 a.listeners[toggle ? 'toggle' : 'click'] = function() {
94 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
112 Roo.each(this.formats, function(f) {
113 style.menu.items.push({
116 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
121 editorcore.insertTag(this.tagname);
128 children.push(style);
131 btn('bold',false,true);
132 btn('italic',false,true);
133 btn('align-left', 'justifyleft',true);
134 btn('align-center', 'justifycenter',true);
135 btn('align-right' , 'justifyright',true);
136 btn('link', false, false, function(btn) {
137 //Roo.log("create link?");
138 var url = prompt(this.createLinkText, this.defaultLinkValue);
139 if(url && url != 'http:/'+'/'){
140 this.editorcore.relayCmd('createlink', url);
143 btn('list','insertunorderedlist',true);
144 btn('pencil', false,true, function(btn){
147 this.toggleSourceEdit(btn.pressed);
163 cog.menu.items.push({
171 editorcore.insertTag(this.tagname);
180 this.xtype = 'NavSimplebar';
182 for(var i=0;i< children.length;i++) {
184 this.buttons.add(this.addxtypeChild(children[i]));
188 editor.on('editorevent', this.updateToolbar, this);
190 onBtnClick : function(id)
192 this.editorcore.relayCmd(id);
193 this.editorcore.focus();
197 * Protected method that will not generally be called directly. It triggers
198 * a toolbar update by reading the markup state of the current selection in the editor.
200 updateToolbar: function(){
202 if(!this.editorcore.activated){
203 this.editor.onFirstFocus(); // is this neeed?
207 var btns = this.buttons;
208 var doc = this.editorcore.doc;
209 btns.get('bold').setActive(doc.queryCommandState('bold'));
210 btns.get('italic').setActive(doc.queryCommandState('italic'));
211 //btns.get('underline').setActive(doc.queryCommandState('underline'));
213 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
214 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
215 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
217 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
218 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
221 var ans = this.editorcore.getAllAncestors();
222 if (this.formatCombo) {
225 var store = this.formatCombo.store;
226 this.formatCombo.setValue("");
227 for (var i =0; i < ans.length;i++) {
228 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
230 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
238 // hides menus... - so this cant be on a menu...
239 Roo.bootstrap.MenuMgr.hideAll();
241 Roo.bootstrap.MenuMgr.hideAll();
242 //this.editorsyncValue();
244 onFirstFocus: function() {
245 this.buttons.each(function(item){
249 toggleSourceEdit : function(sourceEditMode){
253 Roo.log("disabling buttons");
254 this.buttons.each( function(item){
255 if(item.cmd != 'pencil'){
261 Roo.log("enabling buttons");
262 if(this.editorcore.initialized){
263 this.buttons.each( function(item){
269 Roo.log("calling toggole on editor");
270 // tell the editor that it's been pressed..
271 this.editor.toggleSourceEdit(sourceEditMode);