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"],
130 * @cfg {String} defaultFont default font to use.
132 defaultFont: 'tahoma',
139 init : function(editor)
141 this.editor = editor;
144 var fid = editor.frameId;
146 function btn(id, toggle, handler){
147 var xid = fid + '-'+ id ;
151 cls : 'x-btn-icon x-edit-'+id,
152 enableToggle:toggle !== false,
153 scope: editor, // was editor...
154 handler:handler||editor.relayBtnCmd,
155 clickEvent:'mousedown',
156 tooltip: etb.buttonTips[id] || undefined, ///tips ???
163 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
166 tb.el.on('click', function(e){
167 e.preventDefault(); // what does this do?
170 if(!this.disable.font) { // && !Roo.isSafari){
171 /* why no safari for fonts
172 editor.fontSelect = tb.el.createChild({
176 html: this.createFontOptions()
179 editor.fontSelect.on('change', function(){
180 var font = editor.fontSelect.dom.value;
181 editor.relayCmd('fontname', font);
186 editor.fontSelect.dom,
192 if(!this.disable.formats){
193 this.formatCombo = new Roo.form.ComboBox({
194 store: new Roo.data.SimpleStore({
197 data : this.formats // from states.js
201 //autoCreate : {tag: "div", size: "20"},
206 triggerAction: 'all',
211 'select': function(c, r, i) {
212 editor.insertTag(r.get('tag'));
218 tb.addField(this.formatCombo);
222 if(!this.disable.format){
229 if(!this.disable.fontSize){
234 btn('increasefontsize', false, editor.adjustFont),
235 btn('decreasefontsize', false, editor.adjustFont)
240 if(!this.disable.colors){
243 id:editor.frameId +'-forecolor',
244 cls:'x-btn-icon x-edit-forecolor',
245 clickEvent:'mousedown',
246 tooltip: this.buttonTips['forecolor'] || undefined,
248 menu : new Roo.menu.ColorMenu({
253 selectHandler: function(cp, color){
254 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
258 clickEvent:'mousedown'
261 id:editor.frameId +'backcolor',
262 cls:'x-btn-icon x-edit-backcolor',
263 clickEvent:'mousedown',
264 tooltip: this.buttonTips['backcolor'] || undefined,
266 menu : new Roo.menu.ColorMenu({
271 selectHandler: function(cp, color){
273 editor.execCmd('useCSS', false);
274 editor.execCmd('hilitecolor', color);
275 editor.execCmd('useCSS', true);
278 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
279 Roo.isSafari || Roo.isIE ? '#'+color : color);
284 clickEvent:'mousedown'
289 // now add all the items...
292 if(!this.disable.alignments){
296 btn('justifycenter'),
302 if(!this.disable.links){
305 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
309 if(!this.disable.lists){
312 btn('insertorderedlist'),
313 btn('insertunorderedlist')
316 if(!this.disable.sourceEdit){
319 btn('sourceedit', true, function(btn){
320 this.toggleSourceEdit(btn.pressed);
327 // special menu.. - needs to be tidied up..
328 if (!this.disable.special) {
337 for (var i =0; i < this.specialChars.length; i++) {
338 smenu.menu.items.push({
340 html: this.specialChars[i],
341 handler: function(a,b) {
342 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
343 //editor.insertAtCursor(a.html);
357 if (!this.disable.cleanStyles) {
358 Roo.log('init toolbar style');
360 cls: 'x-btn-icon x-btn-clear',
366 for (var i =0; i < this.cleanStyles.length; i++) {
367 cmenu.menu.items.push({
369 html: this.cleanStyles[i],
370 handler: function(a,b) {
371 var c = Roo.get(editor.doc.body);
373 c.select('[style]').each(function(v) {
374 v.dom.style.removeProperty(this.cleanStyles[i]);
388 if (!this.disable.specialElements) {
396 for (var i =0; i < this.specialElements.length; i++) {
397 semenu.menu.items.push(
399 handler: function(a,b) {
400 editor.insertAtCursor(this.ihtml);
402 }, this.specialElements[i])
414 for(var i =0; i< this.btns.length;i++) {
415 var b = Roo.factory(this.btns[i],Roo.form);
416 b.cls = 'x-edit-none';
425 // disable everything...
427 this.tb.items.each(function(item){
428 if(item.id != editor.frameId+ '-sourceedit'){
432 this.rendered = true;
435 editor.on('editorevent', this.updateToolbar, this);
436 // other toolbars need to implement this..
437 //editor.on('editmodechange', this.updateToolbar, this);
443 * Protected method that will not generally be called directly. It triggers
444 * a toolbar update by reading the markup state of the current selection in the editor.
446 updateToolbar: function(){
448 if(!this.editor.activated){
449 this.editor.onFirstFocus();
453 var btns = this.tb.items.map,
454 doc = this.editor.doc,
455 frameId = this.editor.frameId;
457 if(!this.disable.font && !Roo.isSafari){
459 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
460 if(name != this.fontSelect.dom.value){
461 this.fontSelect.dom.value = name;
465 if(!this.disable.format){
466 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
467 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
468 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
470 if(!this.disable.alignments){
471 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
472 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
473 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
475 if(!Roo.isSafari && !this.disable.lists){
476 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
477 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
480 var ans = this.editor.getAllAncestors();
481 if (this.formatCombo) {
484 var store = this.formatCombo.store;
485 this.formatCombo.setValue("");
486 for (var i =0; i < ans.length;i++) {
487 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
489 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
497 // hides menus... - so this cant be on a menu...
498 Roo.menu.MenuMgr.hideAll();
500 //this.editorsyncValue();
504 createFontOptions : function(){
505 var buf = [], fs = this.fontFamilies, ff, lc;
509 for(var i = 0, len = fs.length; i< len; i++){
511 lc = ff.toLowerCase();
513 '<option value="',lc,'" style="font-family:',ff,';"',
514 (this.defaultFont == lc ? ' selected="true">' : '>'),
522 toggleSourceEdit : function(sourceEditMode){
523 if(sourceEditMode === undefined){
524 sourceEditMode = !this.sourceEditMode;
526 this.sourceEditMode = sourceEditMode === true;
527 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
528 // just toggle the button?
529 if(btn.pressed !== this.editor.sourceEditMode){
530 btn.toggle(this.editor.sourceEditMode);
534 if(this.sourceEditMode){
535 this.tb.items.each(function(item){
536 if(item.cmd != 'sourceedit'){
542 if(this.initialized){
543 this.tb.items.each(function(item){
549 // tell the editor that it's been pressed..
550 this.editor.toggleSourceEdit(sourceEditMode);
554 * Object collection of toolbar tooltips for the buttons in the editor. The key
555 * is the command id associated with that button and the value is a valid QuickTips object.
560 title: 'Bold (Ctrl+B)',
561 text: 'Make the selected text bold.',
562 cls: 'x-html-editor-tip'
565 title: 'Italic (Ctrl+I)',
566 text: 'Make the selected text italic.',
567 cls: 'x-html-editor-tip'
575 title: 'Bold (Ctrl+B)',
576 text: 'Make the selected text bold.',
577 cls: 'x-html-editor-tip'
580 title: 'Italic (Ctrl+I)',
581 text: 'Make the selected text italic.',
582 cls: 'x-html-editor-tip'
585 title: 'Underline (Ctrl+U)',
586 text: 'Underline the selected text.',
587 cls: 'x-html-editor-tip'
591 text: 'Increase the font size.',
592 cls: 'x-html-editor-tip'
595 title: 'Shrink Text',
596 text: 'Decrease the font size.',
597 cls: 'x-html-editor-tip'
600 title: 'Text Highlight Color',
601 text: 'Change the background color of the selected text.',
602 cls: 'x-html-editor-tip'
606 text: 'Change the color of the selected text.',
607 cls: 'x-html-editor-tip'
610 title: 'Align Text Left',
611 text: 'Align text to the left.',
612 cls: 'x-html-editor-tip'
615 title: 'Center Text',
616 text: 'Center text in the editor.',
617 cls: 'x-html-editor-tip'
620 title: 'Align Text Right',
621 text: 'Align text to the right.',
622 cls: 'x-html-editor-tip'
624 insertunorderedlist : {
625 title: 'Bullet List',
626 text: 'Start a bulleted list.',
627 cls: 'x-html-editor-tip'
629 insertorderedlist : {
630 title: 'Numbered List',
631 text: 'Start a numbered list.',
632 cls: 'x-html-editor-tip'
636 text: 'Make the selected text a hyperlink.',
637 cls: 'x-html-editor-tip'
640 title: 'Source Edit',
641 text: 'Switch to source editing mode.',
642 cls: 'x-html-editor-tip'
646 onDestroy : function(){
649 this.tb.items.each(function(item){
651 item.menu.removeAll();
653 item.menu.el.destroy();
661 onFirstFocus: function() {
662 this.tb.items.each(function(item){