]> git.proxmox.com Git - sencha-touch.git/blame - src/src/event/publisher/ElementPaint.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / event / publisher / ElementPaint.js
CommitLineData
c4685c84
TL
1/**
2 * @private
3 */
4Ext.define('Ext.event.publisher.ElementPaint', {
5
6 extend: 'Ext.event.publisher.Publisher',
7
8 requires: [
9 'Ext.util.PaintMonitor',
10 'Ext.TaskQueue'
11 ],
12
13 targetType: 'element',
14
15 handledEvents: ['painted'],
16
17 constructor: function() {
18 this.monitors = {};
19
20 this.callSuper(arguments);
21 },
22
23 subscribe: function(target) {
24 var match = target.match(this.idSelectorRegex),
25 subscribers = this.subscribers,
26 id, element;
27
28 if (!match) {
29 return false;
30 }
31
32 id = match[1];
33
34 if (subscribers.hasOwnProperty(id)) {
35 subscribers[id]++;
36 return true;
37 }
38
39 subscribers[id] = 1;
40
41 element = Ext.get(id);
42
43 this.monitors[id] = new Ext.util.PaintMonitor({
44 element: element,
45 callback: this.onElementPainted,
46 scope: this,
47 args: [target, element]
48 });
49
50 return true;
51 },
52
53 unsubscribe: function(target, eventName, all) {
54 var match = target.match(this.idSelectorRegex),
55 subscribers = this.subscribers,
56 id;
57
58 if (!match) {
59 return false;
60 }
61
62 id = match[1];
63
64 if (!subscribers.hasOwnProperty(id) || (!all && --subscribers[id] > 0)) {
65 return true;
66 }
67
68 delete subscribers[id];
69
70 this.monitors[id].destroy();
71 delete this.monitors[id];
72
73 return true;
74 },
75
76 onElementPainted: function(target, element) {
77 Ext.TaskQueue.requestRead('dispatch', this, [target, 'painted', [element]]);
78 }
79});