Browse Source

Merge pull request #1241 from Alex-Code/script-filter

Update script filter
tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
52bf6ac4c6
  1. 12
      framework/yii/assets/yii.js

12
framework/yii/assets/yii.js

@ -219,19 +219,17 @@ yii = (function ($) {
function initScriptFilter() { function initScriptFilter() {
var hostInfo = location.protocol + '//' + location.host; var hostInfo = location.protocol + '//' + location.host;
var loadedScripts = $('script').filter(function () { var loadedScripts = $('script[src]').map(function () {
return this.src;
}).map(function () {
return this.src.charAt(0) === '/' ? hostInfo + this.src : this.src; return this.src.charAt(0) === '/' ? hostInfo + this.src : this.src;
}).toArray(); }).toArray();
$.ajaxPrefilter('script', function (options, originalOptions, xhr) { $.ajaxPrefilter('script', function (options, originalOptions, xhr) {
var url = options.url.charAt(0) === '/' ? hostInfo + options.url : options.url; var url = options.url.charAt(0) === '/' ? hostInfo + options.url : options.url;
if (loadedScripts.indexOf(url) < 0) { if ($.inArray(url, loadedScripts) === -1) {
loadedScripts.push(url); loadedScripts.push(url);
} else { } else {
var found = pub.reloadableScripts.map(function () { var found = $.inArray(url, $.map(pub.reloadableScripts, function (script) {
return this.charAt(0) === '/' ? hostInfo + this : this; return script.charAt(0) === '/' ? hostInfo + script : script;
}).indexOf(url) >= 0; })) !== -1;
if (!found) { if (!found) {
xhr.abort(); xhr.abort();
} }

Loading…
Cancel
Save