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);
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){
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){
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({
400 html: 'Remove MS Word Formating',
401 handler: function(a,b) {
402 editorcore.cleanWord();
403 editorcore.syncValue();
408 cmenu.menu.items.push({
410 html: 'Remove All Styles',
411 handler: function(a,b) {
413 var c = Roo.get(editorcore.doc.body);
414 c.select('[style]').each(function(s) {
415 s.dom.removeAttribute('style');
417 editorcore.syncValue();
421 cmenu.menu.items.push({
423 html: 'Tidy HTML Source',
424 handler: function(a,b) {
425 editorcore.doc.body.innerHTML = editorcore.domToHTML();
426 editorcore.syncValue();
435 if (!this.disable.specialElements) {
443 for (var i =0; i < this.specialElements.length; i++) {
444 semenu.menu.items.push(
446 handler: function(a,b) {
447 editor.insertAtCursor(this.ihtml);
449 }, this.specialElements[i])
461 for(var i =0; i< this.btns.length;i++) {
462 var b = Roo.factory(this.btns[i],Roo.form);
463 b.cls = 'x-edit-none';
464 b.scope = editorcore;
472 // disable everything...
474 this.tb.items.each(function(item){
475 if(item.id != editorcore.frameId+ '-sourceedit'){
479 this.rendered = true;
482 editor.on('editorevent', this.updateToolbar, this);
483 // other toolbars need to implement this..
484 //editor.on('editmodechange', this.updateToolbar, this);
488 relayBtnCmd : function(btn) {
489 this.editorcore.relayCmd(btn.cmd);
491 // private used internally
492 createLink : function(){
493 Roo.log("create link?");
494 var url = prompt(this.createLinkText, this.defaultLinkValue);
495 if(url && url != 'http:/'+'/'){
496 this.editorcore.relayCmd('createlink', url);
502 * Protected method that will not generally be called directly. It triggers
503 * a toolbar update by reading the markup state of the current selection in the editor.
505 updateToolbar: function(){
507 if(!this.editorcore.activated){
508 this.editor.onFirstFocus();
512 var btns = this.tb.items.map,
513 doc = this.editorcore.doc,
514 frameId = this.editorcore.frameId;
516 if(!this.disable.font && !Roo.isSafari){
518 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
519 if(name != this.fontSelect.dom.value){
520 this.fontSelect.dom.value = name;
524 if(!this.disable.format){
525 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
526 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
527 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
529 if(!this.disable.alignments){
530 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
531 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
532 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
534 if(!Roo.isSafari && !this.disable.lists){
535 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
536 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
539 var ans = this.editorcore.getAllAncestors();
540 if (this.formatCombo) {
543 var store = this.formatCombo.store;
544 this.formatCombo.setValue("");
545 for (var i =0; i < ans.length;i++) {
546 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
548 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
556 // hides menus... - so this cant be on a menu...
557 Roo.menu.MenuMgr.hideAll();
559 //this.editorsyncValue();
563 createFontOptions : function(){
564 var buf = [], fs = this.fontFamilies, ff, lc;
568 for(var i = 0, len = fs.length; i< len; i++){
570 lc = ff.toLowerCase();
572 '<option value="',lc,'" style="font-family:',ff,';"',
573 (this.defaultFont == lc ? ' selected="true">' : '>'),
581 toggleSourceEdit : function(sourceEditMode){
583 Roo.log("toolbar toogle");
584 if(sourceEditMode === undefined){
585 sourceEditMode = !this.sourceEditMode;
587 this.sourceEditMode = sourceEditMode === true;
588 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
589 // just toggle the button?
590 if(btn.pressed !== this.sourceEditMode){
591 btn.toggle(this.sourceEditMode);
596 Roo.log("disabling buttons");
597 this.tb.items.each(function(item){
598 if(item.cmd != 'sourceedit'){
604 Roo.log("enabling buttons");
605 if(this.editorcore.initialized){
606 this.tb.items.each(function(item){
612 Roo.log("calling toggole on editor");
613 // tell the editor that it's been pressed..
614 this.editor.toggleSourceEdit(sourceEditMode);
618 * Object collection of toolbar tooltips for the buttons in the editor. The key
619 * is the command id associated with that button and the value is a valid QuickTips object.
624 title: 'Bold (Ctrl+B)',
625 text: 'Make the selected text bold.',
626 cls: 'x-html-editor-tip'
629 title: 'Italic (Ctrl+I)',
630 text: 'Make the selected text italic.',
631 cls: 'x-html-editor-tip'
639 title: 'Bold (Ctrl+B)',
640 text: 'Make the selected text bold.',
641 cls: 'x-html-editor-tip'
644 title: 'Italic (Ctrl+I)',
645 text: 'Make the selected text italic.',
646 cls: 'x-html-editor-tip'
649 title: 'Underline (Ctrl+U)',
650 text: 'Underline the selected text.',
651 cls: 'x-html-editor-tip'
655 text: 'Increase the font size.',
656 cls: 'x-html-editor-tip'
659 title: 'Shrink Text',
660 text: 'Decrease the font size.',
661 cls: 'x-html-editor-tip'
664 title: 'Text Highlight Color',
665 text: 'Change the background color of the selected text.',
666 cls: 'x-html-editor-tip'
670 text: 'Change the color of the selected text.',
671 cls: 'x-html-editor-tip'
674 title: 'Align Text Left',
675 text: 'Align text to the left.',
676 cls: 'x-html-editor-tip'
679 title: 'Center Text',
680 text: 'Center text in the editor.',
681 cls: 'x-html-editor-tip'
684 title: 'Align Text Right',
685 text: 'Align text to the right.',
686 cls: 'x-html-editor-tip'
688 insertunorderedlist : {
689 title: 'Bullet List',
690 text: 'Start a bulleted list.',
691 cls: 'x-html-editor-tip'
693 insertorderedlist : {
694 title: 'Numbered List',
695 text: 'Start a numbered list.',
696 cls: 'x-html-editor-tip'
700 text: 'Make the selected text a hyperlink.',
701 cls: 'x-html-editor-tip'
704 title: 'Source Edit',
705 text: 'Switch to source editing mode.',
706 cls: 'x-html-editor-tip'
710 onDestroy : function(){
713 this.tb.items.each(function(item){
715 item.menu.removeAll();
717 item.menu.el.destroy();
725 onFirstFocus: function() {
726 this.tb.items.each(function(item){