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"],
143 * @cfg {String} defaultFont default font to use.
145 defaultFont: 'tahoma',
152 init : function(editor)
154 this.editor = editor;
155 this.editorcore = editor.editorcore ? editor.editorcore : editor;
156 var editorcore = this.editorcore;
160 var fid = editorcore.frameId;
162 function btn(id, toggle, handler){
163 var xid = fid + '-'+ id ;
167 cls : 'x-btn-icon x-edit-'+id,
168 enableToggle:toggle !== false,
169 scope: _t, // was editor...
170 handler:handler||_t.relayBtnCmd,
171 clickEvent:'mousedown',
172 tooltip: etb.buttonTips[id] || undefined, ///tips ???
179 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
182 tb.el.on('click', function(e){
183 e.preventDefault(); // what does this do?
186 if(!this.disable.font) { // && !Roo.isSafari){
187 /* why no safari for fonts
188 editor.fontSelect = tb.el.createChild({
192 html: this.createFontOptions()
195 editor.fontSelect.on('change', function(){
196 var font = editor.fontSelect.dom.value;
197 editor.relayCmd('fontname', font);
202 editor.fontSelect.dom,
208 if(!this.disable.formats){
209 this.formatCombo = new Roo.form.ComboBox({
210 store: new Roo.data.SimpleStore({
213 data : this.formats // from states.js
217 //autoCreate : {tag: "div", size: "20"},
222 triggerAction: 'all',
227 'select': function(c, r, i) {
228 editorcore.insertTag(r.get('tag'));
234 tb.addField(this.formatCombo);
238 if(!this.disable.format){
246 if(!this.disable.fontSize){
251 btn('increasefontsize', false, editorcore.adjustFont),
252 btn('decreasefontsize', false, editorcore.adjustFont)
257 if(!this.disable.colors){
260 id:editorcore.frameId +'-forecolor',
261 cls:'x-btn-icon x-edit-forecolor',
262 clickEvent:'mousedown',
263 tooltip: this.buttonTips['forecolor'] || undefined,
265 menu : new Roo.menu.ColorMenu({
270 selectHandler: function(cp, color){
271 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
275 clickEvent:'mousedown'
278 id:editorcore.frameId +'backcolor',
279 cls:'x-btn-icon x-edit-backcolor',
280 clickEvent:'mousedown',
281 tooltip: this.buttonTips['backcolor'] || undefined,
283 menu : new Roo.menu.ColorMenu({
288 selectHandler: function(cp, color){
290 editorcore.execCmd('useCSS', false);
291 editorcore.execCmd('hilitecolor', color);
292 editorcore.execCmd('useCSS', true);
295 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
296 Roo.isSafari || Roo.isIE ? '#'+color : color);
301 clickEvent:'mousedown'
306 // now add all the items...
309 if(!this.disable.alignments){
313 btn('justifycenter'),
319 if(!this.disable.links){
322 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
326 if(!this.disable.lists){
329 btn('insertorderedlist'),
330 btn('insertunorderedlist')
333 if(!this.disable.sourceEdit){
336 btn('sourceedit', true, function(btn){
337 this.toggleSourceEdit(btn.pressed);
344 // special menu.. - needs to be tidied up..
345 if (!this.disable.special) {
354 for (var i =0; i < this.specialChars.length; i++) {
355 smenu.menu.items.push({
357 html: this.specialChars[i],
358 handler: function(a,b) {
359 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
360 //editor.insertAtCursor(a.html);
374 if (!this.disable.cleanStyles) {
376 cls: 'x-btn-icon x-btn-clear',
382 for (var i =0; i < this.cleanStyles.length; i++) {
383 cmenu.menu.items.push({
384 actiontype : this.cleanStyles[i],
385 html: 'Remove ' + this.cleanStyles[i],
386 handler: function(a,b) {
389 var c = Roo.get(editorcore.doc.body);
390 c.select('[style]').each(function(s) {
391 s.dom.style.removeProperty(a.actiontype);
393 editorcore.syncValue();
398 cmenu.menu.items.push({
399 actiontype : 'tablewidths',
400 html: 'Remove Table Widths',
401 handler: function(a,b) {
402 editorcore.cleanTableWidths();
403 editorcore.syncValue();
407 cmenu.menu.items.push({
409 html: 'Remove MS Word Formating',
410 handler: function(a,b) {
411 editorcore.cleanWord();
412 editorcore.syncValue();
417 cmenu.menu.items.push({
419 html: 'Remove All Styles',
420 handler: function(a,b) {
422 var c = Roo.get(editorcore.doc.body);
423 c.select('[style]').each(function(s) {
424 s.dom.removeAttribute('style');
426 editorcore.syncValue();
431 cmenu.menu.items.push({
433 html: 'Remove All CSS Classes',
434 handler: function(a,b) {
436 var c = Roo.get(editorcore.doc.body);
437 c.select('[class]').each(function(s) {
438 s.dom.removeAttribute('class');
440 editorcore.cleanWord();
441 editorcore.syncValue();
446 cmenu.menu.items.push({
448 html: 'Tidy HTML Source',
449 handler: function(a,b) {
450 editorcore.doc.body.innerHTML = editorcore.domToHTML();
451 editorcore.syncValue();
460 if (!this.disable.specialElements) {
468 for (var i =0; i < this.specialElements.length; i++) {
469 semenu.menu.items.push(
471 handler: function(a,b) {
472 editor.insertAtCursor(this.ihtml);
474 }, this.specialElements[i])
486 for(var i =0; i< this.btns.length;i++) {
487 var b = Roo.factory(this.btns[i],Roo.form);
488 b.cls = 'x-edit-none';
490 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable') !== -1){
491 b.cls += ' x-init-enable';
494 b.scope = editorcore;
502 // disable everything...
504 this.tb.items.each(function(item){
507 item.id != editorcore.frameId+ '-sourceedit' &&
508 (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)
514 this.rendered = true;
517 editor.on('editorevent', this.updateToolbar, this);
518 // other toolbars need to implement this..
519 //editor.on('editmodechange', this.updateToolbar, this);
523 relayBtnCmd : function(btn) {
524 this.editorcore.relayCmd(btn.cmd);
526 // private used internally
527 createLink : function(){
528 Roo.log("create link?");
529 var url = prompt(this.createLinkText, this.defaultLinkValue);
530 if(url && url != 'http:/'+'/'){
531 this.editorcore.relayCmd('createlink', url);
537 * Protected method that will not generally be called directly. It triggers
538 * a toolbar update by reading the markup state of the current selection in the editor.
540 updateToolbar: function(){
542 if(!this.editorcore.activated){
543 this.editor.onFirstFocus();
547 var btns = this.tb.items.map,
548 doc = this.editorcore.doc,
549 frameId = this.editorcore.frameId;
551 if(!this.disable.font && !Roo.isSafari){
553 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
554 if(name != this.fontSelect.dom.value){
555 this.fontSelect.dom.value = name;
559 if(!this.disable.format){
560 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
561 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
562 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
563 btns[frameId + '-strikethrough'].toggle(doc.queryCommandState('strikethrough'));
565 if(!this.disable.alignments){
566 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
567 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
568 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
570 if(!Roo.isSafari && !this.disable.lists){
571 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
572 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
575 var ans = this.editorcore.getAllAncestors();
576 if (this.formatCombo) {
579 var store = this.formatCombo.store;
580 this.formatCombo.setValue("");
581 for (var i =0; i < ans.length;i++) {
582 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
584 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
592 // hides menus... - so this cant be on a menu...
593 Roo.menu.MenuMgr.hideAll();
595 //this.editorsyncValue();
599 createFontOptions : function(){
600 var buf = [], fs = this.fontFamilies, ff, lc;
604 for(var i = 0, len = fs.length; i< len; i++){
606 lc = ff.toLowerCase();
608 '<option value="',lc,'" style="font-family:',ff,';"',
609 (this.defaultFont == lc ? ' selected="true">' : '>'),
617 toggleSourceEdit : function(sourceEditMode){
619 Roo.log("toolbar toogle");
620 if(sourceEditMode === undefined){
621 sourceEditMode = !this.sourceEditMode;
623 this.sourceEditMode = sourceEditMode === true;
624 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
625 // just toggle the button?
626 if(btn.pressed !== this.sourceEditMode){
627 btn.toggle(this.sourceEditMode);
632 Roo.log("disabling buttons");
633 this.tb.items.each(function(item){
634 if(item.cmd != 'sourceedit' && (typeof(item.cls) != 'undefined' && item.cls.indexOf('x-init-enable') === -1)){
640 Roo.log("enabling buttons");
641 if(this.editorcore.initialized){
642 this.tb.items.each(function(item){
648 Roo.log("calling toggole on editor");
649 // tell the editor that it's been pressed..
650 this.editor.toggleSourceEdit(sourceEditMode);
654 * Object collection of toolbar tooltips for the buttons in the editor. The key
655 * is the command id associated with that button and the value is a valid QuickTips object.
660 title: 'Bold (Ctrl+B)',
661 text: 'Make the selected text bold.',
662 cls: 'x-html-editor-tip'
665 title: 'Italic (Ctrl+I)',
666 text: 'Make the selected text italic.',
667 cls: 'x-html-editor-tip'
675 title: 'Bold (Ctrl+B)',
676 text: 'Make the selected text bold.',
677 cls: 'x-html-editor-tip'
680 title: 'Italic (Ctrl+I)',
681 text: 'Make the selected text italic.',
682 cls: 'x-html-editor-tip'
685 title: 'Underline (Ctrl+U)',
686 text: 'Underline the selected text.',
687 cls: 'x-html-editor-tip'
690 title: 'Strikethrough',
691 text: 'Strikethrough the selected text.',
692 cls: 'x-html-editor-tip'
696 text: 'Increase the font size.',
697 cls: 'x-html-editor-tip'
700 title: 'Shrink Text',
701 text: 'Decrease the font size.',
702 cls: 'x-html-editor-tip'
705 title: 'Text Highlight Color',
706 text: 'Change the background color of the selected text.',
707 cls: 'x-html-editor-tip'
711 text: 'Change the color of the selected text.',
712 cls: 'x-html-editor-tip'
715 title: 'Align Text Left',
716 text: 'Align text to the left.',
717 cls: 'x-html-editor-tip'
720 title: 'Center Text',
721 text: 'Center text in the editor.',
722 cls: 'x-html-editor-tip'
725 title: 'Align Text Right',
726 text: 'Align text to the right.',
727 cls: 'x-html-editor-tip'
729 insertunorderedlist : {
730 title: 'Bullet List',
731 text: 'Start a bulleted list.',
732 cls: 'x-html-editor-tip'
734 insertorderedlist : {
735 title: 'Numbered List',
736 text: 'Start a numbered list.',
737 cls: 'x-html-editor-tip'
741 text: 'Make the selected text a hyperlink.',
742 cls: 'x-html-editor-tip'
745 title: 'Source Edit',
746 text: 'Switch to source editing mode.',
747 cls: 'x-html-editor-tip'
751 onDestroy : function(){
754 this.tb.items.each(function(item){
756 item.menu.removeAll();
758 item.menu.el.destroy();
766 onFirstFocus: function() {
767 this.tb.items.each(function(item){