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);
38 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
39 // dont call parent... till later.
42 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
50 * @cfg {Object} disable List of toolbar elements to disable
55 * @cfg {Array} fontFamilies An array of available font families
73 // "á" , ?? a acute?
78 "°" // , // degrees
80 // "é" , // e ecute
81 // "ú" , // u ecute?
89 handler: function(a,b) {
90 // should we show a dialog.?
91 editor.insertAtCursor('<table><<tr><td></td></tr></table>');
100 handler: function(a,b) {
101 // should we show a dialog.?
102 editor.insertAtCursor('<img src="about:blank"/>');
113 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
114 "input:submit", "input:button", "select", "textarea", "label" ],
117 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
119 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
122 * @cfg {String} defaultFont default font to use.
124 defaultFont: 'tahoma',
131 init : function(editor)
133 this.editor = editor;
136 var fid = editor.frameId;
138 function btn(id, toggle, handler){
139 var xid = fid + '-'+ id ;
143 cls : 'x-btn-icon x-edit-'+id,
144 enableToggle:toggle !== false,
145 scope: editor, // was editor...
146 handler:handler||editor.relayBtnCmd,
147 clickEvent:'mousedown',
148 tooltip: etb.buttonTips[id] || undefined, ///tips ???
155 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
158 tb.el.on('click', function(e){
159 e.preventDefault(); // what does this do?
162 if(!this.disable.font && !Roo.isSafari){
163 /* why no safari for fonts
164 editor.fontSelect = tb.el.createChild({
168 html: editor.createFontOptions()
170 editor.fontSelect.on('change', function(){
171 var font = editor.fontSelect.dom.value;
172 editor.relayCmd('fontname', font);
176 editor.fontSelect.dom,
181 if(!this.disable.formats){
182 this.formatCombo = new Roo.form.ComboBox({
183 store: new Roo.data.SimpleStore({
186 data : this.formats // from states.js
189 //autoCreate : {tag: "div", size: "20"},
194 triggerAction: 'all',
199 'select': function(c, r, i) {
200 editor.insertTag(r.get('tag'));
206 tb.addField(this.formatCombo);
210 if(!this.disable.format){
217 if(!this.disable.fontSize){
222 btn('increasefontsize', false, editor.adjustFont),
223 btn('decreasefontsize', false, editor.adjustFont)
228 if(this.disable.colors){
231 id:editor.frameId +'-forecolor',
232 cls:'x-btn-icon x-edit-forecolor',
233 clickEvent:'mousedown',
234 tooltip: this.buttonTips['forecolor'] || undefined,
236 menu : new Roo.menu.ColorMenu({
241 selectHandler: function(cp, color){
242 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
246 clickEvent:'mousedown'
249 id:editor.frameId +'backcolor',
250 cls:'x-btn-icon x-edit-backcolor',
251 clickEvent:'mousedown',
252 tooltip: this.buttonTips['backcolor'] || undefined,
254 menu : new Roo.menu.ColorMenu({
259 selectHandler: function(cp, color){
261 editor.execCmd('useCSS', false);
262 editor.execCmd('hilitecolor', color);
263 editor.execCmd('useCSS', true);
266 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
267 Roo.isSafari || Roo.isIE ? '#'+color : color);
272 clickEvent:'mousedown'
277 // now add all the items...
280 if(!this.disable.alignments){
284 btn('justifycenter'),
290 if(!this.disable.links){
293 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
297 if(!this.disable.lists){
300 btn('insertorderedlist'),
301 btn('insertunorderedlist')
304 if(!this.disable.sourceEdit){
307 btn('sourceedit', true, function(btn){
308 this.toggleSourceEdit(btn.pressed);
315 // special menu.. - needs to be tidied up..
316 if (!this.disable.special) {
325 for (var i =0; i < this.specialChars.length; i++) {
326 smenu.menu.items.push({
328 html: this.specialChars[i],
329 handler: function(a,b) {
330 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
343 if (!this.disable.specialElements) {
348 items : this.specialElements
359 for(var i =0; i< this.btns.length;i++) {
360 var b = this.btns[i];
361 b.cls = 'x-edit-none';
370 // disable everything...
372 this.tb.items.each(function(item){
373 if(item.id != editor.frameId+ '-sourceedit'){
377 this.rendered = true;
380 editor.on('editorevent', this.updateToolbar, this);
381 // other toolbars need to implement this..
382 //editor.on('editmodechange', this.updateToolbar, this);
388 * Protected method that will not generally be called directly. It triggers
389 * a toolbar update by reading the markup state of the current selection in the editor.
391 updateToolbar: function(){
393 if(!this.editor.activated){
394 this.editor.onFirstFocus();
398 var btns = this.tb.items.map,
399 doc = this.editor.doc,
400 frameId = this.editor.frameId;
402 if(!this.disable.font && !Roo.isSafari){
404 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
405 if(name != this.fontSelect.dom.value){
406 this.fontSelect.dom.value = name;
410 if(!this.disable.format){
411 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
412 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
413 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
415 if(!this.disable.alignments){
416 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
417 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
418 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
420 if(!Roo.isSafari && !this.disable.lists){
421 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
422 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
425 var ans = this.editor.getAllAncestors();
426 if (this.formatCombo) {
429 var store = this.formatCombo.store;
430 this.formatCombo.setValue("");
431 for (var i =0; i < ans.length;i++) {
432 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
434 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
442 // hides menus... - so this cant be on a menu...
443 Roo.menu.MenuMgr.hideAll();
445 //this.editorsyncValue();
449 createFontOptions : function(){
450 var buf = [], fs = this.fontFamilies, ff, lc;
451 for(var i = 0, len = fs.length; i< len; i++){
453 lc = ff.toLowerCase();
455 '<option value="',lc,'" style="font-family:',ff,';"',
456 (this.defaultFont == lc ? ' selected="true">' : '>'),
464 toggleSourceEdit : function(sourceEditMode){
465 if(sourceEditMode === undefined){
466 sourceEditMode = !this.sourceEditMode;
468 this.sourceEditMode = sourceEditMode === true;
469 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
470 // just toggle the button?
471 if(btn.pressed !== this.editor.sourceEditMode){
472 btn.toggle(this.editor.sourceEditMode);
476 if(this.sourceEditMode){
477 this.tb.items.each(function(item){
478 if(item.cmd != 'sourceedit'){
484 if(this.initialized){
485 this.tb.items.each(function(item){
491 // tell the editor that it's been pressed..
492 this.editor.toggleSourceEdit(sourceEditMode);
496 * Object collection of toolbar tooltips for the buttons in the editor. The key
497 * is the command id associated with that button and the value is a valid QuickTips object.
502 title: 'Bold (Ctrl+B)',
503 text: 'Make the selected text bold.',
504 cls: 'x-html-editor-tip'
507 title: 'Italic (Ctrl+I)',
508 text: 'Make the selected text italic.',
509 cls: 'x-html-editor-tip'
517 title: 'Bold (Ctrl+B)',
518 text: 'Make the selected text bold.',
519 cls: 'x-html-editor-tip'
522 title: 'Italic (Ctrl+I)',
523 text: 'Make the selected text italic.',
524 cls: 'x-html-editor-tip'
527 title: 'Underline (Ctrl+U)',
528 text: 'Underline the selected text.',
529 cls: 'x-html-editor-tip'
533 text: 'Increase the font size.',
534 cls: 'x-html-editor-tip'
537 title: 'Shrink Text',
538 text: 'Decrease the font size.',
539 cls: 'x-html-editor-tip'
542 title: 'Text Highlight Color',
543 text: 'Change the background color of the selected text.',
544 cls: 'x-html-editor-tip'
548 text: 'Change the color of the selected text.',
549 cls: 'x-html-editor-tip'
552 title: 'Align Text Left',
553 text: 'Align text to the left.',
554 cls: 'x-html-editor-tip'
557 title: 'Center Text',
558 text: 'Center text in the editor.',
559 cls: 'x-html-editor-tip'
562 title: 'Align Text Right',
563 text: 'Align text to the right.',
564 cls: 'x-html-editor-tip'
566 insertunorderedlist : {
567 title: 'Bullet List',
568 text: 'Start a bulleted list.',
569 cls: 'x-html-editor-tip'
571 insertorderedlist : {
572 title: 'Numbered List',
573 text: 'Start a numbered list.',
574 cls: 'x-html-editor-tip'
578 text: 'Make the selected text a hyperlink.',
579 cls: 'x-html-editor-tip'
582 title: 'Source Edit',
583 text: 'Switch to source editing mode.',
584 cls: 'x-html-editor-tip'
588 onDestroy : function(){
591 this.tb.items.each(function(item){
593 item.menu.removeAll();
595 item.menu.el.destroy();
603 onFirstFocus: function() {
604 this.tb.items.each(function(item){