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?
87 handler: function(a,b) {
88 // should we show a dialog.?
89 editor.insertAtCursor('<table><<tr><td></td></tr></table>');
96 handler: function(a,b) {
97 // should we show a dialog.?
98 editor.insertAtCursor('<img src="about:blank"/>');
109 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
110 "input:submit", "input:button", "select", "textarea", "label" ],
113 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
115 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
118 * @cfg {String} defaultFont default font to use.
120 defaultFont: 'tahoma',
127 init : function(editor)
129 this.editor = editor;
132 var fid = editor.frameId;
134 function btn(id, toggle, handler){
135 var xid = fid + '-'+ id ;
139 cls : 'x-btn-icon x-edit-'+id,
140 enableToggle:toggle !== false,
141 scope: editor, // was editor...
142 handler:handler||editor.relayBtnCmd,
143 clickEvent:'mousedown',
144 tooltip: etb.buttonTips[id] || undefined, ///tips ???
151 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
154 tb.el.on('click', function(e){
155 e.preventDefault(); // what does this do?
158 if(!this.disable.font && !Roo.isSafari){
159 /* why no safari for fonts
160 editor.fontSelect = tb.el.createChild({
164 html: editor.createFontOptions()
166 editor.fontSelect.on('change', function(){
167 var font = editor.fontSelect.dom.value;
168 editor.relayCmd('fontname', font);
172 editor.fontSelect.dom,
177 if(!this.disable.formats){
178 this.formatCombo = new Roo.form.ComboBox({
179 store: new Roo.data.SimpleStore({
182 data : this.formats // from states.js
185 //autoCreate : {tag: "div", size: "20"},
190 triggerAction: 'all',
195 'select': function(c, r, i) {
196 editor.insertTag(r.get('tag'));
202 tb.addField(this.formatCombo);
206 if(!this.disable.format){
213 if(!this.disable.fontSize){
218 btn('increasefontsize', false, editor.adjustFont),
219 btn('decreasefontsize', false, editor.adjustFont)
224 if(this.disable.colors){
227 id:editor.frameId +'-forecolor',
228 cls:'x-btn-icon x-edit-forecolor',
229 clickEvent:'mousedown',
230 tooltip: this.buttonTips['forecolor'] || undefined,
232 menu : new Roo.menu.ColorMenu({
237 selectHandler: function(cp, color){
238 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
242 clickEvent:'mousedown'
245 id:editor.frameId +'backcolor',
246 cls:'x-btn-icon x-edit-backcolor',
247 clickEvent:'mousedown',
248 tooltip: this.buttonTips['backcolor'] || undefined,
250 menu : new Roo.menu.ColorMenu({
255 selectHandler: function(cp, color){
257 editor.execCmd('useCSS', false);
258 editor.execCmd('hilitecolor', color);
259 editor.execCmd('useCSS', true);
262 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
263 Roo.isSafari || Roo.isIE ? '#'+color : color);
268 clickEvent:'mousedown'
273 // now add all the items...
276 if(!this.disable.alignments){
280 btn('justifycenter'),
286 if(!this.disable.links){
289 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
293 if(!this.disable.lists){
296 btn('insertorderedlist'),
297 btn('insertunorderedlist')
300 if(!this.disable.sourceEdit){
303 btn('sourceedit', true, function(btn){
304 this.toggleSourceEdit(btn.pressed);
311 // special menu.. - needs to be tidied up..
312 if (!this.disable.special) {
320 for (var i =0; i < this.specialChars.length; i++) {
321 smenu.menu.items.push({
323 html: this.specialChars[i],
324 handler: function(a,b) {
325 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
338 for(var i =0; i< this.btns.length;i++) {
339 var b = this.btns[i];
340 b.cls = 'x-edit-none';
349 // disable everything...
351 this.tb.items.each(function(item){
352 if(item.id != editor.frameId+ '-sourceedit'){
356 this.rendered = true;
359 editor.on('editorevent', this.updateToolbar, this);
360 // other toolbars need to implement this..
361 //editor.on('editmodechange', this.updateToolbar, this);
367 * Protected method that will not generally be called directly. It triggers
368 * a toolbar update by reading the markup state of the current selection in the editor.
370 updateToolbar: function(){
372 if(!this.editor.activated){
373 this.editor.onFirstFocus();
377 var btns = this.tb.items.map,
378 doc = this.editor.doc,
379 frameId = this.editor.frameId;
381 if(!this.disable.font && !Roo.isSafari){
383 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
384 if(name != this.fontSelect.dom.value){
385 this.fontSelect.dom.value = name;
389 if(!this.disable.format){
390 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
391 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
392 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
394 if(!this.disable.alignments){
395 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
396 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
397 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
399 if(!Roo.isSafari && !this.disable.lists){
400 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
401 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
404 var ans = this.editor.getAllAncestors();
405 if (this.formatCombo) {
408 var store = this.formatCombo.store;
409 this.formatCombo.setValue("");
410 for (var i =0; i < ans.length;i++) {
411 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
413 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
421 // hides menus... - so this cant be on a menu...
422 Roo.menu.MenuMgr.hideAll();
424 //this.editorsyncValue();
428 createFontOptions : function(){
429 var buf = [], fs = this.fontFamilies, ff, lc;
430 for(var i = 0, len = fs.length; i< len; i++){
432 lc = ff.toLowerCase();
434 '<option value="',lc,'" style="font-family:',ff,';"',
435 (this.defaultFont == lc ? ' selected="true">' : '>'),
443 toggleSourceEdit : function(sourceEditMode){
444 if(sourceEditMode === undefined){
445 sourceEditMode = !this.sourceEditMode;
447 this.sourceEditMode = sourceEditMode === true;
448 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
449 // just toggle the button?
450 if(btn.pressed !== this.editor.sourceEditMode){
451 btn.toggle(this.editor.sourceEditMode);
455 if(this.sourceEditMode){
456 this.tb.items.each(function(item){
457 if(item.cmd != 'sourceedit'){
463 if(this.initialized){
464 this.tb.items.each(function(item){
470 // tell the editor that it's been pressed..
471 this.editor.toggleSourceEdit(sourceEditMode);
475 * Object collection of toolbar tooltips for the buttons in the editor. The key
476 * is the command id associated with that button and the value is a valid QuickTips object.
481 title: 'Bold (Ctrl+B)',
482 text: 'Make the selected text bold.',
483 cls: 'x-html-editor-tip'
486 title: 'Italic (Ctrl+I)',
487 text: 'Make the selected text italic.',
488 cls: 'x-html-editor-tip'
496 title: 'Bold (Ctrl+B)',
497 text: 'Make the selected text bold.',
498 cls: 'x-html-editor-tip'
501 title: 'Italic (Ctrl+I)',
502 text: 'Make the selected text italic.',
503 cls: 'x-html-editor-tip'
506 title: 'Underline (Ctrl+U)',
507 text: 'Underline the selected text.',
508 cls: 'x-html-editor-tip'
512 text: 'Increase the font size.',
513 cls: 'x-html-editor-tip'
516 title: 'Shrink Text',
517 text: 'Decrease the font size.',
518 cls: 'x-html-editor-tip'
521 title: 'Text Highlight Color',
522 text: 'Change the background color of the selected text.',
523 cls: 'x-html-editor-tip'
527 text: 'Change the color of the selected text.',
528 cls: 'x-html-editor-tip'
531 title: 'Align Text Left',
532 text: 'Align text to the left.',
533 cls: 'x-html-editor-tip'
536 title: 'Center Text',
537 text: 'Center text in the editor.',
538 cls: 'x-html-editor-tip'
541 title: 'Align Text Right',
542 text: 'Align text to the right.',
543 cls: 'x-html-editor-tip'
545 insertunorderedlist : {
546 title: 'Bullet List',
547 text: 'Start a bulleted list.',
548 cls: 'x-html-editor-tip'
550 insertorderedlist : {
551 title: 'Numbered List',
552 text: 'Start a numbered list.',
553 cls: 'x-html-editor-tip'
557 text: 'Make the selected text a hyperlink.',
558 cls: 'x-html-editor-tip'
561 title: 'Source Edit',
562 text: 'Switch to source editing mode.',
563 cls: 'x-html-editor-tip'
567 onDestroy : function(){
570 this.tb.items.each(function(item){
572 item.menu.removeAll();
574 item.menu.el.destroy();
582 onFirstFocus: function() {
583 this.tb.items.each(function(item){