Added Rewrite HREFs (HTTPS) module

This module will rewrite all the href attributes of HTTPS links to use 
HTTP instead of HTTPS. Links relative to the web root are not rewritten.

Added beef.dom.rewriteLinksProtocol(old_protocol, new_protocol, selector)



git-svn-id: https://beef.googlecode.com/svn/trunk@1317 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
bcoles@gmail.com
2011-09-29 09:55:09 +00:00
parent bf80fbd8f1
commit f7bca3c192

View File

@@ -165,6 +165,31 @@ beef.dom = {
}).length;
},
/**
* @param: {String} old_protocol: the old link protocol to be rewritten
* @param: {String} new_protocol: the new link protocol to be written
* @param: {String} selector: the jquery selector statement to use, defaults to all a tags.
* @return: {Number} the amount of links found in the DOM and rewritten.
*/
rewriteLinksProtocol: function(old_protocol, new_protocol, selector) {
var count = 0;
var re = new RegExp(old_protocol+"://", "gi");
var sel = (selector == null) ? 'a' : selector;
$j(sel).each(function() {
if ($j(this).attr('href') != null) {
var url = $j(this).attr('href');
if (url.match(re)) {
$j(this).attr('href', url.replace(re, new_protocol+"://")).click(function() { return true; });
count++;
}
}
});
return count;
},
/**
* @params: {String} id: reference identifier to the applet.
* @params: {String} code: name of the class to be loaded. For example, beef.class.
@@ -200,4 +225,4 @@ beef.dom = {
};
beef.regCmp('beef.dom');
beef.regCmp('beef.dom');