2 Roo.namespace('Roo.bootstrap.htmleditor');
4 * @class Roo.bootstrap.HtmlEditorToolbar1
10 new Roo.bootstrap.HtmlEditor({
13 new Roo.bootstrap.HtmlEditorToolbar1({
14 disable : { fonts: 1 , format: 1, ..., ... , ...],
20 * @cfg {Object} disable List of elements to disable..
21 * @cfg {Array} btns List of additional buttons.
25 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
28 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
31 Roo.apply(this, config);
33 // default disabled, based on 'good practice'..
34 this.disable = this.disable || {};
35 Roo.applyIf(this.disable, {
38 specialElements : true
40 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
42 this.editor = config.editor;
43 this.editorcore = config.editor.editorcore;
45 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
47 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
48 // dont call parent... till later.
50 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, html){
80 var event = toggle ? 'toggle' : 'click';
89 enableToggle:toggle !== false,
91 pressed : toggle ? false : null,
94 a.listeners[toggle ? 'toggle' : 'click'] = function() {
95 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
101 // var cb_box = function...
115 Roo.each(this.formats, function(f) {
116 style.menu.items.push({
119 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
124 editorcore.insertTag(this.tagname);
131 children.push(style);
133 btn('bold',false,true);
134 btn('italic',false,true);
135 btn('align-left', 'justifyleft',true);
136 btn('align-center', 'justifycenter',true);
137 btn('align-right' , 'justifyright',true);
138 btn('link', false, false, function(btn) {
139 //Roo.log("create link?");
140 var url = prompt(this.createLinkText, this.defaultLinkValue);
141 if(url && url != 'http:/'+'/'){
142 this.editorcore.relayCmd('createlink', url);
145 btn('list','insertunorderedlist',true);
146 btn('pencil', false,true, function(btn){
148 this.toggleSourceEdit(btn.pressed);
151 if (this.editor.btns.length > 0) {
152 for (var i = 0; i<this.editor.btns.length; i++) {
153 children.push(this.editor.btns[i]);
171 cog.menu.items.push({
179 editorcore.insertTag(this.tagname);
188 this.xtype = 'NavSimplebar';
190 for(var i=0;i< children.length;i++) {
192 this.buttons.add(this.addxtypeChild(children[i]));
196 editor.on('editorevent', this.updateToolbar, this);
198 onBtnClick : function(id)
200 this.editorcore.relayCmd(id);
201 this.editorcore.focus();
205 * Protected method that will not generally be called directly. It triggers
206 * a toolbar update by reading the markup state of the current selection in the editor.
208 updateToolbar: function(){
210 if(!this.editorcore.activated){
211 this.editor.onFirstFocus(); // is this neeed?
215 var btns = this.buttons;
216 var doc = this.editorcore.doc;
217 btns.get('bold').setActive(doc.queryCommandState('bold'));
218 btns.get('italic').setActive(doc.queryCommandState('italic'));
219 //btns.get('underline').setActive(doc.queryCommandState('underline'));
221 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
222 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
223 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
225 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
226 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
229 var ans = this.editorcore.getAllAncestors();
230 if (this.formatCombo) {
233 var store = this.formatCombo.store;
234 this.formatCombo.setValue("");
235 for (var i =0; i < ans.length;i++) {
236 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
238 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
246 // hides menus... - so this cant be on a menu...
247 Roo.bootstrap.MenuMgr.hideAll();
249 Roo.bootstrap.MenuMgr.hideAll();
250 //this.editorsyncValue();
252 onFirstFocus: function() {
253 this.buttons.each(function(item){
257 toggleSourceEdit : function(sourceEditMode){
261 Roo.log("disabling buttons");
262 this.buttons.each( function(item){
263 if(item.cmd != 'pencil'){
269 Roo.log("enabling buttons");
270 if(this.editorcore.initialized){
271 this.buttons.each( function(item){
277 Roo.log("calling toggole on editor");
278 // tell the editor that it's been pressed..
279 this.editor.toggleSourceEdit(sourceEditMode);