1 From 18454b17fb19e4fa24b151ad377e43252ecf552f Mon Sep 17 00:00:00 2001
2 From: Minkyeong Kim <minkyeong.kim@samsung.com>
3 Date: Fri, 1 Feb 2013 15:04:58 +0900
4 Subject: [PATCH] [JQM] performance tuning : change self-init method for jQM
8 .../jquery-mobile-1.2.0/js/jquery.mobile.core.js | 38 ++++++++++++++++++++
9 .../jquery-mobile-1.2.0/js/widgets/collapsible.js | 6 ++--
10 .../js/widgets/collapsibleSet.js | 6 ++--
11 libs/js/jquery-mobile-1.2.0/js/widgets/listview.js | 6 ++--
12 libs/js/jquery-mobile-1.2.0/js/widgets/navbar.js | 6 ++--
13 5 files changed, 46 insertions(+), 16 deletions(-)
15 diff --git a/libs/js/jquery-mobile-1.2.0/js/jquery.mobile.core.js b/libs/js/jquery-mobile-1.2.0/js/jquery.mobile.core.js
16 index f8c3a2d..d8a4b42 100644
17 --- a/libs/js/jquery-mobile-1.2.0/js/jquery.mobile.core.js
18 +++ b/libs/js/jquery-mobile-1.2.0/js/jquery.mobile.core.js
19 @@ -345,6 +345,44 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
20 $.find.matchesSelector = function( node, expr ) {
21 return $.find( expr, null, null, [ node ] ).length > 0;
27 + delegateSelfInitWithSingleSelector: function( target, useKeepNative ) {
28 + if ( typeof target !== 'function' ) {
31 + var selector = target.prototype.options.initSelector;
32 + var selectorRE = /:jqmData\(role='[A-z\-]+'\)$/;
33 + if ( selectorRE.test(selector) ) {
34 + var firstIdx = selector.indexOf( "'" ) + 1;
35 + var lastIdx = selector.lastIndexOf( "'" );
36 + var key = selector.substring( firstIdx, lastIdx );
37 + if ( !$.creatorDict.hasOwnProperty( key ) ) {
38 + $.creatorDict[key] = {};
39 + $.creatorDict[key].target = target;
40 + if ( useKeepNative === true ) {
41 + $.creatorDict[key].useKeepNative = useKeepNative;
50 + //auto self-init widgets
51 + $( document ).bind( "pagecreate create", function( e ) {
52 + var selector = "*[data-" + $.mobile.ns + "role]";
53 + $( selector, e.target ).each( function () {
54 + dataRoleValue = this.getAttribute( "data-role" );
55 + matchedObj = $.creatorDict[dataRoleValue];
57 + matchedObj.target.prototype.enhance( this, matchedObj.useKeepNative );
62 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
64 diff --git a/libs/js/jquery-mobile-1.2.0/js/widgets/collapsible.js b/libs/js/jquery-mobile-1.2.0/js/widgets/collapsible.js
65 index ad1ca3b..26dbb61 100644
66 --- a/libs/js/jquery-mobile-1.2.0/js/widgets/collapsible.js
67 +++ b/libs/js/jquery-mobile-1.2.0/js/widgets/collapsible.js
68 @@ -166,10 +166,8 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
72 -//auto self-init widgets
73 -$.mobile.$document.bind( "pagecreate create", function( e ) {
74 - $.mobile.collapsible.prototype.enhanceWithin( e.target );
76 +//delegate auto self-init widgets
77 +$.delegateSelfInitWithSingleSelector( $.mobile.collapsible );
80 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
81 diff --git a/libs/js/jquery-mobile-1.2.0/js/widgets/collapsibleSet.js b/libs/js/jquery-mobile-1.2.0/js/widgets/collapsibleSet.js
82 index ebc762d..43975e8 100644
83 --- a/libs/js/jquery-mobile-1.2.0/js/widgets/collapsibleSet.js
84 +++ b/libs/js/jquery-mobile-1.2.0/js/widgets/collapsibleSet.js
85 @@ -107,10 +107,8 @@ $.widget( "mobile.collapsibleset", $.mobile.widget, {
89 -//auto self-init widgets
90 -$.mobile.$document.bind( "pagecreate create", function( e ) {
91 - $.mobile.collapsibleset.prototype.enhanceWithin( e.target );
93 +//delegate auto self-init widgets
94 +$.delegateSelfInitWithSingleSelector( $.mobile.collapsibleset );
97 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
98 diff --git a/libs/js/jquery-mobile-1.2.0/js/widgets/listview.js b/libs/js/jquery-mobile-1.2.0/js/widgets/listview.js
99 index e0d68f7..58a2d04 100644
100 --- a/libs/js/jquery-mobile-1.2.0/js/widgets/listview.js
101 +++ b/libs/js/jquery-mobile-1.2.0/js/widgets/listview.js
102 @@ -520,10 +520,8 @@ $.widget( "mobile.listview", $.mobile.widget, {
106 -//auto self-init widgets
107 -$.mobile.$document.bind( "pagecreate create", function( e ) {
108 - $.mobile.listview.prototype.enhanceWithin( e.target );
110 +//delegate auto self-init widgets
111 +$.delegateSelfInitWithSingleSelector( $.mobile.listview );
114 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
115 diff --git a/libs/js/jquery-mobile-1.2.0/js/widgets/navbar.js b/libs/js/jquery-mobile-1.2.0/js/widgets/navbar.js
116 index 29c5057..0b52a06 100644
117 --- a/libs/js/jquery-mobile-1.2.0/js/widgets/navbar.js
118 +++ b/libs/js/jquery-mobile-1.2.0/js/widgets/navbar.js
119 @@ -51,10 +51,8 @@ $.widget( "mobile.navbar", $.mobile.widget, {
123 -//auto self-init widgets
124 -$.mobile.$document.bind( "pagecreate create", function( e ) {
125 - $.mobile.navbar.prototype.enhanceWithin( e.target );
127 +//delegate auto self-init widgets
128 +$.delegateSelfInitWithSingleSelector( $.mobile.navbar );
131 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);