ClassManager.html 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  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; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ClassManager'>/**
  19. </span> * @author Jacky Nguyen &lt;jacky@sencha.com&gt;
  20. * @docauthor Jacky Nguyen &lt;jacky@sencha.com&gt;
  21. * @class Ext.ClassManager
  22. *
  23. * Ext.ClassManager manages all classes and handles mapping from string class name to
  24. * actual class objects throughout the whole framework. It is not generally accessed directly, rather through
  25. * these convenient shorthands:
  26. *
  27. * - {@link Ext#define Ext.define}
  28. * - {@link Ext#create Ext.create}
  29. * - {@link Ext#widget Ext.widget}
  30. * - {@link Ext#getClass Ext.getClass}
  31. * - {@link Ext#getClassName Ext.getClassName}
  32. *
  33. * # Basic syntax:
  34. *
  35. * Ext.define(className, properties);
  36. *
  37. * in which `properties` is an object represent a collection of properties that apply to the class. See
  38. * {@link Ext.ClassManager#create} for more detailed instructions.
  39. *
  40. * Ext.define('Person', {
  41. * name: 'Unknown',
  42. *
  43. * constructor: function(name) {
  44. * if (name) {
  45. * this.name = name;
  46. * }
  47. * },
  48. *
  49. * eat: function(foodType) {
  50. * alert(&quot;I'm eating: &quot; + foodType);
  51. *
  52. * return this;
  53. * }
  54. * });
  55. *
  56. * var aaron = new Person(&quot;Aaron&quot;);
  57. * aaron.eat(&quot;Sandwich&quot;); // alert(&quot;I'm eating: Sandwich&quot;);
  58. *
  59. * Ext.Class has a powerful set of extensible {@link Ext.Class#registerPreprocessor pre-processors} which takes care of
  60. * everything related to class creation, including but not limited to inheritance, mixins, configuration, statics, etc.
  61. *
  62. * # Inheritance:
  63. *
  64. * Ext.define('Developer', {
  65. * extend: 'Person',
  66. *
  67. * constructor: function(name, isGeek) {
  68. * this.isGeek = isGeek;
  69. *
  70. * // Apply a method from the parent class' prototype
  71. * this.callParent([name]);
  72. * },
  73. *
  74. * code: function(language) {
  75. * alert(&quot;I'm coding in: &quot; + language);
  76. *
  77. * this.eat(&quot;Bugs&quot;);
  78. *
  79. * return this;
  80. * }
  81. * });
  82. *
  83. * var jacky = new Developer(&quot;Jacky&quot;, true);
  84. * jacky.code(&quot;JavaScript&quot;); // alert(&quot;I'm coding in: JavaScript&quot;);
  85. * // alert(&quot;I'm eating: Bugs&quot;);
  86. *
  87. * See {@link Ext.Base#callParent} for more details on calling superclass' methods
  88. *
  89. * # Mixins:
  90. *
  91. * Ext.define('CanPlayGuitar', {
  92. * playGuitar: function() {
  93. * alert(&quot;F#...G...D...A&quot;);
  94. * }
  95. * });
  96. *
  97. * Ext.define('CanComposeSongs', {
  98. * composeSongs: function() { ... }
  99. * });
  100. *
  101. * Ext.define('CanSing', {
  102. * sing: function() {
  103. * alert(&quot;I'm on the highway to hell...&quot;)
  104. * }
  105. * });
  106. *
  107. * Ext.define('Musician', {
  108. * extend: 'Person',
  109. *
  110. * mixins: {
  111. * canPlayGuitar: 'CanPlayGuitar',
  112. * canComposeSongs: 'CanComposeSongs',
  113. * canSing: 'CanSing'
  114. * }
  115. * })
  116. *
  117. * Ext.define('CoolPerson', {
  118. * extend: 'Person',
  119. *
  120. * mixins: {
  121. * canPlayGuitar: 'CanPlayGuitar',
  122. * canSing: 'CanSing'
  123. * },
  124. *
  125. * sing: function() {
  126. * alert(&quot;Ahem....&quot;);
  127. *
  128. * this.mixins.canSing.sing.call(this);
  129. *
  130. * alert(&quot;[Playing guitar at the same time...]&quot;);
  131. *
  132. * this.playGuitar();
  133. * }
  134. * });
  135. *
  136. * var me = new CoolPerson(&quot;Jacky&quot;);
  137. *
  138. * me.sing(); // alert(&quot;Ahem...&quot;);
  139. * // alert(&quot;I'm on the highway to hell...&quot;);
  140. * // alert(&quot;[Playing guitar at the same time...]&quot;);
  141. * // alert(&quot;F#...G...D...A&quot;);
  142. *
  143. * # Config:
  144. *
  145. * Ext.define('SmartPhone', {
  146. * config: {
  147. * hasTouchScreen: false,
  148. * operatingSystem: 'Other',
  149. * price: 500
  150. * },
  151. *
  152. * isExpensive: false,
  153. *
  154. * constructor: function(config) {
  155. * this.initConfig(config);
  156. * },
  157. *
  158. * applyPrice: function(price) {
  159. * this.isExpensive = (price &gt; 500);
  160. *
  161. * return price;
  162. * },
  163. *
  164. * applyOperatingSystem: function(operatingSystem) {
  165. * if (!(/^(iOS|Android|BlackBerry)$/i).test(operatingSystem)) {
  166. * return 'Other';
  167. * }
  168. *
  169. * return operatingSystem;
  170. * }
  171. * });
  172. *
  173. * var iPhone = new SmartPhone({
  174. * hasTouchScreen: true,
  175. * operatingSystem: 'iOS'
  176. * });
  177. *
  178. * iPhone.getPrice(); // 500;
  179. * iPhone.getOperatingSystem(); // 'iOS'
  180. * iPhone.getHasTouchScreen(); // true;
  181. * iPhone.hasTouchScreen(); // true
  182. *
  183. * iPhone.isExpensive; // false;
  184. * iPhone.setPrice(600);
  185. * iPhone.getPrice(); // 600
  186. * iPhone.isExpensive; // true;
  187. *
  188. * iPhone.setOperatingSystem('AlienOS');
  189. * iPhone.getOperatingSystem(); // 'Other'
  190. *
  191. * # Statics:
  192. *
  193. * Ext.define('Computer', {
  194. * statics: {
  195. * factory: function(brand) {
  196. * // 'this' in static methods refer to the class itself
  197. * return new this(brand);
  198. * }
  199. * },
  200. *
  201. * constructor: function() { ... }
  202. * });
  203. *
  204. * var dellComputer = Computer.factory('Dell');
  205. *
  206. * Also see {@link Ext.Base#statics} and {@link Ext.Base#self} for more details on accessing
  207. * static properties within class methods
  208. *
  209. * @singleton
  210. */
  211. (function(Class, alias, arraySlice, arrayFrom, global) {
  212. // Creates a constructor that has nothing extra in its scope chain.
  213. function makeCtor () {
  214. function constructor () {
  215. // Opera has some problems returning from a constructor when Dragonfly isn't running. The || null seems to
  216. // be sufficient to stop it misbehaving. Known to be required against 10.53, 11.51 and 11.61.
  217. return this.constructor.apply(this, arguments) || null;
  218. }
  219. return constructor;
  220. }
  221. var Manager = Ext.ClassManager = {
  222. <span id='Ext-ClassManager-property-classes'> /**
  223. </span> * @property {Object} classes
  224. * All classes which were defined through the ClassManager. Keys are the
  225. * name of the classes and the values are references to the classes.
  226. * @private
  227. */
  228. classes: {},
  229. <span id='Ext-ClassManager-property-existCache'> /**
  230. </span> * @private
  231. */
  232. existCache: {},
  233. <span id='Ext-ClassManager-property-namespaceRewrites'> /**
  234. </span> * @private
  235. */
  236. namespaceRewrites: [{
  237. from: 'Ext.',
  238. to: Ext
  239. }],
  240. <span id='Ext-ClassManager-property-maps'> /**
  241. </span> * @private
  242. */
  243. maps: {
  244. alternateToName: {},
  245. aliasToName: {},
  246. nameToAliases: {},
  247. nameToAlternates: {}
  248. },
  249. <span id='Ext-ClassManager-property-enableNamespaceParseCache'> /** @private */
  250. </span> enableNamespaceParseCache: true,
  251. <span id='Ext-ClassManager-property-namespaceParseCache'> /** @private */
  252. </span> namespaceParseCache: {},
  253. <span id='Ext-ClassManager-property-instantiators'> /** @private */
  254. </span> instantiators: [],
  255. <span id='Ext-ClassManager-method-isCreated'> /**
  256. </span> * Checks if a class has already been created.
  257. *
  258. * @param {String} className
  259. * @return {Boolean} exist
  260. */
  261. isCreated: function(className) {
  262. var existCache = this.existCache,
  263. i, ln, part, root, parts;
  264. //&lt;debug error&gt;
  265. if (typeof className != 'string' || className.length &lt; 1) {
  266. throw new Error(&quot;[Ext.ClassManager] Invalid classname, must be a string and must not be empty&quot;);
  267. }
  268. //&lt;/debug&gt;
  269. if (this.classes[className] || existCache[className]) {
  270. return true;
  271. }
  272. root = global;
  273. parts = this.parseNamespace(className);
  274. for (i = 0, ln = parts.length; i &lt; ln; i++) {
  275. part = parts[i];
  276. if (typeof part != 'string') {
  277. root = part;
  278. } else {
  279. if (!root || !root[part]) {
  280. return false;
  281. }
  282. root = root[part];
  283. }
  284. }
  285. existCache[className] = true;
  286. this.triggerCreated(className);
  287. return true;
  288. },
  289. <span id='Ext-ClassManager-property-createdListeners'> /**
  290. </span> * @private
  291. */
  292. createdListeners: [],
  293. <span id='Ext-ClassManager-property-nameCreatedListeners'> /**
  294. </span> * @private
  295. */
  296. nameCreatedListeners: {},
  297. <span id='Ext-ClassManager-method-triggerCreated'> /**
  298. </span> * @private
  299. */
  300. triggerCreated: function(className) {
  301. var listeners = this.createdListeners,
  302. nameListeners = this.nameCreatedListeners,
  303. alternateNames = this.maps.nameToAlternates[className],
  304. names = [className],
  305. i, ln, j, subLn, listener, name;
  306. for (i = 0,ln = listeners.length; i &lt; ln; i++) {
  307. listener = listeners[i];
  308. listener.fn.call(listener.scope, className);
  309. }
  310. if (alternateNames) {
  311. names.push.apply(names, alternateNames);
  312. }
  313. for (i = 0,ln = names.length; i &lt; ln; i++) {
  314. name = names[i];
  315. listeners = nameListeners[name];
  316. if (listeners) {
  317. for (j = 0,subLn = listeners.length; j &lt; subLn; j++) {
  318. listener = listeners[j];
  319. listener.fn.call(listener.scope, name);
  320. }
  321. delete nameListeners[name];
  322. }
  323. }
  324. },
  325. <span id='Ext-ClassManager-method-onCreated'> /**
  326. </span> * @private
  327. */
  328. onCreated: function(fn, scope, className) {
  329. var listeners = this.createdListeners,
  330. nameListeners = this.nameCreatedListeners,
  331. listener = {
  332. fn: fn,
  333. scope: scope
  334. };
  335. if (className) {
  336. if (this.isCreated(className)) {
  337. fn.call(scope, className);
  338. return;
  339. }
  340. if (!nameListeners[className]) {
  341. nameListeners[className] = [];
  342. }
  343. nameListeners[className].push(listener);
  344. }
  345. else {
  346. listeners.push(listener);
  347. }
  348. },
  349. <span id='Ext-ClassManager-method-parseNamespace'> /**
  350. </span> * Supports namespace rewriting
  351. * @private
  352. */
  353. parseNamespace: function(namespace) {
  354. //&lt;debug error&gt;
  355. if (typeof namespace != 'string') {
  356. throw new Error(&quot;[Ext.ClassManager] Invalid namespace, must be a string&quot;);
  357. }
  358. //&lt;/debug&gt;
  359. var cache = this.namespaceParseCache,
  360. parts,
  361. rewrites,
  362. root,
  363. name,
  364. rewrite, from, to, i, ln;
  365. if (this.enableNamespaceParseCache) {
  366. if (cache.hasOwnProperty(namespace)) {
  367. return cache[namespace];
  368. }
  369. }
  370. parts = [];
  371. rewrites = this.namespaceRewrites;
  372. root = global;
  373. name = namespace;
  374. for (i = 0, ln = rewrites.length; i &lt; ln; i++) {
  375. rewrite = rewrites[i];
  376. from = rewrite.from;
  377. to = rewrite.to;
  378. if (name === from || name.substring(0, from.length) === from) {
  379. name = name.substring(from.length);
  380. if (typeof to != 'string') {
  381. root = to;
  382. } else {
  383. parts = parts.concat(to.split('.'));
  384. }
  385. break;
  386. }
  387. }
  388. parts.push(root);
  389. parts = parts.concat(name.split('.'));
  390. if (this.enableNamespaceParseCache) {
  391. cache[namespace] = parts;
  392. }
  393. return parts;
  394. },
  395. <span id='Ext-ClassManager-method-setNamespace'> /**
  396. </span> * Creates a namespace and assign the `value` to the created object
  397. *
  398. * Ext.ClassManager.setNamespace('MyCompany.pkg.Example', someObject);
  399. *
  400. * alert(MyCompany.pkg.Example === someObject); // alerts true
  401. *
  402. * @param {String} name
  403. * @param {Object} value
  404. */
  405. setNamespace: function(name, value) {
  406. var root = global,
  407. parts = this.parseNamespace(name),
  408. ln = parts.length - 1,
  409. leaf = parts[ln],
  410. i, part;
  411. for (i = 0; i &lt; ln; i++) {
  412. part = parts[i];
  413. if (typeof part != 'string') {
  414. root = part;
  415. } else {
  416. if (!root[part]) {
  417. root[part] = {};
  418. }
  419. root = root[part];
  420. }
  421. }
  422. root[leaf] = value;
  423. return root[leaf];
  424. },
  425. <span id='Ext-ClassManager-method-createNamespaces'> /**
  426. </span> * The new Ext.ns, supports namespace rewriting
  427. * @private
  428. */
  429. createNamespaces: function() {
  430. var root = global,
  431. parts, part, i, j, ln, subLn;
  432. for (i = 0, ln = arguments.length; i &lt; ln; i++) {
  433. parts = this.parseNamespace(arguments[i]);
  434. for (j = 0, subLn = parts.length; j &lt; subLn; j++) {
  435. part = parts[j];
  436. if (typeof part != 'string') {
  437. root = part;
  438. } else {
  439. if (!root[part]) {
  440. root[part] = {};
  441. }
  442. root = root[part];
  443. }
  444. }
  445. }
  446. return root;
  447. },
  448. <span id='Ext-ClassManager-method-set'> /**
  449. </span> * Sets a name reference to a class.
  450. *
  451. * @param {String} name
  452. * @param {Object} value
  453. * @return {Ext.ClassManager} this
  454. */
  455. set: function(name, value) {
  456. var me = this,
  457. maps = me.maps,
  458. nameToAlternates = maps.nameToAlternates,
  459. targetName = me.getName(value),
  460. alternates;
  461. me.classes[name] = me.setNamespace(name, value);
  462. if (targetName &amp;&amp; targetName !== name) {
  463. maps.alternateToName[name] = targetName;
  464. alternates = nameToAlternates[targetName] || (nameToAlternates[targetName] = []);
  465. alternates.push(name);
  466. }
  467. return this;
  468. },
  469. <span id='Ext-ClassManager-method-get'> /**
  470. </span> * Retrieve a class by its name.
  471. *
  472. * @param {String} name
  473. * @return {Ext.Class} class
  474. */
  475. get: function(name) {
  476. var classes = this.classes,
  477. root,
  478. parts,
  479. part, i, ln;
  480. if (classes[name]) {
  481. return classes[name];
  482. }
  483. root = global;
  484. parts = this.parseNamespace(name);
  485. for (i = 0, ln = parts.length; i &lt; ln; i++) {
  486. part = parts[i];
  487. if (typeof part != 'string') {
  488. root = part;
  489. } else {
  490. if (!root || !root[part]) {
  491. return null;
  492. }
  493. root = root[part];
  494. }
  495. }
  496. return root;
  497. },
  498. <span id='Ext-ClassManager-method-setAlias'> /**
  499. </span> * Register the alias for a class.
  500. *
  501. * @param {Ext.Class/String} cls a reference to a class or a className
  502. * @param {String} alias Alias to use when referring to this class
  503. */
  504. setAlias: function(cls, alias) {
  505. var aliasToNameMap = this.maps.aliasToName,
  506. nameToAliasesMap = this.maps.nameToAliases,
  507. className;
  508. if (typeof cls == 'string') {
  509. className = cls;
  510. } else {
  511. className = this.getName(cls);
  512. }
  513. if (alias &amp;&amp; aliasToNameMap[alias] !== className) {
  514. //&lt;debug info&gt;
  515. if (aliasToNameMap[alias] &amp;&amp; Ext.isDefined(global.console)) {
  516. global.console.log(&quot;[Ext.ClassManager] Overriding existing alias: '&quot; + alias + &quot;' &quot; +
  517. &quot;of: '&quot; + aliasToNameMap[alias] + &quot;' with: '&quot; + className + &quot;'. Be sure it's intentional.&quot;);
  518. }
  519. //&lt;/debug&gt;
  520. aliasToNameMap[alias] = className;
  521. }
  522. if (!nameToAliasesMap[className]) {
  523. nameToAliasesMap[className] = [];
  524. }
  525. if (alias) {
  526. Ext.Array.include(nameToAliasesMap[className], alias);
  527. }
  528. return this;
  529. },
  530. <span id='Ext-ClassManager-method-getByAlias'> /**
  531. </span> * Get a reference to the class by its alias.
  532. *
  533. * @param {String} alias
  534. * @return {Ext.Class} class
  535. */
  536. getByAlias: function(alias) {
  537. return this.get(this.getNameByAlias(alias));
  538. },
  539. <span id='Ext-ClassManager-method-getNameByAlias'> /**
  540. </span> * Get the name of a class by its alias.
  541. *
  542. * @param {String} alias
  543. * @return {String} className
  544. */
  545. getNameByAlias: function(alias) {
  546. return this.maps.aliasToName[alias] || '';
  547. },
  548. <span id='Ext-ClassManager-method-getNameByAlternate'> /**
  549. </span> * Get the name of a class by its alternate name.
  550. *
  551. * @param {String} alternate
  552. * @return {String} className
  553. */
  554. getNameByAlternate: function(alternate) {
  555. return this.maps.alternateToName[alternate] || '';
  556. },
  557. <span id='Ext-ClassManager-method-getAliasesByName'> /**
  558. </span> * Get the aliases of a class by the class name
  559. *
  560. * @param {String} name
  561. * @return {Array} aliases
  562. */
  563. getAliasesByName: function(name) {
  564. return this.maps.nameToAliases[name] || [];
  565. },
  566. <span id='Ext-ClassManager-method-getName'> /**
  567. </span> * Get the name of the class by its reference or its instance;
  568. * usually invoked by the shorthand {@link Ext#getClassName Ext.getClassName}
  569. *
  570. * Ext.ClassManager.getName(Ext.Action); // returns &quot;Ext.Action&quot;
  571. *
  572. * @param {Ext.Class/Object} object
  573. * @return {String} className
  574. */
  575. getName: function(object) {
  576. return object &amp;&amp; object.$className || '';
  577. },
  578. <span id='Ext-ClassManager-method-getClass'> /**
  579. </span> * Get the class of the provided object; returns null if it's not an instance
  580. * of any class created with Ext.define. This is usually invoked by the shorthand {@link Ext#getClass Ext.getClass}
  581. *
  582. * var component = new Ext.Component();
  583. *
  584. * Ext.ClassManager.getClass(component); // returns Ext.Component
  585. *
  586. * @param {Object} object
  587. * @return {Ext.Class} class
  588. */
  589. getClass: function(object) {
  590. return object &amp;&amp; object.self || null;
  591. },
  592. <span id='Ext-ClassManager-method-create'> /**
  593. </span> * Defines a class.
  594. * @deprecated 4.1.0 Use {@link Ext#define} instead, as that also supports creating overrides.
  595. */
  596. create: function(className, data, createdFn) {
  597. //&lt;debug error&gt;
  598. if (className != null &amp;&amp; typeof className != 'string') {
  599. throw new Error(&quot;[Ext.define] Invalid class name '&quot; + className + &quot;' specified, must be a non-empty string&quot;);
  600. }
  601. //&lt;/debug&gt;
  602. var ctor = makeCtor();
  603. if (typeof data == 'function') {
  604. data = data(ctor);
  605. }
  606. //&lt;debug&gt;
  607. if (className) {
  608. ctor.displayName = className;
  609. }
  610. //&lt;/debug&gt;
  611. data.$className = className;
  612. return new Class(ctor, data, function() {
  613. var postprocessorStack = data.postprocessors || Manager.defaultPostprocessors,
  614. registeredPostprocessors = Manager.postprocessors,
  615. postprocessors = [],
  616. postprocessor, i, ln, j, subLn, postprocessorProperties, postprocessorProperty;
  617. delete data.postprocessors;
  618. for (i = 0,ln = postprocessorStack.length; i &lt; ln; i++) {
  619. postprocessor = postprocessorStack[i];
  620. if (typeof postprocessor == 'string') {
  621. postprocessor = registeredPostprocessors[postprocessor];
  622. postprocessorProperties = postprocessor.properties;
  623. if (postprocessorProperties === true) {
  624. postprocessors.push(postprocessor.fn);
  625. }
  626. else if (postprocessorProperties) {
  627. for (j = 0,subLn = postprocessorProperties.length; j &lt; subLn; j++) {
  628. postprocessorProperty = postprocessorProperties[j];
  629. if (data.hasOwnProperty(postprocessorProperty)) {
  630. postprocessors.push(postprocessor.fn);
  631. break;
  632. }
  633. }
  634. }
  635. }
  636. else {
  637. postprocessors.push(postprocessor);
  638. }
  639. }
  640. data.postprocessors = postprocessors;
  641. data.createdFn = createdFn;
  642. Manager.processCreate(className, this, data);
  643. });
  644. },
  645. processCreate: function(className, cls, clsData){
  646. var me = this,
  647. postprocessor = clsData.postprocessors.shift(),
  648. createdFn = clsData.createdFn;
  649. if (!postprocessor) {
  650. if (className) {
  651. me.set(className, cls);
  652. }
  653. if (createdFn) {
  654. createdFn.call(cls, cls);
  655. }
  656. if (className) {
  657. me.triggerCreated(className);
  658. }
  659. return;
  660. }
  661. if (postprocessor.call(me, className, cls, clsData, me.processCreate) !== false) {
  662. me.processCreate(className, cls, clsData);
  663. }
  664. },
  665. createOverride: function (className, data, createdFn) {
  666. var me = this,
  667. overriddenClassName = data.override,
  668. requires = data.requires,
  669. uses = data.uses,
  670. classReady = function () {
  671. var cls, temp;
  672. if (requires) {
  673. temp = requires;
  674. requires = null; // do the real thing next time (which may be now)
  675. // Since the override is going to be used (its target class is now
  676. // created), we need to fetch the required classes for the override
  677. // and call us back once they are loaded:
  678. Ext.Loader.require(temp, classReady);
  679. } else {
  680. // The target class and the required classes for this override are
  681. // ready, so we can apply the override now:
  682. cls = me.get(overriddenClassName);
  683. // We don't want to apply these:
  684. delete data.override;
  685. delete data.requires;
  686. delete data.uses;
  687. Ext.override(cls, data);
  688. // This pushes the overridding file itself into Ext.Loader.history
  689. // Hence if the target class never exists, the overriding file will
  690. // never be included in the build.
  691. me.triggerCreated(className);
  692. if (uses) {
  693. Ext.Loader.addUsedClasses(uses); // get these classes too!
  694. }
  695. if (createdFn) {
  696. createdFn.call(cls); // last but not least!
  697. }
  698. }
  699. };
  700. me.existCache[className] = true;
  701. // Override the target class right after it's created
  702. me.onCreated(classReady, me, overriddenClassName);
  703. return me;
  704. },
  705. <span id='Ext-ClassManager-method-instantiateByAlias'> /**
  706. </span> * Instantiate a class by its alias; usually invoked by the convenient shorthand {@link Ext#createByAlias Ext.createByAlias}
  707. * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has not been defined yet, it will
  708. * attempt to load the class via synchronous loading.
  709. *
  710. * var window = Ext.ClassManager.instantiateByAlias('widget.window', { width: 600, height: 800, ... });
  711. *
  712. * @param {String} alias
  713. * @param {Object...} args Additional arguments after the alias will be passed to the
  714. * class constructor.
  715. * @return {Object} instance
  716. */
  717. instantiateByAlias: function() {
  718. var alias = arguments[0],
  719. args = arraySlice.call(arguments),
  720. className = this.getNameByAlias(alias);
  721. if (!className) {
  722. className = this.maps.aliasToName[alias];
  723. //&lt;debug error&gt;
  724. if (!className) {
  725. throw new Error(&quot;[Ext.createByAlias] Cannot create an instance of unrecognized alias: &quot; + alias);
  726. }
  727. //&lt;/debug&gt;
  728. //&lt;debug warn&gt;
  729. if (global.console) {
  730. global.console.warn(&quot;[Ext.Loader] Synchronously loading '&quot; + className + &quot;'; consider adding &quot; +
  731. &quot;Ext.require('&quot; + alias + &quot;') above Ext.onReady&quot;);
  732. }
  733. //&lt;/debug&gt;
  734. Ext.syncRequire(className);
  735. }
  736. args[0] = className;
  737. return this.instantiate.apply(this, args);
  738. },
  739. <span id='Ext-ClassManager-method-instantiate'> /**
  740. </span> * @private
  741. */
  742. instantiate: function() {
  743. var name = arguments[0],
  744. nameType = typeof name,
  745. args = arraySlice.call(arguments, 1),
  746. alias = name,
  747. possibleName, cls;
  748. if (nameType != 'function') {
  749. if (nameType != 'string' &amp;&amp; args.length === 0) {
  750. args = [name];
  751. name = name.xclass;
  752. }
  753. //&lt;debug error&gt;
  754. if (typeof name != 'string' || name.length &lt; 1) {
  755. throw new Error(&quot;[Ext.create] Invalid class name or alias '&quot; + name + &quot;' specified, must be a non-empty string&quot;);
  756. }
  757. //&lt;/debug&gt;
  758. cls = this.get(name);
  759. }
  760. else {
  761. cls = name;
  762. }
  763. // No record of this class name, it's possibly an alias, so look it up
  764. if (!cls) {
  765. possibleName = this.getNameByAlias(name);
  766. if (possibleName) {
  767. name = possibleName;
  768. cls = this.get(name);
  769. }
  770. }
  771. // Still no record of this class name, it's possibly an alternate name, so look it up
  772. if (!cls) {
  773. possibleName = this.getNameByAlternate(name);
  774. if (possibleName) {
  775. name = possibleName;
  776. cls = this.get(name);
  777. }
  778. }
  779. // Still not existing at this point, try to load it via synchronous mode as the last resort
  780. if (!cls) {
  781. //&lt;debug warn&gt;
  782. if (global.console) {
  783. global.console.warn(&quot;[Ext.Loader] Synchronously loading '&quot; + name + &quot;'; consider adding &quot; +
  784. &quot;Ext.require('&quot; + ((possibleName) ? alias : name) + &quot;') above Ext.onReady&quot;);
  785. }
  786. //&lt;/debug&gt;
  787. Ext.syncRequire(name);
  788. cls = this.get(name);
  789. }
  790. //&lt;debug error&gt;
  791. if (!cls) {
  792. throw new Error(&quot;[Ext.create] Cannot create an instance of unrecognized class name / alias: &quot; + alias);
  793. }
  794. if (typeof cls != 'function') {
  795. throw new Error(&quot;[Ext.create] '&quot; + name + &quot;' is a singleton and cannot be instantiated&quot;);
  796. }
  797. //&lt;/debug&gt;
  798. return this.getInstantiator(args.length)(cls, args);
  799. },
  800. <span id='Ext-ClassManager-method-dynInstantiate'> /**
  801. </span> * @private
  802. * @param name
  803. * @param args
  804. */
  805. dynInstantiate: function(name, args) {
  806. args = arrayFrom(args, true);
  807. args.unshift(name);
  808. return this.instantiate.apply(this, args);
  809. },
  810. <span id='Ext-ClassManager-method-getInstantiator'> /**
  811. </span> * @private
  812. * @param length
  813. */
  814. getInstantiator: function(length) {
  815. var instantiators = this.instantiators,
  816. instantiator,
  817. i,
  818. args;
  819. instantiator = instantiators[length];
  820. if (!instantiator) {
  821. i = length;
  822. args = [];
  823. for (i = 0; i &lt; length; i++) {
  824. args.push('a[' + i + ']');
  825. }
  826. instantiator = instantiators[length] = new Function('c', 'a', 'return new c(' + args.join(',') + ')');
  827. //&lt;debug&gt;
  828. instantiator.displayName = &quot;Ext.ClassManager.instantiate&quot; + length;
  829. //&lt;/debug&gt;
  830. }
  831. return instantiator;
  832. },
  833. <span id='Ext-ClassManager-property-postprocessors'> /**
  834. </span> * @private
  835. */
  836. postprocessors: {},
  837. <span id='Ext-ClassManager-property-defaultPostprocessors'> /**
  838. </span> * @private
  839. */
  840. defaultPostprocessors: [],
  841. <span id='Ext-ClassManager-method-registerPostprocessor'> /**
  842. </span> * Register a post-processor function.
  843. *
  844. * @private
  845. * @param {String} name
  846. * @param {Function} postprocessor
  847. */
  848. registerPostprocessor: function(name, fn, properties, position, relativeTo) {
  849. if (!position) {
  850. position = 'last';
  851. }
  852. if (!properties) {
  853. properties = [name];
  854. }
  855. this.postprocessors[name] = {
  856. name: name,
  857. properties: properties || false,
  858. fn: fn
  859. };
  860. this.setDefaultPostprocessorPosition(name, position, relativeTo);
  861. return this;
  862. },
  863. <span id='Ext-ClassManager-method-setDefaultPostprocessors'> /**
  864. </span> * Set the default post processors array stack which are applied to every class.
  865. *
  866. * @private
  867. * @param {String/Array} The name of a registered post processor or an array of registered names.
  868. * @return {Ext.ClassManager} this
  869. */
  870. setDefaultPostprocessors: function(postprocessors) {
  871. this.defaultPostprocessors = arrayFrom(postprocessors);
  872. return this;
  873. },
  874. <span id='Ext-ClassManager-method-setDefaultPostprocessorPosition'> /**
  875. </span> * Insert this post-processor at a specific position in the stack, optionally relative to
  876. * any existing post-processor
  877. *
  878. * @private
  879. * @param {String} name The post-processor name. Note that it needs to be registered with
  880. * {@link Ext.ClassManager#registerPostprocessor} before this
  881. * @param {String} offset The insertion position. Four possible values are:
  882. * 'first', 'last', or: 'before', 'after' (relative to the name provided in the third argument)
  883. * @param {String} relativeName
  884. * @return {Ext.ClassManager} this
  885. */
  886. setDefaultPostprocessorPosition: function(name, offset, relativeName) {
  887. var defaultPostprocessors = this.defaultPostprocessors,
  888. index;
  889. if (typeof offset == 'string') {
  890. if (offset === 'first') {
  891. defaultPostprocessors.unshift(name);
  892. return this;
  893. }
  894. else if (offset === 'last') {
  895. defaultPostprocessors.push(name);
  896. return this;
  897. }
  898. offset = (offset === 'after') ? 1 : -1;
  899. }
  900. index = Ext.Array.indexOf(defaultPostprocessors, relativeName);
  901. if (index !== -1) {
  902. Ext.Array.splice(defaultPostprocessors, Math.max(0, index + offset), 0, name);
  903. }
  904. return this;
  905. },
  906. <span id='Ext-ClassManager-method-getNamesByExpression'> /**
  907. </span> * Converts a string expression to an array of matching class names. An expression can either refers to class aliases
  908. * or class names. Expressions support wildcards:
  909. *
  910. * // returns ['Ext.window.Window']
  911. * var window = Ext.ClassManager.getNamesByExpression('widget.window');
  912. *
  913. * // returns ['widget.panel', 'widget.window', ...]
  914. * var allWidgets = Ext.ClassManager.getNamesByExpression('widget.*');
  915. *
  916. * // returns ['Ext.data.Store', 'Ext.data.ArrayProxy', ...]
  917. * var allData = Ext.ClassManager.getNamesByExpression('Ext.data.*');
  918. *
  919. * @param {String} expression
  920. * @return {String[]} classNames
  921. */
  922. getNamesByExpression: function(expression) {
  923. var nameToAliasesMap = this.maps.nameToAliases,
  924. names = [],
  925. name, alias, aliases, possibleName, regex, i, ln;
  926. //&lt;debug error&gt;
  927. if (typeof expression != 'string' || expression.length &lt; 1) {
  928. throw new Error(&quot;[Ext.ClassManager.getNamesByExpression] Expression &quot; + expression + &quot; is invalid, must be a non-empty string&quot;);
  929. }
  930. //&lt;/debug&gt;
  931. if (expression.indexOf('*') !== -1) {
  932. expression = expression.replace(/\*/g, '(.*?)');
  933. regex = new RegExp('^' + expression + '$');
  934. for (name in nameToAliasesMap) {
  935. if (nameToAliasesMap.hasOwnProperty(name)) {
  936. aliases = nameToAliasesMap[name];
  937. if (name.search(regex) !== -1) {
  938. names.push(name);
  939. }
  940. else {
  941. for (i = 0, ln = aliases.length; i &lt; ln; i++) {
  942. alias = aliases[i];
  943. if (alias.search(regex) !== -1) {
  944. names.push(name);
  945. break;
  946. }
  947. }
  948. }
  949. }
  950. }
  951. } else {
  952. possibleName = this.getNameByAlias(expression);
  953. if (possibleName) {
  954. names.push(possibleName);
  955. } else {
  956. possibleName = this.getNameByAlternate(expression);
  957. if (possibleName) {
  958. names.push(possibleName);
  959. } else {
  960. names.push(expression);
  961. }
  962. }
  963. }
  964. return names;
  965. }
  966. };
  967. //&lt;feature classSystem.alias&gt;
  968. <span id='Ext-Class-cfg-alias'> /**
  969. </span> * @cfg {String[]} alias
  970. * @member Ext.Class
  971. * List of short aliases for class names. Most useful for defining xtypes for widgets:
  972. *
  973. * Ext.define('MyApp.CoolPanel', {
  974. * extend: 'Ext.panel.Panel',
  975. * alias: ['widget.coolpanel'],
  976. * title: 'Yeah!'
  977. * });
  978. *
  979. * // Using Ext.create
  980. * Ext.create('widget.coolpanel');
  981. *
  982. * // Using the shorthand for defining widgets by xtype
  983. * Ext.widget('panel', {
  984. * items: [
  985. * {xtype: 'coolpanel', html: 'Foo'},
  986. * {xtype: 'coolpanel', html: 'Bar'}
  987. * ]
  988. * });
  989. *
  990. * Besides &quot;widget&quot; for xtype there are alias namespaces like &quot;feature&quot; for ftype and &quot;plugin&quot; for ptype.
  991. */
  992. Manager.registerPostprocessor('alias', function(name, cls, data) {
  993. var aliases = data.alias,
  994. i, ln;
  995. for (i = 0,ln = aliases.length; i &lt; ln; i++) {
  996. alias = aliases[i];
  997. this.setAlias(cls, alias);
  998. }
  999. }, ['xtype', 'alias']);
  1000. //&lt;/feature&gt;
  1001. //&lt;feature classSystem.singleton&gt;
  1002. <span id='Ext-Class-cfg-singleton'> /**
  1003. </span> * @cfg {Boolean} singleton
  1004. * @member Ext.Class
  1005. * When set to true, the class will be instantiated as singleton. For example:
  1006. *
  1007. * Ext.define('Logger', {
  1008. * singleton: true,
  1009. * log: function(msg) {
  1010. * console.log(msg);
  1011. * }
  1012. * });
  1013. *
  1014. * Logger.log('Hello');
  1015. */
  1016. Manager.registerPostprocessor('singleton', function(name, cls, data, fn) {
  1017. fn.call(this, name, new cls(), data);
  1018. return false;
  1019. });
  1020. //&lt;/feature&gt;
  1021. //&lt;feature classSystem.alternateClassName&gt;
  1022. <span id='Ext-Class-cfg-alternateClassName'> /**
  1023. </span> * @cfg {String/String[]} alternateClassName
  1024. * @member Ext.Class
  1025. * Defines alternate names for this class. For example:
  1026. *
  1027. * Ext.define('Developer', {
  1028. * alternateClassName: ['Coder', 'Hacker'],
  1029. * code: function(msg) {
  1030. * alert('Typing... ' + msg);
  1031. * }
  1032. * });
  1033. *
  1034. * var joe = Ext.create('Developer');
  1035. * joe.code('stackoverflow');
  1036. *
  1037. * var rms = Ext.create('Hacker');
  1038. * rms.code('hack hack');
  1039. */
  1040. Manager.registerPostprocessor('alternateClassName', function(name, cls, data) {
  1041. var alternates = data.alternateClassName,
  1042. i, ln, alternate;
  1043. if (!(alternates instanceof Array)) {
  1044. alternates = [alternates];
  1045. }
  1046. for (i = 0, ln = alternates.length; i &lt; ln; i++) {
  1047. alternate = alternates[i];
  1048. //&lt;debug error&gt;
  1049. if (typeof alternate != 'string') {
  1050. throw new Error(&quot;[Ext.define] Invalid alternate of: '&quot; + alternate + &quot;' for class: '&quot; + name + &quot;'; must be a valid string&quot;);
  1051. }
  1052. //&lt;/debug&gt;
  1053. this.set(alternate, cls);
  1054. }
  1055. });
  1056. //&lt;/feature&gt;
  1057. Ext.apply(Ext, {
  1058. <span id='Ext-method-create'> /**
  1059. </span> * Instantiate a class by either full name, alias or alternate name.
  1060. *
  1061. * If {@link Ext.Loader} is {@link Ext.Loader#setConfig enabled} and the class has
  1062. * not been defined yet, it will attempt to load the class via synchronous loading.
  1063. *
  1064. * For example, all these three lines return the same result:
  1065. *
  1066. * // alias
  1067. * var window = Ext.create('widget.window', {
  1068. * width: 600,
  1069. * height: 800,
  1070. * ...
  1071. * });
  1072. *
  1073. * // alternate name
  1074. * var window = Ext.create('Ext.Window', {
  1075. * width: 600,
  1076. * height: 800,
  1077. * ...
  1078. * });
  1079. *
  1080. * // full class name
  1081. * var window = Ext.create('Ext.window.Window', {
  1082. * width: 600,
  1083. * height: 800,
  1084. * ...
  1085. * });
  1086. *
  1087. * // single object with xclass property:
  1088. * var window = Ext.create({
  1089. * xclass: 'Ext.window.Window', // any valid value for 'name' (above)
  1090. * width: 600,
  1091. * height: 800,
  1092. * ...
  1093. * });
  1094. *
  1095. * @param {String} [name] The class name or alias. Can be specified as `xclass`
  1096. * property if only one object parameter is specified.
  1097. * @param {Object...} [args] Additional arguments after the name will be passed to
  1098. * the class' constructor.
  1099. * @return {Object} instance
  1100. * @member Ext
  1101. * @method create
  1102. */
  1103. create: alias(Manager, 'instantiate'),
  1104. <span id='Ext-method-widget'> /**
  1105. </span> * Convenient shorthand to create a widget by its xtype or a config object.
  1106. * See also {@link Ext.ClassManager#instantiateByAlias}.
  1107. *
  1108. * var button = Ext.widget('button'); // Equivalent to Ext.create('widget.button');
  1109. *
  1110. * var panel = Ext.widget('panel', { // Equivalent to Ext.create('widget.panel')
  1111. * title: 'Panel'
  1112. * });
  1113. *
  1114. * var grid = Ext.widget({
  1115. * xtype: 'grid',
  1116. * ...
  1117. * });
  1118. *
  1119. * If a {@link Ext.Component component} instance is passed, it is simply returned.
  1120. *
  1121. * @member Ext
  1122. * @param {String} [name] The xtype of the widget to create.
  1123. * @param {Object} [config] The configuration object for the widget constructor.
  1124. * @return {Object} The widget instance
  1125. */
  1126. widget: function(name, config) {
  1127. // forms:
  1128. // 1: (xtype)
  1129. // 2: (xtype, config)
  1130. // 3: (config)
  1131. // 4: (xtype, component)
  1132. // 5: (component)
  1133. //
  1134. var xtype = name,
  1135. alias, className, T, load;
  1136. if (typeof xtype != 'string') { // if (form 3 or 5)
  1137. // first arg is config or component
  1138. config = name; // arguments[0]
  1139. xtype = config.xtype;
  1140. } else {
  1141. config = config || {};
  1142. }
  1143. if (config.isComponent) {
  1144. return config;
  1145. }
  1146. alias = 'widget.' + xtype;
  1147. className = Manager.getNameByAlias(alias);
  1148. // this is needed to support demand loading of the class
  1149. if (!className) {
  1150. load = true;
  1151. }
  1152. T = Manager.get(className);
  1153. if (load || !T) {
  1154. return Manager.instantiateByAlias(alias, config);
  1155. }
  1156. return new T(config);
  1157. },
  1158. <span id='Ext-method-createByAlias'> /**
  1159. </span> * Convenient shorthand, see {@link Ext.ClassManager#instantiateByAlias}
  1160. * @member Ext
  1161. * @method createByAlias
  1162. */
  1163. createByAlias: alias(Manager, 'instantiateByAlias'),
  1164. <span id='Ext-method-define'> /**
  1165. </span> * @method
  1166. * Defines a class or override. A basic class is defined like this:
  1167. *
  1168. * Ext.define('My.awesome.Class', {
  1169. * someProperty: 'something',
  1170. *
  1171. * someMethod: function(s) {
  1172. * alert(s + this.someProperty);
  1173. * }
  1174. *
  1175. * ...
  1176. * });
  1177. *
  1178. * var obj = new My.awesome.Class();
  1179. *
  1180. * obj.someMethod('Say '); // alerts 'Say something'
  1181. *
  1182. * To create an anonymous class, pass `null` for the `className`:
  1183. *
  1184. * Ext.define(null, {
  1185. * constructor: function () {
  1186. * // ...
  1187. * }
  1188. * });
  1189. *
  1190. * In some cases, it is helpful to create a nested scope to contain some private
  1191. * properties. The best way to do this is to pass a function instead of an object
  1192. * as the second parameter. This function will be called to produce the class
  1193. * body:
  1194. *
  1195. * Ext.define('MyApp.foo.Bar', function () {
  1196. * var id = 0;
  1197. *
  1198. * return {
  1199. * nextId: function () {
  1200. * return ++id;
  1201. * }
  1202. * };
  1203. * });
  1204. *
  1205. * When using this form of `Ext.define`, the function is passed a reference to its
  1206. * class. This can be used as an efficient way to access any static properties you
  1207. * may have:
  1208. *
  1209. * Ext.define('MyApp.foo.Bar', function (Bar) {
  1210. * return {
  1211. * statics: {
  1212. * staticMethod: function () {
  1213. * // ...
  1214. * }
  1215. * },
  1216. *
  1217. * method: function () {
  1218. * return Bar.staticMethod();
  1219. * }
  1220. * };
  1221. * });
  1222. *
  1223. * To define an override, include the `override` property. The content of an
  1224. * override is aggregated with the specified class in order to extend or modify
  1225. * that class. This can be as simple as setting default property values or it can
  1226. * extend and/or replace methods. This can also extend the statics of the class.
  1227. *
  1228. * One use for an override is to break a large class into manageable pieces.
  1229. *
  1230. * // File: /src/app/Panel.js
  1231. *
  1232. * Ext.define('My.app.Panel', {
  1233. * extend: 'Ext.panel.Panel',
  1234. * requires: [
  1235. * 'My.app.PanelPart2',
  1236. * 'My.app.PanelPart3'
  1237. * ]
  1238. *
  1239. * constructor: function (config) {
  1240. * this.callParent(arguments); // calls Ext.panel.Panel's constructor
  1241. * //...
  1242. * },
  1243. *
  1244. * statics: {
  1245. * method: function () {
  1246. * return 'abc';
  1247. * }
  1248. * }
  1249. * });
  1250. *
  1251. * // File: /src/app/PanelPart2.js
  1252. * Ext.define('My.app.PanelPart2', {
  1253. * override: 'My.app.Panel',
  1254. *
  1255. * constructor: function (config) {
  1256. * this.callParent(arguments); // calls My.app.Panel's constructor
  1257. * //...
  1258. * }
  1259. * });
  1260. *
  1261. * Another use of overrides is to provide optional parts of classes that can be
  1262. * independently required. In this case, the class may even be unaware of the
  1263. * override altogether.
  1264. *
  1265. * Ext.define('My.ux.CoolTip', {
  1266. * override: 'Ext.tip.ToolTip',
  1267. *
  1268. * constructor: function (config) {
  1269. * this.callParent(arguments); // calls Ext.tip.ToolTip's constructor
  1270. * //...
  1271. * }
  1272. * });
  1273. *
  1274. * The above override can now be required as normal.
  1275. *
  1276. * Ext.define('My.app.App', {
  1277. * requires: [
  1278. * 'My.ux.CoolTip'
  1279. * ]
  1280. * });
  1281. *
  1282. * Overrides can also contain statics:
  1283. *
  1284. * Ext.define('My.app.BarMod', {
  1285. * override: 'Ext.foo.Bar',
  1286. *
  1287. * statics: {
  1288. * method: function (x) {
  1289. * return this.callParent([x * 2]); // call Ext.foo.Bar.method
  1290. * }
  1291. * }
  1292. * });
  1293. *
  1294. * IMPORTANT: An override is only included in a build if the class it overrides is
  1295. * required. Otherwise, the override, like the target class, is not included.
  1296. *
  1297. * @param {String} className The class name to create in string dot-namespaced format, for example:
  1298. * 'My.very.awesome.Class', 'FeedViewer.plugin.CoolPager'
  1299. * It is highly recommended to follow this simple convention:
  1300. * - The root and the class name are 'CamelCased'
  1301. * - Everything else is lower-cased
  1302. * Pass `null` to create an anonymous class.
  1303. * @param {Object} data The key - value pairs of properties to apply to this class. Property names can be of any valid
  1304. * strings, except those in the reserved listed below:
  1305. * - `mixins`
  1306. * - `statics`
  1307. * - `config`
  1308. * - `alias`
  1309. * - `self`
  1310. * - `singleton`
  1311. * - `alternateClassName`
  1312. * - `override`
  1313. *
  1314. * @param {Function} createdFn Optional callback to execute after the class is created, the execution scope of which
  1315. * (`this`) will be the newly created class itself.
  1316. * @return {Ext.Base}
  1317. * @markdown
  1318. * @member Ext
  1319. * @method define
  1320. */
  1321. define: function (className, data, createdFn) {
  1322. if (data.override) {
  1323. return Manager.createOverride.apply(Manager, arguments);
  1324. }
  1325. return Manager.create.apply(Manager, arguments);
  1326. },
  1327. <span id='Ext-method-getClassName'> /**
  1328. </span> * Convenient shorthand, see {@link Ext.ClassManager#getName}
  1329. * @member Ext
  1330. * @method getClassName
  1331. */
  1332. getClassName: alias(Manager, 'getName'),
  1333. <span id='Ext-ClassManager-method-getDisplayName'> /**
  1334. </span> * Returns the displayName property or className or object. When all else fails, returns &quot;Anonymous&quot;.
  1335. * @param {Object} object
  1336. * @return {String}
  1337. */
  1338. getDisplayName: function(object) {
  1339. if (object) {
  1340. if (object.displayName) {
  1341. return object.displayName;
  1342. }
  1343. if (object.$name &amp;&amp; object.$class) {
  1344. return Ext.getClassName(object.$class) + '#' + object.$name;
  1345. }
  1346. if (object.$className) {
  1347. return object.$className;
  1348. }
  1349. }
  1350. return 'Anonymous';
  1351. },
  1352. <span id='Ext-method-getClass'> /**
  1353. </span> * Convenient shorthand, see {@link Ext.ClassManager#getClass}
  1354. * @member Ext
  1355. * @method getClass
  1356. */
  1357. getClass: alias(Manager, 'getClass'),
  1358. <span id='Ext-method-namespace'> /**
  1359. </span> * Creates namespaces to be used for scoping variables and classes so that they are not global.
  1360. * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
  1361. *
  1362. * Ext.namespace('Company', 'Company.data');
  1363. *
  1364. * // equivalent and preferable to the above syntax
  1365. * Ext.ns('Company.data');
  1366. *
  1367. * Company.Widget = function() { ... };
  1368. *
  1369. * Company.data.CustomStore = function(config) { ... };
  1370. *
  1371. * @param {String...} namespaces
  1372. * @return {Object} The namespace object.
  1373. * (If multiple arguments are passed, this will be the last namespace created)
  1374. * @member Ext
  1375. * @method namespace
  1376. */
  1377. namespace: alias(Manager, 'createNamespaces')
  1378. });
  1379. <span id='Ext-method-createWidget'> /**
  1380. </span> * Old name for {@link Ext#widget}.
  1381. * @deprecated 4.0.0 Use {@link Ext#widget} instead.
  1382. * @method createWidget
  1383. * @member Ext
  1384. */
  1385. Ext.createWidget = Ext.widget;
  1386. <span id='Ext-method-ns'> /**
  1387. </span> * Convenient alias for {@link Ext#namespace Ext.namespace}.
  1388. * @inheritdoc Ext#namespace
  1389. * @member Ext
  1390. * @method ns
  1391. */
  1392. Ext.ns = Ext.namespace;
  1393. Class.registerPreprocessor('className', function(cls, data) {
  1394. if (data.$className) {
  1395. cls.$className = data.$className;
  1396. //&lt;debug&gt;
  1397. cls.displayName = cls.$className;
  1398. //&lt;/debug&gt;
  1399. }
  1400. }, true, 'first');
  1401. Class.registerPreprocessor('alias', function(cls, data) {
  1402. var prototype = cls.prototype,
  1403. xtypes = arrayFrom(data.xtype),
  1404. aliases = arrayFrom(data.alias),
  1405. widgetPrefix = 'widget.',
  1406. widgetPrefixLength = widgetPrefix.length,
  1407. xtypesChain = Array.prototype.slice.call(prototype.xtypesChain || []),
  1408. xtypesMap = Ext.merge({}, prototype.xtypesMap || {}),
  1409. i, ln, alias, xtype;
  1410. for (i = 0,ln = aliases.length; i &lt; ln; i++) {
  1411. alias = aliases[i];
  1412. //&lt;debug error&gt;
  1413. if (typeof alias != 'string' || alias.length &lt; 1) {
  1414. throw new Error(&quot;[Ext.define] Invalid alias of: '&quot; + alias + &quot;' for class: '&quot; + name + &quot;'; must be a valid string&quot;);
  1415. }
  1416. //&lt;/debug&gt;
  1417. if (alias.substring(0, widgetPrefixLength) === widgetPrefix) {
  1418. xtype = alias.substring(widgetPrefixLength);
  1419. Ext.Array.include(xtypes, xtype);
  1420. }
  1421. }
  1422. cls.xtype = data.xtype = xtypes[0];
  1423. data.xtypes = xtypes;
  1424. for (i = 0,ln = xtypes.length; i &lt; ln; i++) {
  1425. xtype = xtypes[i];
  1426. if (!xtypesMap[xtype]) {
  1427. xtypesMap[xtype] = true;
  1428. xtypesChain.push(xtype);
  1429. }
  1430. }
  1431. data.xtypesChain = xtypesChain;
  1432. data.xtypesMap = xtypesMap;
  1433. Ext.Function.interceptAfter(data, 'onClassCreated', function() {
  1434. var mixins = prototype.mixins,
  1435. key, mixin;
  1436. for (key in mixins) {
  1437. if (mixins.hasOwnProperty(key)) {
  1438. mixin = mixins[key];
  1439. xtypes = mixin.xtypes;
  1440. if (xtypes) {
  1441. for (i = 0,ln = xtypes.length; i &lt; ln; i++) {
  1442. xtype = xtypes[i];
  1443. if (!xtypesMap[xtype]) {
  1444. xtypesMap[xtype] = true;
  1445. xtypesChain.push(xtype);
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. });
  1452. for (i = 0,ln = xtypes.length; i &lt; ln; i++) {
  1453. xtype = xtypes[i];
  1454. //&lt;debug error&gt;
  1455. if (typeof xtype != 'string' || xtype.length &lt; 1) {
  1456. throw new Error(&quot;[Ext.define] Invalid xtype of: '&quot; + xtype + &quot;' for class: '&quot; + name + &quot;'; must be a valid non-empty string&quot;);
  1457. }
  1458. //&lt;/debug&gt;
  1459. Ext.Array.include(aliases, widgetPrefix + xtype);
  1460. }
  1461. data.alias = aliases;
  1462. }, ['xtype', 'alias']);
  1463. }(Ext.Class, Ext.Function.alias, Array.prototype.slice, Ext.Array.from, Ext.global));
  1464. </pre>
  1465. </body>
  1466. </html>