2.0_beta sync to rsa
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / js / jquery.mobile.widget.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Widget factory extentions for mobile.
3 //>>label: Widget Factory 
4 //>>group: Core
5 //>>css: ../css/themes/default/jquery.mobile.theme.css
6
7 define( [ "jquery", "../external/requirejs/depend!./jquery.ui.widget[jquery]" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
10
11 $.widget( "mobile.widget", {
12         // decorate the parent _createWidget to trigger `widgetinit` for users
13         // who wish to do post post `widgetcreate` alterations/additions
14         //
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' );
20         },
21
22         _getCreateOptions: function() {
23
24                 var elem = this.element,
25                         options = {};
26
27                 $.each( this.options, function( option ) {
28
29                         var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
30                                                         return "-" + c.toLowerCase();
31                                                 })
32                                         );
33
34                         if ( value !== undefined ) {
35                                 options[ option ] = value;
36                         }
37                 });
38
39                 return options;
40         },
41
42         enhanceWithin: function( target, useKeepNative ) {
43                 this.enhance( $( this.options.initSelector, $( target )), useKeepNative );
44         },
45
46         enhance: function( targets, useKeepNative ) {
47                 var page, keepNative, $widgetElements = $( targets ), self = this;
48
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 );
53
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()) || "";
60
61                         $widgetElements = $widgetElements.not( keepNative );
62                 }
63
64                 $widgetElements[ this.widgetName ]();
65         },
66
67         raise: function( msg ) {
68                 throw "Widget [" + this.widgetName + "]: " + msg;
69         }
70 });
71
72 })( jQuery );
73 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
74 });
75 //>>excludeEnd("jqmBuildExclude");