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, {
60 * @cfg {Object} disable List of toolbar elements to disable
65 * @cfg {Array} fontFamilies An array of available font families
83 // "á" , ?? a acute?
88 "°" // , // degrees
90 // "é" , // e ecute
91 // "ú" , // u ecute?
99 ihtml : '<table><tr><td>Cell</td></tr></table>'
103 text: "Insert Image",
106 ihtml : '<img src="about:blank"/>'
115 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
116 "input:submit", "input:button", "select", "textarea", "label" ],
119 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
121 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
124 * @cfg {String} defaultFont default font to use.
126 defaultFont: 'tahoma',
133 init : function(editor)
135 this.editor = editor;
138 var fid = editor.frameId;
140 function btn(id, toggle, handler){
141 var xid = fid + '-'+ id ;
145 cls : 'x-btn-icon x-edit-'+id,
146 enableToggle:toggle !== false,
147 scope: editor, // was editor...
148 handler:handler||editor.relayBtnCmd,
149 clickEvent:'mousedown',
150 tooltip: etb.buttonTips[id] || undefined, ///tips ???
157 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
160 tb.el.on('click', function(e){
161 e.preventDefault(); // what does this do?
164 if(!this.disable.font && !Roo.isSafari){
165 /* why no safari for fonts
166 editor.fontSelect = tb.el.createChild({
170 html: editor.createFontOptions()
172 editor.fontSelect.on('change', function(){
173 var font = editor.fontSelect.dom.value;
174 editor.relayCmd('fontname', font);
178 editor.fontSelect.dom,
183 if(!this.disable.formats){
184 this.formatCombo = new Roo.form.ComboBox({
185 store: new Roo.data.SimpleStore({
188 data : this.formats // from states.js
191 //autoCreate : {tag: "div", size: "20"},
196 triggerAction: 'all',
201 'select': function(c, r, i) {
202 editor.insertTag(r.get('tag'));
208 tb.addField(this.formatCombo);
212 if(!this.disable.format){
219 if(!this.disable.fontSize){
224 btn('increasefontsize', false, editor.adjustFont),
225 btn('decreasefontsize', false, editor.adjustFont)
230 if(!this.disable.colors){
233 id:editor.frameId +'-forecolor',
234 cls:'x-btn-icon x-edit-forecolor',
235 clickEvent:'mousedown',
236 tooltip: this.buttonTips['forecolor'] || undefined,
238 menu : new Roo.menu.ColorMenu({
243 selectHandler: function(cp, color){
244 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
248 clickEvent:'mousedown'
251 id:editor.frameId +'backcolor',
252 cls:'x-btn-icon x-edit-backcolor',
253 clickEvent:'mousedown',
254 tooltip: this.buttonTips['backcolor'] || undefined,
256 menu : new Roo.menu.ColorMenu({
261 selectHandler: function(cp, color){
263 editor.execCmd('useCSS', false);
264 editor.execCmd('hilitecolor', color);
265 editor.execCmd('useCSS', true);
268 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
269 Roo.isSafari || Roo.isIE ? '#'+color : color);
274 clickEvent:'mousedown'
279 // now add all the items...
282 if(!this.disable.alignments){
286 btn('justifycenter'),
292 if(!this.disable.links){
295 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
299 if(!this.disable.lists){
302 btn('insertorderedlist'),
303 btn('insertunorderedlist')
306 if(!this.disable.sourceEdit){
309 btn('sourceedit', true, function(btn){
310 this.toggleSourceEdit(btn.pressed);
317 // special menu.. - needs to be tidied up..
318 if (!this.disable.special) {
327 for (var i =0; i < this.specialChars.length; i++) {
328 smenu.menu.items.push({
330 html: this.specialChars[i],
331 handler: function(a,b) {
332 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
345 if (!this.disable.specialElements) {
353 for (var i =0; i < this.specialElements.length; i++) {
354 semenu.menu.items.push(
356 handler: function(a,b) {
357 editor.insertAtCursor(this.ihtml);
359 }, this.specialElements[i])
371 for(var i =0; i< this.btns.length;i++) {
372 var b = this.btns[i];
373 b.cls = 'x-edit-none';
382 // disable everything...
384 this.tb.items.each(function(item){
385 if(item.id != editor.frameId+ '-sourceedit'){
389 this.rendered = true;
392 editor.on('editorevent', this.updateToolbar, this);
393 // other toolbars need to implement this..
394 //editor.on('editmodechange', this.updateToolbar, this);
400 * Protected method that will not generally be called directly. It triggers
401 * a toolbar update by reading the markup state of the current selection in the editor.
403 updateToolbar: function(){
405 if(!this.editor.activated){
406 this.editor.onFirstFocus();
410 var btns = this.tb.items.map,
411 doc = this.editor.doc,
412 frameId = this.editor.frameId;
414 if(!this.disable.font && !Roo.isSafari){
416 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
417 if(name != this.fontSelect.dom.value){
418 this.fontSelect.dom.value = name;
422 if(!this.disable.format){
423 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
424 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
425 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
427 if(!this.disable.alignments){
428 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
429 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
430 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
432 if(!Roo.isSafari && !this.disable.lists){
433 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
434 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
437 var ans = this.editor.getAllAncestors();
438 if (this.formatCombo) {
441 var store = this.formatCombo.store;
442 this.formatCombo.setValue("");
443 for (var i =0; i < ans.length;i++) {
444 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
446 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
454 // hides menus... - so this cant be on a menu...
455 Roo.menu.MenuMgr.hideAll();
457 //this.editorsyncValue();
461 createFontOptions : function(){
462 var buf = [], fs = this.fontFamilies, ff, lc;
463 for(var i = 0, len = fs.length; i< len; i++){
465 lc = ff.toLowerCase();
467 '<option value="',lc,'" style="font-family:',ff,';"',
468 (this.defaultFont == lc ? ' selected="true">' : '>'),
476 toggleSourceEdit : function(sourceEditMode){
477 if(sourceEditMode === undefined){
478 sourceEditMode = !this.sourceEditMode;
480 this.sourceEditMode = sourceEditMode === true;
481 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
482 // just toggle the button?
483 if(btn.pressed !== this.editor.sourceEditMode){
484 btn.toggle(this.editor.sourceEditMode);
488 if(this.sourceEditMode){
489 this.tb.items.each(function(item){
490 if(item.cmd != 'sourceedit'){
496 if(this.initialized){
497 this.tb.items.each(function(item){
503 // tell the editor that it's been pressed..
504 this.editor.toggleSourceEdit(sourceEditMode);
508 * Object collection of toolbar tooltips for the buttons in the editor. The key
509 * is the command id associated with that button and the value is a valid QuickTips object.
514 title: 'Bold (Ctrl+B)',
515 text: 'Make the selected text bold.',
516 cls: 'x-html-editor-tip'
519 title: 'Italic (Ctrl+I)',
520 text: 'Make the selected text italic.',
521 cls: 'x-html-editor-tip'
529 title: 'Bold (Ctrl+B)',
530 text: 'Make the selected text bold.',
531 cls: 'x-html-editor-tip'
534 title: 'Italic (Ctrl+I)',
535 text: 'Make the selected text italic.',
536 cls: 'x-html-editor-tip'
539 title: 'Underline (Ctrl+U)',
540 text: 'Underline the selected text.',
541 cls: 'x-html-editor-tip'
545 text: 'Increase the font size.',
546 cls: 'x-html-editor-tip'
549 title: 'Shrink Text',
550 text: 'Decrease the font size.',
551 cls: 'x-html-editor-tip'
554 title: 'Text Highlight Color',
555 text: 'Change the background color of the selected text.',
556 cls: 'x-html-editor-tip'
560 text: 'Change the color of the selected text.',
561 cls: 'x-html-editor-tip'
564 title: 'Align Text Left',
565 text: 'Align text to the left.',
566 cls: 'x-html-editor-tip'
569 title: 'Center Text',
570 text: 'Center text in the editor.',
571 cls: 'x-html-editor-tip'
574 title: 'Align Text Right',
575 text: 'Align text to the right.',
576 cls: 'x-html-editor-tip'
578 insertunorderedlist : {
579 title: 'Bullet List',
580 text: 'Start a bulleted list.',
581 cls: 'x-html-editor-tip'
583 insertorderedlist : {
584 title: 'Numbered List',
585 text: 'Start a numbered list.',
586 cls: 'x-html-editor-tip'
590 text: 'Make the selected text a hyperlink.',
591 cls: 'x-html-editor-tip'
594 title: 'Source Edit',
595 text: 'Switch to source editing mode.',
596 cls: 'x-html-editor-tip'
600 onDestroy : function(){
603 this.tb.items.each(function(item){
605 item.menu.removeAll();
607 item.menu.el.destroy();
615 onFirstFocus: function() {
616 this.tb.items.each(function(item){