Created
May 28, 2009 17:43
-
-
Save kara-ryli/119462 to your computer and use it in GitHub Desktop.
Changes the innerHTML of an element into a Template object.
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
Element.addMethods({ | |
/** | |
* Browser caveats: IE6 does not add quotes to DOM attributes | |
* when it does not need to. Use `class="#{className} ie"` if | |
* you're going to replace attribute values with spaces. Also, | |
* most browsers load `<img src="#{src}" />` as a 404. | |
*/ | |
templatize: (function(){ | |
var FIND = /(?:#|%23)%7B([^%]+)%7D/g, REPLACE = "#{$1}", | |
ERROR = 'Could not templatize element ', EMPTY = ""; | |
return function( _ref ) { | |
var el, t; | |
el = $(_ref); | |
if (! el) { throw( ERROR + _ref ); } | |
t = new Template( el.innerHTML.replace( FIND, REPLACE ) ); | |
el.update( EMPTY ); | |
el.hide(); | |
return t; | |
}; | |
})() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment