]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/src/util/sizemonitor/Abstract.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / src / util / sizemonitor / Abstract.js
CommitLineData
6527f429
DM
1/**\r
2 * @private\r
3 */\r
4Ext.define('Ext.util.sizemonitor.Abstract', {\r
5\r
6 mixins: ['Ext.mixin.Templatable'],\r
7\r
8 requires: [\r
9 'Ext.TaskQueue'\r
10 ],\r
11\r
12 config: {\r
13 element: null,\r
14\r
15 callback: Ext.emptyFn,\r
16\r
17 scope: null,\r
18\r
19 args: []\r
20 },\r
21\r
22 width: 0,\r
23\r
24 height: 0,\r
25\r
26 contentWidth: 0,\r
27\r
28 contentHeight: 0,\r
29\r
30 constructor: function(config) {\r
31 this.refresh = Ext.Function.bind(this.refresh, this);\r
32\r
33 this.info = {\r
34 width: 0,\r
35 height: 0,\r
36 contentWidth: 0,\r
37 contentHeight: 0,\r
38 flag: 0\r
39 };\r
40\r
41 this.initElement();\r
42\r
43 this.initConfig(config);\r
44\r
45 this.bindListeners(true);\r
46 },\r
47\r
48 bindListeners: Ext.emptyFn,\r
49\r
50 applyElement: function(element) {\r
51 if (element) {\r
52 return Ext.get(element);\r
53 }\r
54 },\r
55\r
56 updateElement: function(element) {\r
57 element.append(this.detectorsContainer);\r
58 element.addCls(Ext.baseCSSPrefix + 'size-monitored');\r
59 },\r
60\r
61 applyArgs: function(args) {\r
62 return args.concat([this.info]);\r
63 },\r
64\r
65 refreshMonitors: Ext.emptyFn,\r
66\r
67 forceRefresh: function() {\r
68 Ext.TaskQueue.requestRead('refresh', this);\r
69 },\r
70\r
71 getContentBounds: function() {\r
72 return this.detectorsContainer.getBoundingClientRect();\r
73 },\r
74\r
75 getContentWidth: function() {\r
76 return this.detectorsContainer.offsetWidth;\r
77 },\r
78\r
79 getContentHeight: function() {\r
80 return this.detectorsContainer.offsetHeight;\r
81 },\r
82\r
83 refreshSize: function() {\r
84 var element = this.getElement();\r
85\r
86 if (!element || element.destroyed) {\r
87 return false;\r
88 }\r
89\r
90 var width = element.getWidth(),\r
91 height = element.getHeight(),\r
92 contentWidth = this.getContentWidth(),\r
93 contentHeight = this.getContentHeight(),\r
94 currentContentWidth = this.contentWidth,\r
95 currentContentHeight = this.contentHeight,\r
96 info = this.info,\r
97 resized = false,\r
98 flag;\r
99\r
100 this.width = width;\r
101 this.height = height;\r
102 this.contentWidth = contentWidth;\r
103 this.contentHeight = contentHeight;\r
104\r
105 flag = ((currentContentWidth !== contentWidth ? 1 : 0) + (currentContentHeight !== contentHeight ? 2 : 0));\r
106\r
107 if (flag > 0) {\r
108 info.width = width;\r
109 info.height = height;\r
110 info.contentWidth = contentWidth;\r
111 info.contentHeight = contentHeight;\r
112 info.flag = flag;\r
113\r
114 resized = true;\r
115 this.getCallback().apply(this.getScope(), this.getArgs());\r
116 }\r
117\r
118 return resized;\r
119 },\r
120\r
121 refresh: function(force) {\r
122 if (this.refreshSize() || force) {\r
123 Ext.TaskQueue.requestWrite('refreshMonitors', this);\r
124 }\r
125 },\r
126\r
127 destroy: function() {\r
128 var me = this,\r
129 element = me.getElement();\r
130\r
131 me.bindListeners(false);\r
132\r
133 if (element && !element.destroyed) {\r
134 element.removeCls(Ext.baseCSSPrefix + 'size-monitored');\r
135 }\r
136\r
137 delete me._element;\r
138\r
139 me.callParent();\r
140 }\r
141});\r