Skip to content

Commit 14eef0b

Browse files
author
Gabriel Schulhof
committed
Registry: Do depth-first search instead of rendering order to an array.
This allows the registration of new widget classes at any time.
1 parent 9b759b2 commit 14eef0b

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

js/jquery.mobile.registry.js

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,21 @@ define( [ "jquery", "./jquery.mobile.ns" ], function( jQuery ) {
1010
var doc = $( document );
1111

1212
function Enhancer() {
13-
this._callbacks = [],
14-
this._dependencies = {},
15-
this._document = doc;
13+
this._dependencies = {};
14+
this._enhanceCount = 0;
1615
}
1716

1817
$.extend( Enhancer.prototype, {
19-
_addWidget: function( fullName ) {
20-
var idx,
21-
depinfo = this._dependencies[ fullName ];
22-
23-
if ( depinfo && !depinfo.added ) {
24-
for ( idx in depinfo.deps ) {
25-
this._addWidget( depinfo.deps[ idx ] );
26-
}
27-
this._callbacks.push( depinfo.callback );
28-
depinfo.added = true;
29-
}
30-
},
3118

3219
_defaultCallback: function( widget ) {
3320
var parts = widget.split( "." ),
3421
ns = parts[ 0 ],
3522
name = parts[ 1 ],
3623
ret = function( targetEl ) {
37-
// First try to grab the initSelector from the namespace, to avoid
38-
// triggering the widget class's definition, but, failing that, look
39-
// for the initSelector also in the prototype's options.
40-
var targets = $( $[ ns ][ name ].initSelector ||
41-
$[ ns ][ name ].prototype.options.initSelector, targetEl );
24+
// First try to grab the initSelector from the old location in case
25+
// some legacy code modified it. If not, grab it from the new location.
26+
var targets = $( $[ ns ][ name ].prototype.options.initSelector ||
27+
$[ ns ][ name ].initSelector, targetEl );
4228

4329
if ( targets.length ) {
4430
$[ ns ][ name ].prototype.enhance( targets, true );
@@ -61,30 +47,35 @@ $.extend( Enhancer.prototype, {
6147

6248
deps[ widget ] = {
6349
deps: widgetDeps.dependencies,
64-
callback: callback
50+
callback: callback,
51+
enhanceCount: this._enhanceCount
6552
};
6653

67-
if ( deps.processed ) {
68-
this._addWidget( widget );
69-
}
70-
7154
return this;
7255
},
7356

74-
enhance: function( targetEl ) {
75-
var idx,
76-
deps = this._dependencies,
77-
cbs = this._callbacks;
57+
_enhance: function( el, idx ) {
58+
var depIdx,
59+
enhanceCount = this._enhanceCount,
60+
dep = this._dependencies[ idx ];
7861

79-
if ( !deps.processed ) {
80-
for ( idx in deps ) {
81-
this._addWidget( idx );
62+
if ( dep && dep.enhanceCount !== enhanceCount ) {
63+
for ( depIdx in dep.deps ) {
64+
this._enhance( el, dep.deps[ depIdx ] );
8265
}
83-
deps.processed = true;
66+
dep.callback( el );
67+
dep.enhanceCount = enhanceCount;
8468
}
69+
},
70+
71+
enhance: function( targetEl ) {
72+
var idx,
73+
deps = this._dependencies;
74+
75+
this._enhanceCount++;
8576

86-
for ( idx in cbs ) {
87-
cbs[ idx ]( targetEl );
77+
for ( idx in deps ) {
78+
this._enhance( targetEl, idx );
8879
}
8980

9081
return this;

0 commit comments

Comments
 (0)