1
+ //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2
+ //>>description: Mobile versions of Data functions to allow for namespaceing
3
+ //>>label: jqmData
4
+ //>>group: Core
5
+ //>>css.structure: ../css/structure/jquery.mobile.core.css
6
+ //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
7
+
8
+ define ( [ "jquery" , "./jquery.mobile.ns" , "json!../package.json" ] , function ( jQuery , ns , pkg , __version__ ) {
9
+ //>>excludeEnd("jqmBuildExclude");
10
+ ( function ( $ , window , undefined ) {
11
+ var nsNormalizeDict = { } ,
12
+ // Monkey-patching Sizzle to filter the :jqmData selector
13
+ oldFind = $ . find ,
14
+ jqmDataRE = / : j q m D a t a \( ( [ ^ ) ] * ) \) / g;
15
+
16
+ $ . extend ( $ . mobile , {
17
+
18
+ // Namespace used framework-wide for data-attrs. Default is no namespace
19
+
20
+ ns : "" ,
21
+
22
+ // Retrieve an attribute from an element and perform some massaging of the value
23
+
24
+ getAttribute : function ( e , key , dns ) {
25
+ var value ;
26
+
27
+ if ( dns ) {
28
+ key = "data-" + $ . mobile . ns + key ;
29
+ }
30
+
31
+ value = e . getAttribute ( key ) ;
32
+
33
+ return value === "true" ? true :
34
+ value === "false" ? false :
35
+ value === null ? undefined : value ;
36
+ } ,
37
+
38
+ // Expose our cache for testing purposes.
39
+ nsNormalizeDict : nsNormalizeDict ,
40
+
41
+ // Take a data attribute property, prepend the namespace
42
+ // and then camel case the attribute string. Add the result
43
+ // to our nsNormalizeDict so we don't have to do this again.
44
+ nsNormalize : function ( prop ) {
45
+ return nsNormalizeDict [ prop ] || ( nsNormalizeDict [ prop ] = $ . camelCase ( $ . mobile . ns + prop ) ) ;
46
+ } ,
47
+
48
+ // Find the closest javascript page element to gather settings data jsperf test
49
+ // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
50
+ // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
51
+ // the page and dialog selector is negligable. This could probably be speed up by
52
+ // doing a similar parent node traversal to the one found in the inherited theme code above
53
+ closestPageData : function ( $target ) {
54
+ return $target
55
+ . closest ( ":jqmData(role='page'), :jqmData(role='dialog')" )
56
+ . data ( "mobile-page" ) ;
57
+ }
58
+
59
+ } ) ;
60
+ // Mobile version of data and removeData and hasData methods
61
+ // ensures all data is set and retrieved using jQuery Mobile's data namespace
62
+ $ . fn . jqmData = function ( prop , value ) {
63
+ var result ;
64
+ if ( typeof prop !== "undefined" ) {
65
+ if ( prop ) {
66
+ prop = $ . mobile . nsNormalize ( prop ) ;
67
+ }
68
+
69
+ // undefined is permitted as an explicit input for the second param
70
+ // in this case it returns the value and does not set it to undefined
71
+ if ( arguments . length < 2 || value === undefined ) {
72
+ result = this . data ( prop ) ;
73
+ } else {
74
+ result = this . data ( prop , value ) ;
75
+ }
76
+ }
77
+ return result ;
78
+ } ;
79
+
80
+ $ . jqmData = function ( elem , prop , value ) {
81
+ var result ;
82
+ if ( typeof prop !== "undefined" ) {
83
+ result = $ . data ( elem , prop ? $ . mobile . nsNormalize ( prop ) : prop , value ) ;
84
+ }
85
+ return result ;
86
+ } ;
87
+
88
+ $ . fn . jqmRemoveData = function ( prop ) {
89
+ return this . removeData ( $ . mobile . nsNormalize ( prop ) ) ;
90
+ } ;
91
+
92
+ $ . jqmRemoveData = function ( elem , prop ) {
93
+ return $ . removeData ( elem , $ . mobile . nsNormalize ( prop ) ) ;
94
+ } ;
95
+
96
+
97
+ $ . find = function ( selector , context , ret , extra ) {
98
+ selector = selector . replace ( jqmDataRE , "[data-" + ( $ . mobile . ns || "" ) + "$1]" ) ;
99
+
100
+ return oldFind . call ( this , selector , context , ret , extra ) ;
101
+ } ;
102
+
103
+ $ . extend ( $ . find , oldFind ) ;
104
+
105
+ } ) ( jQuery , this ) ;
106
+ //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
107
+ } ) ;
108
+ //>>excludeEnd("jqmBuildExclude");
0 commit comments