Mobile Widget Prototype
by HYEONGJINKIM
JavaScript
/*!
* (jQuery mobile) jQuery UI Widget-factory plugin boilerplate (for 1.8/9+)
* Author: @scottjehl
* Further changes: @addyosmani
* Licensed under the MIT license
*/
;
(function ($, window, document, undefined) {
//define a widget under a namespace of your choice
//here 'mobile' has been used in the first parameter
$.widget("mobile.widgetName", $.mobile.widget, {
//Options to be used as defaults
options: {
foo: true,
bar: false
},
_create: function () {
// _create will automatically run the first time this
// widget is called. Put the initial widget set-up code
// here, then you can access the element on which
// the widget was called via this.element
// The options defined above can be accessed via
// this.options
var m = this.element;
//p = m.parents(":jqmData(role='page')"),
//c = p.find(":jqmData(role='content')")
console.log(m);
},
// Private methods/props start with underscores
_dosomething: function () {},
// Public methods like these below can can be called
// externally:
// $("#myelem").foo( "enable", arguments );
enable: function () {},
// Destroy an instantiated plugin and clean up modifications
// the widget has made to the DOM
destroy: function () {
//this.element.removeStuff();
// For UI 1.8, destroy must be invoked from the
// base widget
$.Widget.prototype.destroy.call(this);
// For UI 1.9, define _destroy instead and don't
// worry about calling the base widget
},
methodB: function (event) {
//_trigger dispatches callbacks the plugin user can
// subscribe to
//signature: _trigger( "callbackName" , [eventObject],
// [uiObject] )
...