4 * Copyright(c) 2006-2007, Ext JS, LLC.
10 * @class Roo.form.HtmlEditor.ToolbarStandard
15 new Roo.form.HtmlEditor({
18 new Roo.form.HtmlEditorToolbar1({
19 disable : { fonts: 1 , format: 1, ..., ... , ...],
25 * @cfg {Object} disable List of elements to disable..
26 * @cfg {Roo.Toolbar.Item|Roo.Toolbar.Button|Roo.Toolbar.SplitButton|Roo.form.Field} btns[] List of additional buttons.
30 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
33 Roo.form.HtmlEditor.ToolbarStandard = function(config)
36 Roo.apply(this, config);
38 // default disabled, based on 'good practice'..
39 this.disable = this.disable || {};
40 Roo.applyIf(this.disable, {
43 specialElements : true
47 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
48 // dont call parent... till later.
51 Roo.form.HtmlEditor.ToolbarStandard.prototype = {
60 * @cfg {Object} disable List of toolbar elements to disable
67 * @cfg {String} createLinkText The default text for the create link prompt
69 createLinkText : 'Please enter the URL for the link:',
71 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
73 defaultLinkValue : 'http:/'+'/',
77 * @cfg {Array} fontFamilies An array of available font families
95 // "á" , ?? a acute?
100 "°" // , // degrees
102 // "é" , // e ecute
103 // "ú" , // u ecute?
108 text: "Insert Table",
111 ihtml : '<table><tr><td>Cell</td></tr></table>'
115 text: "Insert Image",
118 ihtml : '<img src="about:blank"/>'
127 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
128 "input:submit", "input:button", "select", "textarea", "label" ],
131 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
133 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
142 * @cfg {String} defaultFont default font to use.
144 defaultFont: 'tahoma',
151 init : function(editor)
153 this.editor = editor;
154 this.editorcore = editor.editorcore ? editor.editorcore : editor;
155 var editorcore = this.editorcore;
159 var fid = editorcore.frameId;
161 function btn(id, toggle, handler){
162 var xid = fid + '-'+ id ;
166 cls : 'x-btn-icon x-edit-'+id,
167 enableToggle:toggle !== false,
168 scope: _t, // was editor...
169 handler:handler||_t.relayBtnCmd,
170 clickEvent:'mousedown',
171 tooltip: etb.buttonTips[id] || undefined, ///tips ???
178 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
181 tb.el.on('click', function(e){
182 e.preventDefault(); // what does this do?
185 if(!this.disable.font) { // && !Roo.isSafari){
186 /* why no safari for fonts
187 editor.fontSelect = tb.el.createChild({
191 html: this.createFontOptions()
194 editor.fontSelect.on('change', function(){
195 var font = editor.fontSelect.dom.value;
196 editor.relayCmd('fontname', font);
201 editor.fontSelect.dom,
207 if(!this.disable.formats){
208 this.formatCombo = new Roo.form.ComboBox({
209 store: new Roo.data.SimpleStore({
212 data : this.formats // from states.js
216 //autoCreate : {tag: "div", size: "20"},
221 triggerAction: 'all',
226 'select': function(c, r, i) {
227 editorcore.insertTag(r.get('tag'));
233 tb.addField(this.formatCombo);
237 if(!this.disable.format){
245 if(!this.disable.fontSize){
250 btn('increasefontsize', false, editorcore.adjustFont),
251 btn('decreasefontsize', false, editorcore.adjustFont)
256 if(!this.disable.colors){
259 id:editorcore.frameId +'-forecolor',
260 cls:'x-btn-icon x-edit-forecolor',
261 clickEvent:'mousedown',
262 tooltip: this.buttonTips['forecolor'] || undefined,
264 menu : new Roo.menu.ColorMenu({
269 selectHandler: function(cp, color){
270 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
274 clickEvent:'mousedown'
277 id:editorcore.frameId +'backcolor',
278 cls:'x-btn-icon x-edit-backcolor',
279 clickEvent:'mousedown',
280 tooltip: this.buttonTips['backcolor'] || undefined,
282 menu : new Roo.menu.ColorMenu({
287 selectHandler: function(cp, color){
289 editorcore.execCmd('useCSS', false);
290 editorcore.execCmd('hilitecolor', color);
291 editorcore.execCmd('useCSS', true);
294 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
295 Roo.isSafari || Roo.isIE ? '#'+color : color);
300 clickEvent:'mousedown'
305 // now add all the items...
308 if(!this.disable.alignments){
312 btn('justifycenter'),
318 if(!this.disable.links){
321 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
325 if(!this.disable.lists){
328 btn('insertorderedlist'),
329 btn('insertunorderedlist')
332 if(!this.disable.sourceEdit){
335 btn('sourceedit', true, function(btn){
336 this.toggleSourceEdit(btn.pressed);
343 // special menu.. - needs to be tidied up..
344 if (!this.disable.special) {
353 for (var i =0; i < this.specialChars.length; i++) {
354 smenu.menu.items.push({
356 html: this.specialChars[i],
357 handler: function(a,b) {
358 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
359 //editor.insertAtCursor(a.html);
373 if (!this.disable.cleanStyles) {
375 cls: 'x-btn-icon x-btn-clear',
381 for (var i =0; i < this.cleanStyles.length; i++) {
382 cmenu.menu.items.push({
383 actiontype : this.cleanStyles[i],
384 html: 'Remove ' + this.cleanStyles[i],
385 handler: function(a,b) {
388 var c = Roo.get(editorcore.doc.body);
389 c.select('[style]').each(function(s) {
390 s.dom.style.removeProperty(a.actiontype);
392 editorcore.syncValue();
397 cmenu.menu.items.push({
398 actiontype : 'tablewidths',
399 html: 'Remove Table Widths',
400 handler: function(a,b) {
401 editorcore.cleanTableWidths();
402 editorcore.syncValue();
406 cmenu.menu.items.push({
408 html: 'Remove MS Word Formating',
409 handler: function(a,b) {
410 editorcore.cleanWord();
411 editorcore.syncValue();
416 cmenu.menu.items.push({
418 html: 'Remove All Styles',
419 handler: function(a,b) {
421 var c = Roo.get(editorcore.doc.body);
422 c.select('[style]').each(function(s) {
423 s.dom.removeAttribute('style');
425 editorcore.syncValue();
430 cmenu.menu.items.push({
432 html: 'Remove All CSS Classes',
433 handler: function(a,b) {
435 var c = Roo.get(editorcore.doc.body);
436 c.select('[class]').each(function(s) {
437 s.dom.removeAttribute('class');
439 editorcore.cleanWord();
440 editorcore.syncValue();
445 cmenu.menu.items.push({
447 html: 'Tidy HTML Source',
448 handler: function(a,b) {
449 new Roo.htmleditor.Tidy(editorcore.doc.body);
450 editorcore.syncValue();
459 if (!this.disable.specialElements) {
467 for (var i =0; i < this.specialElements.length; i++) {
468 semenu.menu.items.push(
470 handler: function(a,b) {
471 editor.insertAtCursor(this.ihtml);
473 }, this.specialElements[i])
485 for(var i =0; i< this.btns.length;i++) {
486 var b = Roo.factory(this.btns[i],this.btns[i].xns || Roo.form);
487 b.cls = 'x-edit-none';
489 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
490 b.cls += ' x-init-enable';
493 b.scope = editorcore;
501 // disable everything...
503 this.tb.items.each(function(item){
506 item.id != editorcore.frameId+ '-sourceedit' &&
507 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
513 this.rendered = true;
516 editor.on('editorevent', this.updateToolbar, this);
517 // other toolbars need to implement this..
518 //editor.on('editmodechange', this.updateToolbar, this);
522 relayBtnCmd : function(btn) {
523 this.editorcore.relayCmd(btn.cmd);
525 // private used internally
526 createLink : function(){
527 //Roo.log("create link?");
528 var ec = this.editorcore;
529 Roo.MessageBox.prompt("Add Link URL",this.createLinkText, function(btn, url) {
533 if(url && url != 'http:/'+'/'){
534 ec.relayCmd('createlink', url);
542 * Protected method that will not generally be called directly. It triggers
543 * a toolbar update by reading the markup state of the current selection in the editor.
545 updateToolbar: function(){
547 if(!this.editorcore.activated){
548 this.editor.onFirstFocus();
552 var btns = this.tb.items.map,
553 doc = this.editorcore.doc,
554 frameId = this.editorcore.frameId;
556 if(!this.disable.font && !Roo.isSafari){
558 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
559 if(name != this.fontSelect.dom.value){
560 this.fontSelect.dom.value = name;
564 if(!this.disable.format){
565 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
566 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
567 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
568 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
570 if(!this.disable.alignments){
571 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
572 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
573 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
575 if(!Roo.isSafari && !this.disable.lists){
576 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
577 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
580 var ans = this.editorcore.getAllAncestors();
581 if (this.formatCombo) {
584 var store = this.formatCombo.store;
585 this.formatCombo.setValue("");
586 for (var i =0; i < ans.length;i++) {
587 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
589 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
597 // hides menus... - so this cant be on a menu...
598 Roo.menu.MenuMgr.hideAll();
600 //this.editorsyncValue();
604 createFontOptions : function(){
605 var buf = [], fs = this.fontFamilies, ff, lc;
609 for(var i = 0, len = fs.length; i< len; i++){
611 lc = ff.toLowerCase();
613 '<option value="',lc,'" style="font-family:',ff,';"',
614 (this.defaultFont == lc ? ' selected="true">' : '>'),
622 toggleSourceEdit : function(sourceEditMode){
624 Roo.log("toolbar toogle");
625 if(sourceEditMode === undefined){
626 sourceEditMode = !this.sourceEditMode;
628 this.sourceEditMode = sourceEditMode === true;
629 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
630 // just toggle the button?
631 if(btn.pressed !== this.sourceEditMode){
632 btn.toggle(this.sourceEditMode);
637 Roo.log("disabling buttons");
638 this.tb.items.each(function(item){
639 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
645 Roo.log("enabling buttons");
646 if(this.editorcore.initialized){
647 this.tb.items.each(function(item){
650 // initialize 'blocks'
651 Roo.each(Roo.get(this.editorcore.doc.body).query('*[data-block]'), function(e) {
652 Roo.htmleditor.Block.factory(e).updateElement(e);
658 Roo.log("calling toggole on editor");
659 // tell the editor that it's been pressed..
660 this.editor.toggleSourceEdit(sourceEditMode);
664 * Object collection of toolbar tooltips for the buttons in the editor. The key
665 * is the command id associated with that button and the value is a valid QuickTips object.
670 title: 'Bold (Ctrl+B)',
671 text: 'Make the selected text bold.',
672 cls: 'x-html-editor-tip'
675 title: 'Italic (Ctrl+I)',
676 text: 'Make the selected text italic.',
677 cls: 'x-html-editor-tip'
685 title: 'Bold (Ctrl+B)',
686 text: 'Make the selected text bold.',
687 cls: 'x-html-editor-tip'
690 title: 'Italic (Ctrl+I)',
691 text: 'Make the selected text italic.',
692 cls: 'x-html-editor-tip'
695 title: 'Underline (Ctrl+U)',
696 text: 'Underline the selected text.',
697 cls: 'x-html-editor-tip'
700 title: 'Strikethrough',
701 text: 'Strikethrough the selected text.',
702 cls: 'x-html-editor-tip'
706 text: 'Increase the font size.',
707 cls: 'x-html-editor-tip'
710 title: 'Shrink Text',
711 text: 'Decrease the font size.',
712 cls: 'x-html-editor-tip'
715 title: 'Text Highlight Color',
716 text: 'Change the background color of the selected text.',
717 cls: 'x-html-editor-tip'
721 text: 'Change the color of the selected text.',
722 cls: 'x-html-editor-tip'
725 title: 'Align Text Left',
726 text: 'Align text to the left.',
727 cls: 'x-html-editor-tip'
730 title: 'Center Text',
731 text: 'Center text in the editor.',
732 cls: 'x-html-editor-tip'
735 title: 'Align Text Right',
736 text: 'Align text to the right.',
737 cls: 'x-html-editor-tip'
739 insertunorderedlist : {
740 title: 'Bullet List',
741 text: 'Start a bulleted list.',
742 cls: 'x-html-editor-tip'
744 insertorderedlist : {
745 title: 'Numbered List',
746 text: 'Start a numbered list.',
747 cls: 'x-html-editor-tip'
751 text: 'Make the selected text a hyperlink.',
752 cls: 'x-html-editor-tip'
755 title: 'Source Edit',
756 text: 'Switch to source editing mode.',
757 cls: 'x-html-editor-tip'
761 onDestroy : function(){
764 this.tb.items.each(function(item){
766 item.menu.removeAll();
768 item.menu.el.destroy();
776 onFirstFocus: function() {
777 this.tb.items.each(function(item){