2 Roo.namespace('Roo.bootstrap.htmleditor');
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, {
59 "h1","h2","h3","h4","h5","h6",
61 "abbr", "acronym", "address", "cite", "samp", "var",
65 onRender : function(ct, position)
67 // Roo.log("Call onRender: " + this.xtype);
69 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
71 this.el.dom.style.marginBottom = '0';
73 var editorcore = this.editorcore;
74 var editor= this.editor;
77 var btn = function(id,cmd , toggle, handler){
79 var event = toggle ? 'toggle' : 'click';
87 enableToggle:toggle !== false,
89 pressed : toggle ? false : null,
92 a.listeners[toggle ? 'toggle' : 'click'] = function() {
93 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
111 Roo.each(this.formats, function(f) {
112 style.menu.items.push({
115 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
120 editorcore.insertTag(this.tagname);
127 children.push(style);
129 Roo.log(this.editor.btns.length);
131 if (this.editor.btns.length > 0) {
132 for (var i = 0; i<this.editor.btns.length; i++) {
133 Roo.log(this.editor.btns[i]);
137 btn('bold',false,true);
138 btn('italic',false,true);
139 btn('align-left', 'justifyleft',true);
140 btn('align-center', 'justifycenter',true);
141 btn('align-right' , 'justifyright',true);
142 btn('link', false, false, function(btn) {
143 //Roo.log("create link?");
144 var url = prompt(this.createLinkText, this.defaultLinkValue);
145 if(url && url != 'http:/'+'/'){
146 this.editorcore.relayCmd('createlink', url);
149 btn('list','insertunorderedlist',true);
150 btn('pencil', false,true, function(btn){
152 this.toggleSourceEdit(btn.pressed);
168 cog.menu.items.push({
176 editorcore.insertTag(this.tagname);
185 this.xtype = 'NavSimplebar';
187 for(var i=0;i< children.length;i++) {
189 this.buttons.add(this.addxtypeChild(children[i]));
193 editor.on('editorevent', this.updateToolbar, this);
195 onBtnClick : function(id)
197 this.editorcore.relayCmd(id);
198 this.editorcore.focus();
202 * Protected method that will not generally be called directly. It triggers
203 * a toolbar update by reading the markup state of the current selection in the editor.
205 updateToolbar: function(){
207 if(!this.editorcore.activated){
208 this.editor.onFirstFocus(); // is this neeed?
212 var btns = this.buttons;
213 var doc = this.editorcore.doc;
214 btns.get('bold').setActive(doc.queryCommandState('bold'));
215 btns.get('italic').setActive(doc.queryCommandState('italic'));
216 //btns.get('underline').setActive(doc.queryCommandState('underline'));
218 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
219 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
220 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
222 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
223 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
226 var ans = this.editorcore.getAllAncestors();
227 if (this.formatCombo) {
230 var store = this.formatCombo.store;
231 this.formatCombo.setValue("");
232 for (var i =0; i < ans.length;i++) {
233 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
235 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
243 // hides menus... - so this cant be on a menu...
244 Roo.bootstrap.MenuMgr.hideAll();
246 Roo.bootstrap.MenuMgr.hideAll();
247 //this.editorsyncValue();
249 onFirstFocus: function() {
250 this.buttons.each(function(item){
254 toggleSourceEdit : function(sourceEditMode){
258 Roo.log("disabling buttons");
259 this.buttons.each( function(item){
260 if(item.cmd != 'pencil'){
266 Roo.log("enabling buttons");
267 if(this.editorcore.initialized){
268 this.buttons.each( function(item){
274 Roo.log("calling toggole on editor");
275 // tell the editor that it's been pressed..
276 this.editor.toggleSourceEdit(sourceEditMode);