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;
530 Roo.MessageBox.prompt("Add Link URL",this.createLinkText, function(btn, url) {
534 if(url && url != 'http:/'+'/'){
535 ec.relayCmd('createlink', url);
538 }).defer(100, this); // we have to defer this , otherwise the mouse click gives focus to the main window.
544 * Protected method that will not generally be called directly. It triggers
545 * a toolbar update by reading the markup state of the current selection in the editor.
547 updateToolbar: function(){
549 if(!this.editorcore.activated){
550 this.editor.onFirstFocus();
554 var btns = this.tb.items.map,
555 doc = this.editorcore.doc,
556 frameId = this.editorcore.frameId;
558 if(!this.disable.font && !Roo.isSafari){
560 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
561 if(name != this.fontSelect.dom.value){
562 this.fontSelect.dom.value = name;
566 if(!this.disable.format){
567 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
568 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
569 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
570 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
572 if(!this.disable.alignments){
573 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
574 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
575 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
577 if(!Roo.isSafari && !this.disable.lists){
578 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
579 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
582 var ans = this.editorcore.getAllAncestors();
583 if (this.formatCombo) {
586 var store = this.formatCombo.store;
587 this.formatCombo.setValue("");
588 for (var i =0; i < ans.length;i++) {
589 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
591 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
599 // hides menus... - so this cant be on a menu...
600 Roo.menu.MenuMgr.hideAll();
602 //this.editorsyncValue();
606 createFontOptions : function(){
607 var buf = [], fs = this.fontFamilies, ff, lc;
611 for(var i = 0, len = fs.length; i< len; i++){
613 lc = ff.toLowerCase();
615 '<option value="',lc,'" style="font-family:',ff,';"',
616 (this.defaultFont == lc ? ' selected="true">' : '>'),
624 toggleSourceEdit : function(sourceEditMode){
626 Roo.log("toolbar toogle");
627 if(sourceEditMode === undefined){
628 sourceEditMode = !this.sourceEditMode;
630 this.sourceEditMode = sourceEditMode === true;
631 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
632 // just toggle the button?
633 if(btn.pressed !== this.sourceEditMode){
634 btn.toggle(this.sourceEditMode);
639 Roo.log("disabling buttons");
640 this.tb.items.each(function(item){
641 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
647 Roo.log("enabling buttons");
648 if(this.editorcore.initialized){
649 this.tb.items.each(function(item){
652 // initialize 'blocks'
653 Roo.each(Roo.get(this.editorcore.doc.body).query('*[data-block]'), function(e) {
654 Roo.htmleditor.Block.factory(e).updateElement(e);
660 Roo.log("calling toggole on editor");
661 // tell the editor that it's been pressed..
662 this.editor.toggleSourceEdit(sourceEditMode);
666 * Object collection of toolbar tooltips for the buttons in the editor. The key
667 * is the command id associated with that button and the value is a valid QuickTips object.
672 title: 'Bold (Ctrl+B)',
673 text: 'Make the selected text bold.',
674 cls: 'x-html-editor-tip'
677 title: 'Italic (Ctrl+I)',
678 text: 'Make the selected text italic.',
679 cls: 'x-html-editor-tip'
687 title: 'Bold (Ctrl+B)',
688 text: 'Make the selected text bold.',
689 cls: 'x-html-editor-tip'
692 title: 'Italic (Ctrl+I)',
693 text: 'Make the selected text italic.',
694 cls: 'x-html-editor-tip'
697 title: 'Underline (Ctrl+U)',
698 text: 'Underline the selected text.',
699 cls: 'x-html-editor-tip'
702 title: 'Strikethrough',
703 text: 'Strikethrough the selected text.',
704 cls: 'x-html-editor-tip'
708 text: 'Increase the font size.',
709 cls: 'x-html-editor-tip'
712 title: 'Shrink Text',
713 text: 'Decrease the font size.',
714 cls: 'x-html-editor-tip'
717 title: 'Text Highlight Color',
718 text: 'Change the background color of the selected text.',
719 cls: 'x-html-editor-tip'
723 text: 'Change the color of the selected text.',
724 cls: 'x-html-editor-tip'
727 title: 'Align Text Left',
728 text: 'Align text to the left.',
729 cls: 'x-html-editor-tip'
732 title: 'Center Text',
733 text: 'Center text in the editor.',
734 cls: 'x-html-editor-tip'
737 title: 'Align Text Right',
738 text: 'Align text to the right.',
739 cls: 'x-html-editor-tip'
741 insertunorderedlist : {
742 title: 'Bullet List',
743 text: 'Start a bulleted list.',
744 cls: 'x-html-editor-tip'
746 insertorderedlist : {
747 title: 'Numbered List',
748 text: 'Start a numbered list.',
749 cls: 'x-html-editor-tip'
753 text: 'Make the selected text a hyperlink.',
754 cls: 'x-html-editor-tip'
757 title: 'Source Edit',
758 text: 'Switch to source editing mode.',
759 cls: 'x-html-editor-tip'
763 onDestroy : function(){
766 this.tb.items.each(function(item){
768 item.menu.removeAll();
770 item.menu.el.destroy();
778 onFirstFocus: function() {
779 this.tb.items.each(function(item){