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 var ar = ec.getAllAncestors();
531 for(var i = 0;i< ar.length;i++) {
532 if (ar[i] && ar[i].nodeName == 'A') {
540 Roo.MessageBox.show({
541 title : "Add / Edit Link URL",
542 msg : "Enter the url for the link",
543 buttons: Roo.MessageBox.OKCANCEL,
544 fn: function(btn, url){
548 if(url && url != 'http:/'+'/'){
550 n.setAttribute('href', url);
552 ec.relayCmd('createlink', url);
558 //multiline: multiline,
560 value : n ? n.getAttribute('href') : ''
564 }).defer(100, this); // we have to defer this , otherwise the mouse click gives focus to the main window.
570 * Protected method that will not generally be called directly. It triggers
571 * a toolbar update by reading the markup state of the current selection in the editor.
573 updateToolbar: function(){
575 if(!this.editorcore.activated){
576 this.editor.onFirstFocus();
580 var btns = this.tb.items.map,
581 doc = this.editorcore.doc,
582 frameId = this.editorcore.frameId;
584 if(!this.disable.font && !Roo.isSafari){
586 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
587 if(name != this.fontSelect.dom.value){
588 this.fontSelect.dom.value = name;
592 if(!this.disable.format){
593 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
594 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
595 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
596 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
598 if(!this.disable.alignments){
599 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
600 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
601 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
603 if(!Roo.isSafari && !this.disable.lists){
604 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
605 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
608 var ans = this.editorcore.getAllAncestors();
609 if (this.formatCombo) {
612 var store = this.formatCombo.store;
613 this.formatCombo.setValue("");
614 for (var i =0; i < ans.length;i++) {
615 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
617 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
625 // hides menus... - so this cant be on a menu...
626 Roo.menu.MenuMgr.hideAll();
628 //this.editorsyncValue();
632 createFontOptions : function(){
633 var buf = [], fs = this.fontFamilies, ff, lc;
637 for(var i = 0, len = fs.length; i< len; i++){
639 lc = ff.toLowerCase();
641 '<option value="',lc,'" style="font-family:',ff,';"',
642 (this.defaultFont == lc ? ' selected="true">' : '>'),
650 toggleSourceEdit : function(sourceEditMode){
652 Roo.log("toolbar toogle");
653 if(sourceEditMode === undefined){
654 sourceEditMode = !this.sourceEditMode;
656 this.sourceEditMode = sourceEditMode === true;
657 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
658 // just toggle the button?
659 if(btn.pressed !== this.sourceEditMode){
660 btn.toggle(this.sourceEditMode);
665 Roo.log("disabling buttons");
666 this.tb.items.each(function(item){
667 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
673 Roo.log("enabling buttons");
674 if(this.editorcore.initialized){
675 this.tb.items.each(function(item){
678 // initialize 'blocks'
679 Roo.each(Roo.get(this.editorcore.doc.body).query('*[data-block]'), function(e) {
680 Roo.htmleditor.Block.factory(e).updateElement(e);
686 Roo.log("calling toggole on editor");
687 // tell the editor that it's been pressed..
688 this.editor.toggleSourceEdit(sourceEditMode);
692 * Object collection of toolbar tooltips for the buttons in the editor. The key
693 * is the command id associated with that button and the value is a valid QuickTips object.
698 title: 'Bold (Ctrl+B)',
699 text: 'Make the selected text bold.',
700 cls: 'x-html-editor-tip'
703 title: 'Italic (Ctrl+I)',
704 text: 'Make the selected text italic.',
705 cls: 'x-html-editor-tip'
713 title: 'Bold (Ctrl+B)',
714 text: 'Make the selected text bold.',
715 cls: 'x-html-editor-tip'
718 title: 'Italic (Ctrl+I)',
719 text: 'Make the selected text italic.',
720 cls: 'x-html-editor-tip'
723 title: 'Underline (Ctrl+U)',
724 text: 'Underline the selected text.',
725 cls: 'x-html-editor-tip'
728 title: 'Strikethrough',
729 text: 'Strikethrough the selected text.',
730 cls: 'x-html-editor-tip'
734 text: 'Increase the font size.',
735 cls: 'x-html-editor-tip'
738 title: 'Shrink Text',
739 text: 'Decrease the font size.',
740 cls: 'x-html-editor-tip'
743 title: 'Text Highlight Color',
744 text: 'Change the background color of the selected text.',
745 cls: 'x-html-editor-tip'
749 text: 'Change the color of the selected text.',
750 cls: 'x-html-editor-tip'
753 title: 'Align Text Left',
754 text: 'Align text to the left.',
755 cls: 'x-html-editor-tip'
758 title: 'Center Text',
759 text: 'Center text in the editor.',
760 cls: 'x-html-editor-tip'
763 title: 'Align Text Right',
764 text: 'Align text to the right.',
765 cls: 'x-html-editor-tip'
767 insertunorderedlist : {
768 title: 'Bullet List',
769 text: 'Start a bulleted list.',
770 cls: 'x-html-editor-tip'
772 insertorderedlist : {
773 title: 'Numbered List',
774 text: 'Start a numbered list.',
775 cls: 'x-html-editor-tip'
779 text: 'Make the selected text a hyperlink.',
780 cls: 'x-html-editor-tip'
783 title: 'Source Edit',
784 text: 'Switch to source editing mode.',
785 cls: 'x-html-editor-tip'
789 onDestroy : function(){
792 this.tb.items.each(function(item){
794 item.menu.removeAll();
796 item.menu.el.destroy();
804 onFirstFocus: function() {
805 this.tb.items.each(function(item){