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
21 Ext.applyIf(Ext.Element, {
22 unitRe: /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
23 camelRe: /(-[a-z])/gi,
24 opacityRe: /alpha\(opacity=(.*)\)/i,
25 cssRe: /([a-z0-9-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi,
27 defaultUnit : "px",
28 borders: {l: 'border-left-width', r: 'border-right-width', t: 'border-top-width', b: 'border-bottom-width'},
29 paddings: {l: 'padding-left', r: 'padding-right', t: 'padding-top', b: 'padding-bottom'},
30 margins: {l: 'margin-left', r: 'margin-right', t: 'margin-top', b: 'margin-bottom'},
32 // Reference the prototype's version of the method. Signatures are identical.
33 addUnits : Ext.Element.prototype.addUnits,
35 <span id='Ext-Element-static-method-parseBox'> /**
36 </span> * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
37 * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
39 * @param {Number/String} box The encoded margins
40 * @return {Object} An object with margin sizes for top, right, bottom and left
42 parseBox : function(box) {
43 if (Ext.isObject(box)) {
46 right: box.right || 0,
47 bottom: box.bottom || 0,
51 if (typeof box != 'string') {
54 var parts = box.split(' '),
58 parts[1] = parts[2] = parts[3] = parts[0];
69 top :parseFloat(parts[0]) || 0,
70 right :parseFloat(parts[1]) || 0,
71 bottom:parseFloat(parts[2]) || 0,
72 left :parseFloat(parts[3]) || 0
78 <span id='Ext-Element-static-method-unitizeBox'> /**
79 </span> * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
80 * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result)
82 * @param {Number/String} box The encoded margins
83 * @param {String} units The type of units to add
84 * @return {String} An string with unitized (px if units is not specified) metrics for top, right, bottom and left
86 unitizeBox : function(box, units) {
87 var A = this.addUnits,
88 B = this.parseBox(box);
90 return A(B.top, units) + ' ' +
91 A(B.right, units) + ' ' +
92 A(B.bottom, units) + ' ' +
98 camelReplaceFn : function(m, a) {
99 return a.charAt(1).toUpperCase();
102 <span id='Ext-Element-static-method-normalize'> /**
103 </span> * Normalizes CSS property keys from dash delimited to camel case JavaScript Syntax.
106 * <li>border-width -> borderWidth</li>
107 * <li>padding-top -> paddingTop</li>
110 * @param {String} prop The property to normalize
111 * @return {String} The normalized string
113 normalize : function(prop) {
114 if (prop == 'float') {
115 prop = Ext.supports.Float ? 'cssFloat' : 'styleFloat';
117 return this.propertyCache[prop] || (this.propertyCache[prop] = prop.replace(this.camelRe, this.camelReplaceFn));
120 <span id='Ext-Element-static-method-getDocumentHeight'> /**
121 </span> * Retrieves the document height
123 * @return {Number} documentHeight
125 getDocumentHeight: function() {
126 return Math.max(!Ext.isStrict ? document.body.scrollHeight : document.documentElement.scrollHeight, this.getViewportHeight());
129 <span id='Ext-Element-static-method-getDocumentWidth'> /**
130 </span> * Retrieves the document width
132 * @return {Number} documentWidth
134 getDocumentWidth: function() {
135 return Math.max(!Ext.isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth, this.getViewportWidth());
138 <span id='Ext-Element-static-method-getViewportHeight'> /**
139 </span> * Retrieves the viewport height of the window.
141 * @return {Number} viewportHeight
143 getViewportHeight: function(){
144 return window.innerHeight;
147 <span id='Ext-Element-static-method-getViewportWidth'> /**
148 </span> * Retrieves the viewport width of the window.
150 * @return {Number} viewportWidth
152 getViewportWidth : function() {
153 return window.innerWidth;
156 <span id='Ext-Element-static-method-getViewSize'> /**
157 </span> * Retrieves the viewport size of the window.
159 * @return {Object} object containing width and height properties
161 getViewSize : function() {
163 width: window.innerWidth,
164 height: window.innerHeight
168 <span id='Ext-Element-static-method-getOrientation'> /**
169 </span> * Retrieves the current orientation of the window. This is calculated by
170 * determing if the height is greater than the width.
172 * @return {String} Orientation of window: 'portrait' or 'landscape'
174 getOrientation : function() {
175 if (Ext.supports.OrientationChange) {
176 return (window.orientation == 0) ? 'portrait' : 'landscape';
179 return (window.innerHeight > window.innerWidth) ? 'portrait' : 'landscape';
182 <span id='Ext-Element-static-method-fromPoint'> /**
183 </span> * Returns the top Element that is located at the passed coordinates
185 * @param {Number} x The x coordinate
186 * @param {Number} y The y coordinate
187 * @return {String} The found Element
189 fromPoint: function(x, y) {
190 return Ext.get(document.elementFromPoint(x, y));
193 <span id='Ext-Element-static-method-parseStyles'> /**
194 </span> * Converts a CSS string into an object with a property for each style.
196 * The sample code below would return an object with 2 properties, one
197 * for background-color and one for color.</p>
198 * <pre><code>
199 var css = 'background-color: red;color: blue; ';
200 console.log(Ext.Element.parseStyles(css));
201 * </code></pre>
203 * @param {String} styles A CSS string
204 * @return {Object} styles
206 parseStyles: function(styles){
212 // Since we're using the g flag on the regex, we need to set the lastIndex.
213 // This automatically happens on some implementations, but not others, see:
214 // http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
215 // http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
217 while ((matches = cssRe.exec(styles))) {
218 out[matches[1]] = matches[2];