Created
March 15, 2011 20:40
-
-
Save SlexAxton/871434 to your computer and use it in GitHub Desktop.
For yepnope. don't reexecute dupes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Yepnope Once Filter | |
* | |
* by Alex Sexton | |
* WTFPL | |
* | |
* Run this (ideally concatenated into the yepnope minified file) and any script that | |
* you try to include twice will automatically be skipped (but your callback will still run). | |
* | |
*/ | |
(function ( yepnope ) { | |
var urlMap = {}; | |
yepnope.addFilter(function ( resource ) { | |
if ( map[ resource.url ] ) { | |
resource.instead = function ( input, callback, chain, index, testresult ) { | |
if ( testresult ) { | |
// Determine callback, if any | |
if ( callback ) { | |
callback = ( {}.toString.call( callback ) == '[object Function]' ) ? callback : callback[ input ] || callback[ index ] || callback[ ( input.split( '/' ).pop().split( '?' )[ 0 ] ) ]; | |
} | |
callback && callback( resource.origUrl, testResult, index ); | |
resource.autoCallback && resource.autoCallback( resource.origUrl, testResult, index ); | |
} | |
else { | |
resource.bypass = true; | |
} | |
}; | |
} | |
else { | |
map[ resource.url ] = true; | |
} | |
return resource; | |
}); | |
})( yepnope ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No you're absolutely correct. This was just a test, but that'd be a good thing to consider when I eventually make this a real addition. I appreciate the input.