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){
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({
399 html: 'Remove MS Word Formating',
400 handler: function(a,b) {
401 editorcore.cleanWord();
402 editorcore.syncValue();
407 cmenu.menu.items.push({
409 html: 'Remove All Styles',
410 handler: function(a,b) {
412 var c = Roo.get(editorcore.doc.body);
413 c.select('[style]').each(function(s) {
414 s.dom.removeAttribute('style');
416 editorcore.syncValue();
420 cmenu.menu.items.push({
422 html: 'Tidy HTML Source',
423 handler: function(a,b) {
424 editorcore.doc.body.innerHTML = editorcore.domToHTML();
425 editorcore.syncValue();
434 if (!this.disable.specialElements) {
442 for (var i =0; i < this.specialElements.length; i++) {
443 semenu.menu.items.push(
445 handler: function(a,b) {
446 editor.insertAtCursor(this.ihtml);
448 }, this.specialElements[i])
460 for(var i =0; i< this.btns.length;i++) {
461 var b = Roo.factory(this.btns[i],Roo.form);
462 b.cls = 'x-edit-none';
464 if(typeof(this.btns[i].cls) != 'undefined' && this.btns[i].cls.indexOf('x-init-enable')){
465 b.cls += ' x-init-enable';
468 b.scope = editorcore;
476 // disable everything...
478 this.tb.items.each(function(item){
479 Roo.log('Itme!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1');
482 item.id != editorcore.frameId+ '-sourceedit'
488 this.rendered = true;
491 editor.on('editorevent', this.updateToolbar, this);
492 // other toolbars need to implement this..
493 //editor.on('editmodechange', this.updateToolbar, this);
497 relayBtnCmd : function(btn) {
498 this.editorcore.relayCmd(btn.cmd);
500 // private used internally
501 createLink : function(){
502 Roo.log("create link?");
503 var url = prompt(this.createLinkText, this.defaultLinkValue);
504 if(url && url != 'http:/'+'/'){
505 this.editorcore.relayCmd('createlink', url);
511 * Protected method that will not generally be called directly. It triggers
512 * a toolbar update by reading the markup state of the current selection in the editor.
514 updateToolbar: function(){
516 if(!this.editorcore.activated){
517 this.editor.onFirstFocus();
521 var btns = this.tb.items.map,
522 doc = this.editorcore.doc,
523 frameId = this.editorcore.frameId;
525 if(!this.disable.font && !Roo.isSafari){
527 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
528 if(name != this.fontSelect.dom.value){
529 this.fontSelect.dom.value = name;
533 if(!this.disable.format){
534 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
535 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
536 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
538 if(!this.disable.alignments){
539 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
540 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
541 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
543 if(!Roo.isSafari && !this.disable.lists){
544 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
545 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
548 var ans = this.editorcore.getAllAncestors();
549 if (this.formatCombo) {
552 var store = this.formatCombo.store;
553 this.formatCombo.setValue("");
554 for (var i =0; i < ans.length;i++) {
555 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
557 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
565 // hides menus... - so this cant be on a menu...
566 Roo.menu.MenuMgr.hideAll();
568 //this.editorsyncValue();
572 createFontOptions : function(){
573 var buf = [], fs = this.fontFamilies, ff, lc;
577 for(var i = 0, len = fs.length; i< len; i++){
579 lc = ff.toLowerCase();
581 '<option value="',lc,'" style="font-family:',ff,';"',
582 (this.defaultFont == lc ? ' selected="true">' : '>'),
590 toggleSourceEdit : function(sourceEditMode){
592 Roo.log("toolbar toogle");
593 if(sourceEditMode === undefined){
594 sourceEditMode = !this.sourceEditMode;
596 this.sourceEditMode = sourceEditMode === true;
597 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
598 // just toggle the button?
599 if(btn.pressed !== this.sourceEditMode){
600 btn.toggle(this.sourceEditMode);
605 Roo.log("disabling buttons");
606 this.tb.items.each(function(item){
607 if(item.cmd != 'sourceedit'){
613 Roo.log("enabling buttons");
614 if(this.editorcore.initialized){
615 this.tb.items.each(function(item){
621 Roo.log("calling toggole on editor");
622 // tell the editor that it's been pressed..
623 this.editor.toggleSourceEdit(sourceEditMode);
627 * Object collection of toolbar tooltips for the buttons in the editor. The key
628 * is the command id associated with that button and the value is a valid QuickTips object.
633 title: 'Bold (Ctrl+B)',
634 text: 'Make the selected text bold.',
635 cls: 'x-html-editor-tip'
638 title: 'Italic (Ctrl+I)',
639 text: 'Make the selected text italic.',
640 cls: 'x-html-editor-tip'
648 title: 'Bold (Ctrl+B)',
649 text: 'Make the selected text bold.',
650 cls: 'x-html-editor-tip'
653 title: 'Italic (Ctrl+I)',
654 text: 'Make the selected text italic.',
655 cls: 'x-html-editor-tip'
658 title: 'Underline (Ctrl+U)',
659 text: 'Underline the selected text.',
660 cls: 'x-html-editor-tip'
664 text: 'Increase the font size.',
665 cls: 'x-html-editor-tip'
668 title: 'Shrink Text',
669 text: 'Decrease the font size.',
670 cls: 'x-html-editor-tip'
673 title: 'Text Highlight Color',
674 text: 'Change the background color of the selected text.',
675 cls: 'x-html-editor-tip'
679 text: 'Change the color of the selected text.',
680 cls: 'x-html-editor-tip'
683 title: 'Align Text Left',
684 text: 'Align text to the left.',
685 cls: 'x-html-editor-tip'
688 title: 'Center Text',
689 text: 'Center text in the editor.',
690 cls: 'x-html-editor-tip'
693 title: 'Align Text Right',
694 text: 'Align text to the right.',
695 cls: 'x-html-editor-tip'
697 insertunorderedlist : {
698 title: 'Bullet List',
699 text: 'Start a bulleted list.',
700 cls: 'x-html-editor-tip'
702 insertorderedlist : {
703 title: 'Numbered List',
704 text: 'Start a numbered list.',
705 cls: 'x-html-editor-tip'
709 text: 'Make the selected text a hyperlink.',
710 cls: 'x-html-editor-tip'
713 title: 'Source Edit',
714 text: 'Switch to source editing mode.',
715 cls: 'x-html-editor-tip'
719 onDestroy : function(){
722 this.tb.items.each(function(item){
724 item.menu.removeAll();
726 item.menu.el.destroy();
734 onFirstFocus: function() {
735 this.tb.items.each(function(item){