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-Version'>/**
19 </span> * @author Jacky Nguyen <jacky@sencha.com>
20 * @docauthor Jacky Nguyen <jacky@sencha.com>
23 * A utility class that wrap around a string version number and provide convenient
24 * method to perform comparison. See also: {@link Ext.Version#compare compare}. Example:
26 var version = new Ext.Version('1.0.2beta');
27 console.log("Version is " + version); // Version is 1.0.2beta
29 console.log(version.getMajor()); // 1
30 console.log(version.getMinor()); // 0
31 console.log(version.getPatch()); // 2
32 console.log(version.getBuild()); // 0
33 console.log(version.getRelease()); // beta
35 console.log(version.isGreaterThan('1.0.1')); // True
36 console.log(version.isGreaterThan('1.0.2alpha')); // True
37 console.log(version.isGreaterThan('1.0.2RC')); // False
38 console.log(version.isGreaterThan('1.0.2')); // False
39 console.log(version.isLessThan('1.0.2')); // True
41 console.log(version.match(1.0)); // True
42 console.log(version.match('1.0.2')); // True
48 // Current core version
49 var version = '4.0.7', Version;
50 Ext.Version = Version = Ext.extend(Object, {
52 <span id='Ext-Version-method-constructor'> /**
53 </span> * @param {String/Number} version The version number in the follow standard format: major[.minor[.patch[.build[release]]]]
54 * Examples: 1.0 or 1.2.3beta or 1.2.3.4RC
55 * @return {Ext.Version} this
57 constructor: function(version) {
58 var parts, releaseStartIndex;
60 if (version instanceof Version) {
64 this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
66 releaseStartIndex = this.version.search(/([^\d\.])/);
68 if (releaseStartIndex !== -1) {
69 this.release = this.version.substr(releaseStartIndex, version.length);
70 this.shortVersion = this.version.substr(0, releaseStartIndex);
73 this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
75 parts = this.version.split('.');
77 this.major = parseInt(parts.shift() || 0, 10);
78 this.minor = parseInt(parts.shift() || 0, 10);
79 this.patch = parseInt(parts.shift() || 0, 10);
80 this.build = parseInt(parts.shift() || 0, 10);
85 <span id='Ext-Version-method-toString'> /**
86 </span> * Override the native toString method
88 * @return {String} version
90 toString: function() {
94 <span id='Ext-Version-method-valueOf'> /**
95 </span> * Override the native valueOf method
97 * @return {String} version
103 <span id='Ext-Version-method-getMajor'> /**
104 </span> * Returns the major component value
105 * @return {Number} major
107 getMajor: function() {
108 return this.major || 0;
111 <span id='Ext-Version-method-getMinor'> /**
112 </span> * Returns the minor component value
113 * @return {Number} minor
115 getMinor: function() {
116 return this.minor || 0;
119 <span id='Ext-Version-method-getPatch'> /**
120 </span> * Returns the patch component value
121 * @return {Number} patch
123 getPatch: function() {
124 return this.patch || 0;
127 <span id='Ext-Version-method-getBuild'> /**
128 </span> * Returns the build component value
129 * @return {Number} build
131 getBuild: function() {
132 return this.build || 0;
135 <span id='Ext-Version-method-getRelease'> /**
136 </span> * Returns the release component value
137 * @return {Number} release
139 getRelease: function() {
140 return this.release || '';
143 <span id='Ext-Version-method-isGreaterThan'> /**
144 </span> * Returns whether this version if greater than the supplied argument
145 * @param {String/Number} target The version to compare with
146 * @return {Boolean} True if this version if greater than the target, false otherwise
148 isGreaterThan: function(target) {
149 return Version.compare(this.version, target) === 1;
152 <span id='Ext-Version-method-isLessThan'> /**
153 </span> * Returns whether this version if smaller than the supplied argument
154 * @param {String/Number} target The version to compare with
155 * @return {Boolean} True if this version if smaller than the target, false otherwise
157 isLessThan: function(target) {
158 return Version.compare(this.version, target) === -1;
161 <span id='Ext-Version-method-equals'> /**
162 </span> * Returns whether this version equals to the supplied argument
163 * @param {String/Number} target The version to compare with
164 * @return {Boolean} True if this version equals to the target, false otherwise
166 equals: function(target) {
167 return Version.compare(this.version, target) === 0;
170 <span id='Ext-Version-method-match'> /**
171 </span> * Returns whether this version matches the supplied argument. Example:
172 * <pre><code>
173 * var version = new Ext.Version('1.0.2beta');
174 * console.log(version.match(1)); // True
175 * console.log(version.match(1.0)); // True
176 * console.log(version.match('1.0.2')); // True
177 * console.log(version.match('1.0.2RC')); // False
178 * </code></pre>
179 * @param {String/Number} target The version to compare with
180 * @return {Boolean} True if this version matches the target, false otherwise
182 match: function(target) {
183 target = String(target);
184 return this.version.substr(0, target.length) === target;
187 <span id='Ext-Version-method-toArray'> /**
188 </span> * Returns this format: [major, minor, patch, build, release]. Useful for comparison
191 toArray: function() {
192 return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
195 <span id='Ext-Version-method-getShortVersion'> /**
196 </span> * Returns shortVersion version without dots and release
199 getShortVersion: function() {
200 return this.shortVersion;
218 <span id='Ext-Version-static-method-getComponentValue'> /**
219 </span> * Converts a version component to a comparable value
222 * @param {Object} value The value to convert
225 getComponentValue: function(value) {
226 return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
229 <span id='Ext-Version-static-method-compare'> /**
230 </span> * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
231 * they are handled in the following order:
232 * 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
235 * @param {String} current The current version to compare to
236 * @param {String} target The target version to compare to
237 * @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
239 compare: function(current, target) {
240 var currentValue, targetValue, i;
242 current = new Version(current).toArray();
243 target = new Version(target).toArray();
245 for (i = 0; i < Math.max(current.length, target.length); i++) {
246 currentValue = this.getComponentValue(current[i]);
247 targetValue = this.getComponentValue(target[i]);
249 if (currentValue < targetValue) {
251 } else if (currentValue > targetValue) {
261 <span id='Ext-Version-property-versions'> /**
266 <span id='Ext-Version-property-lastRegisteredVersion'> /**
269 lastRegisteredVersion: null,
271 <span id='Ext-Version-method-setVersion'> /**
272 </span> * Set version number for the given package name.
274 * @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
275 * @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
278 setVersion: function(packageName, version) {
279 Ext.versions[packageName] = new Version(version);
280 Ext.lastRegisteredVersion = Ext.versions[packageName];
285 <span id='Ext-Version-method-getVersion'> /**
286 </span> * Get the version number of the supplied package name; will return the last registered version
287 * (last Ext.setVersion call) if there's no package name given.
289 * @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
290 * @return {Ext.Version} The version
292 getVersion: function(packageName) {
293 if (packageName === undefined) {
294 return Ext.lastRegisteredVersion;
297 return Ext.versions[packageName];
300 <span id='Ext-Version-method-deprecate'> /**
301 </span> * Create a closure for deprecated code.
303 // This means Ext.oldMethod is only supported in 4.0.0beta and older.
304 // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
305 // the closure will not be invoked
306 Ext.deprecate('extjs', '4.0.0beta', function() {
307 Ext.oldMethod = Ext.newMethod;
312 * @param {String} packageName The package name
313 * @param {String} since The last version before it's deprecated
314 * @param {Function} closure The callback function to be executed with the specified version is less than the current version
315 * @param {Object} scope The execution scope (<tt>this</tt>) if the closure
318 deprecate: function(packageName, since, closure, scope) {
319 if (Version.compare(Ext.getVersion(packageName), since) < 1) {
323 }); // End Versioning
325 Ext.setVersion('core', version);