2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('plugin', function(Y) {
10
* Provides the base Plugin class for building widget plugins.
16
* Plugin provides a base class for all Plugin classes.
20
* @param {Object} config The configuration object for the
23
function Plugin(config) {
24
Plugin.superclass.constructor.apply(this, arguments);
29
* Static property provides a string to identify the class.
31
* @property Plugin.NAME
35
Plugin.NAME = 'plugin';
38
* Static property provides the namespace the plugin will be
51
* Initializer lifecycle implementation.
54
* @param {Object} config Configuration object literal for the plugin
56
initializer : function(config) {
59
this._owner = config.owner;
68
* desctructor lifecycle implementation.
70
* Removes any listeners attached by the Plugin and restores
71
* and over-ridden methods.
75
destructor: function() {
78
for (var i = 0, l = this._handles.length; i < l; i++) {
79
this._handles[i].detach();
85
* Listens for events and methods fired by the owner widget.
86
* The handler is called before the event handler or method is called.
88
* @param sFn The event of method to listen for.
89
* @param fn The handler function to call when the listener fires.
90
* @param context An optional context to call the handler with.
91
* Default context is the plugin instance.
92
* @return Handle A handle that can be used to detach the handler (e.g. "handle.detach()").
94
doBefore: function(sFn, fn, context) {
95
var owner = this._owner,
98
context = context || this;
100
if (sFn in owner) { // method
101
handle = Y.Do.before(fn, this._owner, sFn, context);
102
} else if (owner.on) { // event
103
handle = owner.on(sFn, fn, context);
106
this._handles.push(handle);
111
* Listens for events and methods fired by the owner widget.
112
* The handler is called after the event handler or method is called.
114
* @param sFn The event of method to listen for.
115
* @param fn The handler function to call when the listener fires.
116
* @param context An optional context to call the handler with.
117
* Default context is the plugin instance.
118
* @return Handle A handle that can be used to detach the handler (e.g. "handle.detach()").
120
doAfter: function(sFn, fn, context) {
121
var owner = this._owner,
124
context = context || this;
126
if (sFn in owner) { // method
127
handle = Y.Do.after(fn, this._owner, sFn, context);
128
} else if (owner.after) { // event
129
handle = owner.after(sFn, fn, context);
132
this._handles.push(handle);
136
toString: function() {
137
return this.constructor.NAME + '[' + this.constructor.NS + ']';
141
Y.extend(Plugin, Y.Base, proto);
145
}, '3.0.0pr2' ,{requires:['base']});