1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Widget factory extentions for mobile.
3 //>>label: Widget Factory
5 //>>css: ../css/themes/default/jquery.mobile.theme.css
7 define( [ "jquery", "../external/requirejs/depend!./jquery.ui.widget[jquery]" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
11 $.widget( "mobile.widget", {
12 // decorate the parent _createWidget to trigger `widgetinit` for users
13 // who wish to do post post `widgetcreate` alterations/additions
15 // TODO create a pull request for jquery ui to trigger this event
16 // in the original _createWidget
17 _createWidget: function() {
18 $.Widget.prototype._createWidget.apply( this, arguments );
19 this._trigger( 'init' );
22 _getCreateOptions: function() {
24 var elem = this.element,
27 $.each( this.options, function( option ) {
29 var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
30 return "-" + c.toLowerCase();
34 if ( value !== undefined ) {
35 options[ option ] = value;
42 enhanceWithin: function( target, useKeepNative ) {
43 this.enhance( $( this.options.initSelector, $( target )), useKeepNative );
46 enhance: function( targets, useKeepNative ) {
47 var page, keepNative, $widgetElements = $( targets ), self = this;
49 // if ignoreContentEnabled is set to true the framework should
50 // only enhance the selected elements when they do NOT have a
51 // parent with the data-namespace-ignore attribute
52 $widgetElements = $.mobile.enhanceable( $widgetElements );
54 if ( useKeepNative && $widgetElements.length ) {
55 // TODO remove dependency on the page widget for the keepNative.
56 // Currently the keepNative value is defined on the page prototype so
57 // the method is as well
58 page = $.mobile.closestPageData( $widgetElements );
59 keepNative = (page && page.keepNativeSelector()) || "";
61 $widgetElements = $widgetElements.not( keepNative );
64 $widgetElements[ this.widgetName ]();
67 raise: function( msg ) {
68 throw "Widget [" + this.widgetName + "]: " + msg;
73 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
75 //>>excludeEnd("jqmBuildExclude");