Created
September 8, 2011 00:51
-
-
Save kenji4569/1202320 to your computer and use it in GitHub Desktop.
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
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