From f7bca3c19281b12e91e56e5c9ea27a937e74edc7 Mon Sep 17 00:00:00 2001 From: "bcoles@gmail.com" Date: Thu, 29 Sep 2011 09:55:09 +0000 Subject: [PATCH] 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 --- core/main/client/dom.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/core/main/client/dom.js b/core/main/client/dom.js index 5bef972a2..6c9709b85 100644 --- a/core/main/client/dom.js +++ b/core/main/client/dom.js @@ -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'); \ No newline at end of file +beef.regCmp('beef.dom');