1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-Version'>/**
2 </span> * @author Jacky Nguyen <jacky@sencha.com>
3 * @docauthor Jacky Nguyen <jacky@sencha.com>
6 * A utility class that wrap around a string version number and provide convenient
7 * method to perform comparison. See also: {@link Ext.Version#compare compare}. Example:
9 var version = new Ext.Version('1.0.2beta');
10 console.log("Version is " + version); // Version is 1.0.2beta
12 console.log(version.getMajor()); // 1
13 console.log(version.getMinor()); // 0
14 console.log(version.getPatch()); // 2
15 console.log(version.getBuild()); // 0
16 console.log(version.getRelease()); // beta
18 console.log(version.isGreaterThan('1.0.1')); // True
19 console.log(version.isGreaterThan('1.0.2alpha')); // True
20 console.log(version.isGreaterThan('1.0.2RC')); // False
21 console.log(version.isGreaterThan('1.0.2')); // False
22 console.log(version.isLessThan('1.0.2')); // True
24 console.log(version.match(1.0)); // True
25 console.log(version.match('1.0.2')); // True
31 // Current core version
32 var version = '4.0.0', Version;
33 Ext.Version = Version = Ext.extend(Object, {
35 <span id='Ext-Version-method-constructor'> /**
36 </span> * @constructor
37 * @param {String/Number} version The version number in the follow standard format: major[.minor[.patch[.build[release]]]]
38 * Examples: 1.0 or 1.2.3beta or 1.2.3.4RC
39 * @return {Ext.Version} this
42 constructor: function(version) {
43 var parts, releaseStartIndex;
45 if (version instanceof Version) {
49 this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
51 releaseStartIndex = this.version.search(/([^\d\.])/);
53 if (releaseStartIndex !== -1) {
54 this.release = this.version.substr(releaseStartIndex, version.length);
55 this.shortVersion = this.version.substr(0, releaseStartIndex);
58 this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
60 parts = this.version.split('.');
62 this.major = parseInt(parts.shift() || 0, 10);
63 this.minor = parseInt(parts.shift() || 0, 10);
64 this.patch = parseInt(parts.shift() || 0, 10);
65 this.build = parseInt(parts.shift() || 0, 10);
70 <span id='Ext-Version-method-toString'> /**
71 </span> * Override the native toString method
73 * @return {String} version
75 toString: function() {
79 <span id='Ext-Version-method-valueOf'> /**
80 </span> * Override the native valueOf method
82 * @return {String} version
88 <span id='Ext-Version-method-getMajor'> /**
89 </span> * Returns the major component value
90 * @return {Number} major
92 getMajor: function() {
93 return this.major || 0;
96 <span id='Ext-Version-method-getMinor'> /**
97 </span> * Returns the minor component value
98 * @return {Number} minor
100 getMinor: function() {
101 return this.minor || 0;
104 <span id='Ext-Version-method-getPatch'> /**
105 </span> * Returns the patch component value
106 * @return {Number} patch
108 getPatch: function() {
109 return this.patch || 0;
112 <span id='Ext-Version-method-getBuild'> /**
113 </span> * Returns the build component value
114 * @return {Number} build
116 getBuild: function() {
117 return this.build || 0;
120 <span id='Ext-Version-method-getRelease'> /**
121 </span> * Returns the release component value
122 * @return {Number} release
124 getRelease: function() {
125 return this.release || '';
128 <span id='Ext-Version-method-isGreaterThan'> /**
129 </span> * Returns whether this version if greater than the supplied argument
130 * @param {String/Number} target The version to compare with
131 * @return {Boolean} True if this version if greater than the target, false otherwise
133 isGreaterThan: function(target) {
134 return Version.compare(this.version, target) === 1;
137 <span id='Ext-Version-method-isLessThan'> /**
138 </span> * Returns whether this version if smaller than the supplied argument
139 * @param {String/Number} target The version to compare with
140 * @return {Boolean} True if this version if smaller than the target, false otherwise
142 isLessThan: function(target) {
143 return Version.compare(this.version, target) === -1;
146 <span id='Ext-Version-method-equals'> /**
147 </span> * Returns whether this version equals to the supplied argument
148 * @param {String/Number} target The version to compare with
149 * @return {Boolean} True if this version equals to the target, false otherwise
151 equals: function(target) {
152 return Version.compare(this.version, target) === 0;
155 <span id='Ext-Version-method-match'> /**
156 </span> * Returns whether this version matches the supplied argument. Example:
157 * <pre><code>
158 * var version = new Ext.Version('1.0.2beta');
159 * console.log(version.match(1)); // True
160 * console.log(version.match(1.0)); // True
161 * console.log(version.match('1.0.2')); // True
162 * console.log(version.match('1.0.2RC')); // False
163 * </code></pre>
164 * @param {String/Number} target The version to compare with
165 * @return {Boolean} True if this version matches the target, false otherwise
167 match: function(target) {
168 target = String(target);
169 return this.version.substr(0, target.length) === target;
172 <span id='Ext-Version-method-toArray'> /**
173 </span> * Returns this format: [major, minor, patch, build, release]. Useful for comparison
176 toArray: function() {
177 return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
180 <span id='Ext-Version-method-getShortVersion'> /**
181 </span> * Returns shortVersion version without dots and release
184 getShortVersion: function() {
185 return this.shortVersion;
203 <span id='Ext-Version-method-getComponentValue'> /**
204 </span> * Converts a version component to a comparable value
207 * @param {Mixed} value The value to convert
210 getComponentValue: function(value) {
211 return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
214 <span id='Ext-Version-method-compare'> /**
215 </span> * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
216 * they are handled in the following order:
217 * 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
220 * @param {String} current The current version to compare to
221 * @param {String} target The target version to compare to
222 * @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
224 compare: function(current, target) {
225 var currentValue, targetValue, i;
227 current = new Version(current).toArray();
228 target = new Version(target).toArray();
230 for (i = 0; i < Math.max(current.length, target.length); i++) {
231 currentValue = this.getComponentValue(current[i]);
232 targetValue = this.getComponentValue(target[i]);
234 if (currentValue < targetValue) {
236 } else if (currentValue > targetValue) {
246 <span id='Ext-Version-property-versions'> /**
251 <span id='Ext-Version-property-lastRegisteredVersion'> /**
254 lastRegisteredVersion: null,
256 <span id='Ext-Version-method-setVersion'> /**
257 </span> * Set version number for the given package name.
259 * @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
260 * @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
263 setVersion: function(packageName, version) {
264 Ext.versions[packageName] = new Version(version);
265 Ext.lastRegisteredVersion = Ext.versions[packageName];
270 <span id='Ext-Version-method-getVersion'> /**
271 </span> * Get the version number of the supplied package name; will return the last registered version
272 * (last Ext.setVersion call) if there's no package name given.
274 * @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
275 * @return {Ext.Version} The version
277 getVersion: function(packageName) {
278 if (packageName === undefined) {
279 return Ext.lastRegisteredVersion;
282 return Ext.versions[packageName];
285 <span id='Ext-Version-method-deprecate'> /**
286 </span> * Create a closure for deprecated code.
288 // This means Ext.oldMethod is only supported in 4.0.0beta and older.
289 // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
290 // the closure will not be invoked
291 Ext.deprecate('extjs', '4.0.0beta', function() {
292 Ext.oldMethod = Ext.newMethod;
297 * @param {String} packageName The package name
298 * @param {String} since The last version before it's deprecated
299 * @param {Function} closure The callback function to be executed with the specified version is less than the current version
300 * @param {Object} scope The execution scope (<tt>this</tt>) if the closure
303 deprecate: function(packageName, since, closure, scope) {
304 if (Version.compare(Ext.getVersion(packageName), since) < 1) {
308 }); // End Versioning
310 Ext.setVersion('core', version);
313 </pre></pre></body></html>