Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed bug in lazy proxy that prevented filter functions from working …

…properly, added enhanceable from jqm to perf tests
  • Loading branch information...
commit aae4e7110e4aba401e2ec65490c8de6f852086d9 1 parent 2fd0919
John Bender authored June 09, 2012
11  lazy.js
@@ -9,7 +9,9 @@
9 9
 
10 10
 		// TODO compilation step to generate method definitions might be faster
11 11
 		for( prop in jQuery.fn ){
12  
-			if( !jQuery.fn.hasOwnProperty( prop ) || typeof jQuery.fn[ prop ] !== "function" ){
  12
+			if( !jQuery.fn.hasOwnProperty( prop ) ||
  13
+					typeof jQuery.fn[ prop ] !== "function" ||
  14
+					prop === "force" ){
13 15
 				continue;
14 16
 			}
15 17
 
@@ -55,18 +57,17 @@
55 57
 					return this;
56 58
 				} else {
57 59
 					if( state.composed ) {
58  
-						proxy.force.call( this );
  60
+						return proxy.force.call( this );
59 61
 					}
60 62
 
61  
-					property.apply( this, arguments );
62  
-					return this;
  63
+					return property.apply( this, arguments );
63 64
 				}
64 65
 			};
65 66
 		}
66 67
 	};
67 68
 
68 69
 	jQuery.fn.force = function() {
69  
-		this._proxy.force.call( this );
  70
+		return this._proxy.force.call( this );
70 71
 	};
71 72
 
72 73
 	jQuery.functor = function( htmlMorphism ) {
12  test/lazy-test.js
@@ -111,4 +111,16 @@
111 111
 		divs.force();
112 112
 		equal( divs.composed, undefined );
113 113
 	});
  114
+
  115
+	test( "filter functions should work properly", function() {
  116
+		var $divs = $( "<div>" );
  117
+
  118
+		ok( $divs.length > 0, "there are elements in the list" );
  119
+
  120
+		$divs = $divs.map(function() {
  121
+			return undefined;
  122
+		}).force();
  123
+
  124
+		equal( $divs.length, 0, "all elements are filtered" );
  125
+	});
114 126
 })( jQuery, QUnit );
61  test/proxies-perf.js
... ...
@@ -1,30 +1,30 @@
1 1
 jQuery.LazyProxy.init();
2 2
 
3 3
 for( var i = 0; i <= (window.testElementCount || 100); i++ ){
4  
-  var div = document.createElement("div");
5  
-  div.setAttribute("data-test", "true");
  4
+	var div = document.createElement("div");
  5
+	div.setAttribute("data-test", "true");
6 6
 	div.setAttribute("data-test-foo", "true");
7  
-  $( div ).data("baz", "bak").appendTo( "body" );
  7
+	$( div ).data("baz", "bak").appendTo( "body" );
8 8
 }
9 9
 
10 10
 var addClassRaw = function( elem ){
11  
-  elem.setAttribute( "class", elem.getAttribute( "class" ) + " foo" );
12  
-  return elem;
  11
+	elem.setAttribute( "class", elem.getAttribute( "class" ) + " foo" );
  12
+	return elem;
13 13
 };
14 14
 
15 15
 var clearClassRaw = function( elem ) {
16  
-  elem.setAttribute( "class", "" );
17  
-  return elem;
  16
+	elem.setAttribute( "class", "" );
  17
+	return elem;
18 18
 };
19 19
 
20 20
 $.fn.simpleAddClass = function(){
21  
-  $.map(this, addClassRaw);
22  
-  return this;
  21
+	$.map(this, addClassRaw);
  22
+	return this;
23 23
 };
24 24
 
25 25
 $.fn.simpleClearClass = function(){
26  
-  $.map(this, clearClassRaw);
27  
-  return this;
  26
+	$.map(this, clearClassRaw);
  27
+	return this;
28 28
 };
29 29
 
30 30
 $.fn.lazyClearClass = $.functor(clearClassRaw);
@@ -32,9 +32,9 @@ $.fn.lazyClearClass = $.functor(clearClassRaw);
32 32
 $.fn.lazyAddClass = $.functor(addClassRaw);
33 33
 
34 34
 $.fn.manualAddClearClass = function(){
35  
-  $.map(this, function( elem ){
36  
-    addClassRaw(clearClassRaw(elem));
37  
-  });
  35
+	$.map(this, function( elem ){
  36
+		addClassRaw(clearClassRaw(elem));
  37
+	});
38 38
 };
39 39
 
40 40
 $.fn.removeAttr.composable = function( value ) {
@@ -134,3 +134,36 @@ $.fn.cleanUpJustAttrs = function( fstAttrKey, sndAttrKey ) {
134 134
 
135 135
 	return this;
136 136
 };
  137
+
  138
+$.enhanceable = function( elem ) {
  139
+	var e = elem, c;
  140
+
  141
+	while ( e ) {
  142
+		c = e.getAttribute ? e.getAttribute( "data-enhance" ) : "";
  143
+
  144
+		if ( c === "false" ) {
  145
+			return undefined;
  146
+		}
  147
+
  148
+		e = e.parentNode;
  149
+	}
  150
+
  151
+	return elem;
  152
+};
  153
+
  154
+$.fn.enhanceable = function() {
  155
+	var all = $.map( this, $.enhanceable );
  156
+	return all;
  157
+};
  158
+
  159
+$.fn.enhanceableCleanAttr = function( cleanAttr ) {
  160
+	return $.map( this, function( elem ) {
  161
+		elem = $.enhanceable( elem );
  162
+
  163
+		if( elem ){
  164
+			$.removeAttr( elem, cleanAttr );
  165
+		}
  166
+
  167
+		return elem;
  168
+	});
  169
+};

0 notes on commit aae4e71

Please sign in to comment.
Something went wrong with that request. Please try again.