2 Roo.namespace('Roo.bootstrap.htmleditor');
4 * @class Roo.bootstrap.HtmlEditorToolbar1
5 * @extends Roo.bootstrap.nav.Simplebar
11 new Roo.bootstrap.HtmlEditor({
14 new Roo.bootstrap.HtmlEditorToolbar1({
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.htmleditor.ToolbarStandard = 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.htmleditor.ToolbarStandard.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.cmd; });
48 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
49 // dont call parent... till later.
51 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.nav.Simplebar, {
61 "h1","h2","h3","h4","h5","h6",
63 "abbr", "acronym", "address", "cite", "samp", "var",
67 onRender : function(ct, position)
69 // Roo.log("Call onRender: " + this.xtype);
71 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
73 this.el.dom.style.marginBottom = '0';
75 var editorcore = this.editorcore;
76 var editor= this.editor;
79 var btn = function(id,cmd , toggle, handler, html){
81 var event = toggle ? 'toggle' : 'click';
90 enableToggle:toggle !== false,
92 pressed : toggle ? false : null,
95 a.listeners[toggle ? 'toggle' : 'click'] = function() {
96 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
102 // var cb_box = function...
116 Roo.each(this.formats, function(f) {
117 style.menu.items.push({
120 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
125 editorcore.insertTag(this.tagname);
132 children.push(style);
134 btn('bold',false,true);
135 btn('italic',false,true);
136 btn('align-left', 'justifyleft',true);
137 btn('align-center', 'justifycenter',true);
138 btn('align-right' , 'justifyright',true);
139 btn('link', false, false, function(btn) {
140 //Roo.log("create link?");
141 var url = prompt(this.createLinkText, this.defaultLinkValue);
142 if(url && url != 'http:/'+'/'){
143 this.editorcore.relayCmd('createlink', url);
146 btn('list','insertunorderedlist',true);
147 btn('pencil', false,true, function(btn){
149 this.toggleSourceEdit(btn.pressed);
152 if (this.editor.btns.length > 0) {
153 for (var i = 0; i<this.editor.btns.length; i++) {
154 children.push(this.editor.btns[i]);
172 cog.menu.items.push({
180 editorcore.insertTag(this.tagname);
189 this.xtype = 'NavSimplebar';
191 for(var i=0;i< children.length;i++) {
193 this.buttons.add(this.addxtypeChild(children[i]));
197 editor.on('editorevent', this.updateToolbar, this);
199 onBtnClick : function(id)
201 this.editorcore.relayCmd(id);
202 this.editorcore.focus();
206 * Protected method that will not generally be called directly. It triggers
207 * a toolbar update by reading the markup state of the current selection in the editor.
209 updateToolbar: function(){
211 if(!this.editorcore.activated){
212 this.editor.onFirstFocus(); // is this neeed?
216 var btns = this.buttons;
217 var doc = this.editorcore.doc;
218 btns.get('bold').setActive(doc.queryCommandState('bold'));
219 btns.get('italic').setActive(doc.queryCommandState('italic'));
220 //btns.get('underline').setActive(doc.queryCommandState('underline'));
222 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
223 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
224 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
226 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
227 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
230 var ans = this.editorcore.getAllAncestors();
231 if (this.formatCombo) {
234 var store = this.formatCombo.store;
235 this.formatCombo.setValue("");
236 for (var i =0; i < ans.length;i++) {
237 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
239 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
247 // hides menus... - so this cant be on a menu...
248 Roo.bootstrap.MenuMgr.hideAll();
250 Roo.bootstrap.menu.Manager.hideAll();
251 //this.editorsyncValue();
253 onFirstFocus: function() {
254 this.buttons.each(function(item){
258 toggleSourceEdit : function(sourceEditMode){
262 Roo.log("disabling buttons");
263 this.buttons.each( function(item){
264 if(item.cmd != 'pencil'){
270 Roo.log("enabling buttons");
271 if(this.editorcore.initialized){
272 this.buttons.each( function(item){
278 Roo.log("calling toggole on editor");
279 // tell the editor that it's been pressed..
280 this.editor.toggleSourceEdit(sourceEditMode);