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"],
129 * @cfg {String} defaultFont default font to use.
131 defaultFont: 'tahoma',
138 init : function(editor)
140 this.editor = editor;
143 var fid = editor.frameId;
145 function btn(id, toggle, handler){
146 var xid = fid + '-'+ id ;
150 cls : 'x-btn-icon x-edit-'+id,
151 enableToggle:toggle !== false,
152 scope: editor, // was editor...
153 handler:handler||editor.relayBtnCmd,
154 clickEvent:'mousedown',
155 tooltip: etb.buttonTips[id] || undefined, ///tips ???
162 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
165 tb.el.on('click', function(e){
166 e.preventDefault(); // what does this do?
169 if(!this.disable.font) { // && !Roo.isSafari){
170 /* why no safari for fonts
171 editor.fontSelect = tb.el.createChild({
175 html: this.createFontOptions()
178 editor.fontSelect.on('change', function(){
179 var font = editor.fontSelect.dom.value;
180 editor.relayCmd('fontname', font);
185 editor.fontSelect.dom,
191 if(!this.disable.formats){
192 this.formatCombo = new Roo.form.ComboBox({
193 store: new Roo.data.SimpleStore({
196 data : this.formats // from states.js
200 //autoCreate : {tag: "div", size: "20"},
205 triggerAction: 'all',
210 'select': function(c, r, i) {
211 editor.insertTag(r.get('tag'));
217 tb.addField(this.formatCombo);
221 if(!this.disable.format){
228 if(!this.disable.fontSize){
233 btn('increasefontsize', false, editor.adjustFont),
234 btn('decreasefontsize', false, editor.adjustFont)
239 if(!this.disable.colors){
242 id:editor.frameId +'-forecolor',
243 cls:'x-btn-icon x-edit-forecolor',
244 clickEvent:'mousedown',
245 tooltip: this.buttonTips['forecolor'] || undefined,
247 menu : new Roo.menu.ColorMenu({
252 selectHandler: function(cp, color){
253 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
257 clickEvent:'mousedown'
260 id:editor.frameId +'backcolor',
261 cls:'x-btn-icon x-edit-backcolor',
262 clickEvent:'mousedown',
263 tooltip: this.buttonTips['backcolor'] || undefined,
265 menu : new Roo.menu.ColorMenu({
270 selectHandler: function(cp, color){
272 editor.execCmd('useCSS', false);
273 editor.execCmd('hilitecolor', color);
274 editor.execCmd('useCSS', true);
277 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
278 Roo.isSafari || Roo.isIE ? '#'+color : color);
283 clickEvent:'mousedown'
288 // now add all the items...
291 if(!this.disable.alignments){
295 btn('justifycenter'),
301 if(!this.disable.links){
304 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
308 if(!this.disable.lists){
311 btn('insertorderedlist'),
312 btn('insertunorderedlist')
315 if(!this.disable.sourceEdit){
318 btn('sourceedit', true, function(btn){
319 this.toggleSourceEdit(btn.pressed);
326 // special menu.. - needs to be tidied up..
327 if (!this.disable.special) {
336 for (var i =0; i < this.specialChars.length; i++) {
337 smenu.menu.items.push({
339 html: this.specialChars[i],
340 handler: function(a,b) {
341 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
342 //editor.insertAtCursor(a.html);
356 if (!this.disable.cleanStyles) {
358 cls: 'x-btn-icon x-btn-clear',
364 for (var i =0; i < this.cleanStyles.length; i++) {
365 cmenu.menu.items.push({
366 actiontype : this.cleanStyles[i],
367 html: 'Remove ' + this.cleanStyles[i],
368 handler: function(a,b) {
371 var c = Roo.get(editor.doc.body);
372 c.select('[style]').each(function(s) {
373 s.dom.style.removeProperty(a.actiontype);
384 if (!this.disable.specialElements) {
392 for (var i =0; i < this.specialElements.length; i++) {
393 semenu.menu.items.push(
395 handler: function(a,b) {
396 editor.insertAtCursor(this.ihtml);
398 }, this.specialElements[i])
410 for(var i =0; i< this.btns.length;i++) {
411 var b = Roo.factory(this.btns[i],Roo.form);
412 b.cls = 'x-edit-none';
421 // disable everything...
423 this.tb.items.each(function(item){
424 if(item.id != editor.frameId+ '-sourceedit'){
428 this.rendered = true;
431 editor.on('editorevent', this.updateToolbar, this);
432 // other toolbars need to implement this..
433 //editor.on('editmodechange', this.updateToolbar, this);
439 * Protected method that will not generally be called directly. It triggers
440 * a toolbar update by reading the markup state of the current selection in the editor.
442 updateToolbar: function(){
444 if(!this.editor.activated){
445 this.editor.onFirstFocus();
449 var btns = this.tb.items.map,
450 doc = this.editor.doc,
451 frameId = this.editor.frameId;
453 if(!this.disable.font && !Roo.isSafari){
455 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
456 if(name != this.fontSelect.dom.value){
457 this.fontSelect.dom.value = name;
461 if(!this.disable.format){
462 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
463 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
464 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
466 if(!this.disable.alignments){
467 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
468 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
469 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
471 if(!Roo.isSafari && !this.disable.lists){
472 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
473 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
476 var ans = this.editor.getAllAncestors();
477 if (this.formatCombo) {
480 var store = this.formatCombo.store;
481 this.formatCombo.setValue("");
482 for (var i =0; i < ans.length;i++) {
483 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
485 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
493 // hides menus... - so this cant be on a menu...
494 Roo.menu.MenuMgr.hideAll();
496 //this.editorsyncValue();
500 createFontOptions : function(){
501 var buf = [], fs = this.fontFamilies, ff, lc;
505 for(var i = 0, len = fs.length; i< len; i++){
507 lc = ff.toLowerCase();
509 '<option value="',lc,'" style="font-family:',ff,';"',
510 (this.defaultFont == lc ? ' selected="true">' : '>'),
518 toggleSourceEdit : function(sourceEditMode){
519 if(sourceEditMode === undefined){
520 sourceEditMode = !this.sourceEditMode;
522 this.sourceEditMode = sourceEditMode === true;
523 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
524 // just toggle the button?
525 if(btn.pressed !== this.editor.sourceEditMode){
526 btn.toggle(this.editor.sourceEditMode);
530 if(this.sourceEditMode){
531 this.tb.items.each(function(item){
532 if(item.cmd != 'sourceedit'){
538 if(this.initialized){
539 this.tb.items.each(function(item){
545 // tell the editor that it's been pressed..
546 this.editor.toggleSourceEdit(sourceEditMode);
550 * Object collection of toolbar tooltips for the buttons in the editor. The key
551 * is the command id associated with that button and the value is a valid QuickTips object.
556 title: 'Bold (Ctrl+B)',
557 text: 'Make the selected text bold.',
558 cls: 'x-html-editor-tip'
561 title: 'Italic (Ctrl+I)',
562 text: 'Make the selected text italic.',
563 cls: 'x-html-editor-tip'
571 title: 'Bold (Ctrl+B)',
572 text: 'Make the selected text bold.',
573 cls: 'x-html-editor-tip'
576 title: 'Italic (Ctrl+I)',
577 text: 'Make the selected text italic.',
578 cls: 'x-html-editor-tip'
581 title: 'Underline (Ctrl+U)',
582 text: 'Underline the selected text.',
583 cls: 'x-html-editor-tip'
587 text: 'Increase the font size.',
588 cls: 'x-html-editor-tip'
591 title: 'Shrink Text',
592 text: 'Decrease the font size.',
593 cls: 'x-html-editor-tip'
596 title: 'Text Highlight Color',
597 text: 'Change the background color of the selected text.',
598 cls: 'x-html-editor-tip'
602 text: 'Change the color of the selected text.',
603 cls: 'x-html-editor-tip'
606 title: 'Align Text Left',
607 text: 'Align text to the left.',
608 cls: 'x-html-editor-tip'
611 title: 'Center Text',
612 text: 'Center text in the editor.',
613 cls: 'x-html-editor-tip'
616 title: 'Align Text Right',
617 text: 'Align text to the right.',
618 cls: 'x-html-editor-tip'
620 insertunorderedlist : {
621 title: 'Bullet List',
622 text: 'Start a bulleted list.',
623 cls: 'x-html-editor-tip'
625 insertorderedlist : {
626 title: 'Numbered List',
627 text: 'Start a numbered list.',
628 cls: 'x-html-editor-tip'
632 text: 'Make the selected text a hyperlink.',
633 cls: 'x-html-editor-tip'
636 title: 'Source Edit',
637 text: 'Switch to source editing mode.',
638 cls: 'x-html-editor-tip'
642 onDestroy : function(){
645 this.tb.items.each(function(item){
647 item.menu.removeAll();
649 item.menu.el.destroy();
657 onFirstFocus: function() {
658 this.tb.items.each(function(item){