Permalink
Browse files

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

…properly, added enhanceable from jqm to perf tests
  • Loading branch information...
1 parent 2fd0919 commit aae4e7110e4aba401e2ec65490c8de6f852086d9 @johnbender johnbender committed Jun 10, 2012
Showing with 65 additions and 19 deletions.
  1. +6 −5 lazy.js
  2. +12 −0 test/lazy-test.js
  3. +47 −14 test/proxies-perf.js
View
11 lazy.js
@@ -9,7 +9,9 @@
// TODO compilation step to generate method definitions might be faster
for( prop in jQuery.fn ){
- if( !jQuery.fn.hasOwnProperty( prop ) || typeof jQuery.fn[ prop ] !== "function" ){
+ if( !jQuery.fn.hasOwnProperty( prop ) ||
+ typeof jQuery.fn[ prop ] !== "function" ||
+ prop === "force" ){
continue;
}
@@ -55,18 +57,17 @@
return this;
} else {
if( state.composed ) {
- proxy.force.call( this );
+ return proxy.force.call( this );
}
- property.apply( this, arguments );
- return this;
+ return property.apply( this, arguments );
}
};
}
};
jQuery.fn.force = function() {
- this._proxy.force.call( this );
+ return this._proxy.force.call( this );
};
jQuery.functor = function( htmlMorphism ) {
View
12 test/lazy-test.js
@@ -111,4 +111,16 @@
divs.force();
equal( divs.composed, undefined );
});
+
+ test( "filter functions should work properly", function() {
+ var $divs = $( "<div>" );
+
+ ok( $divs.length > 0, "there are elements in the list" );
+
+ $divs = $divs.map(function() {
+ return undefined;
+ }).force();
+
+ equal( $divs.length, 0, "all elements are filtered" );
+ });
})( jQuery, QUnit );
View
61 test/proxies-perf.js
@@ -1,40 +1,40 @@
jQuery.LazyProxy.init();
for( var i = 0; i <= (window.testElementCount || 100); i++ ){
- var div = document.createElement("div");
- div.setAttribute("data-test", "true");
+ var div = document.createElement("div");
+ div.setAttribute("data-test", "true");
div.setAttribute("data-test-foo", "true");
- $( div ).data("baz", "bak").appendTo( "body" );
+ $( div ).data("baz", "bak").appendTo( "body" );
}
var addClassRaw = function( elem ){
- elem.setAttribute( "class", elem.getAttribute( "class" ) + " foo" );
- return elem;
+ elem.setAttribute( "class", elem.getAttribute( "class" ) + " foo" );
+ return elem;
};
var clearClassRaw = function( elem ) {
- elem.setAttribute( "class", "" );
- return elem;
+ elem.setAttribute( "class", "" );
+ return elem;
};
$.fn.simpleAddClass = function(){
- $.map(this, addClassRaw);
- return this;
+ $.map(this, addClassRaw);
+ return this;
};
$.fn.simpleClearClass = function(){
- $.map(this, clearClassRaw);
- return this;
+ $.map(this, clearClassRaw);
+ return this;
};
$.fn.lazyClearClass = $.functor(clearClassRaw);
$.fn.lazyAddClass = $.functor(addClassRaw);
$.fn.manualAddClearClass = function(){
- $.map(this, function( elem ){
- addClassRaw(clearClassRaw(elem));
- });
+ $.map(this, function( elem ){
+ addClassRaw(clearClassRaw(elem));
+ });
};
$.fn.removeAttr.composable = function( value ) {
@@ -134,3 +134,36 @@ $.fn.cleanUpJustAttrs = function( fstAttrKey, sndAttrKey ) {
return this;
};
+
+$.enhanceable = function( elem ) {
+ var e = elem, c;
+
+ while ( e ) {
+ c = e.getAttribute ? e.getAttribute( "data-enhance" ) : "";
+
+ if ( c === "false" ) {
+ return undefined;
+ }
+
+ e = e.parentNode;
+ }
+
+ return elem;
+};
+
+$.fn.enhanceable = function() {
+ var all = $.map( this, $.enhanceable );
+ return all;
+};
+
+$.fn.enhanceableCleanAttr = function( cleanAttr ) {
+ return $.map( this, function( elem ) {
+ elem = $.enhanceable( elem );
+
+ if( elem ){
+ $.removeAttr( elem, cleanAttr );
+ }
+
+ return elem;
+ });
+};

0 comments on commit aae4e71

Please sign in to comment.