4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
19 </span> * @class Ext.Element
24 isCSS1 = doc.compatMode == "CSS1Compat",
25 ELEMENT = Ext.Element,
28 _fly = new Ext.Element.Flyweight();
34 // If the browser does not support document.activeElement we need some assistance.
35 // This covers old Safari 3.2 (4.0 added activeElement along with just about all
36 // other browsers). We need this support to handle issues with old Safari.
37 if (!('activeElement' in doc) && doc.addEventListener) {
38 doc.addEventListener('focus',
40 if (ev && ev.target) {
41 activeElement = (ev.target == doc) ? null : ev.target;
47 * Helper function to create the function that will restore the selection.
49 function makeSelectionRestoreFn (activeEl, start, end) {
51 activeEl.selectionStart = start;
52 activeEl.selectionEnd = end;
57 isAncestor : function(p, c) {
65 } else if (p.compareDocumentPosition) {
66 return !!(p.compareDocumentPosition(c) & 16);
68 while ((c = c.parentNode)) {
76 <span id='Ext-Element-method-getActiveElement'> /**
77 </span> * Returns the active element in the DOM. If the browser supports activeElement
78 * on the document, this is returned. If not, the focus is tracked and the active
79 * element is maintained internally.
80 * @return {HTMLElement} The active (focused) element in the document.
82 getActiveElement: function () {
83 return doc.activeElement || activeElement;
86 <span id='Ext-Element-method-getRightMarginFixCleaner'> /**
87 </span> * Creates a function to call to clean up problems with the work-around for the
88 * WebKit RightMargin bug. The work-around is to add "display: 'inline-block'" to
89 * the element before calling getComputedStyle and then to restore its original
90 * display value. The problem with this is that it corrupts the selection of an
91 * INPUT or TEXTAREA element (as in the "I-beam" goes away but ths focus remains).
92 * To cleanup after this, we need to capture the selection of any such element and
93 * then restore it after we have restored the display style.
95 * @param target {Element} The top-most element being adjusted.
98 getRightMarginFixCleaner: function (target) {
99 var supports = Ext.supports,
100 hasInputBug = supports.DisplayChangeInputSelectionBug,
101 hasTextAreaBug = supports.DisplayChangeTextAreaSelectionBug;
103 if (hasInputBug || hasTextAreaBug) {
104 var activeEl = doc.activeElement || activeElement, // save a call
105 tag = activeEl && activeEl.tagName,
109 if ((hasTextAreaBug && tag == 'TEXTAREA') ||
110 (hasInputBug && tag == 'INPUT' && activeEl.type == 'text')) {
111 if (ELEMENT.isAncestor(target, activeEl)) {
112 start = activeEl.selectionStart;
113 end = activeEl.selectionEnd;
115 if (Ext.isNumber(start) && Ext.isNumber(end)) { // to be safe...
116 // We don't create the raw closure here inline because that
117 // will be costly even if we don't want to return it (nested
118 // function decls and exprs are often instantiated on entry
119 // regardless of whether execution ever reaches them):
120 return makeSelectionRestoreFn(activeEl, start, end);
126 return Ext.emptyFn; // avoid special cases, just return a nop
129 getViewWidth : function(full) {
130 return full ? ELEMENT.getDocumentWidth() : ELEMENT.getViewportWidth();
133 getViewHeight : function(full) {
134 return full ? ELEMENT.getDocumentHeight() : ELEMENT.getViewportHeight();
137 getDocumentHeight: function() {
138 return Math.max(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, ELEMENT.getViewportHeight());
141 getDocumentWidth: function() {
142 return Math.max(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, ELEMENT.getViewportWidth());
145 getViewportHeight: function(){
147 (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
151 getViewportWidth : function() {
152 return (!Ext.isStrict && !Ext.isOpera) ? doc.body.clientWidth :
153 Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
156 getY : function(el) {
157 return ELEMENT.getXY(el)[1];
160 getX : function(el) {
161 return ELEMENT.getXY(el)[0];
164 getOffsetParent: function (el) {
167 // accessing offsetParent can throw "Unspecified Error" in IE6-8 (not 9)
168 return el.offsetParent;
170 var body = document.body; // safe bet, unless...
171 return (el == body) ? null : body;
175 getXY : function(el) {
186 bd = (doc.body || doc.documentElement),
192 hasAbsolute = fly(el).isStyle("position", "absolute");
194 if (el.getBoundingClientRect) {
196 b = el.getBoundingClientRect();
197 scroll = fly(document).getScroll();
198 ret = [ Math.round(b.left + scroll.left), Math.round(b.top + scroll.top) ];
200 // IE6-8 can also throw from getBoundingClientRect...
205 for (p = el; p; p = ELEMENT.getOffsetParent(p)) {
210 hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
213 y += bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
214 x += bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
216 if (p != el && !pe.isStyle('overflow','visible')) {
223 if (Ext.isSafari && hasAbsolute) {
228 if (Ext.isGecko && !hasAbsolute) {
230 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
231 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
235 while (p && p != bd) {
236 if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
248 setXY : function(el, xy) {
249 (el = Ext.fly(el, '_setXY')).position();
251 var pts = el.translatePoints(xy),
252 style = el.dom.style,
256 if (!isNaN(pts[pos])) {
257 style[pos] = pts[pos] + "px";
262 setX : function(el, x) {
263 ELEMENT.setXY(el, [x, false]);
266 setY : function(el, y) {
267 ELEMENT.setXY(el, [false, y]);
270 <span id='Ext-Element-method-serializeForm'> /**
271 </span> * Serializes a DOM form into a url encoded string
272 * @param {Object} form The form
273 * @return {String} The url encoded form
275 serializeForm: function(form) {
276 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
278 encoder = encodeURIComponent,
284 Ext.each(fElements, function(element){
288 if (!element.disabled && name) {
289 if (/select-(one|multiple)/i.test(type)) {
290 Ext.each(element.options, function(opt){
292 hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
293 data += Ext.String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
296 } else if (!(/file|undefined|reset|button/i.test(type))) {
297 if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) {
298 data += encoder(name) + '=' + encoder(element.value) + '&';
299 hasSubmit = /submit/i.test(type);
304 return data.substr(0, data.length - 1);