1 // <script type="text/javascript">
5 * Copyright(c) 2006-2007, Ext JS, LLC.
12 * @class Roo.form.HtmlEditor.ToolbarContext
17 new Roo.form.HtmlEditor({
20 new Roo.form.HtmlEditor.ToolbarStandard(),
21 new Roo.form.HtmlEditor.ToolbarContext()
26 * @config : {Object} disable List of elements to disable.. (not done yet.)
31 Roo.form.HtmlEditor.ToolbarContext = function(config)
34 Roo.apply(this, config);
35 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
36 // dont call parent... till later.
38 Roo.form.HtmlEditor.ToolbarContext.types = {
50 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
112 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
117 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
181 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
189 * @cfg {Object} disable List of toolbar elements to disable
198 init : function(editor)
200 this.editor = editor;
203 var fid = editor.frameId;
205 function btn(id, toggle, handler){
206 var xid = fid + '-'+ id ;
210 cls : 'x-btn-icon x-edit-'+id,
211 enableToggle:toggle !== false,
212 scope: editor, // was editor...
213 handler:handler||editor.relayBtnCmd,
214 clickEvent:'mousedown',
215 tooltip: etb.buttonTips[id] || undefined, ///tips ???
219 // create a new element.
220 var wdiv = editor.wrap.createChild({
222 }, editor.wrap.dom.firstChild.nextSibling, true);
224 // can we do this more than once??
229 // disable everything...
230 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
234 this.toolbars[i] = this.buildToolbar(ty[i],i);
236 this.tb = this.toolbars.BODY;
240 this.rendered = true;
243 editor.on('editorevent', this.updateToolbar, this);
244 // other toolbars need to implement this..
245 //editor.on('editmodechange', this.updateToolbar, this);
251 * Protected method that will not generally be called directly. It triggers
252 * a toolbar update by reading the markup state of the current selection in the editor.
254 updateToolbar: function(){
256 if(!this.editor.activated){
257 this.editor.onFirstFocus();
262 var ans = this.editor.getAllAncestors();
265 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
266 var sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editor.doc.body;
267 sel = sel ? sel : this.editor.doc.body;
268 sel = sel.tagName.length ? sel : this.editor.doc.body;
269 var tn = sel.tagName.toUpperCase();
270 sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
271 tn = sel.tagName.toUpperCase();
272 if (this.tb.name == tn) {
276 ///console.log("show: " + tn);
277 this.tb = this.toolbars[tn];
279 this.tb.fields.each(function(e) {
280 e.setValue(sel.getAttribute(e.name));
282 this.tb.selectedNode = sel;
285 Roo.menu.MenuMgr.hideAll();
287 //this.editorsyncValue();
292 onDestroy : function(){
295 this.tb.items.each(function(item){
297 item.menu.removeAll();
299 item.menu.el.destroy();
307 onFirstFocus: function() {
308 // need to do this for all the toolbars..
309 this.tb.items.each(function(item){
313 buildToolbar: function(tlist, nm)
315 var editor = this.editor;
316 // create a new element.
317 var wdiv = editor.wrap.createChild({
319 }, editor.wrap.dom.firstChild.nextSibling, true);
322 var tb = new Roo.Toolbar(wdiv);
323 tb.add(nm+ ": ");
324 for (var i in tlist) {
326 tb.add(item.title + ": ");
331 tb.addField( new Roo.form.ComboBox({
332 store: new Roo.data.SimpleStore({
335 data : item.opts // from states.js
342 triggerAction: 'all',
345 width: item.width ? item.width : 130,
347 'select': function(c, r, i) {
348 tb.selectedNode.setAttribute(c.name, r.get('val'));
359 tb.addField( new Roo.form.TextField({
367 tb.addField( new Roo.form.TextField({
373 'change' : function(f, nv, ov) {
374 tb.selectedNode.setAttribute(f.name, nv);
380 tb.el.on('click', function(e){
381 e.preventDefault(); // what does this do?
383 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
386 // dont need to disable them... as they will get hidden