3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.form.HtmlEditor"></div>/**
\r
9 * @class Ext.form.HtmlEditor
\r
10 * @extends Ext.form.Field
\r
11 * Provides a lightweight HTML Editor component. Some toolbar features are not supported by Safari and will be
\r
12 * automatically hidden when needed. These are noted in the config options where appropriate.
\r
13 * <br><br>The editor's toolbar buttons have tooltips defined in the {@link #buttonTips} property, but they are not
\r
14 * enabled by default unless the global {@link Ext.QuickTips} singleton is {@link Ext.QuickTips#init initialized}.
\r
15 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
\r
16 * supported by this editor.</b>
\r
17 * <br><br>An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
\r
18 * any element that has display set to 'none' can cause problems in Safari and Firefox due to their default iframe reloading bugs.
\r
19 * <br><br>Example usage:
\r
21 // Simple example rendered with default options:
\r
22 Ext.QuickTips.init(); // enable tooltips
\r
23 new Ext.form.HtmlEditor({
\r
24 renderTo: Ext.getBody(),
\r
29 // Passed via xtype into a container and with custom options:
\r
30 Ext.QuickTips.init(); // enable tooltips
\r
32 title: 'HTML Editor',
\r
33 renderTo: Ext.getBody(),
\r
39 xtype: 'htmleditor',
\r
40 enableColors: false,
\r
41 enableAlignments: false
\r
46 * Create a new HtmlEditor
\r
47 * @param {Object} config
\r
51 Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, {
\r
52 <div id="cfg-Ext.form.HtmlEditor-enableFormat"></div>/**
\r
53 * @cfg {Boolean} enableFormat Enable the bold, italic and underline buttons (defaults to true)
\r
55 enableFormat : true,
\r
56 <div id="cfg-Ext.form.HtmlEditor-enableFontSize"></div>/**
\r
57 * @cfg {Boolean} enableFontSize Enable the increase/decrease font size buttons (defaults to true)
\r
59 enableFontSize : true,
\r
60 <div id="cfg-Ext.form.HtmlEditor-enableColors"></div>/**
\r
61 * @cfg {Boolean} enableColors Enable the fore/highlight color buttons (defaults to true)
\r
63 enableColors : true,
\r
64 <div id="cfg-Ext.form.HtmlEditor-enableAlignments"></div>/**
\r
65 * @cfg {Boolean} enableAlignments Enable the left, center, right alignment buttons (defaults to true)
\r
67 enableAlignments : true,
\r
68 <div id="cfg-Ext.form.HtmlEditor-enableLists"></div>/**
\r
69 * @cfg {Boolean} enableLists Enable the bullet and numbered list buttons. Not available in Safari. (defaults to true)
\r
72 <div id="cfg-Ext.form.HtmlEditor-enableSourceEdit"></div>/**
\r
73 * @cfg {Boolean} enableSourceEdit Enable the switch to source edit button. Not available in Safari. (defaults to true)
\r
75 enableSourceEdit : true,
\r
76 <div id="cfg-Ext.form.HtmlEditor-enableLinks"></div>/**
\r
77 * @cfg {Boolean} enableLinks Enable the create link button. Not available in Safari. (defaults to true)
\r
80 <div id="cfg-Ext.form.HtmlEditor-enableFont"></div>/**
\r
81 * @cfg {Boolean} enableFont Enable font selection. Not available in Safari. (defaults to true)
\r
84 <div id="cfg-Ext.form.HtmlEditor-createLinkText"></div>/**
\r
85 * @cfg {String} createLinkText The default text for the create link prompt
\r
87 createLinkText : 'Please enter the URL for the link:',
\r
88 <div id="cfg-Ext.form.HtmlEditor-defaultLinkValue"></div>/**
\r
89 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
\r
91 defaultLinkValue : 'http:/'+'/',
\r
92 <div id="cfg-Ext.form.HtmlEditor-fontFamilies"></div>/**
\r
93 * @cfg {Array} fontFamilies An array of available font families
\r
102 defaultFont: 'tahoma',
\r
103 <div id="cfg-Ext.form.HtmlEditor-defaultValue"></div>/**
\r
104 * @cfg {String} defaultValue A default value to be put into the editor to resolve focus issues (defaults to ​ (Zero-width space), (Non-breaking space) in Opera and IE6).
\r
106 defaultValue: (Ext.isOpera || Ext.isIE6) ? ' ' : '​',
\r
108 // private properties
\r
109 actionMode: 'wrap',
\r
110 validationEvent : false,
\r
112 initialized : false,
\r
114 sourceEditMode : false,
\r
115 onFocus : Ext.emptyFn,
\r
117 hideMode:'offsets',
\r
118 defaultAutoCreate : {
\r
120 style:"width:500px;height:300px;",
\r
121 autocomplete: "off"
\r
125 initComponent : function(){
\r
127 <div id="event-Ext.form.HtmlEditor-initialize"></div>/**
\r
128 * @event initialize
\r
129 * Fires when the editor is fully initialized (including the iframe)
\r
130 * @param {HtmlEditor} this
\r
133 <div id="event-Ext.form.HtmlEditor-activate"></div>/**
\r
135 * Fires when the editor is first receives the focus. Any insertion must wait
\r
136 * until after this event.
\r
137 * @param {HtmlEditor} this
\r
140 <div id="event-Ext.form.HtmlEditor-beforesync"></div>/**
\r
141 * @event beforesync
\r
142 * Fires before the textarea is updated with content from the editor iframe. Return false
\r
143 * to cancel the sync.
\r
144 * @param {HtmlEditor} this
\r
145 * @param {String} html
\r
148 <div id="event-Ext.form.HtmlEditor-beforepush"></div>/**
\r
149 * @event beforepush
\r
150 * Fires before the iframe editor is updated with content from the textarea. Return false
\r
151 * to cancel the push.
\r
152 * @param {HtmlEditor} this
\r
153 * @param {String} html
\r
156 <div id="event-Ext.form.HtmlEditor-sync"></div>/**
\r
158 * Fires when the textarea is updated with content from the editor iframe.
\r
159 * @param {HtmlEditor} this
\r
160 * @param {String} html
\r
163 <div id="event-Ext.form.HtmlEditor-push"></div>/**
\r
165 * Fires when the iframe editor is updated with content from the textarea.
\r
166 * @param {HtmlEditor} this
\r
167 * @param {String} html
\r
170 <div id="event-Ext.form.HtmlEditor-editmodechange"></div>/**
\r
171 * @event editmodechange
\r
172 * Fires when the editor switches edit modes
\r
173 * @param {HtmlEditor} this
\r
174 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
\r
181 createFontOptions : function(){
\r
182 var buf = [], fs = this.fontFamilies, ff, lc;
\r
183 for(var i = 0, len = fs.length; i< len; i++){
\r
185 lc = ff.toLowerCase();
\r
187 '<option value="',lc,'" style="font-family:',ff,';"',
\r
188 (this.defaultFont == lc ? ' selected="true">' : '>'),
\r
193 return buf.join('');
\r
197 * Protected method that will not generally be called directly. It
\r
198 * is called when the editor creates its toolbar. Override this method if you need to
\r
199 * add custom toolbar buttons.
\r
200 * @param {HtmlEditor} editor
\r
202 createToolbar : function(editor){
\r
204 var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled();
\r
206 function btn(id, toggle, handler){
\r
209 cls : 'x-btn-icon',
\r
210 iconCls: 'x-edit-'+id,
\r
211 enableToggle:toggle !== false,
\r
213 handler:handler||editor.relayBtnCmd,
\r
214 clickEvent:'mousedown',
\r
215 tooltip: tipsEnabled ? editor.buttonTips[id] || undefined : undefined,
\r
216 overflowText: editor.buttonTips[id].title || undefined,
\r
221 // build the toolbar
\r
222 var tb = new Ext.Toolbar({
\r
223 renderTo:this.wrap.dom.firstChild
\r
226 // stop form submits
\r
227 this.mon(tb.el, 'click', function(e){
\r
228 e.preventDefault();
\r
231 if(this.enableFont && !Ext.isSafari2){
\r
232 this.fontSelect = tb.el.createChild({
\r
234 cls:'x-font-select',
\r
235 html: this.createFontOptions()
\r
237 this.mon(this.fontSelect, 'change', function(){
\r
238 var font = this.fontSelect.dom.value;
\r
239 this.relayCmd('fontname', font);
\r
244 this.fontSelect.dom,
\r
249 if(this.enableFormat){
\r
257 if(this.enableFontSize){
\r
260 btn('increasefontsize', false, this.adjustFont),
\r
261 btn('decreasefontsize', false, this.adjustFont)
\r
265 if(this.enableColors){
\r
268 itemId:'forecolor',
\r
270 iconCls: 'x-edit-forecolor',
\r
271 clickEvent:'mousedown',
\r
272 tooltip: tipsEnabled ? editor.buttonTips.forecolor || undefined : undefined,
\r
274 menu : new Ext.menu.ColorMenu({
\r
275 allowReselect: true,
\r
276 focus: Ext.emptyFn,
\r
281 select: function(cp, color){
\r
282 this.execCmd('forecolor', Ext.isWebKit || Ext.isIE ? '#'+color : color);
\r
286 clickEvent:'mousedown'
\r
289 itemId:'backcolor',
\r
291 iconCls: 'x-edit-backcolor',
\r
292 clickEvent:'mousedown',
\r
293 tooltip: tipsEnabled ? editor.buttonTips.backcolor || undefined : undefined,
\r
295 menu : new Ext.menu.ColorMenu({
\r
296 focus: Ext.emptyFn,
\r
299 allowReselect: true,
\r
302 select: function(cp, color){
\r
304 this.execCmd('useCSS', false);
\r
305 this.execCmd('hilitecolor', color);
\r
306 this.execCmd('useCSS', true);
\r
309 this.execCmd(Ext.isOpera ? 'hilitecolor' : 'backcolor', Ext.isWebKit || Ext.isIE ? '#'+color : color);
\r
314 clickEvent:'mousedown'
\r
320 if(this.enableAlignments){
\r
323 btn('justifyleft'),
\r
324 btn('justifycenter'),
\r
325 btn('justifyright')
\r
329 if(!Ext.isSafari2){
\r
330 if(this.enableLinks){
\r
333 btn('createlink', false, this.createLink)
\r
337 if(this.enableLists){
\r
340 btn('insertorderedlist'),
\r
341 btn('insertunorderedlist')
\r
344 if(this.enableSourceEdit){
\r
347 btn('sourceedit', true, function(btn){
\r
348 this.toggleSourceEdit(!this.sourceEditMode);
\r
357 <div id="method-Ext.form.HtmlEditor-getDocMarkup"></div>/**
\r
358 * Protected method that will not generally be called directly. It
\r
359 * is called when the editor initializes the iframe with HTML contents. Override this method if you
\r
360 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
\r
362 getDocMarkup : function(){
\r
363 return '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;}</style></head><body></body></html>';
\r
367 getEditorBody : function(){
\r
368 return this.doc.body || this.doc.documentElement;
\r
372 getDoc : function(){
\r
373 return Ext.isIE ? this.getWin().document : (this.iframe.contentDocument || this.getWin().document);
\r
377 getWin : function(){
\r
378 return Ext.isIE ? this.iframe.contentWindow : window.frames[this.iframe.name];
\r
382 onRender : function(ct, position){
\r
383 Ext.form.HtmlEditor.superclass.onRender.call(this, ct, position);
\r
384 this.el.dom.style.border = '0 none';
\r
385 this.el.dom.setAttribute('tabIndex', -1);
\r
386 this.el.addClass('x-hidden');
\r
387 if(Ext.isIE){ // fix IE 1px bogus margin
\r
388 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
\r
390 this.wrap = this.el.wrap({
\r
391 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
\r
394 this.createToolbar(this);
\r
396 this.disableItems(true);
\r
398 // this.tb.doLayout();
\r
400 this.createIFrame();
\r
403 var sz = this.el.getSize();
\r
404 this.setSize(sz.width, this.height || sz.height);
\r
408 createIFrame: function(){
\r
409 var iframe = document.createElement('iframe');
\r
410 iframe.name = Ext.id();
\r
411 iframe.frameBorder = '0';
\r
412 iframe.src = Ext.isIE ? Ext.SSL_SECURE_URL : "javascript:;";
\r
413 this.wrap.dom.appendChild(iframe);
\r
415 this.iframe = iframe;
\r
417 this.monitorTask = Ext.TaskMgr.start({
\r
418 run: this.checkDesignMode,
\r
424 initFrame : function(){
\r
425 Ext.TaskMgr.stop(this.monitorTask);
\r
426 this.doc = this.getDoc();
\r
427 this.win = this.getWin();
\r
430 this.doc.write(this.getDocMarkup());
\r
433 var task = { // must defer to wait for browser to be ready
\r
435 if(this.doc.body || this.doc.readyState == 'complete'){
\r
436 Ext.TaskMgr.stop(task);
\r
437 this.doc.designMode="on";
\r
438 this.initEditor.defer(10, this);
\r
445 Ext.TaskMgr.start(task);
\r
449 checkDesignMode : function(){
\r
450 if(this.wrap && this.wrap.dom.offsetWidth){
\r
451 var doc = this.getDoc();
\r
455 if(!doc.editorInitialized || String(doc.designMode).toLowerCase() != 'on'){
\r
461 disableItems: function(disabled){
\r
462 if(this.fontSelect){
\r
463 this.fontSelect.dom.disabled = disabled;
\r
465 this.tb.items.each(function(item){
\r
466 if(item.itemId != 'sourceedit'){
\r
467 item.setDisabled(disabled);
\r
473 onResize : function(w, h){
\r
474 Ext.form.HtmlEditor.superclass.onResize.apply(this, arguments);
\r
475 if(this.el && this.iframe){
\r
476 if(typeof w == 'number'){
\r
477 var aw = w - this.wrap.getFrameWidth('lr');
\r
478 this.el.setWidth(this.adjustWidth('textarea', aw));
\r
479 this.tb.setWidth(aw);
\r
480 this.iframe.style.width = Math.max(aw, 0) + 'px';
\r
482 if(typeof h == 'number'){
\r
483 var ah = h - this.wrap.getFrameWidth('tb') - this.tb.el.getHeight();
\r
484 this.el.setHeight(this.adjustWidth('textarea', ah));
\r
485 this.iframe.style.height = Math.max(ah, 0) + 'px';
\r
487 this.getEditorBody().style.height = Math.max((ah - (this.iframePad*2)), 0) + 'px';
\r
493 <div id="method-Ext.form.HtmlEditor-toggleSourceEdit"></div>/**
\r
494 * Toggles the editor between standard and source edit mode.
\r
495 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
\r
497 toggleSourceEdit : function(sourceEditMode){
\r
498 if(sourceEditMode === undefined){
\r
499 sourceEditMode = !this.sourceEditMode;
\r
501 this.sourceEditMode = sourceEditMode === true;
\r
502 var btn = this.tb.items.get('sourceedit');
\r
503 if(btn.pressed !== this.sourceEditMode){
\r
504 btn.toggle(this.sourceEditMode);
\r
505 if(!btn.xtbHidden){
\r
509 if(this.sourceEditMode){
\r
510 this.disableItems(true);
\r
512 this.iframe.className = 'x-hidden';
\r
513 this.el.removeClass('x-hidden');
\r
514 this.el.dom.removeAttribute('tabIndex');
\r
517 if(this.initialized){
\r
518 this.disableItems(false);
\r
521 this.iframe.className = '';
\r
522 this.el.addClass('x-hidden');
\r
523 this.el.dom.setAttribute('tabIndex', -1);
\r
526 var lastSize = this.lastSize;
\r
528 delete this.lastSize;
\r
529 this.setSize(lastSize);
\r
531 this.fireEvent('editmodechange', this, this.sourceEditMode);
\r
534 // private used internally
\r
535 createLink : function(){
\r
536 var url = prompt(this.createLinkText, this.defaultLinkValue);
\r
537 if(url && url != 'http:/'+'/'){
\r
538 this.relayCmd('createlink', url);
\r
542 // private (for BoxComponent)
\r
543 adjustSize : Ext.BoxComponent.prototype.adjustSize,
\r
545 // private (for BoxComponent)
\r
546 getResizeEl : function(){
\r
550 // private (for BoxComponent)
\r
551 getPositionEl : function(){
\r
556 initEvents : function(){
\r
557 this.originalValue = this.getValue();
\r
560 <div id="method-Ext.form.HtmlEditor-markInvalid"></div>/**
\r
561 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
\r
564 markInvalid : Ext.emptyFn,
\r
566 <div id="method-Ext.form.HtmlEditor-clearInvalid"></div>/**
\r
567 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
\r
570 clearInvalid : Ext.emptyFn,
\r
572 // docs inherit from Field
\r
573 setValue : function(v){
\r
574 Ext.form.HtmlEditor.superclass.setValue.call(this, v);
\r
579 <div id="method-Ext.form.HtmlEditor-cleanHtml"></div>/**
\r
580 * Protected method that will not generally be called directly. If you need/want
\r
581 * custom HTML cleanup, this is the method you should override.
\r
582 * @param {String} html The HTML to be cleaned
\r
583 * @return {String} The cleaned HTML
\r
585 cleanHtml : function(html){
\r
586 html = String(html);
\r
587 if(html.length > 5){
\r
588 if(Ext.isWebKit){ // strip safari nonsense
\r
589 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
\r
592 if(html == this.defaultValue){
\r
598 <div id="method-Ext.form.HtmlEditor-syncValue"></div>/**
\r
599 * Protected method that will not generally be called directly. Syncs the contents
\r
600 * of the editor iframe with the textarea.
\r
602 syncValue : function(){
\r
603 if(this.initialized){
\r
604 var bd = this.getEditorBody();
\r
605 var html = bd.innerHTML;
\r
607 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
\r
608 var m = bs.match(/text-align:(.*?);/i);
\r
610 html = '<div style="'+m[0]+'">' + html + '</div>';
\r
613 html = this.cleanHtml(html);
\r
614 if(this.fireEvent('beforesync', this, html) !== false){
\r
615 this.el.dom.value = html;
\r
616 this.fireEvent('sync', this, html);
\r
621 //docs inherit from Field
\r
622 getValue : function() {
\r
623 this[this.sourceEditMode ? 'pushValue' : 'syncValue']();
\r
624 return Ext.form.HtmlEditor.superclass.getValue.call(this);
\r
627 <div id="method-Ext.form.HtmlEditor-pushValue"></div>/**
\r
628 * Protected method that will not generally be called directly. Pushes the value of the textarea
\r
629 * into the iframe editor.
\r
631 pushValue : function(){
\r
632 if(this.initialized){
\r
633 var v = this.el.dom.value;
\r
634 if(!this.activated && v.length < 1){
\r
635 v = this.defaultValue;
\r
637 if(this.fireEvent('beforepush', this, v) !== false){
\r
638 this.getEditorBody().innerHTML = v;
\r
640 // Gecko hack, see: https://bugzilla.mozilla.org/show_bug.cgi?id=232791#c8
\r
642 mode = d.designMode.toLowerCase();
\r
644 d.designMode = mode.toggle('on', 'off');
\r
645 d.designMode = mode;
\r
647 this.fireEvent('push', this, v);
\r
653 deferFocus : function(){
\r
654 this.focus.defer(10, this);
\r
657 // docs inherit from Field
\r
658 focus : function(){
\r
659 if(this.win && !this.sourceEditMode){
\r
667 initEditor : function(){
\r
668 //Destroying the component during/before initEditor can cause issues.
\r
670 var dbody = this.getEditorBody();
\r
671 var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
\r
672 ss['background-attachment'] = 'fixed'; // w3c
\r
673 dbody.bgProperties = 'fixed'; // ie
\r
675 Ext.DomHelper.applyStyles(dbody, ss);
\r
679 Ext.EventManager.removeAll(this.doc);
\r
683 this.doc = this.getDoc();
\r
685 Ext.EventManager.on(this.doc, {
\r
686 'mousedown': this.onEditorEvent,
\r
687 'dblclick': this.onEditorEvent,
\r
688 'click': this.onEditorEvent,
\r
689 'keyup': this.onEditorEvent,
\r
695 Ext.EventManager.on(this.doc, 'keypress', this.applyCommand, this);
\r
697 if(Ext.isIE || Ext.isWebKit || Ext.isOpera){
\r
698 Ext.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
\r
700 this.initialized = true;
\r
701 this.fireEvent('initialize', this);
\r
702 this.doc.editorInitialized = true;
\r
708 onDestroy : function(){
\r
709 if(this.monitorTask){
\r
710 Ext.TaskMgr.stop(this.monitorTask);
\r
713 Ext.destroy(this.tb);
\r
715 this.wrap.dom.innerHTML = '';
\r
716 this.wrap.remove();
\r
720 this.el.removeAllListeners();
\r
726 Ext.EventManager.removeAll(this.doc);
\r
727 for (var prop in this.doc){
\r
728 delete this.doc[prop];
\r
732 this.purgeListeners();
\r
736 onFirstFocus : function(){
\r
737 this.activated = true;
\r
738 this.disableItems(false);
\r
739 if(Ext.isGecko){ // prevent silly gecko errors
\r
741 var s = this.win.getSelection();
\r
742 if(!s.focusNode || s.focusNode.nodeType != 3){
\r
743 var r = s.getRangeAt(0);
\r
744 r.selectNodeContents(this.getEditorBody());
\r
749 this.execCmd('useCSS', true);
\r
750 this.execCmd('styleWithCSS', false);
\r
753 this.fireEvent('activate', this);
\r
757 adjustFont: function(btn){
\r
758 var adjust = btn.itemId == 'increasefontsize' ? 1 : -1;
\r
760 var v = parseInt(this.doc.queryCommandValue('FontSize') || 2, 10);
\r
761 if((Ext.isSafari && !Ext.isSafari2) || Ext.isChrome || Ext.isAir){
\r
763 // 1 = 10px, 2 = 13px, 3 = 16px, 4 = 18px, 5 = 24px, 6 = 32px
\r
777 v = v.constrain(1, 6);
\r
779 if(Ext.isSafari){ // safari
\r
782 v = Math.max(1, v+adjust) + (Ext.isSafari ? 'px' : 0);
\r
784 this.execCmd('FontSize', v);
\r
788 onEditorEvent : function(e){
\r
789 this.updateToolbar();
\r
793 <div id="method-Ext.form.HtmlEditor-updateToolbar"></div>/**
\r
794 * Protected method that will not generally be called directly. It triggers
\r
795 * a toolbar update by reading the markup state of the current selection in the editor.
\r
797 updateToolbar: function(){
\r
799 if(!this.activated){
\r
800 this.onFirstFocus();
\r
804 var btns = this.tb.items.map, doc = this.doc;
\r
806 if(this.enableFont && !Ext.isSafari2){
\r
807 var name = (this.doc.queryCommandValue('FontName')||this.defaultFont).toLowerCase();
\r
808 if(name != this.fontSelect.dom.value){
\r
809 this.fontSelect.dom.value = name;
\r
812 if(this.enableFormat){
\r
813 btns.bold.toggle(doc.queryCommandState('bold'));
\r
814 btns.italic.toggle(doc.queryCommandState('italic'));
\r
815 btns.underline.toggle(doc.queryCommandState('underline'));
\r
817 if(this.enableAlignments){
\r
818 btns.justifyleft.toggle(doc.queryCommandState('justifyleft'));
\r
819 btns.justifycenter.toggle(doc.queryCommandState('justifycenter'));
\r
820 btns.justifyright.toggle(doc.queryCommandState('justifyright'));
\r
822 if(!Ext.isSafari2 && this.enableLists){
\r
823 btns.insertorderedlist.toggle(doc.queryCommandState('insertorderedlist'));
\r
824 btns.insertunorderedlist.toggle(doc.queryCommandState('insertunorderedlist'));
\r
827 Ext.menu.MenuMgr.hideAll();
\r
833 relayBtnCmd : function(btn){
\r
834 this.relayCmd(btn.itemId);
\r
837 <div id="method-Ext.form.HtmlEditor-relayCmd"></div>/**
\r
838 * Executes a Midas editor command on the editor document and performs necessary focus and
\r
839 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
\r
840 * @param {String} cmd The Midas command
\r
841 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
\r
843 relayCmd : function(cmd, value){
\r
846 this.execCmd(cmd, value);
\r
847 this.updateToolbar();
\r
848 }).defer(10, this);
\r
851 <div id="method-Ext.form.HtmlEditor-execCmd"></div>/**
\r
852 * Executes a Midas editor command directly on the editor document.
\r
853 * For visual commands, you should use {@link #relayCmd} instead.
\r
854 * <b>This should only be called after the editor is initialized.</b>
\r
855 * @param {String} cmd The Midas command
\r
856 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
\r
858 execCmd : function(cmd, value){
\r
859 this.doc.execCommand(cmd, false, value === undefined ? null : value);
\r
864 applyCommand : function(e){
\r
866 var c = e.getCharCode(), cmd;
\r
868 c = String.fromCharCode(c);
\r
884 e.preventDefault();
\r
890 <div id="method-Ext.form.HtmlEditor-insertAtCursor"></div>/**
\r
891 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
\r
893 * @param {String} text
\r
895 insertAtCursor : function(text){
\r
896 if(!this.activated){
\r
901 var r = this.doc.selection.createRange();
\r
908 }else if(Ext.isGecko || Ext.isOpera){
\r
910 this.execCmd('InsertHTML', text);
\r
912 }else if(Ext.isWebKit){
\r
913 this.execCmd('InsertText', text);
\r
919 fixKeys : function(){ // load time branching for fastest keydown performance
\r
921 return function(e){
\r
922 var k = e.getKey(), r;
\r
925 r = this.doc.selection.createRange();
\r
928 r.pasteHTML(' ');
\r
931 }else if(k == e.ENTER){
\r
932 r = this.doc.selection.createRange();
\r
934 var target = r.parentElement();
\r
935 if(!target || target.tagName.toLowerCase() != 'li'){
\r
937 r.pasteHTML('<br />');
\r
944 }else if(Ext.isOpera){
\r
945 return function(e){
\r
946 var k = e.getKey();
\r
950 this.execCmd('InsertHTML',' ');
\r
954 }else if(Ext.isWebKit){
\r
955 return function(e){
\r
956 var k = e.getKey();
\r
959 this.execCmd('InsertText','\t');
\r
966 <div id="method-Ext.form.HtmlEditor-getToolbar"></div>/**
\r
967 * Returns the editor's toolbar. <b>This is only available after the editor has been rendered.</b>
\r
968 * @return {Ext.Toolbar}
\r
970 getToolbar : function(){
\r
974 <div id="prop-Ext.form.HtmlEditor-buttonTips"></div>/**
\r
975 * Object collection of toolbar tooltips for the buttons in the editor. The key
\r
976 * is the command id associated with that button and the value is a valid QuickTips object.
\r
981 title: 'Bold (Ctrl+B)',
\r
982 text: 'Make the selected text bold.',
\r
983 cls: 'x-html-editor-tip'
\r
986 title: 'Italic (Ctrl+I)',
\r
987 text: 'Make the selected text italic.',
\r
988 cls: 'x-html-editor-tip'
\r
996 title: 'Bold (Ctrl+B)',
\r
997 text: 'Make the selected text bold.',
\r
998 cls: 'x-html-editor-tip'
\r
1001 title: 'Italic (Ctrl+I)',
\r
1002 text: 'Make the selected text italic.',
\r
1003 cls: 'x-html-editor-tip'
\r
1006 title: 'Underline (Ctrl+U)',
\r
1007 text: 'Underline the selected text.',
\r
1008 cls: 'x-html-editor-tip'
\r
1010 increasefontsize : {
\r
1011 title: 'Grow Text',
\r
1012 text: 'Increase the font size.',
\r
1013 cls: 'x-html-editor-tip'
\r
1015 decreasefontsize : {
\r
1016 title: 'Shrink Text',
\r
1017 text: 'Decrease the font size.',
\r
1018 cls: 'x-html-editor-tip'
\r
1021 title: 'Text Highlight Color',
\r
1022 text: 'Change the background color of the selected text.',
\r
1023 cls: 'x-html-editor-tip'
\r
1026 title: 'Font Color',
\r
1027 text: 'Change the color of the selected text.',
\r
1028 cls: 'x-html-editor-tip'
\r
1031 title: 'Align Text Left',
\r
1032 text: 'Align text to the left.',
\r
1033 cls: 'x-html-editor-tip'
\r
1036 title: 'Center Text',
\r
1037 text: 'Center text in the editor.',
\r
1038 cls: 'x-html-editor-tip'
\r
1041 title: 'Align Text Right',
\r
1042 text: 'Align text to the right.',
\r
1043 cls: 'x-html-editor-tip'
\r
1045 insertunorderedlist : {
\r
1046 title: 'Bullet List',
\r
1047 text: 'Start a bulleted list.',
\r
1048 cls: 'x-html-editor-tip'
\r
1050 insertorderedlist : {
\r
1051 title: 'Numbered List',
\r
1052 text: 'Start a numbered list.',
\r
1053 cls: 'x-html-editor-tip'
\r
1056 title: 'Hyperlink',
\r
1057 text: 'Make the selected text a hyperlink.',
\r
1058 cls: 'x-html-editor-tip'
\r
1061 title: 'Source Edit',
\r
1062 text: 'Switch to source editing mode.',
\r
1063 cls: 'x-html-editor-tip'
\r
1067 // hide stuff that is not compatible
\r
1068 <div id="event-Ext.form.HtmlEditor-blur"></div>/**
\r
1072 <div id="event-Ext.form.HtmlEditor-change"></div>/**
\r
1076 <div id="event-Ext.form.HtmlEditor-focus"></div>/**
\r
1080 <div id="event-Ext.form.HtmlEditor-specialkey"></div>/**
\r
1081 * @event specialkey
\r
1084 <div id="cfg-Ext.form.HtmlEditor-fieldClass"></div>/**
\r
1085 * @cfg {String} fieldClass @hide
\r
1087 <div id="cfg-Ext.form.HtmlEditor-focusClass"></div>/**
\r
1088 * @cfg {String} focusClass @hide
\r
1090 <div id="cfg-Ext.form.HtmlEditor-autoCreate"></div>/**
\r
1091 * @cfg {String} autoCreate @hide
\r
1093 <div id="cfg-Ext.form.HtmlEditor-inputType"></div>/**
\r
1094 * @cfg {String} inputType @hide
\r
1096 <div id="cfg-Ext.form.HtmlEditor-invalidClass"></div>/**
\r
1097 * @cfg {String} invalidClass @hide
\r
1099 <div id="cfg-Ext.form.HtmlEditor-invalidText"></div>/**
\r
1100 * @cfg {String} invalidText @hide
\r
1102 <div id="cfg-Ext.form.HtmlEditor-msgFx"></div>/**
\r
1103 * @cfg {String} msgFx @hide
\r
1105 <div id="cfg-Ext.form.HtmlEditor-validateOnBlur"></div>/**
\r
1106 * @cfg {String} validateOnBlur @hide
\r
1108 <div id="cfg-Ext.form.HtmlEditor-allowDomMove"></div>/**
\r
1109 * @cfg {Boolean} allowDomMove @hide
\r
1111 <div id="cfg-Ext.form.HtmlEditor-applyTo"></div>/**
\r
1112 * @cfg {String} applyTo @hide
\r
1114 <div id="cfg-Ext.form.HtmlEditor-autoHeight"></div>/**
\r
1115 * @cfg {String} autoHeight @hide
\r
1117 <div id="cfg-Ext.form.HtmlEditor-autoWidth"></div>/**
\r
1118 * @cfg {String} autoWidth @hide
\r
1120 <div id="cfg-Ext.form.HtmlEditor-cls"></div>/**
\r
1121 * @cfg {String} cls @hide
\r
1123 <div id="cfg-Ext.form.HtmlEditor-disabled"></div>/**
\r
1124 * @cfg {String} disabled @hide
\r
1126 <div id="cfg-Ext.form.HtmlEditor-disabledClass"></div>/**
\r
1127 * @cfg {String} disabledClass @hide
\r
1129 <div id="cfg-Ext.form.HtmlEditor-msgTarget"></div>/**
\r
1130 * @cfg {String} msgTarget @hide
\r
1132 <div id="cfg-Ext.form.HtmlEditor-readOnly"></div>/**
\r
1133 * @cfg {String} readOnly @hide
\r
1135 <div id="cfg-Ext.form.HtmlEditor-style"></div>/**
\r
1136 * @cfg {String} style @hide
\r
1138 <div id="cfg-Ext.form.HtmlEditor-validationDelay"></div>/**
\r
1139 * @cfg {String} validationDelay @hide
\r
1141 <div id="cfg-Ext.form.HtmlEditor-validationEvent"></div>/**
\r
1142 * @cfg {String} validationEvent @hide
\r
1144 <div id="cfg-Ext.form.HtmlEditor-tabIndex"></div>/**
\r
1145 * @cfg {String} tabIndex @hide
\r
1147 <div id="prop-Ext.form.HtmlEditor-disabled"></div>/**
\r
1148 * @property disabled
\r
1151 <div id="method-Ext.form.HtmlEditor-applyToMarkup"></div>/**
\r
1152 * @method applyToMarkup
\r
1155 <div id="method-Ext.form.HtmlEditor-disable"></div>/**
\r
1159 <div id="method-Ext.form.HtmlEditor-enable"></div>/**
\r
1163 <div id="method-Ext.form.HtmlEditor-validate"></div>/**
\r
1164 * @method validate
\r
1167 <div id="event-Ext.form.HtmlEditor-valid"></div>/**
\r
1171 <div id="method-Ext.form.HtmlEditor-setDisabled"></div>/**
\r
1172 * @method setDisabled
\r
1175 <div id="cfg-Ext.form.HtmlEditor-null"></div>/**
\r
1180 Ext.reg('htmleditor', Ext.form.HtmlEditor);</pre>
\r