Skip to content

Instantly share code, notes, and snippets.

@jbasdf
Created February 8, 2011 18:41
Show Gist options
  • Save jbasdf/816946 to your computer and use it in GitHub Desktop.
Save jbasdf/816946 to your computer and use it in GitHub Desktop.
clean_snippet: function(snippet){
snippet = snippet.replace(/'/gi, "("); // single quote will cause javascript problems inline.
snippet = snippet.replace(/[\t\n\r]/gi, ""); // remove tabs, newlines, and return chars
return this.rewrite_links(snippet);
},
// Rewrite links in the snippets so they go back to the parent site.
rewrite_links: function(snippet){
var obj = jQuery(snippet);
obj.find('[href]').attr('href', function(){ return com.oerglue.browser.make_abs_url(this.href); });
obj.find('[src]').attr('src', function(){ return com.oerglue.browser.make_abs_url(this.src); });
obj.find('[action]').attr('action', function(){ return com.oerglue.browser.make_abs_url(this.action); });
return com.oerglue.common.obj_to_s(obj);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment