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
66 * @cfg {Array} fontFamilies An array of available font families
84 // "á" , ?? a acute?
89 "°" // , // degrees
91 // "é" , // e ecute
92 // "ú" , // u ecute?
100 ihtml : '<table><tr><td>Cell</td></tr></table>'
104 text: "Insert Image",
107 ihtml : '<img src="about:blank"/>'
116 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
117 "input:submit", "input:button", "select", "textarea", "label" ],
120 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
122 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"],
130 * @cfg {String} defaultFont default font to use.
132 defaultFont: 'tahoma',
139 init : function(editor)
141 this.editor = editor;
142 this.editorcore = editor.editorcore ? editor.editorcore : editor;
143 var editorcore = this.editorcore;
147 var fid = editorcore.frameId;
149 function btn(id, toggle, handler){
150 var xid = fid + '-'+ id ;
154 cls : 'x-btn-icon x-edit-'+id,
155 enableToggle:toggle !== false,
156 scope: _t, // was editor...
157 handler:handler||_t.relayBtnCmd,
158 clickEvent:'mousedown',
159 tooltip: etb.buttonTips[id] || undefined, ///tips ???
166 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
169 tb.el.on('click', function(e){
170 e.preventDefault(); // what does this do?
173 if(!this.disable.font) { // && !Roo.isSafari){
174 /* why no safari for fonts
175 editor.fontSelect = tb.el.createChild({
179 html: this.createFontOptions()
182 editor.fontSelect.on('change', function(){
183 var font = editor.fontSelect.dom.value;
184 editor.relayCmd('fontname', font);
189 editor.fontSelect.dom,
195 if(!this.disable.formats){
196 this.formatCombo = new Roo.form.ComboBox({
197 store: new Roo.data.SimpleStore({
200 data : this.formats // from states.js
204 //autoCreate : {tag: "div", size: "20"},
209 triggerAction: 'all',
214 'select': function(c, r, i) {
215 editorcore.insertTag(r.get('tag'));
221 tb.addField(this.formatCombo);
225 if(!this.disable.format){
232 if(!this.disable.fontSize){
237 btn('increasefontsize', false, editorcore.adjustFont),
238 btn('decreasefontsize', false, editorcore.adjustFont)
243 if(!this.disable.colors){
246 id:editorcore.frameId +'-forecolor',
247 cls:'x-btn-icon x-edit-forecolor',
248 clickEvent:'mousedown',
249 tooltip: this.buttonTips['forecolor'] || undefined,
251 menu : new Roo.menu.ColorMenu({
256 selectHandler: function(cp, color){
257 editorcore.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
261 clickEvent:'mousedown'
264 id:editorcore.frameId +'backcolor',
265 cls:'x-btn-icon x-edit-backcolor',
266 clickEvent:'mousedown',
267 tooltip: this.buttonTips['backcolor'] || undefined,
269 menu : new Roo.menu.ColorMenu({
274 selectHandler: function(cp, color){
276 editorcore.execCmd('useCSS', false);
277 editorcore.execCmd('hilitecolor', color);
278 editorcore.execCmd('useCSS', true);
281 editorcore.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
282 Roo.isSafari || Roo.isIE ? '#'+color : color);
287 clickEvent:'mousedown'
292 // now add all the items...
295 if(!this.disable.alignments){
299 btn('justifycenter'),
305 if(!this.disable.links){
308 btn('createlink', false, this.createLink) /// MOVE TO HERE?!!?!?!?!
312 if(!this.disable.lists){
315 btn('insertorderedlist'),
316 btn('insertunorderedlist')
319 if(!this.disable.sourceEdit){
322 btn('sourceedit', true, function(btn){
324 this.toggleSourceEdit(btn.pressed);
331 // special menu.. - needs to be tidied up..
332 if (!this.disable.special) {
341 for (var i =0; i < this.specialChars.length; i++) {
342 smenu.menu.items.push({
344 html: this.specialChars[i],
345 handler: function(a,b) {
346 editorcore.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
347 //editor.insertAtCursor(a.html);
361 if (!this.disable.cleanStyles) {
363 cls: 'x-btn-icon x-btn-clear',
369 for (var i =0; i < this.cleanStyles.length; i++) {
370 cmenu.menu.items.push({
371 actiontype : this.cleanStyles[i],
372 html: 'Remove ' + this.cleanStyles[i],
373 handler: function(a,b) {
376 var c = Roo.get(editorcore.doc.body);
377 c.select('[style]').each(function(s) {
378 s.dom.style.removeProperty(a.actiontype);
389 if (!this.disable.specialElements) {
397 for (var i =0; i < this.specialElements.length; i++) {
398 semenu.menu.items.push(
400 handler: function(a,b) {
401 editor.insertAtCursor(this.ihtml);
403 }, this.specialElements[i])
415 for(var i =0; i< this.btns.length;i++) {
416 var b = Roo.factory(this.btns[i],Roo.form);
417 b.cls = 'x-edit-none';
418 b.scope = editorcore;
426 // disable everything...
428 this.tb.items.each(function(item){
429 if(item.id != editorcore.frameId+ '-sourceedit'){
433 this.rendered = true;
436 editor.on('editorevent', this.updateToolbar, this);
437 // other toolbars need to implement this..
438 //editor.on('editmodechange', this.updateToolbar, this);
442 relayBtnCmd : function(btn) {
443 this.editorcore.relayCmd(btn.cmd);
448 * Protected method that will not generally be called directly. It triggers
449 * a toolbar update by reading the markup state of the current selection in the editor.
451 updateToolbar: function(){
453 if(!this.editorcore.activated){
454 this.editor.onFirstFocus();
458 var btns = this.tb.items.map,
459 doc = this.editorcore.doc,
460 frameId = this.editorcore.frameId;
462 if(!this.disable.font && !Roo.isSafari){
464 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
465 if(name != this.fontSelect.dom.value){
466 this.fontSelect.dom.value = name;
470 if(!this.disable.format){
471 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
472 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
473 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
475 if(!this.disable.alignments){
476 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
477 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
478 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
480 if(!Roo.isSafari && !this.disable.lists){
481 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
482 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
485 var ans = this.editorcore.getAllAncestors();
486 if (this.formatCombo) {
489 var store = this.formatCombo.store;
490 this.formatCombo.setValue("");
491 for (var i =0; i < ans.length;i++) {
492 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
494 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
502 // hides menus... - so this cant be on a menu...
503 Roo.menu.MenuMgr.hideAll();
505 //this.editorsyncValue();
509 createFontOptions : function(){
510 var buf = [], fs = this.fontFamilies, ff, lc;
514 for(var i = 0, len = fs.length; i< len; i++){
516 lc = ff.toLowerCase();
518 '<option value="',lc,'" style="font-family:',ff,';"',
519 (this.defaultFont == lc ? ' selected="true">' : '>'),
527 toggleSourceEdit : function(sourceEditMode){
529 Roo.log("toolbar toogle");
530 if(sourceEditMode === undefined){
531 sourceEditMode = !this.sourceEditMode;
533 this.sourceEditMode = sourceEditMode === true;
534 var btn = this.tb.items.get(this.editorcore.frameId +'-sourceedit');
535 // just toggle the button?
536 if(btn.pressed !== this.sourceEditMode){
537 btn.toggle(this.sourceEditMode);
541 if(this.editorcore.sourceEditMode){
542 this.tb.items.each(function(item){
543 if(item.cmd != 'sourceedit'){
549 if(this.initialized){
550 this.tb.items.each(function(item){
556 Roo.log("calling toggole on editor");
557 // tell the editor that it's been pressed..
558 this.editor.toggleSourceEdit(sourceEditMode);
562 * Object collection of toolbar tooltips for the buttons in the editor. The key
563 * is the command id associated with that button and the value is a valid QuickTips object.
568 title: 'Bold (Ctrl+B)',
569 text: 'Make the selected text bold.',
570 cls: 'x-html-editor-tip'
573 title: 'Italic (Ctrl+I)',
574 text: 'Make the selected text italic.',
575 cls: 'x-html-editor-tip'
583 title: 'Bold (Ctrl+B)',
584 text: 'Make the selected text bold.',
585 cls: 'x-html-editor-tip'
588 title: 'Italic (Ctrl+I)',
589 text: 'Make the selected text italic.',
590 cls: 'x-html-editor-tip'
593 title: 'Underline (Ctrl+U)',
594 text: 'Underline the selected text.',
595 cls: 'x-html-editor-tip'
599 text: 'Increase the font size.',
600 cls: 'x-html-editor-tip'
603 title: 'Shrink Text',
604 text: 'Decrease the font size.',
605 cls: 'x-html-editor-tip'
608 title: 'Text Highlight Color',
609 text: 'Change the background color of the selected text.',
610 cls: 'x-html-editor-tip'
614 text: 'Change the color of the selected text.',
615 cls: 'x-html-editor-tip'
618 title: 'Align Text Left',
619 text: 'Align text to the left.',
620 cls: 'x-html-editor-tip'
623 title: 'Center Text',
624 text: 'Center text in the editor.',
625 cls: 'x-html-editor-tip'
628 title: 'Align Text Right',
629 text: 'Align text to the right.',
630 cls: 'x-html-editor-tip'
632 insertunorderedlist : {
633 title: 'Bullet List',
634 text: 'Start a bulleted list.',
635 cls: 'x-html-editor-tip'
637 insertorderedlist : {
638 title: 'Numbered List',
639 text: 'Start a numbered list.',
640 cls: 'x-html-editor-tip'
644 text: 'Make the selected text a hyperlink.',
645 cls: 'x-html-editor-tip'
648 title: 'Source Edit',
649 text: 'Switch to source editing mode.',
650 cls: 'x-html-editor-tip'
654 onDestroy : function(){
657 this.tb.items.each(function(item){
659 item.menu.removeAll();
661 item.menu.el.destroy();
669 onFirstFocus: function() {
670 this.tb.items.each(function(item){