-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprivate.html
138 lines (105 loc) · 4.84 KB
/
private.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<title>aciPlugin private data demo - A jQuery plugin boilerplate</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.aciPlugin.js"></script>
</head>
<body>
<p>Private data test: each call first increments the _instance and _private with a/b/c string values.<br />Calling 'before' will call the parent
method then output the values. Calling 'after' will output the values and after that will call the parent method.</p>
<p>Note: see the source code to understand what's going on with the 'privateDemo' implementation.</p>
<div class="result"></div>
<script class="code" type="text/javascript">
aciPluginClass.plugins.privateDemo = aciPluginClass.aciPluginUi.extend({
__extend: function(){
this._instance.value = 'instance A';
this._private.value = 'private A';
},
write_A: function(){
this._instance.jQuery.append('from A: ' + this._instance.value + ' ' + this._private.value + '<br />');
},
before: function(){
this._instance.value += '[a]';
this._private.value += '[a]';
this.write_A();
},
after: function(){
this._instance.value += '[a]';
this._private.value += '[a]';
this.write_A();
}
}, 'private_a');
aciPluginClass.plugins.privateDemo = aciPluginClass.plugins.privateDemo.extend({
__extend: function(){
this._super();
// instance should override parent value
this._instance.value = 'instance B';
// private should remain local
this._private.value = 'private B';
},
write_B: function(){
this._instance.jQuery.append('from B: ' + this._instance.value + ' ' + this._private.value + '<br />');
},
before: function(){
this._instance.value += '[b]';
this._private.value += '[b]';
this._super();
this.write_A();
this.write_B();
},
after: function(){
this._instance.value += '[b]';
this._private.value += '[b]';
this.write_A();
this.write_B();
this._super();
}
}, 'private_b');
aciPluginClass.plugins.privateDemo = aciPluginClass.plugins.privateDemo.extend({
__extend: function(){
this._super();
// instance should override parent value
this._instance.value = 'instance C';
// private should remain local
this._private.value = 'private C';
},
write_C: function(){
this._instance.jQuery.append('from C: ' + this._instance.value + ' ' + this._private.value + '<br />');
},
before: function(){
this._instance.value += '[c]';
this._private.value += '[c]';
this._super();
this.write_A();
this.write_B();
this.write_C();
},
after: function(){
this._instance.value += '[c]';
this._private.value += '[c]';
this.write_A();
this.write_B();
this.write_C();
this._super();
}
}, 'private_c');
aciPluginClass.publish('privateDemo');
// call _super before write
$('.result').append('before:<br/>').privateDemo('api').before();
// this will reset the values (in our case)
$('.result').privateDemo('api').__extend();
// call _super after write
$('.result').append('after:<br/>').privateDemo('api').after();
</script>
<script type="text/javascript">
$(function() {
$('script.code').each(function() {
$(this).before('<div style="clear:both;margin:10px 0 10px 0"><pre style="padding:20px;border:1px dashed #000;background:#f6f6f6;display:inline-block;"></pre></div>');
$(this).prev('div').find('pre').text($(this).html());
});
});
</script>
</body>
</html>