4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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.0', Version;
50 Ext.Version = Version = Ext.extend(Object, {
52 <span id='Ext-Version-method-constructor'> /**
53 </span> * @constructor
54 * @param {String/Number} version The version number in the follow standard format: major[.minor[.patch[.build[release]]]]
55 * Examples: 1.0 or 1.2.3beta or 1.2.3.4RC
56 * @return {Ext.Version} this
59 constructor: function(version) {
60 var parts, releaseStartIndex;
62 if (version instanceof Version) {
66 this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
68 releaseStartIndex = this.version.search(/([^\d\.])/);
70 if (releaseStartIndex !== -1) {
71 this.release = this.version.substr(releaseStartIndex, version.length);
72 this.shortVersion = this.version.substr(0, releaseStartIndex);
75 this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
77 parts = this.version.split('.');
79 this.major = parseInt(parts.shift() || 0, 10);
80 this.minor = parseInt(parts.shift() || 0, 10);
81 this.patch = parseInt(parts.shift() || 0, 10);
82 this.build = parseInt(parts.shift() || 0, 10);
87 <span id='Ext-Version-method-toString'> /**
88 </span> * Override the native toString method
90 * @return {String} version
92 toString: function() {
96 <span id='Ext-Version-method-valueOf'> /**
97 </span> * Override the native valueOf method
99 * @return {String} version
101 valueOf: function() {
105 <span id='Ext-Version-method-getMajor'> /**
106 </span> * Returns the major component value
107 * @return {Number} major
109 getMajor: function() {
110 return this.major || 0;
113 <span id='Ext-Version-method-getMinor'> /**
114 </span> * Returns the minor component value
115 * @return {Number} minor
117 getMinor: function() {
118 return this.minor || 0;
121 <span id='Ext-Version-method-getPatch'> /**
122 </span> * Returns the patch component value
123 * @return {Number} patch
125 getPatch: function() {
126 return this.patch || 0;
129 <span id='Ext-Version-method-getBuild'> /**
130 </span> * Returns the build component value
131 * @return {Number} build
133 getBuild: function() {
134 return this.build || 0;
137 <span id='Ext-Version-method-getRelease'> /**
138 </span> * Returns the release component value
139 * @return {Number} release
141 getRelease: function() {
142 return this.release || '';
145 <span id='Ext-Version-method-isGreaterThan'> /**
146 </span> * Returns whether this version if greater than the supplied argument
147 * @param {String/Number} target The version to compare with
148 * @return {Boolean} True if this version if greater than the target, false otherwise
150 isGreaterThan: function(target) {
151 return Version.compare(this.version, target) === 1;
154 <span id='Ext-Version-method-isLessThan'> /**
155 </span> * Returns whether this version if smaller than the supplied argument
156 * @param {String/Number} target The version to compare with
157 * @return {Boolean} True if this version if smaller than the target, false otherwise
159 isLessThan: function(target) {
160 return Version.compare(this.version, target) === -1;
163 <span id='Ext-Version-method-equals'> /**
164 </span> * Returns whether this version equals to the supplied argument
165 * @param {String/Number} target The version to compare with
166 * @return {Boolean} True if this version equals to the target, false otherwise
168 equals: function(target) {
169 return Version.compare(this.version, target) === 0;
172 <span id='Ext-Version-method-match'> /**
173 </span> * Returns whether this version matches the supplied argument. Example:
174 * <pre><code>
175 * var version = new Ext.Version('1.0.2beta');
176 * console.log(version.match(1)); // True
177 * console.log(version.match(1.0)); // True
178 * console.log(version.match('1.0.2')); // True
179 * console.log(version.match('1.0.2RC')); // False
180 * </code></pre>
181 * @param {String/Number} target The version to compare with
182 * @return {Boolean} True if this version matches the target, false otherwise
184 match: function(target) {
185 target = String(target);
186 return this.version.substr(0, target.length) === target;
189 <span id='Ext-Version-method-toArray'> /**
190 </span> * Returns this format: [major, minor, patch, build, release]. Useful for comparison
193 toArray: function() {
194 return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
197 <span id='Ext-Version-method-getShortVersion'> /**
198 </span> * Returns shortVersion version without dots and release
201 getShortVersion: function() {
202 return this.shortVersion;
220 <span id='Ext-Version-method-getComponentValue'> /**
221 </span> * Converts a version component to a comparable value
224 * @param {Mixed} value The value to convert
227 getComponentValue: function(value) {
228 return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
231 <span id='Ext-Version-method-compare'> /**
232 </span> * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
233 * they are handled in the following order:
234 * 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
237 * @param {String} current The current version to compare to
238 * @param {String} target The target version to compare to
239 * @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
241 compare: function(current, target) {
242 var currentValue, targetValue, i;
244 current = new Version(current).toArray();
245 target = new Version(target).toArray();
247 for (i = 0; i < Math.max(current.length, target.length); i++) {
248 currentValue = this.getComponentValue(current[i]);
249 targetValue = this.getComponentValue(target[i]);
251 if (currentValue < targetValue) {
253 } else if (currentValue > targetValue) {
263 <span id='Ext-Version-property-versions'> /**
268 <span id='Ext-Version-property-lastRegisteredVersion'> /**
271 lastRegisteredVersion: null,
273 <span id='Ext-Version-method-setVersion'> /**
274 </span> * Set version number for the given package name.
276 * @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
277 * @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
280 setVersion: function(packageName, version) {
281 Ext.versions[packageName] = new Version(version);
282 Ext.lastRegisteredVersion = Ext.versions[packageName];
287 <span id='Ext-Version-method-getVersion'> /**
288 </span> * Get the version number of the supplied package name; will return the last registered version
289 * (last Ext.setVersion call) if there's no package name given.
291 * @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
292 * @return {Ext.Version} The version
294 getVersion: function(packageName) {
295 if (packageName === undefined) {
296 return Ext.lastRegisteredVersion;
299 return Ext.versions[packageName];
302 <span id='Ext-Version-method-deprecate'> /**
303 </span> * Create a closure for deprecated code.
305 // This means Ext.oldMethod is only supported in 4.0.0beta and older.
306 // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
307 // the closure will not be invoked
308 Ext.deprecate('extjs', '4.0.0beta', function() {
309 Ext.oldMethod = Ext.newMethod;
314 * @param {String} packageName The package name
315 * @param {String} since The last version before it's deprecated
316 * @param {Function} closure The callback function to be executed with the specified version is less than the current version
317 * @param {Object} scope The execution scope (<tt>this</tt>) if the closure
320 deprecate: function(packageName, since, closure, scope) {
321 if (Version.compare(Ext.getVersion(packageName), since) < 1) {
325 }); // End Versioning
327 Ext.setVersion('core', version);