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, {
61 * @cfg {Object} disable List of toolbar elements to disable
68 * @cfg {String} createLinkText The default text for the create link prompt
70 createLinkText : 'Please enter the URL for the link:',
72 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
74 defaultLinkValue : 'http:/'+'/',
78 * @cfg {Array} fontFamilies An array of available font families
96 // "á" , ?? a acute?
101 "°" // , // degrees
103 // "é" , // e ecute
104 // "ú" , // u ecute?
109 text: "Insert Table",
112 ihtml : '<table><tr><td>Cell</td></tr></table>'
116 text: "Insert Image",
119 ihtml : '<img src="about:blank"/>'
128 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
129 "input:submit", "input:button", "select", "textarea", "label" ],
132 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
134 ["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){
244 if(!this.disable.fontSize){
249 btn('increasefontsize', false, editorcore.adjustFont),
250 btn('decreasefontsize', false, editorcore.adjustFont)
255 if(!this.disable.colors){
258 id:editorcore.frameId +'-forecolor',
259 cls:'x-btn-icon x-edit-forecolor',
260 clickEvent:'mousedown',
261 tooltip: this.buttonTips['forecolor'] || undefined,
263 menu : new Roo.menu.ColorMenu({
268 selectHandler: function(cp, color){
269 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
273 clickEvent:'mousedown'
276 id:editorcore.frameId +'backcolor',
277 cls:'x-btn-icon x-edit-backcolor',
278 clickEvent:'mousedown',
279 tooltip: this.buttonTips['backcolor'] || undefined,
281 menu : new Roo.menu.ColorMenu({
286 selectHandler: function(cp, color){
288 editorcore.execCmd('useCSS', false);
289 editorcore.execCmd('hilitecolor', color);
290 editorcore.execCmd('useCSS', true);
293 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
294 Roo.isSafari || Roo.isIE ? '#'+color : color);
299 clickEvent:'mousedown'
304 // now add all the items...
307 if(!this.disable.alignments){
311 btn('justifycenter'),
317 if(!this.disable.links){
320 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
324 if(!this.disable.lists){
327 btn('insertorderedlist'),
328 btn('insertunorderedlist')
331 if(!this.disable.sourceEdit){
334 btn('sourceedit', true, function(btn){
335 this.toggleSourceEdit(btn.pressed);
342 // special menu.. - needs to be tidied up..
343 if (!this.disable.special) {
352 for (var i =0; i < this.specialChars.length; i++) {
353 smenu.menu.items.push({
355 html: this.specialChars[i],
356 handler: function(a,b) {
357 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
358 //editor.insertAtCursor(a.html);
372 if (!this.disable.cleanStyles) {
374 cls: 'x-btn-icon x-btn-clear',
380 for (var i =0; i < this.cleanStyles.length; i++) {
381 cmenu.menu.items.push({
382 actiontype : this.cleanStyles[i],
383 html: 'Remove ' + this.cleanStyles[i],
384 handler: function(a,b) {
387 var c = Roo.get(editorcore.doc.body);
388 c.select('[style]').each(function(s) {
389 s.dom.style.removeProperty(a.actiontype);
391 editorcore.syncValue();
396 cmenu.menu.items.push({
398 html: 'Remove MS Word Formating',
399 handler: function(a,b) {
400 editorcore.cleanWord();
401 editorcore.syncValue();
406 cmenu.menu.items.push({
408 html: 'Remove All Styles',
409 handler: function(a,b) {
411 var c = Roo.get(editorcore.doc.body);
412 c.select('[style]').each(function(s) {
413 s.dom.removeAttribute('style');
415 editorcore.syncValue();
419 cmenu.menu.items.push({
421 html: 'Tidy HTML Source',
422 handler: function(a,b) {
423 editorcore.doc.body.innerHTML = editorcore.domToHTML();
424 editorcore.syncValue();
433 if (!this.disable.specialElements) {
441 for (var i =0; i < this.specialElements.length; i++) {
442 semenu.menu.items.push(
444 handler: function(a,b) {
445 editor.insertAtCursor(this.ihtml);
447 }, this.specialElements[i])
459 for(var i =0; i< this.btns.length;i++) {
460 var b = Roo.factory(this.btns[i],Roo.form);
461 b.cls = 'x-edit-none';
463 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
464 b.cls += ' x-init-enable';
467 b.scope = editorcore;
475 // disable everything...
477 this.tb.items.each(function(item){
480 item.id != editorcore.frameId+ '-sourceedit' &&
481 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
487 this.rendered = true;
490 editor.on('editorevent', this.updateToolbar, this);
491 // other toolbars need to implement this..
492 //editor.on('editmodechange', this.updateToolbar, this);
496 relayBtnCmd : function(btn) {
497 this.editorcore.relayCmd(btn.cmd);
499 // private used internally
500 createLink : function(){
501 Roo.log("create link?");
502 var url = prompt(this.createLinkText, this.defaultLinkValue);
503 if(url && url != 'http:/'+'/'){
504 this.editorcore.relayCmd('createlink', url);
510 * Protected method that will not generally be called directly. It triggers
511 * a toolbar update by reading the markup state of the current selection in the editor.
513 updateToolbar: function(){
515 if(!this.editorcore.activated){
516 this.editor.onFirstFocus();
520 var btns = this.tb.items.map,
521 doc = this.editorcore.doc,
522 frameId = this.editorcore.frameId;
524 if(!this.disable.font && !Roo.isSafari){
526 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
527 if(name != this.fontSelect.dom.value){
528 this.fontSelect.dom.value = name;
532 if(!this.disable.format){
533 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
534 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
535 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
537 if(!this.disable.alignments){
538 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
539 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
540 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
542 if(!Roo.isSafari && !this.disable.lists){
543 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
544 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
547 var ans = this.editorcore.getAllAncestors();
548 if (this.formatCombo) {
551 var store = this.formatCombo.store;
552 this.formatCombo.setValue("");
553 for (var i =0; i < ans.length;i++) {
554 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
556 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
564 // hides menus... - so this cant be on a menu...
565 Roo.menu.MenuMgr.hideAll();
567 //this.editorsyncValue();
571 createFontOptions : function(){
572 var buf = [], fs = this.fontFamilies, ff, lc;
576 for(var i = 0, len = fs.length; i< len; i++){
578 lc = ff.toLowerCase();
580 '<option value="',lc,'" style="font-family:',ff,';"',
581 (this.defaultFont == lc ? ' selected="true">' : '>'),
589 toggleSourceEdit : function(sourceEditMode){
591 Roo.log("toolbar toogle");
592 if(sourceEditMode === undefined){
593 sourceEditMode = !this.sourceEditMode;
595 this.sourceEditMode = sourceEditMode === true;
596 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
597 // just toggle the button?
598 if(btn.pressed !== this.sourceEditMode){
599 btn.toggle(this.sourceEditMode);
604 Roo.log("disabling buttons");
605 this.tb.items.each(function(item){
606 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
612 Roo.log("enabling buttons");
613 if(this.editorcore.initialized){
614 this.tb.items.each(function(item){
620 Roo.log("calling toggole on editor");
621 // tell the editor that it's been pressed..
622 this.editor.toggleSourceEdit(sourceEditMode);
626 * Object collection of toolbar tooltips for the buttons in the editor. The key
627 * is the command id associated with that button and the value is a valid QuickTips object.
632 title: 'Bold (Ctrl+B)',
633 text: 'Make the selected text bold.',
634 cls: 'x-html-editor-tip'
637 title: 'Italic (Ctrl+I)',
638 text: 'Make the selected text italic.',
639 cls: 'x-html-editor-tip'
647 title: 'Bold (Ctrl+B)',
648 text: 'Make the selected text bold.',
649 cls: 'x-html-editor-tip'
652 title: 'Italic (Ctrl+I)',
653 text: 'Make the selected text italic.',
654 cls: 'x-html-editor-tip'
657 title: 'Underline (Ctrl+U)',
658 text: 'Underline the selected text.',
659 cls: 'x-html-editor-tip'
663 text: 'Increase the font size.',
664 cls: 'x-html-editor-tip'
667 title: 'Shrink Text',
668 text: 'Decrease the font size.',
669 cls: 'x-html-editor-tip'
672 title: 'Text Highlight Color',
673 text: 'Change the background color of the selected text.',
674 cls: 'x-html-editor-tip'
678 text: 'Change the color of the selected text.',
679 cls: 'x-html-editor-tip'
682 title: 'Align Text Left',
683 text: 'Align text to the left.',
684 cls: 'x-html-editor-tip'
687 title: 'Center Text',
688 text: 'Center text in the editor.',
689 cls: 'x-html-editor-tip'
692 title: 'Align Text Right',
693 text: 'Align text to the right.',
694 cls: 'x-html-editor-tip'
696 insertunorderedlist : {
697 title: 'Bullet List',
698 text: 'Start a bulleted list.',
699 cls: 'x-html-editor-tip'
701 insertorderedlist : {
702 title: 'Numbered List',
703 text: 'Start a numbered list.',
704 cls: 'x-html-editor-tip'
708 text: 'Make the selected text a hyperlink.',
709 cls: 'x-html-editor-tip'
712 title: 'Source Edit',
713 text: 'Switch to source editing mode.',
714 cls: 'x-html-editor-tip'
718 onDestroy : function(){
721 this.tb.items.each(function(item){
723 item.menu.removeAll();
725 item.menu.el.destroy();
733 onFirstFocus: function() {
734 this.tb.items.each(function(item){