支持AMD

This commit is contained in:
Zongmin Lei
2015-01-16 20:27:23 +08:00
parent 04aaceb1b0
commit 85594379e2
8 changed files with 189 additions and 107 deletions

50
dist/xss.js vendored
View File

@@ -407,28 +407,38 @@ for (var i in DEFAULT) exports[i] = DEFAULT[i];
for (var i in parser) exports[i] = parser[i];
// 低版本浏览器支持
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (item) {
for (var i = 0; i < this.length; i++) {
if (this[i] === item) return i;
}
return -1;
};
}
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fn, scope) {
for (var i = 0; i < this.length; i++) {
fn.call(scope, this[i], i, this);
}
};
}
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, '');
};
}
// 在AMD下使用
if (typeof define === 'function' && define.amd) {
define(function () {
return module.exports;
});
}
// 在浏览器端使用
if (typeof window !== 'undefined') {
// 低版本浏览器支持
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (item) {
for(var i=0;i<this.length;i++){
if(this[i] == item) return i;
}
return -1;
};
}
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fn, scope) {
for (var i = 0; i < this.length; i++) fn.call(scope, this[i], i, this);
};
}
if(!String.prototype.trim){
String.prototype.trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, '');
};
}
// 输出
window.filterXSS = module.exports;
}