Skip to content

Instantly share code, notes, and snippets.

@kenji4569
Created September 8, 2011 00:51
Show Gist options
  • Save kenji4569/1202320 to your computer and use it in GitHub Desktop.
Save kenji4569/1202320 to your computer and use it in GitHub Desktop.
def _set_files(files):
if current.request.ajax:
current.response.js = (current.response.js or '') + """;(function ($) {
var srcs = $('script').map(function(){return $(this).attr('src');}),
hrefs = $('link').map(function(){return $(this).attr('href');});
$.each(%s, function() {
if ((this.slice(-3) == '.js') && ($.inArray(this.toString(), srcs) == -1)) {
var el = document.createElement('script'); el.type = 'text/javascript'; el.src = this;
document.body.appendChild(el);
} else if ((this.slice(-4) == '.css') && ($.inArray(this.toString(), hrefs) == -1)) {
$('<link rel="stylesheet" type="text/css" href="' + this + '" />').prependTo('head');
if (/* for IE */ document.createStyleSheet){document.createStyleSheet(this);}
}});})(jQuery);""" % ('[%s]' % ','.join(["'%s'" % f.lower().split('?')[0] for f in files]))
else:
current.response.files[:0] = [f for f in files if f not in current.response.files]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment