Permalink
Browse files

adding escape option so you can transform a url into a parameter (if …

…you wanted to automatically check the google cache or somesuch)
  • Loading branch information...
1 parent 96397b6 commit ae436464d221d3ba4535455f616ceb473e07e0cc @rampion committed Mar 10, 2012
Showing with 23 additions and 7 deletions.
  1. +15 −5 chrome/js/redirect.js
  2. +2 −0 chrome/js/redirector-ui.js
  3. +1 −1 chrome/js/redirector.js
  4. +5 −1 chrome/redirector.html
View
@@ -2,8 +2,8 @@
var EXPORTED_SYMBOLS = ['Redirect'];
-function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) {
- this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled);
+function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) {
+ this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled);
}
//Static
@@ -36,6 +36,7 @@ Redirect.prototype = {
},
unescapeMatches : false,
+ escapeMatches : false,
disabled : false,
@@ -57,6 +58,7 @@ Redirect.prototype = {
redirectUrl : this.redirectUrl,
patternType : this.patternType,
unescapeMatches : this.unescapeMatches,
+ escapeMatches : this.escapeMatches,
disabled : !!this.disabled
};
},
@@ -75,6 +77,7 @@ Redirect.prototype = {
this.redirectUrl = other.redirectUrl;
this.patternType = other.patternType;
this.unescapeMatches = other.unescapeMatches;
+ this.escapeMatches = other.escapeMatches;
this.disabled = other.disabled;
},
@@ -85,6 +88,7 @@ Redirect.prototype = {
&& this.redirectUrl == redirect.redirectUrl
&& this.patternType == redirect.patternType
&& this.unescapeMatches == redirect.unescapeMatches
+ && this.escapeMatches == redirect.escapeMatches
;
},
@@ -164,13 +168,14 @@ Redirect.prototype = {
return new RegExp(this._preparePattern(pattern),"gi");
},
- _init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) {
+ _init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) {
this.exampleUrl = exampleUrl || '';
this.includePattern = includePattern || '';
this.excludePattern = excludePattern || '';
this.redirectUrl = redirectUrl || '';
this.patternType = patternType || Redirect.WILDCARD;
this.unescapeMatches = (unescapeMatches === 'true' || unescapeMatches === true);
+ this.escapeMatches = (escapeMatches === 'true' || escapeMatches === true);
this.disabled = (disabled === 'true' || disabled === true);
},
@@ -182,6 +187,7 @@ Redirect.prototype = {
+ '\n\tRedirect url : ' + this.redirectUrl
+ '\n\tPattern type : ' + this.patternType
+ '\n\tUnescape matches : ' + this.unescapeMatches
+ + '\n\tEscape matches : ' + this.escapeMatches
+ '\n\tDisabled : ' + this.disabled
+ '\n}\n';
},
@@ -196,7 +202,11 @@ Redirect.prototype = {
}
var resultUrl = this.redirectUrl;
for (var i = 1; i < matches.length; i++) {
- resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), this.unescapeMatches ? unescape(matches[i]) : matches[i]);
+ resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'),
+ this.unescapeMatches ? unescape(matches[i]) :
+ this.escapeMatches ? encodeURIComponent(matches[i]) :
+ matches[i]
+ );
}
this._rxInclude.lastIndex = 0;
return resultUrl;
@@ -210,4 +220,4 @@ Redirect.prototype = {
this._rxExclude.lastIndex = 0;
return shouldExclude;
}
-};
+};
@@ -148,6 +148,7 @@ function bindRedirect(redirect) {
$('#redirect-to').val(redirect.redirectUrl);
$('#redirect-enabled').attr('checked', !redirect.disabled);
$('#unescape-matches').attr('checked', redirect.unescapeMatches);
+ $('#escape-matches').attr('checked', redirect.escapeMatches);
$('#regex-pattern').attr('checked', redirect.patternType == Redirect.REGEX);
$('#wildcard-pattern').attr('checked', redirect.patternType == Redirect.WILDCARD);
}
@@ -180,6 +181,7 @@ function controlsToRedirect(redirect) {
redirect.redirectUrl = $('#redirect-to').val();
redirect.disabled = !$('#redirect-enabled').attr('checked');
redirect.unescapeMatches = $('#unescape-matches').attr('checked');
+ redirect.escapeMatches = $('#escape-matches').attr('checked');
return true;
}
View
@@ -345,4 +345,4 @@ Redirector = {
}
};
-Redirector.init();
+Redirector.init();
View
@@ -67,6 +67,10 @@
<input type="checkbox" id="unescape-matches" />
</div>
<div>
+ <label>Escape matches</label>
+ <input type="checkbox" id="escape-matches" />
+ </div>
+ <div>
<label>Enabled</label>
<input type="checkbox" id="redirect-enabled" />
</div>
@@ -77,4 +81,4 @@
</div>
</div>
</body>
-</html>
+</html>

1 comment on commit ae43646

Thank you. This will appear in the 2.8 release.

Please sign in to comment.