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"],
125 * @cfg {String} defaultFont default font to use.
127 defaultFont: 'tahoma',
134 init : function(editor)
136 this.editor = editor;
139 var fid = editor.frameId;
141 function btn(id, toggle, handler){
142 var xid = fid + '-'+ id ;
146 cls : 'x-btn-icon x-edit-'+id,
147 enableToggle:toggle !== false,
148 scope: editor, // was editor...
149 handler:handler||editor.relayBtnCmd,
150 clickEvent:'mousedown',
151 tooltip: etb.buttonTips[id] || undefined, ///tips ???
158 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
161 tb.el.on('click', function(e){
162 e.preventDefault(); // what does this do?
165 if(!this.disable.font) { // && !Roo.isSafari){
166 /* why no safari for fonts
167 editor.fontSelect = tb.el.createChild({
171 html: this.createFontOptions()
174 editor.fontSelect.on('change', function(){
175 var font = editor.fontSelect.dom.value;
176 editor.relayCmd('fontname', font);
181 editor.fontSelect.dom,
187 if(!this.disable.formats){
188 this.formatCombo = new Roo.form.ComboBox({
189 store: new Roo.data.SimpleStore({
192 data : this.formats // from states.js
196 //autoCreate : {tag: "div", size: "20"},
201 triggerAction: 'all',
206 'select': function(c, r, i) {
207 editor.insertTag(r.get('tag'));
213 tb.addField(this.formatCombo);
217 if(!this.disable.format){
224 if(!this.disable.fontSize){
229 btn('increasefontsize', false, editor.adjustFont),
230 btn('decreasefontsize', false, editor.adjustFont)
235 if(!this.disable.colors){
238 id:editor.frameId +'-forecolor',
239 cls:'x-btn-icon x-edit-forecolor',
240 clickEvent:'mousedown',
241 tooltip: this.buttonTips['forecolor'] || undefined,
243 menu : new Roo.menu.ColorMenu({
248 selectHandler: function(cp, color){
249 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
253 clickEvent:'mousedown'
256 id:editor.frameId +'backcolor',
257 cls:'x-btn-icon x-edit-backcolor',
258 clickEvent:'mousedown',
259 tooltip: this.buttonTips['backcolor'] || undefined,
261 menu : new Roo.menu.ColorMenu({
266 selectHandler: function(cp, color){
268 editor.execCmd('useCSS', false);
269 editor.execCmd('hilitecolor', color);
270 editor.execCmd('useCSS', true);
273 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
274 Roo.isSafari || Roo.isIE ? '#'+color : color);
279 clickEvent:'mousedown'
284 // now add all the items...
287 if(!this.disable.alignments){
291 btn('justifycenter'),
297 if(!this.disable.links){
300 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
304 if(!this.disable.lists){
307 btn('insertorderedlist'),
308 btn('insertunorderedlist')
311 if(!this.disable.sourceEdit){
314 btn('sourceedit', true, function(btn){
315 this.toggleSourceEdit(btn.pressed);
322 // special menu.. - needs to be tidied up..
323 if (!this.disable.special) {
332 for (var i =0; i < this.specialChars.length; i++) {
333 smenu.menu.items.push({
335 html: this.specialChars[i],
336 handler: function(a,b) {
337 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
338 //editor.insertAtCursor(a.html);
351 if (!this.disable.specialElements) {
359 for (var i =0; i < this.specialElements.length; i++) {
360 semenu.menu.items.push(
362 handler: function(a,b) {
363 editor.insertAtCursor(this.ihtml);
365 }, this.specialElements[i])
377 for(var i =0; i< this.btns.length;i++) {
378 var b = Roo.factory(this.btns[i],Roo.form);
379 b.cls = 'x-edit-none';
388 // disable everything...
390 this.tb.items.each(function(item){
391 if(item.id != editor.frameId+ '-sourceedit'){
395 this.rendered = true;
398 editor.on('editorevent', this.updateToolbar, this);
399 // other toolbars need to implement this..
400 //editor.on('editmodechange', this.updateToolbar, this);
406 * Protected method that will not generally be called directly. It triggers
407 * a toolbar update by reading the markup state of the current selection in the editor.
409 updateToolbar: function(){
411 if(!this.editor.activated){
412 this.editor.onFirstFocus();
416 var btns = this.tb.items.map,
417 doc = this.editor.doc,
418 frameId = this.editor.frameId;
420 if(!this.disable.font && !Roo.isSafari){
422 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
423 if(name != this.fontSelect.dom.value){
424 this.fontSelect.dom.value = name;
428 if(!this.disable.format){
429 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
430 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
431 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
433 if(!this.disable.alignments){
434 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
435 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
436 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
438 if(!Roo.isSafari && !this.disable.lists){
439 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
440 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
443 var ans = this.editor.getAllAncestors();
444 if (this.formatCombo) {
447 var store = this.formatCombo.store;
448 this.formatCombo.setValue("");
449 for (var i =0; i < ans.length;i++) {
450 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
452 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
460 // hides menus... - so this cant be on a menu...
461 Roo.menu.MenuMgr.hideAll();
463 //this.editorsyncValue();
467 createFontOptions : function(){
468 var buf = [], fs = this.fontFamilies, ff, lc;
472 for(var i = 0, len = fs.length; i< len; i++){
474 lc = ff.toLowerCase();
476 '<option value="',lc,'" style="font-family:',ff,';"',
477 (this.defaultFont == lc ? ' selected="true">' : '>'),
485 toggleSourceEdit : function(sourceEditMode){
486 if(sourceEditMode === undefined){
487 sourceEditMode = !this.sourceEditMode;
489 this.sourceEditMode = sourceEditMode === true;
490 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
491 // just toggle the button?
492 if(btn.pressed !== this.editor.sourceEditMode){
493 btn.toggle(this.editor.sourceEditMode);
497 if(this.sourceEditMode){
498 this.tb.items.each(function(item){
499 if(item.cmd != 'sourceedit'){
505 if(this.initialized){
506 this.tb.items.each(function(item){
512 // tell the editor that it's been pressed..
513 this.editor.toggleSourceEdit(sourceEditMode);
517 * Object collection of toolbar tooltips for the buttons in the editor. The key
518 * is the command id associated with that button and the value is a valid QuickTips object.
523 title: 'Bold (Ctrl+B)',
524 text: 'Make the selected text bold.',
525 cls: 'x-html-editor-tip'
528 title: 'Italic (Ctrl+I)',
529 text: 'Make the selected text italic.',
530 cls: 'x-html-editor-tip'
538 title: 'Bold (Ctrl+B)',
539 text: 'Make the selected text bold.',
540 cls: 'x-html-editor-tip'
543 title: 'Italic (Ctrl+I)',
544 text: 'Make the selected text italic.',
545 cls: 'x-html-editor-tip'
548 title: 'Underline (Ctrl+U)',
549 text: 'Underline the selected text.',
550 cls: 'x-html-editor-tip'
554 text: 'Increase the font size.',
555 cls: 'x-html-editor-tip'
558 title: 'Shrink Text',
559 text: 'Decrease the font size.',
560 cls: 'x-html-editor-tip'
563 title: 'Text Highlight Color',
564 text: 'Change the background color of the selected text.',
565 cls: 'x-html-editor-tip'
569 text: 'Change the color of the selected text.',
570 cls: 'x-html-editor-tip'
573 title: 'Align Text Left',
574 text: 'Align text to the left.',
575 cls: 'x-html-editor-tip'
578 title: 'Center Text',
579 text: 'Center text in the editor.',
580 cls: 'x-html-editor-tip'
583 title: 'Align Text Right',
584 text: 'Align text to the right.',
585 cls: 'x-html-editor-tip'
587 insertunorderedlist : {
588 title: 'Bullet List',
589 text: 'Start a bulleted list.',
590 cls: 'x-html-editor-tip'
592 insertorderedlist : {
593 title: 'Numbered List',
594 text: 'Start a numbered list.',
595 cls: 'x-html-editor-tip'
599 text: 'Make the selected text a hyperlink.',
600 cls: 'x-html-editor-tip'
603 title: 'Source Edit',
604 text: 'Switch to source editing mode.',
605 cls: 'x-html-editor-tip'
609 onDestroy : function(){
612 this.tb.items.each(function(item){
614 item.menu.removeAll();
616 item.menu.el.destroy();
624 onFirstFocus: function() {
625 this.tb.items.each(function(item){