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);
179 Roo.log('ToobarStandard tb!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
183 tb.el.on('click', function(e){
184 e.preventDefault(); // what does this do?
187 if(!this.disable.font) { // && !Roo.isSafari){
188 /* why no safari for fonts
189 editor.fontSelect = tb.el.createChild({
193 html: this.createFontOptions()
196 editor.fontSelect.on('change', function(){
197 var font = editor.fontSelect.dom.value;
198 editor.relayCmd('fontname', font);
203 editor.fontSelect.dom,
209 if(!this.disable.formats){
210 this.formatCombo = new Roo.form.ComboBox({
211 store: new Roo.data.SimpleStore({
214 data : this.formats // from states.js
218 //autoCreate : {tag: "div", size: "20"},
223 triggerAction: 'all',
228 'select': function(c, r, i) {
229 editorcore.insertTag(r.get('tag'));
235 tb.addField(this.formatCombo);
239 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){
338 this.toggleSourceEdit(btn.pressed);
345 // special menu.. - needs to be tidied up..
346 if (!this.disable.special) {
355 for (var i =0; i < this.specialChars.length; i++) {
356 smenu.menu.items.push({
358 html: this.specialChars[i],
359 handler: function(a,b) {
360 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
361 //editor.insertAtCursor(a.html);
375 if (!this.disable.cleanStyles) {
377 cls: 'x-btn-icon x-btn-clear',
383 for (var i =0; i < this.cleanStyles.length; i++) {
384 cmenu.menu.items.push({
385 actiontype : this.cleanStyles[i],
386 html: 'Remove ' + this.cleanStyles[i],
387 handler: function(a,b) {
390 var c = Roo.get(editorcore.doc.body);
391 c.select('[style]').each(function(s) {
392 s.dom.style.removeProperty(a.actiontype);
394 editorcore.syncValue();
399 cmenu.menu.items.push({
401 html: 'Remove MS Word Formating',
402 handler: function(a,b) {
403 editorcore.cleanWord();
404 editorcore.syncValue();
409 cmenu.menu.items.push({
411 html: 'Remove All Styles',
412 handler: function(a,b) {
414 var c = Roo.get(editorcore.doc.body);
415 c.select('[style]').each(function(s) {
416 s.dom.removeAttribute('style');
418 editorcore.syncValue();
422 cmenu.menu.items.push({
424 html: 'Tidy HTML Source',
425 handler: function(a,b) {
426 editorcore.doc.body.innerHTML = editorcore.domToHTML();
427 editorcore.syncValue();
436 if (!this.disable.specialElements) {
444 for (var i =0; i < this.specialElements.length; i++) {
445 semenu.menu.items.push(
447 handler: function(a,b) {
448 editor.insertAtCursor(this.ihtml);
450 }, this.specialElements[i])
462 for(var i =0; i< this.btns.length;i++) {
463 var b = Roo.factory(this.btns[i],Roo.form);
464 b.cls = 'x-edit-none';
465 b.scope = editorcore;
473 // disable everything...
475 this.tb.items.each(function(item){
476 if(item.id != editorcore.frameId+ '-sourceedit'){
480 this.rendered = true;
483 editor.on('editorevent', this.updateToolbar, this);
484 // other toolbars need to implement this..
485 //editor.on('editmodechange', this.updateToolbar, this);
489 relayBtnCmd : function(btn) {
490 this.editorcore.relayCmd(btn.cmd);
492 // private used internally
493 createLink : function(){
494 Roo.log("create link?");
495 var url = prompt(this.createLinkText, this.defaultLinkValue);
496 if(url && url != 'http:/'+'/'){
497 this.editorcore.relayCmd('createlink', url);
503 * Protected method that will not generally be called directly. It triggers
504 * a toolbar update by reading the markup state of the current selection in the editor.
506 updateToolbar: function(){
508 if(!this.editorcore.activated){
509 this.editor.onFirstFocus();
513 var btns = this.tb.items.map,
514 doc = this.editorcore.doc,
515 frameId = this.editorcore.frameId;
517 if(!this.disable.font && !Roo.isSafari){
519 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
520 if(name != this.fontSelect.dom.value){
521 this.fontSelect.dom.value = name;
525 if(!this.disable.format){
526 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
527 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
528 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
530 if(!this.disable.alignments){
531 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
532 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
533 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
535 if(!Roo.isSafari && !this.disable.lists){
536 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
537 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
540 var ans = this.editorcore.getAllAncestors();
541 if (this.formatCombo) {
544 var store = this.formatCombo.store;
545 this.formatCombo.setValue("");
546 for (var i =0; i < ans.length;i++) {
547 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
549 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
557 // hides menus... - so this cant be on a menu...
558 Roo.menu.MenuMgr.hideAll();
560 //this.editorsyncValue();
564 createFontOptions : function(){
565 var buf = [], fs = this.fontFamilies, ff, lc;
569 for(var i = 0, len = fs.length; i< len; i++){
571 lc = ff.toLowerCase();
573 '<option value="',lc,'" style="font-family:',ff,';"',
574 (this.defaultFont == lc ? ' selected="true">' : '>'),
582 toggleSourceEdit : function(sourceEditMode){
584 Roo.log("toolbar toogle");
585 if(sourceEditMode === undefined){
586 sourceEditMode = !this.sourceEditMode;
588 this.sourceEditMode = sourceEditMode === true;
589 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
590 // just toggle the button?
591 if(btn.pressed !== this.sourceEditMode){
592 btn.toggle(this.sourceEditMode);
597 Roo.log("disabling buttons");
598 this.tb.items.each(function(item){
599 if(item.cmd != 'sourceedit'){
605 Roo.log("enabling buttons");
606 if(this.editorcore.initialized){
607 this.tb.items.each(function(item){
613 Roo.log("calling toggole on editor");
614 // tell the editor that it's been pressed..
615 this.editor.toggleSourceEdit(sourceEditMode);
619 * Object collection of toolbar tooltips for the buttons in the editor. The key
620 * is the command id associated with that button and the value is a valid QuickTips object.
625 title: 'Bold (Ctrl+B)',
626 text: 'Make the selected text bold.',
627 cls: 'x-html-editor-tip'
630 title: 'Italic (Ctrl+I)',
631 text: 'Make the selected text italic.',
632 cls: 'x-html-editor-tip'
640 title: 'Bold (Ctrl+B)',
641 text: 'Make the selected text bold.',
642 cls: 'x-html-editor-tip'
645 title: 'Italic (Ctrl+I)',
646 text: 'Make the selected text italic.',
647 cls: 'x-html-editor-tip'
650 title: 'Underline (Ctrl+U)',
651 text: 'Underline the selected text.',
652 cls: 'x-html-editor-tip'
656 text: 'Increase the font size.',
657 cls: 'x-html-editor-tip'
660 title: 'Shrink Text',
661 text: 'Decrease the font size.',
662 cls: 'x-html-editor-tip'
665 title: 'Text Highlight Color',
666 text: 'Change the background color of the selected text.',
667 cls: 'x-html-editor-tip'
671 text: 'Change the color of the selected text.',
672 cls: 'x-html-editor-tip'
675 title: 'Align Text Left',
676 text: 'Align text to the left.',
677 cls: 'x-html-editor-tip'
680 title: 'Center Text',
681 text: 'Center text in the editor.',
682 cls: 'x-html-editor-tip'
685 title: 'Align Text Right',
686 text: 'Align text to the right.',
687 cls: 'x-html-editor-tip'
689 insertunorderedlist : {
690 title: 'Bullet List',
691 text: 'Start a bulleted list.',
692 cls: 'x-html-editor-tip'
694 insertorderedlist : {
695 title: 'Numbered List',
696 text: 'Start a numbered list.',
697 cls: 'x-html-editor-tip'
701 text: 'Make the selected text a hyperlink.',
702 cls: 'x-html-editor-tip'
705 title: 'Source Edit',
706 text: 'Switch to source editing mode.',
707 cls: 'x-html-editor-tip'
711 onDestroy : function(){
714 this.tb.items.each(function(item){
716 item.menu.removeAll();
718 item.menu.el.destroy();
726 onFirstFocus: function() {
727 this.tb.items.each(function(item){