This property contains a jQuery reference to a DOM element on the page. Reference provided by
this.$e
points to the DOM element the instance was initialized for.
While PluginFactory provides you with a comfortable way of creating and registering new plugins, it would be incomplete without a set of base plugins that can be further extended. Q.PluginFactory.Base is the most basic plugin blueprint. All other plugins are based on it and inherit its properties and methods.
Q.PluginFactory.Base is a part of the Q.PluginFactory and does not require any additional files.
When developing a plugin, we encounter one of the greatest problems with handling events. In Javascript, event handlers are anonymous functions, so-called closures, which run in their own isolated context and have no reference of the class instance that called them. This, naturally, results in many complicated solutions to re-discovering the this context.
We can save all the pain by introducing a mandatory parameter instance
to every event
handler. The handler function would then use event.data.instance
as reference to its
relevant instance. When the event handler is called, provide this
as value of the parameter.
Base plugin is a barebone plugin without any User Interface. It only introduces important events and methods, necessary for development of more advanced plugins.
PluginFactory does not provide any properties of its own. Instead, look into individual plugins' properties.
This property contains a jQuery reference to a DOM element on the page. Reference provided by
this.$e
points to the DOM element the instance was initialized for.
This property contains name of a Q plugin. It may be anything the creator of the plugin decides, though it is recommended to keep the naming convention "Q.PluginFactory.PluginName". A plugin's name property will be used by Q's stack method to help you identify the origin of a stack trace record.
Default: "Q.PluginFactory.Base"
ID is a unique identifier of the instance. It is either inherited from its DOM counterpart (for plugins that are tied to a HTML element), or auto-generated using Q.GUID() method. While it is false in a prototype plugin, it gets populated during initialization of the plugin, therefore it always has a unique value.
Default: false (see description)
Collection of configuration variables, which can be passed on to a plugin during initialization time.
These are merged with default_options
(see below) and override their values.
Note: Only use the options for initialization of plugins.
Default: empty Object
This is a reserved property.
Note: This property is currently not used. It will be used in the future for reverse inheritance features.
Default: false
This object serves as data cache for plugins that work with external data.
Default: empty object
This object contains default values of options
. It is merged with supplied options
during initialization.
Default: { super:false, bubbleEvents:{} }
This Base plugin comes with several key events and a mechanism for handling multiple event handlers already in place.
The onInit event is triggered after the supplied options have been loaded and applied,
but before the this.init()
method was executed. This provides you with an option to process
data and perform operations before the plugin was first loaded.
The onReady event is triggered after the this.init()
method was executed.
The premise of this.init()
method is to run all necessary operations to retrieve data,
perform initial calculations, and manipulate DOM structures in order to prepare the plugin for use.
Once that is done, onReady event is triggered.
The onDestroy event is triggered before execution of the this.destroy()
method.
This gives you the opportunity to retrieve and/or submit any vital data before the plugin is unregistered,
events destroyed and all of its DOM structures removed.
Following methods provide vital functionality to Base plugin and ensure that all plugins based on it would be equipped in the same way.
Returns no value.
This method is reserved for native plugin initialization.
this.$e
.
Returns no value.
This method is empty by default, ready to be used by your custom initialization routine.
this.$e
.
Returns no value.
This method accepts no parameters.
When this.destroy()
is called, the event onDestroy
gets triggered first, allowing you to retrieve potentially critical data and perform additional operations.
Next, all event handlers are unlinked from the DOM element and its children, and all custom data related
to the plugin are removed.
Returns no value.
In order to deliver a custom, fully customizable and highly effective event mechanism,
Q introduces several methods that ensure this requirement is met. this.eventTrigger
is
among them.
Upon receiving a call, this method loops over all event handlers registered under the appropriate event, and executes them within context of this, passing any received parameters.
event.data
within the handler methods.
Returns no value.
This method is another of several that ensure completely flexible and customizable event model of Q.
By calling this.dropEvent("myEvent")
, you will remove all event handlers linked to event
"myEvent". By supplying a second parameter in the form of an anonymous function (closure), you will
limit the removal only to that particular closure.
This can be used to selectively remove outdated event handlers. Keep in mind though that you need to exactly match the closure you wish to remove.