]> git.proxmox.com Git - extjs.git/blob - extjs/packages/core/src/mixin/Hookable.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / src / mixin / Hookable.js
1 /**
2 * @private
3 */
4 Ext.define('Ext.mixin.Hookable', {
5 extend: 'Ext.Mixin',
6
7 mixinConfig: {
8 id: 'hookable'
9 },
10
11 bindHook: function(instance, boundMethod, bindingMethod, preventDefault, extraArgs) {
12 if (!bindingMethod) {
13 bindingMethod = boundMethod;
14 }
15
16 var boundFn = instance[boundMethod],
17 fn, binding;
18
19 if (boundFn && boundFn.hasOwnProperty('$binding')) {
20 binding = boundFn.$binding;
21 if (binding.bindingMethod === bindingMethod && binding.bindingScope === this) {
22 return this;
23 }
24 }
25
26 instance[boundMethod] = fn = function() {
27 var binding = fn.$binding,
28 scope = binding.bindingScope,
29 args = Array.prototype.slice.call(arguments);
30
31 args.push(arguments);
32
33 if (extraArgs) {
34 args.push.apply(args, extraArgs);
35 }
36
37 if (!binding.preventDefault && scope[binding.bindingMethod].apply(scope, args) !== false) {
38 return binding.boundFn.apply(this, arguments);
39 }
40 };
41 fn.$binding = {
42 preventDefault: !!preventDefault,
43 boundFn: boundFn,
44 bindingMethod: bindingMethod,
45 bindingScope: this
46 };
47
48 return this;
49 },
50
51 unbindHook: function(instance, boundMethod, bindingMethod) {
52 if (!bindingMethod) {
53 bindingMethod = boundMethod;
54 }
55
56 var fn = instance[boundMethod],
57 binding = fn.$binding,
58 boundFn, currentBinding;
59
60 while (binding) {
61 boundFn = binding.boundFn;
62
63 if (binding.bindingMethod === bindingMethod && binding.bindingScope === this) {
64 if (currentBinding) {
65 currentBinding.boundFn = boundFn;
66 }
67 else {
68 instance[boundMethod] = boundFn;
69 }
70
71 return this;
72 }
73
74 currentBinding = binding;
75 binding = boundFn.$binding;
76 }
77
78 return this;
79 }
80 });