1 // <script type="text/javascript">
5 * Copyright(c) 2006-2007, Ext JS, LLC.
11 * @class Roo.form.HtmlEditorToolbar1
16 new Roo.form.HtmlEditor({
19 new Roo.form.HtmlEditorToolbar1({
20 disable : { fonts: 1 , format: 1, ..., ... , ...],
26 * @cfg {Object} disable List of elements to disable..
27 * @cfg {Array} btns List of additional buttons.
31 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
34 Roo.form.HtmlEditor.ToolbarStandard = function(config)
37 Roo.apply(this, config);
38 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
39 // dont call parent... till later.
42 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
50 * @cfg {Object} disable List of toolbar elements to disable
55 * @cfg {Array} fontFamilies An array of available font families
73 // "á" , ?? a acute?
78 "°" // , // degrees
80 // "é" , // e ecute
81 // "ú" , // u ecute?
84 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
85 "input:submit", "input:button", "select", "textarea", "label" ],
88 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
90 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
93 * @cfg {String} defaultFont default font to use.
95 defaultFont: 'tahoma',
102 init : function(editor)
104 this.editor = editor;
107 var fid = editor.frameId;
109 function btn(id, toggle, handler){
110 var xid = fid + '-'+ id ;
114 cls : 'x-btn-icon x-edit-'+id,
115 enableToggle:toggle !== false,
116 scope: editor, // was editor...
117 handler:handler||editor.relayBtnCmd,
118 clickEvent:'mousedown',
119 tooltip: etb.buttonTips[id] || undefined, ///tips ???
126 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
129 tb.el.on('click', function(e){
130 e.preventDefault(); // what does this do?
133 if(!this.disable.font && !Roo.isSafari){
134 /* why no safari for fonts
135 editor.fontSelect = tb.el.createChild({
139 html: editor.createFontOptions()
141 editor.fontSelect.on('change', function(){
142 var font = editor.fontSelect.dom.value;
143 editor.relayCmd('fontname', font);
147 editor.fontSelect.dom,
152 if(!this.disable.formats){
153 this.formatCombo = new Roo.form.ComboBox({
154 store: new Roo.data.SimpleStore({
157 data : this.formats // from states.js
160 //autoCreate : {tag: "div", size: "20"},
165 triggerAction: 'all',
170 'select': function(c, r, i) {
171 editor.insertTag(r.get('tag'));
177 tb.addField(this.formatCombo);
181 if(!this.disable.format){
188 if(!this.disable.fontSize){
193 btn('increasefontsize', false, editor.adjustFont),
194 btn('decreasefontsize', false, editor.adjustFont)
199 if(this.disable.colors){
202 id:editor.frameId +'-forecolor',
203 cls:'x-btn-icon x-edit-forecolor',
204 clickEvent:'mousedown',
205 tooltip: this.buttonTips['forecolor'] || undefined,
207 menu : new Roo.menu.ColorMenu({
212 selectHandler: function(cp, color){
213 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
217 clickEvent:'mousedown'
220 id:editor.frameId +'backcolor',
221 cls:'x-btn-icon x-edit-backcolor',
222 clickEvent:'mousedown',
223 tooltip: this.buttonTips['backcolor'] || undefined,
225 menu : new Roo.menu.ColorMenu({
230 selectHandler: function(cp, color){
232 editor.execCmd('useCSS', false);
233 editor.execCmd('hilitecolor', color);
234 editor.execCmd('useCSS', true);
237 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
238 Roo.isSafari || Roo.isIE ? '#'+color : color);
243 clickEvent:'mousedown'
248 // now add all the items...
251 if(!this.disable.alignments){
255 btn('justifycenter'),
261 if(!this.disable.links){
264 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
268 if(!this.disable.lists){
271 btn('insertorderedlist'),
272 btn('insertunorderedlist')
275 if(!this.disable.sourceEdit){
278 btn('sourceedit', true, function(btn){
279 this.toggleSourceEdit(btn.pressed);
286 // special menu.. - needs to be tidied up..
287 if (!this.disable.special) {
295 for (var i =0; i < this.specialChars.length; i++) {
296 smenu.menu.items.push({
298 text: this.specialChars[i],
299 handler: function(a,b) {
300 editor.insertAtCursor(String.fromCharCode(a.text.replace('&#','').replace(';', '')));
312 for(var i =0; i< this.btns.length;i++) {
313 var b = this.btns[i];
314 b.cls = 'x-edit-none';
323 // disable everything...
325 this.tb.items.each(function(item){
326 if(item.id != editor.frameId+ '-sourceedit'){
330 this.rendered = true;
333 editor.on('editorevent', this.updateToolbar, this);
334 // other toolbars need to implement this..
335 //editor.on('editmodechange', this.updateToolbar, this);
341 * Protected method that will not generally be called directly. It triggers
342 * a toolbar update by reading the markup state of the current selection in the editor.
344 updateToolbar: function(){
346 if(!this.editor.activated){
347 this.editor.onFirstFocus();
351 var btns = this.tb.items.map,
352 doc = this.editor.doc,
353 frameId = this.editor.frameId;
355 if(!this.disable.font && !Roo.isSafari){
357 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
358 if(name != this.fontSelect.dom.value){
359 this.fontSelect.dom.value = name;
363 if(!this.disable.format){
364 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
365 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
366 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
368 if(!this.disable.alignments){
369 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
370 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
371 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
373 if(!Roo.isSafari && !this.disable.lists){
374 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
375 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
378 var ans = this.editor.getAllAncestors();
379 if (this.formatCombo) {
382 var store = this.formatCombo.store;
383 this.formatCombo.setValue("");
384 for (var i =0; i < ans.length;i++) {
385 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), true).length) {
387 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
395 // hides menus... - so this cant be on a menu...
396 Roo.menu.MenuMgr.hideAll();
398 //this.editorsyncValue();
402 createFontOptions : function(){
403 var buf = [], fs = this.fontFamilies, ff, lc;
404 for(var i = 0, len = fs.length; i< len; i++){
406 lc = ff.toLowerCase();
408 '<option value="',lc,'" style="font-family:',ff,';"',
409 (this.defaultFont == lc ? ' selected="true">' : '>'),
417 toggleSourceEdit : function(sourceEditMode){
418 if(sourceEditMode === undefined){
419 sourceEditMode = !this.sourceEditMode;
421 this.sourceEditMode = sourceEditMode === true;
422 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
423 // just toggle the button?
424 if(btn.pressed !== this.editor.sourceEditMode){
425 btn.toggle(this.editor.sourceEditMode);
429 if(this.sourceEditMode){
430 this.tb.items.each(function(item){
431 if(item.cmd != 'sourceedit'){
437 if(this.initialized){
438 this.tb.items.each(function(item){
444 // tell the editor that it's been pressed..
445 this.editor.toggleSourceEdit(sourceEditMode);
449 * Object collection of toolbar tooltips for the buttons in the editor. The key
450 * is the command id associated with that button and the value is a valid QuickTips object.
455 title: 'Bold (Ctrl+B)',
456 text: 'Make the selected text bold.',
457 cls: 'x-html-editor-tip'
460 title: 'Italic (Ctrl+I)',
461 text: 'Make the selected text italic.',
462 cls: 'x-html-editor-tip'
470 title: 'Bold (Ctrl+B)',
471 text: 'Make the selected text bold.',
472 cls: 'x-html-editor-tip'
475 title: 'Italic (Ctrl+I)',
476 text: 'Make the selected text italic.',
477 cls: 'x-html-editor-tip'
480 title: 'Underline (Ctrl+U)',
481 text: 'Underline the selected text.',
482 cls: 'x-html-editor-tip'
486 text: 'Increase the font size.',
487 cls: 'x-html-editor-tip'
490 title: 'Shrink Text',
491 text: 'Decrease the font size.',
492 cls: 'x-html-editor-tip'
495 title: 'Text Highlight Color',
496 text: 'Change the background color of the selected text.',
497 cls: 'x-html-editor-tip'
501 text: 'Change the color of the selected text.',
502 cls: 'x-html-editor-tip'
505 title: 'Align Text Left',
506 text: 'Align text to the left.',
507 cls: 'x-html-editor-tip'
510 title: 'Center Text',
511 text: 'Center text in the editor.',
512 cls: 'x-html-editor-tip'
515 title: 'Align Text Right',
516 text: 'Align text to the right.',
517 cls: 'x-html-editor-tip'
519 insertunorderedlist : {
520 title: 'Bullet List',
521 text: 'Start a bulleted list.',
522 cls: 'x-html-editor-tip'
524 insertorderedlist : {
525 title: 'Numbered List',
526 text: 'Start a numbered list.',
527 cls: 'x-html-editor-tip'
531 text: 'Make the selected text a hyperlink.',
532 cls: 'x-html-editor-tip'
535 title: 'Source Edit',
536 text: 'Switch to source editing mode.',
537 cls: 'x-html-editor-tip'
541 onDestroy : function(){
544 this.tb.items.each(function(item){
546 item.menu.removeAll();
548 item.menu.el.destroy();
556 onFirstFocus: function() {
557 this.tb.items.each(function(item){