19bd2762a317f7d3e56d1ec2a8ca29c715c77765
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / js / jquery.mobile.widget.js
1 /*
2 * widget factory extentions for mobile
3 */
4
5 (function( $, undefined ) {
6
7 $.widget( "mobile.widget", {
8         // decorate the parent _createWidget to trigger `widgetinit` for users
9         // who wish to do post post `widgetcreate` alterations/additions
10         //
11         // TODO create a pull request for jquery ui to trigger this event
12         // in the original _createWidget
13         _createWidget: function() {
14                 $.Widget.prototype._createWidget.apply( this, arguments );
15                 this._trigger( 'init' );
16         },
17
18         _getCreateOptions: function() {
19
20                 var elem = this.element,
21                         options = {};
22
23                 $.each( this.options, function( option ) {
24
25                         var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
26                                                         return "-" + c.toLowerCase();
27                                                 })
28                                         );
29
30                         if ( value !== undefined ) {
31                                 options[ option ] = value;
32                         }
33                 });
34
35                 return options;
36         },
37
38         enhanceWithin: function( target ) {
39                 // TODO remove dependency on the page widget for the keepNative.
40                 // Currently the keepNative value is defined on the page prototype so
41                 // the method is as well
42                 var page = $(target).closest(":jqmData(role='page')").data( "page" ),
43                         keepNative = (page && page.keepNativeSelector()) || "";
44
45                 $( this.options.initSelector, target ).not( keepNative )[ this.widgetName ]();
46         }
47 });
48
49 })( jQuery );