aboutsummaryrefslogtreecommitdiff
path: root/chrome/js/redirect.js
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/js/redirect.js')
-rw-r--r--chrome/js/redirect.js85
1 files changed, 42 insertions, 43 deletions
diff --git a/chrome/js/redirect.js b/chrome/js/redirect.js
index eab14f8..e1e1c68 100644
--- a/chrome/js/redirect.js
+++ b/chrome/js/redirect.js
@@ -1,4 +1,3 @@
-
var EXPORTED_SYMBOLS = ['Redirect'];
@@ -11,43 +10,43 @@ Redirect.WILDCARD = 'W';
Redirect.REGEX = 'R';
Redirect.prototype = {
-
+
//attributes
exampleUrl : null,
-
+
get includePattern() { return this._includePattern; },
- set includePattern(value) {
+ set includePattern(value) {
this._includePattern = value;
- this._rxInclude = this._compile(value);
+ this._rxInclude = this._compile(value);
},
-
+
get excludePattern() { return this._excludePattern; },
- set excludePattern(value) {
- this._excludePattern = value;
- this._rxExclude = this._compile(value);
+ set excludePattern(value) {
+ this._excludePattern = value;
+ this._rxExclude = this._compile(value);
},
-
+
redirectUrl : null,
-
+
get patternType() { return this._patternType; },
- set patternType(value) {
+ set patternType(value) {
this._patternType = value;
this.compile();
},
unescapeMatches : false,
escapeMatches : false,
-
+
disabled : false,
-
+
//Functions
clone : function() {
return new Redirect().fromObject(this.toObject());
},
-
+
compile : function() {
- this._rxInclude = this._compile(this._includePattern);
- this._rxExclude = this._compile(this._excludePattern);
+ this._rxInclude = this._compile(this._includePattern);
+ this._rxExclude = this._compile(this._excludePattern);
},
toObject : function() {
@@ -69,7 +68,7 @@ Redirect.prototype = {
}
return this;
},
-
+
copyValues : function(other) {
this.exampleUrl = other.exampleUrl;
this.includePattern = other.includePattern;
@@ -91,16 +90,16 @@ Redirect.prototype = {
&& this.escapeMatches == redirect.escapeMatches
;
},
-
+
getMatch: function(url) {
- var result = {
- isMatch : false,
- isExcludeMatch : false,
- isDisabledMatch : false,
+ var result = {
+ isMatch : false,
+ isExcludeMatch : false,
+ isDisabledMatch : false,
redirectTo : '',
- toString : function() { return "{ isMatch : " + this.isMatch +
- ", isExcludeMatch : " + this.isExcludeMatch +
- ", isDisabledMatch : " + this.isDisabledMatch +
+ toString : function() { return "{ isMatch : " + this.isMatch +
+ ", isExcludeMatch : " + this.isExcludeMatch +
+ ", isDisabledMatch : " + this.isDisabledMatch +
", redirectTo : \"" + this.redirectTo + "\"" +
"}"; }
};
@@ -117,33 +116,33 @@ Redirect.prototype = {
result.redirectTo = redirectTo;
}
}
- return result;
+ return result;
},
-
+
isRegex: function() {
return this.patternType == Redirect.REGEX;
},
-
+
isWildcard : function() {
- return this.patternType == Redirect.WILDCARD;
+ return this.patternType == Redirect.WILDCARD;
},
test : function() {
- return this.getMatch(this.exampleUrl);
+ return this.getMatch(this.exampleUrl);
},
-
- //Private functions below
+
+ //Private functions below
_includePattern : null,
_excludePattern : null,
_patternType : null,
_rxInclude : null,
_rxExclude : null,
-
+
_preparePattern : function(pattern) {
if (this.patternType == Redirect.REGEX) {
- return pattern;
+ return pattern;
} else { //Convert wildcard to regex pattern
var converted = '^';
for (var i = 0; i < pattern.length; i++) {
@@ -167,7 +166,7 @@ Redirect.prototype = {
}
return new RegExp(this._preparePattern(pattern),"gi");
},
-
+
_init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) {
this.exampleUrl = exampleUrl || '';
this.includePattern = includePattern || '';
@@ -178,10 +177,10 @@ Redirect.prototype = {
this.escapeMatches = (escapeMatches === 'true' || escapeMatches === true);
this.disabled = (disabled === 'true' || disabled === true);
},
-
+
toString : function() {
return 'REDIRECT: {'
- + '\n\tExample url : ' + this.exampleUrl
+ + '\n\tExample url : ' + this.exampleUrl
+ '\n\tInclude pattern : ' + this.includePattern
+ '\n\tExclude pattern : ' + this.excludePattern
+ '\n\tRedirect url : ' + this.redirectUrl
@@ -191,11 +190,11 @@ Redirect.prototype = {
+ '\n\tDisabled : ' + this.disabled
+ '\n}\n';
},
-
+
_includeMatch : function(url) {
if (!this._rxInclude) {
return null;
- }
+ }
var matches = this._rxInclude.exec(url);
if (!matches) {
return null;
@@ -214,12 +213,12 @@ Redirect.prototype = {
this._rxInclude.lastIndex = 0;
return resultUrl;
},
-
+
_excludeMatch : function(url) {
if (!this._rxExclude) {
- return false;
+ return false;
}
- var shouldExclude = !!this._rxExclude.exec(url);
+ var shouldExclude = !!this._rxExclude.exec(url);
this._rxExclude.lastIndex = 0;
return shouldExclude;
}