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: this.createFontOptions()
173 editor.fontSelect.on('change', function(){
174 var font = editor.fontSelect.dom.value;
175 editor.relayCmd('fontname', font);
180 editor.fontSelect.dom,
186 if(!this.disable.formats){
187 this.formatCombo = new Roo.form.ComboBox({
188 store: new Roo.data.SimpleStore({
191 data : this.formats // from states.js
195 //autoCreate : {tag: "div", size: "20"},
200 triggerAction: 'all',
205 'select': function(c, r, i) {
206 editor.insertTag(r.get('tag'));
212 tb.addField(this.formatCombo);
216 if(!this.disable.format){
223 if(!this.disable.fontSize){
228 btn('increasefontsize', false, editor.adjustFont),
229 btn('decreasefontsize', false, editor.adjustFont)
234 if(!this.disable.colors){
237 id:editor.frameId +'-forecolor',
238 cls:'x-btn-icon x-edit-forecolor',
239 clickEvent:'mousedown',
240 tooltip: this.buttonTips['forecolor'] || undefined,
242 menu : new Roo.menu.ColorMenu({
247 selectHandler: function(cp, color){
248 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
252 clickEvent:'mousedown'
255 id:editor.frameId +'backcolor',
256 cls:'x-btn-icon x-edit-backcolor',
257 clickEvent:'mousedown',
258 tooltip: this.buttonTips['backcolor'] || undefined,
260 menu : new Roo.menu.ColorMenu({
265 selectHandler: function(cp, color){
267 editor.execCmd('useCSS', false);
268 editor.execCmd('hilitecolor', color);
269 editor.execCmd('useCSS', true);
272 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
273 Roo.isSafari || Roo.isIE ? '#'+color : color);
278 clickEvent:'mousedown'
283 // now add all the items...
286 if(!this.disable.alignments){
290 btn('justifycenter'),
296 if(!this.disable.links){
299 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
303 if(!this.disable.lists){
306 btn('insertorderedlist'),
307 btn('insertunorderedlist')
310 if(!this.disable.sourceEdit){
313 btn('sourceedit', true, function(btn){
314 this.toggleSourceEdit(btn.pressed);
321 // special menu.. - needs to be tidied up..
322 if (!this.disable.special) {
331 for (var i =0; i < this.specialChars.length; i++) {
332 smenu.menu.items.push({
334 html: this.specialChars[i],
335 handler: function(a,b) {
336 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
337 //editor.insertAtCursor(a.html);
350 if (!this.disable.specialElements) {
358 for (var i =0; i < this.specialElements.length; i++) {
359 semenu.menu.items.push(
361 handler: function(a,b) {
362 editor.insertAtCursor(this.ihtml);
364 }, this.specialElements[i])
376 for(var i =0; i< this.btns.length;i++) {
377 var b = Roo.factory(this.btns[i],Roo.form);
378 b.cls = 'x-edit-none';
387 // disable everything...
389 this.tb.items.each(function(item){
390 if(item.id != editor.frameId+ '-sourceedit'){
394 this.rendered = true;
397 editor.on('editorevent', this.updateToolbar, this);
398 // other toolbars need to implement this..
399 //editor.on('editmodechange', this.updateToolbar, this);
405 * Protected method that will not generally be called directly. It triggers
406 * a toolbar update by reading the markup state of the current selection in the editor.
408 updateToolbar: function(){
410 if(!this.editor.activated){
411 this.editor.onFirstFocus();
415 var btns = this.tb.items.map,
416 doc = this.editor.doc,
417 frameId = this.editor.frameId;
419 if(!this.disable.font && !Roo.isSafari){
421 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
422 if(name != this.fontSelect.dom.value){
423 this.fontSelect.dom.value = name;
427 if(!this.disable.format){
428 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
429 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
430 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
432 if(!this.disable.alignments){
433 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
434 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
435 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
437 if(!Roo.isSafari && !this.disable.lists){
438 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
439 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
442 var ans = this.editor.getAllAncestors();
443 if (this.formatCombo) {
446 var store = this.formatCombo.store;
447 this.formatCombo.setValue("");
448 for (var i =0; i < ans.length;i++) {
449 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
451 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
459 // hides menus... - so this cant be on a menu...
460 Roo.menu.MenuMgr.hideAll();
462 //this.editorsyncValue();
466 createFontOptions : function(){
467 var buf = [], fs = this.fontFamilies, ff, lc;
471 for(var i = 0, len = fs.length; i< len; i++){
473 lc = ff.toLowerCase();
475 '<option value="',lc,'" style="font-family:',ff,';"',
476 (this.defaultFont == lc ? ' selected="true">' : '>'),
484 toggleSourceEdit : function(sourceEditMode){
485 if(sourceEditMode === undefined){
486 sourceEditMode = !this.sourceEditMode;
488 this.sourceEditMode = sourceEditMode === true;
489 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
490 // just toggle the button?
491 if(btn.pressed !== this.editor.sourceEditMode){
492 btn.toggle(this.editor.sourceEditMode);
496 if(this.sourceEditMode){
497 this.tb.items.each(function(item){
498 if(item.cmd != 'sourceedit'){
504 if(this.initialized){
505 this.tb.items.each(function(item){
511 // tell the editor that it's been pressed..
512 this.editor.toggleSourceEdit(sourceEditMode);
516 * Object collection of toolbar tooltips for the buttons in the editor. The key
517 * is the command id associated with that button and the value is a valid QuickTips object.
522 title: 'Bold (Ctrl+B)',
523 text: 'Make the selected text bold.',
524 cls: 'x-html-editor-tip'
527 title: 'Italic (Ctrl+I)',
528 text: 'Make the selected text italic.',
529 cls: 'x-html-editor-tip'
537 title: 'Bold (Ctrl+B)',
538 text: 'Make the selected text bold.',
539 cls: 'x-html-editor-tip'
542 title: 'Italic (Ctrl+I)',
543 text: 'Make the selected text italic.',
544 cls: 'x-html-editor-tip'
547 title: 'Underline (Ctrl+U)',
548 text: 'Underline the selected text.',
549 cls: 'x-html-editor-tip'
553 text: 'Increase the font size.',
554 cls: 'x-html-editor-tip'
557 title: 'Shrink Text',
558 text: 'Decrease the font size.',
559 cls: 'x-html-editor-tip'
562 title: 'Text Highlight Color',
563 text: 'Change the background color of the selected text.',
564 cls: 'x-html-editor-tip'
568 text: 'Change the color of the selected text.',
569 cls: 'x-html-editor-tip'
572 title: 'Align Text Left',
573 text: 'Align text to the left.',
574 cls: 'x-html-editor-tip'
577 title: 'Center Text',
578 text: 'Center text in the editor.',
579 cls: 'x-html-editor-tip'
582 title: 'Align Text Right',
583 text: 'Align text to the right.',
584 cls: 'x-html-editor-tip'
586 insertunorderedlist : {
587 title: 'Bullet List',
588 text: 'Start a bulleted list.',
589 cls: 'x-html-editor-tip'
591 insertorderedlist : {
592 title: 'Numbered List',
593 text: 'Start a numbered list.',
594 cls: 'x-html-editor-tip'
598 text: 'Make the selected text a hyperlink.',
599 cls: 'x-html-editor-tip'
602 title: 'Source Edit',
603 text: 'Switch to source editing mode.',
604 cls: 'x-html-editor-tip'
608 onDestroy : function(){
611 this.tb.items.each(function(item){
613 item.menu.removeAll();
615 item.menu.el.destroy();
623 onFirstFocus: function() {
624 this.tb.items.each(function(item){