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,
210 Roo.log('disable formats????????????????????????')
211 Roo.log(this.disable);
212 Roo.log(this.disable.formats);
213 if(!this.disable.formats){
214 this.formatCombo = new Roo.form.ComboBox({
215 store: new Roo.data.SimpleStore({
218 data : this.formats // from states.js
222 //autoCreate : {tag: "div", size: "20"},
227 triggerAction: 'all',
232 'select': function(c, r, i) {
233 editorcore.insertTag(r.get('tag'));
239 tb.addField(this.formatCombo);
243 if(!this.disable.format){
250 if(!this.disable.fontSize){
255 btn('increasefontsize', false, editorcore.adjustFont),
256 btn('decreasefontsize', false, editorcore.adjustFont)
261 if(!this.disable.colors){
264 id:editorcore.frameId +'-forecolor',
265 cls:'x-btn-icon x-edit-forecolor',
266 clickEvent:'mousedown',
267 tooltip: this.buttonTips['forecolor'] || undefined,
269 menu : new Roo.menu.ColorMenu({
274 selectHandler: function(cp, color){
275 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
279 clickEvent:'mousedown'
282 id:editorcore.frameId +'backcolor',
283 cls:'x-btn-icon x-edit-backcolor',
284 clickEvent:'mousedown',
285 tooltip: this.buttonTips['backcolor'] || undefined,
287 menu : new Roo.menu.ColorMenu({
292 selectHandler: function(cp, color){
294 editorcore.execCmd('useCSS', false);
295 editorcore.execCmd('hilitecolor', color);
296 editorcore.execCmd('useCSS', true);
299 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
300 Roo.isSafari || Roo.isIE ? '#'+color : color);
305 clickEvent:'mousedown'
310 // now add all the items...
313 if(!this.disable.alignments){
317 btn('justifycenter'),
323 if(!this.disable.links){
326 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
330 if(!this.disable.lists){
333 btn('insertorderedlist'),
334 btn('insertunorderedlist')
337 if(!this.disable.sourceEdit){
340 btn('sourceedit', true, function(btn){
342 this.toggleSourceEdit(btn.pressed);
349 // special menu.. - needs to be tidied up..
350 if (!this.disable.special) {
359 for (var i =0; i < this.specialChars.length; i++) {
360 smenu.menu.items.push({
362 html: this.specialChars[i],
363 handler: function(a,b) {
364 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
365 //editor.insertAtCursor(a.html);
379 if (!this.disable.cleanStyles) {
381 cls: 'x-btn-icon x-btn-clear',
387 for (var i =0; i < this.cleanStyles.length; i++) {
388 cmenu.menu.items.push({
389 actiontype : this.cleanStyles[i],
390 html: 'Remove ' + this.cleanStyles[i],
391 handler: function(a,b) {
394 var c = Roo.get(editorcore.doc.body);
395 c.select('[style]').each(function(s) {
396 s.dom.style.removeProperty(a.actiontype);
398 editorcore.syncValue();
403 cmenu.menu.items.push({
405 html: 'Remove MS Word Formating',
406 handler: function(a,b) {
407 editorcore.cleanWord();
408 editorcore.syncValue();
413 cmenu.menu.items.push({
415 html: 'Remove All Styles',
416 handler: function(a,b) {
418 var c = Roo.get(editorcore.doc.body);
419 c.select('[style]').each(function(s) {
420 s.dom.removeAttribute('style');
422 editorcore.syncValue();
426 cmenu.menu.items.push({
428 html: 'Tidy HTML Source',
429 handler: function(a,b) {
430 editorcore.doc.body.innerHTML = editorcore.domToHTML();
431 editorcore.syncValue();
440 if (!this.disable.specialElements) {
448 for (var i =0; i < this.specialElements.length; i++) {
449 semenu.menu.items.push(
451 handler: function(a,b) {
452 editor.insertAtCursor(this.ihtml);
454 }, this.specialElements[i])
466 for(var i =0; i< this.btns.length;i++) {
467 var b = Roo.factory(this.btns[i],Roo.form);
468 b.cls = 'x-edit-none';
469 b.scope = editorcore;
477 // disable everything...
479 this.tb.items.each(function(item){
480 if(item.id != editorcore.frameId+ '-sourceedit'){
484 this.rendered = true;
487 editor.on('editorevent', this.updateToolbar, this);
488 // other toolbars need to implement this..
489 //editor.on('editmodechange', this.updateToolbar, this);
493 relayBtnCmd : function(btn) {
494 this.editorcore.relayCmd(btn.cmd);
496 // private used internally
497 createLink : function(){
498 Roo.log("create link?");
499 var url = prompt(this.createLinkText, this.defaultLinkValue);
500 if(url && url != 'http:/'+'/'){
501 this.editorcore.relayCmd('createlink', url);
507 * Protected method that will not generally be called directly. It triggers
508 * a toolbar update by reading the markup state of the current selection in the editor.
510 updateToolbar: function(){
512 if(!this.editorcore.activated){
513 this.editor.onFirstFocus();
517 var btns = this.tb.items.map,
518 doc = this.editorcore.doc,
519 frameId = this.editorcore.frameId;
521 if(!this.disable.font && !Roo.isSafari){
523 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
524 if(name != this.fontSelect.dom.value){
525 this.fontSelect.dom.value = name;
529 if(!this.disable.format){
530 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
531 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
532 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
534 if(!this.disable.alignments){
535 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
536 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
537 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
539 if(!Roo.isSafari && !this.disable.lists){
540 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
541 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
544 var ans = this.editorcore.getAllAncestors();
545 if (this.formatCombo) {
548 var store = this.formatCombo.store;
549 this.formatCombo.setValue("");
550 for (var i =0; i < ans.length;i++) {
551 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
553 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
561 // hides menus... - so this cant be on a menu...
562 Roo.menu.MenuMgr.hideAll();
564 //this.editorsyncValue();
568 createFontOptions : function(){
569 var buf = [], fs = this.fontFamilies, ff, lc;
573 for(var i = 0, len = fs.length; i< len; i++){
575 lc = ff.toLowerCase();
577 '<option value="',lc,'" style="font-family:',ff,';"',
578 (this.defaultFont == lc ? ' selected="true">' : '>'),
586 toggleSourceEdit : function(sourceEditMode){
588 Roo.log("toolbar toogle");
589 if(sourceEditMode === undefined){
590 sourceEditMode = !this.sourceEditMode;
592 this.sourceEditMode = sourceEditMode === true;
593 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
594 // just toggle the button?
595 if(btn.pressed !== this.sourceEditMode){
596 btn.toggle(this.sourceEditMode);
601 Roo.log("disabling buttons");
602 this.tb.items.each(function(item){
603 if(item.cmd != 'sourceedit'){
609 Roo.log("enabling buttons");
610 if(this.editorcore.initialized){
611 this.tb.items.each(function(item){
617 Roo.log("calling toggole on editor");
618 // tell the editor that it's been pressed..
619 this.editor.toggleSourceEdit(sourceEditMode);
623 * Object collection of toolbar tooltips for the buttons in the editor. The key
624 * is the command id associated with that button and the value is a valid QuickTips object.
629 title: 'Bold (Ctrl+B)',
630 text: 'Make the selected text bold.',
631 cls: 'x-html-editor-tip'
634 title: 'Italic (Ctrl+I)',
635 text: 'Make the selected text italic.',
636 cls: 'x-html-editor-tip'
644 title: 'Bold (Ctrl+B)',
645 text: 'Make the selected text bold.',
646 cls: 'x-html-editor-tip'
649 title: 'Italic (Ctrl+I)',
650 text: 'Make the selected text italic.',
651 cls: 'x-html-editor-tip'
654 title: 'Underline (Ctrl+U)',
655 text: 'Underline the selected text.',
656 cls: 'x-html-editor-tip'
660 text: 'Increase the font size.',
661 cls: 'x-html-editor-tip'
664 title: 'Shrink Text',
665 text: 'Decrease the font size.',
666 cls: 'x-html-editor-tip'
669 title: 'Text Highlight Color',
670 text: 'Change the background color of the selected text.',
671 cls: 'x-html-editor-tip'
675 text: 'Change the color of the selected text.',
676 cls: 'x-html-editor-tip'
679 title: 'Align Text Left',
680 text: 'Align text to the left.',
681 cls: 'x-html-editor-tip'
684 title: 'Center Text',
685 text: 'Center text in the editor.',
686 cls: 'x-html-editor-tip'
689 title: 'Align Text Right',
690 text: 'Align text to the right.',
691 cls: 'x-html-editor-tip'
693 insertunorderedlist : {
694 title: 'Bullet List',
695 text: 'Start a bulleted list.',
696 cls: 'x-html-editor-tip'
698 insertorderedlist : {
699 title: 'Numbered List',
700 text: 'Start a numbered list.',
701 cls: 'x-html-editor-tip'
705 text: 'Make the selected text a hyperlink.',
706 cls: 'x-html-editor-tip'
709 title: 'Source Edit',
710 text: 'Switch to source editing mode.',
711 cls: 'x-html-editor-tip'
715 onDestroy : function(){
718 this.tb.items.each(function(item){
720 item.menu.removeAll();
722 item.menu.el.destroy();
730 onFirstFocus: function() {
731 this.tb.items.each(function(item){