]> git.proxmox.com Git - sencha-touch.git/blob - src/src/mixin/Identifiable.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / mixin / Identifiable.js
1 //@tag dom,core
2 //@require Ext.dom.Helper
3
4 /**
5 * An Identifiable mixin.
6 * @private
7 */
8 Ext.define('Ext.mixin.Identifiable', {
9 statics: {
10 uniqueIds: {}
11 },
12
13 isIdentifiable: true,
14
15 mixinId: 'identifiable',
16
17 idCleanRegex: /\.|[^\w\-]/g,
18
19 defaultIdPrefix: 'ext-',
20
21 defaultIdSeparator: '-',
22
23 getOptimizedId: function() {
24 return this.id;
25 },
26
27 getUniqueId: function() {
28 var id = this.id,
29 prototype, separator, xtype, uniqueIds, prefix;
30
31 if (!id) {
32 prototype = this.self.prototype;
33 separator = this.defaultIdSeparator;
34
35 uniqueIds = Ext.mixin.Identifiable.uniqueIds;
36
37 if (!prototype.hasOwnProperty('identifiablePrefix')) {
38 xtype = this.xtype;
39
40 if (xtype) {
41 prefix = this.defaultIdPrefix + xtype + separator;
42 }
43 else {
44 prefix = prototype.$className.replace(this.idCleanRegex, separator).toLowerCase() + separator;
45 }
46
47 prototype.identifiablePrefix = prefix;
48 }
49
50 prefix = this.identifiablePrefix;
51
52 if (!uniqueIds.hasOwnProperty(prefix)) {
53 uniqueIds[prefix] = 0;
54 }
55
56 id = this.id = prefix + (++uniqueIds[prefix]);
57 }
58
59 this.getUniqueId = this.getOptimizedId;
60
61 return id;
62 },
63
64 setId: function(id) {
65 this.id = id;
66 },
67
68 /**
69 * Retrieves the id of this component. Will autogenerate an id if one has not already been set.
70 * @return {String} id
71 */
72 getId: function() {
73 var id = this.id;
74
75 if (!id) {
76 id = this.getUniqueId();
77 }
78
79 this.getId = this.getOptimizedId;
80
81 return id;
82 }
83 });