1
// START WRAPPER: The YUI.add wrapper is added by the build system, when you use YUI Builder to build your component from the raw source in this file
2
// YUI.add("myplugin", function(Y) {
4
/* Any frequently used shortcuts, strings and constants */
7
/* MyPlugin class constructor */
8
function MyPlugin(config) {
9
MyPlugin.superclass.constructor.apply(this, arguments);
13
* Required NAME static field, to identify the class and
14
* used as an event prefix, to generate class names etc. (set to the
15
* class name in camel case).
17
MyPlugin.NAME = "myPlugin";
20
* Required NS static field, to identify the property on the host which will,
21
* be used to refer to the plugin instance ( e.g. host.feature.doSomething() )
23
MyPlugin.NS = "feature";
26
* The attribute configuration for the plugin. This defines the core user facing state of the plugin
31
value: "A" // The default value for attrA, used if the user does not set a value during construction.
34
, valueFn: "_defAttrAVal" // Can be used as a substitute for "value", when you need access to "this" to set the default value.
36
, setter: "_setAttrA" // Used to normalize attrA's value while during set. Refers to a prototype method, to make customization easier
37
, getter: "_getAttrA" // Used to normalize attrA's value while during get. Refers to a prototype method, to make customization easier
38
, validator: "_validateAttrA" // Used to validate attrA's value before updating it. Refers to a prototype method, to make customization easier
40
, readOnly: true // Cannot be set by the end user. Can be set by the component developer at any time, using _set
41
, writeOnce: true // Can only be set once by the end user (usually during construction). Can be set by the component developer at any time, using _set
43
, lazyAdd: false // Add (configure) the attribute during initialization.
45
// You only need to set lazyAdd to false if your attribute is
46
// setting some other state in your setter which needs to be set during initialization
47
// (not generally recommended - the setter should be used for normalization.
48
// You should use listeners to update alternate state).
50
, broadcast: 1 // Whether the attribute change event should be broadcast or not.
54
// ... attrB, attrC, attrD ... attribute configurations.
56
// Can also include attributes for the super class if you want to override or add configuration parameters
59
/* MyPlugin extends the base Plugin.Base class */
60
Y.extend(MyPlugin, Y.Plugin.Base, {
62
initializer: function() {
64
* initializer is part of the lifecycle introduced by
65
* the Base class. It is invoked during construction, when
66
* the plugin is plugged into the host, and can be used to
67
* register listeners, or inject logic before or after methods
70
* It does not need to invoke the superclass initializer.
71
* init() will call initializer() for all classes in the hierarchy.
74
// See Y.Do.before, Y.Do.after
75
this.beforeHostMethod("show", this._beforeHostShowMethod);
76
this.afterHostMethod("show", this._afterHostShowMethod);
78
// See Y.EventTarget.on, Y.EventTarget.after
79
this.onHostEvent("render", this._onHostRenderEvent);
80
this.afterHostEvent("render", this._afterHostRenderEvent);
84
destructor : function() {
86
* destructor is part of the lifecycle introduced by
87
* the Base class. It is invoked when the plugin is unplugged.
89
* Any listeners registered using Plugin.Base's onHostEvent/afterHostEvent methods,
90
* or any methods displaced using it's beforeHostMethod/afterHostMethod methods
91
* will be detached/restored by Plugin.Base's destructor.
93
* We only need to clean up anything we change on the host
95
* It does not need to invoke the superclass destructor.
96
* destroy() will call initializer() for all classes in the hierarchy.
100
/* Supporting Methods */
102
_onHostRenderEvent : function(e) {
103
/* React on the host render event */
106
_afterHostRenderEvent : function(e) {
107
/* React after the host render event */
110
_beforeHostShowMethod : function() {
111
/* Inject logic before the host's show method is called. */
114
_afterHostShowMethod : function() {
115
/* Inject logic after the host's show method is called. */
120
Y.namespace("Plugin.MyApp").MyPlugin = MyPlugin;
122
// }, "3.1.0", {requires:["plugin"]});