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);
39 // default disabled, based on 'good practice'..
40 this.disable = this.disable || {};
41 Roo.applyIf(this.disable, {
44 specialElements : true
48 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
49 // dont call parent... till later.
52 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
60 * @cfg {Object} disable List of toolbar elements to disable
65 * @cfg {Array} fontFamilies An array of available font families
83 // "á" , ?? a acute?
88 "°" // , // degrees
90 // "é" , // e ecute
91 // "ú" , // u ecute?
99 ihtml : '<table><tr><td>Cell</td></tr></table>'
103 text: "Insert Image",
106 ihtml : '<img src="about:blank"/>'
115 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
116 "input:submit", "input:button", "select", "textarea", "label" ],
119 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
121 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
130 * @cfg {String} defaultFont default font to use.
132 defaultFont: 'tahoma',
139 init : function(editor)
141 this.editor = editor;
144 var fid = editor.frameId;
146 function btn(id, toggle, handler){
147 var xid = fid + '-'+ id ;
151 cls : 'x-btn-icon x-edit-'+id,
152 enableToggle:toggle !== false,
153 scope: editor, // was editor...
154 handler:handler||editor.relayBtnCmd,
155 clickEvent:'mousedown',
156 tooltip: etb.buttonTips[id] || undefined, ///tips ???
163 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
166 tb.el.on('click', function(e){
167 e.preventDefault(); // what does this do?
170 if(!this.disable.font) { // && !Roo.isSafari){
171 /* why no safari for fonts
172 editor.fontSelect = tb.el.createChild({
176 html: this.createFontOptions()
179 editor.fontSelect.on('change', function(){
180 var font = editor.fontSelect.dom.value;
181 editor.relayCmd('fontname', font);
186 editor.fontSelect.dom,
192 if(!this.disable.formats){
193 this.formatCombo = new Roo.form.ComboBox({
194 store: new Roo.data.SimpleStore({
197 data : this.formats // from states.js
201 //autoCreate : {tag: "div", size: "20"},
206 triggerAction: 'all',
211 'select': function(c, r, i) {
212 editor.insertTag(r.get('tag'));
218 tb.addField(this.formatCombo);
222 if(!this.disable.format){
229 if(!this.disable.fontSize){
234 btn('increasefontsize', false, editor.adjustFont),
235 btn('decreasefontsize', false, editor.adjustFont)
240 if(!this.disable.colors){
243 id:editor.frameId +'-forecolor',
244 cls:'x-btn-icon x-edit-forecolor',
245 clickEvent:'mousedown',
246 tooltip: this.buttonTips['forecolor'] || undefined,
248 menu : new Roo.menu.ColorMenu({
253 selectHandler: function(cp, color){
254 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
258 clickEvent:'mousedown'
261 id:editor.frameId +'backcolor',
262 cls:'x-btn-icon x-edit-backcolor',
263 clickEvent:'mousedown',
264 tooltip: this.buttonTips['backcolor'] || undefined,
266 menu : new Roo.menu.ColorMenu({
271 selectHandler: function(cp, color){
273 editor.execCmd('useCSS', false);
274 editor.execCmd('hilitecolor', color);
275 editor.execCmd('useCSS', true);
278 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
279 Roo.isSafari || Roo.isIE ? '#'+color : color);
284 clickEvent:'mousedown'
289 // now add all the items...
292 if(!this.disable.alignments){
296 btn('justifycenter'),
302 if(!this.disable.links){
305 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
309 if(!this.disable.lists){
312 btn('insertorderedlist'),
313 btn('insertunorderedlist')
316 if(!this.disable.sourceEdit){
319 btn('sourceedit', true, function(btn){
320 this.toggleSourceEdit(btn.pressed);
327 // special menu.. - needs to be tidied up..
328 if (!this.disable.special) {
337 for (var i =0; i < this.specialChars.length; i++) {
338 smenu.menu.items.push({
340 html: this.specialChars[i],
341 handler: function(a,b) {
342 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
343 //editor.insertAtCursor(a.html);
357 if (!this.disable.cleanStyles) {
359 cls: 'x-btn-icon x-btn-clear',
365 for (var i =0; i < this.cleanStyles.length; i++) {
366 cmenu.menu.items.push({
367 actiontype : this.cleanStyles[i],
368 html: 'Remove ' + this.cleanStyles[i],
369 handler: function(a,b) {
372 var c = Roo.get(editor.doc.body);
373 c.select('[style]').each(function(s) {
374 s.dom.style.removeProperty(a.actiontype);
385 if (!this.disable.specialElements) {
393 for (var i =0; i < this.specialElements.length; i++) {
394 semenu.menu.items.push(
396 handler: function(a,b) {
397 editor.insertAtCursor(this.ihtml);
399 }, this.specialElements[i])
411 for(var i =0; i< this.btns.length;i++) {
412 var b = Roo.factory(this.btns[i],Roo.form);
413 b.cls = 'x-edit-none';
422 // disable everything...
424 this.tb.items.each(function(item){
425 if(item.id != editor.frameId+ '-sourceedit'){
429 this.rendered = true;
432 editor.on('editorevent', this.updateToolbar, this);
433 // other toolbars need to implement this..
434 //editor.on('editmodechange', this.updateToolbar, this);
440 * Protected method that will not generally be called directly. It triggers
441 * a toolbar update by reading the markup state of the current selection in the editor.
443 updateToolbar: function(){
445 if(!this.editor.activated){
446 this.editor.onFirstFocus();
450 var btns = this.tb.items.map,
451 doc = this.editor.doc,
452 frameId = this.editor.frameId;
454 if(!this.disable.font && !Roo.isSafari){
456 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
457 if(name != this.fontSelect.dom.value){
458 this.fontSelect.dom.value = name;
462 if(!this.disable.format){
463 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
464 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
465 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
467 if(!this.disable.alignments){
468 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
469 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
470 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
472 if(!Roo.isSafari && !this.disable.lists){
473 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
474 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
477 var ans = this.editor.getAllAncestors();
478 if (this.formatCombo) {
481 var store = this.formatCombo.store;
482 this.formatCombo.setValue("");
483 for (var i =0; i < ans.length;i++) {
484 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
486 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
494 // hides menus... - so this cant be on a menu...
495 Roo.menu.MenuMgr.hideAll();
497 //this.editorsyncValue();
501 createFontOptions : function(){
502 var buf = [], fs = this.fontFamilies, ff, lc;
506 for(var i = 0, len = fs.length; i< len; i++){
508 lc = ff.toLowerCase();
510 '<option value="',lc,'" style="font-family:',ff,';"',
511 (this.defaultFont == lc ? ' selected="true">' : '>'),
519 toggleSourceEdit : function(sourceEditMode){
520 if(sourceEditMode === undefined){
521 sourceEditMode = !this.sourceEditMode;
523 this.sourceEditMode = sourceEditMode === true;
524 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
525 // just toggle the button?
526 if(btn.pressed !== this.editor.sourceEditMode){
527 btn.toggle(this.editor.sourceEditMode);
531 if(this.sourceEditMode){
532 this.tb.items.each(function(item){
533 if(item.cmd != 'sourceedit'){
539 if(this.initialized){
540 this.tb.items.each(function(item){
546 // tell the editor that it's been pressed..
547 this.editor.toggleSourceEdit(sourceEditMode);
551 * Object collection of toolbar tooltips for the buttons in the editor. The key
552 * is the command id associated with that button and the value is a valid QuickTips object.
557 title: 'Bold (Ctrl+B)',
558 text: 'Make the selected text bold.',
559 cls: 'x-html-editor-tip'
562 title: 'Italic (Ctrl+I)',
563 text: 'Make the selected text italic.',
564 cls: 'x-html-editor-tip'
572 title: 'Bold (Ctrl+B)',
573 text: 'Make the selected text bold.',
574 cls: 'x-html-editor-tip'
577 title: 'Italic (Ctrl+I)',
578 text: 'Make the selected text italic.',
579 cls: 'x-html-editor-tip'
582 title: 'Underline (Ctrl+U)',
583 text: 'Underline the selected text.',
584 cls: 'x-html-editor-tip'
588 text: 'Increase the font size.',
589 cls: 'x-html-editor-tip'
592 title: 'Shrink Text',
593 text: 'Decrease the font size.',
594 cls: 'x-html-editor-tip'
597 title: 'Text Highlight Color',
598 text: 'Change the background color of the selected text.',
599 cls: 'x-html-editor-tip'
603 text: 'Change the color of the selected text.',
604 cls: 'x-html-editor-tip'
607 title: 'Align Text Left',
608 text: 'Align text to the left.',
609 cls: 'x-html-editor-tip'
612 title: 'Center Text',
613 text: 'Center text in the editor.',
614 cls: 'x-html-editor-tip'
617 title: 'Align Text Right',
618 text: 'Align text to the right.',
619 cls: 'x-html-editor-tip'
621 insertunorderedlist : {
622 title: 'Bullet List',
623 text: 'Start a bulleted list.',
624 cls: 'x-html-editor-tip'
626 insertorderedlist : {
627 title: 'Numbered List',
628 text: 'Start a numbered list.',
629 cls: 'x-html-editor-tip'
633 text: 'Make the selected text a hyperlink.',
634 cls: 'x-html-editor-tip'
637 title: 'Source Edit',
638 text: 'Switch to source editing mode.',
639 cls: 'x-html-editor-tip'
643 onDestroy : function(){
646 this.tb.items.each(function(item){
648 item.menu.removeAll();
650 item.menu.el.destroy();
658 onFirstFocus: function() {
659 this.tb.items.each(function(item){