1 (function( $, undefined ) {
3 $.widget( "mobile.widget", {
4 // decorate the parent _createWidget to trigger `widgetinit` for users
5 // who wish to do post post `widgetcreate` alterations/additions
7 // TODO create a pull request for jquery ui to trigger this event
8 // in the original _createWidget
9 _createWidget: function() {
10 $.Widget.prototype._createWidget.apply( this, arguments );
11 this._trigger( 'init' );
14 _getCreateOptions: function() {
16 var elem = this.element,
19 $.each( this.options, function( option ) {
21 var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
22 return "-" + c.toLowerCase();
26 if ( value !== undefined ) {
27 options[ option ] = value;
34 enhanceWithin: function( target, useKeepNative ) {
35 this.enhance( $( this.options.initSelector, $( target )), useKeepNative );
38 enhance: function( targets, useKeepNative ) {
39 var page, keepNative, $widgetElements = $( targets ), self = this;
41 // if ignoreContentEnabled is set to true the framework should
42 // only enhance the selected elements when they do NOT have a
43 // parent with the data-namespace-ignore attribute
44 $widgetElements = $.mobile.enhanceable( $widgetElements );
46 if ( useKeepNative && $widgetElements.length ) {
47 // TODO remove dependency on the page widget for the keepNative.
48 // Currently the keepNative value is defined on the page prototype so
49 // the method is as well
50 page = $.mobile.closestPageData( $widgetElements );
51 keepNative = ( page && page.keepNativeSelector()) || "";
53 $widgetElements = $widgetElements.not( keepNative );
56 $widgetElements[ this.widgetName ]();
59 raise: function( msg ) {
60 throw "Widget [" + this.widgetName + "]: " + msg;