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 html: this.specialChars[i],
299 handler: function(a,b) {
300 //editor.insertAtCursor(String.fromCharCode(a.text.replace('&#','').replace(';', '')));
301 editor.insertAtCursor(a.html.replace('&#','').replace(';', '')));
313 for(var i =0; i< this.btns.length;i++) {
314 var b = this.btns[i];
315 b.cls = 'x-edit-none';
324 // disable everything...
326 this.tb.items.each(function(item){
327 if(item.id != editor.frameId+ '-sourceedit'){
331 this.rendered = true;
334 editor.on('editorevent', this.updateToolbar, this);
335 // other toolbars need to implement this..
336 //editor.on('editmodechange', this.updateToolbar, this);
342 * Protected method that will not generally be called directly. It triggers
343 * a toolbar update by reading the markup state of the current selection in the editor.
345 updateToolbar: function(){
347 if(!this.editor.activated){
348 this.editor.onFirstFocus();
352 var btns = this.tb.items.map,
353 doc = this.editor.doc,
354 frameId = this.editor.frameId;
356 if(!this.disable.font && !Roo.isSafari){
358 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
359 if(name != this.fontSelect.dom.value){
360 this.fontSelect.dom.value = name;
364 if(!this.disable.format){
365 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
366 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
367 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
369 if(!this.disable.alignments){
370 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
371 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
372 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
374 if(!Roo.isSafari && !this.disable.lists){
375 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
376 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
379 var ans = this.editor.getAllAncestors();
380 if (this.formatCombo) {
383 var store = this.formatCombo.store;
384 this.formatCombo.setValue("");
385 for (var i =0; i < ans.length;i++) {
386 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
388 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
396 // hides menus... - so this cant be on a menu...
397 Roo.menu.MenuMgr.hideAll();
399 //this.editorsyncValue();
403 createFontOptions : function(){
404 var buf = [], fs = this.fontFamilies, ff, lc;
405 for(var i = 0, len = fs.length; i< len; i++){
407 lc = ff.toLowerCase();
409 '<option value="',lc,'" style="font-family:',ff,';"',
410 (this.defaultFont == lc ? ' selected="true">' : '>'),
418 toggleSourceEdit : function(sourceEditMode){
419 if(sourceEditMode === undefined){
420 sourceEditMode = !this.sourceEditMode;
422 this.sourceEditMode = sourceEditMode === true;
423 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
424 // just toggle the button?
425 if(btn.pressed !== this.editor.sourceEditMode){
426 btn.toggle(this.editor.sourceEditMode);
430 if(this.sourceEditMode){
431 this.tb.items.each(function(item){
432 if(item.cmd != 'sourceedit'){
438 if(this.initialized){
439 this.tb.items.each(function(item){
445 // tell the editor that it's been pressed..
446 this.editor.toggleSourceEdit(sourceEditMode);
450 * Object collection of toolbar tooltips for the buttons in the editor. The key
451 * is the command id associated with that button and the value is a valid QuickTips object.
456 title: 'Bold (Ctrl+B)',
457 text: 'Make the selected text bold.',
458 cls: 'x-html-editor-tip'
461 title: 'Italic (Ctrl+I)',
462 text: 'Make the selected text italic.',
463 cls: 'x-html-editor-tip'
471 title: 'Bold (Ctrl+B)',
472 text: 'Make the selected text bold.',
473 cls: 'x-html-editor-tip'
476 title: 'Italic (Ctrl+I)',
477 text: 'Make the selected text italic.',
478 cls: 'x-html-editor-tip'
481 title: 'Underline (Ctrl+U)',
482 text: 'Underline the selected text.',
483 cls: 'x-html-editor-tip'
487 text: 'Increase the font size.',
488 cls: 'x-html-editor-tip'
491 title: 'Shrink Text',
492 text: 'Decrease the font size.',
493 cls: 'x-html-editor-tip'
496 title: 'Text Highlight Color',
497 text: 'Change the background color of the selected text.',
498 cls: 'x-html-editor-tip'
502 text: 'Change the color of the selected text.',
503 cls: 'x-html-editor-tip'
506 title: 'Align Text Left',
507 text: 'Align text to the left.',
508 cls: 'x-html-editor-tip'
511 title: 'Center Text',
512 text: 'Center text in the editor.',
513 cls: 'x-html-editor-tip'
516 title: 'Align Text Right',
517 text: 'Align text to the right.',
518 cls: 'x-html-editor-tip'
520 insertunorderedlist : {
521 title: 'Bullet List',
522 text: 'Start a bulleted list.',
523 cls: 'x-html-editor-tip'
525 insertorderedlist : {
526 title: 'Numbered List',
527 text: 'Start a numbered list.',
528 cls: 'x-html-editor-tip'
532 text: 'Make the selected text a hyperlink.',
533 cls: 'x-html-editor-tip'
536 title: 'Source Edit',
537 text: 'Switch to source editing mode.',
538 cls: 'x-html-editor-tip'
542 onDestroy : function(){
545 this.tb.items.each(function(item){
547 item.menu.removeAll();
549 item.menu.el.destroy();
557 onFirstFocus: function() {
558 this.tb.items.each(function(item){