Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created May 28, 2009 17:43
Show Gist options
  • Save kara-ryli/119462 to your computer and use it in GitHub Desktop.
Save kara-ryli/119462 to your computer and use it in GitHub Desktop.
Changes the innerHTML of an element into a Template object.
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