From 5cfbefe1b683e94d6c36a5e77ec3de84e012ca10 Mon Sep 17 00:00:00 2001
From: Seth Meranda <smeranda2@unl.edu>
Date: Wed, 6 Apr 2011 17:44:09 +0000
Subject: [PATCH] If we're doing a mobile search, rewrite all the URLs in the
 search results to use the mobile proxy.

---
 www/index.php     | 7 +++++--
 www/searchFunc.js | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/www/index.php b/www/index.php
index 4082fd0..c062cc9 100644
--- a/www/index.php
+++ b/www/index.php
@@ -21,8 +21,11 @@ $page->head .= '
 <link rel="stylesheet" type="text/css" href="searchCSS.css" />
 ';
 if ($template == 'Mobile') {
-	$page->head .='<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />';
-};
+	$page->head .='<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" >
+	<script type="text/javascript">var mobileSearch = true;</script>';
+} else {
+	$page->head .='<script type="text/javascript">var mobileSearch = false;</script>';
+}
 $page->addScript('searchFunc.js');
 
 if (isset($_GET['u']) //u is referring site
diff --git a/www/searchFunc.js b/www/searchFunc.js
index 659cf3d..bc65912 100644
--- a/www/searchFunc.js
+++ b/www/searchFunc.js
@@ -119,6 +119,14 @@ UNL_Search.handleResults = function (result_div, searchobj) {
 			}
 			resultsDIV.appendChild(searchobj.results[i].html);
 		}
+		if (mobileSearch) { //if we're doing a mobile search, rewrite link URLs to use mobile proxy
+			WDN.jQuery(resultsDIV).find('a.gs-title').each(function(){
+				//href= WDN.jQuery(this).attr('href');
+				WDN.jQuery(this).attr('href', function(i, val){
+					return 'http://m.unl.edu/?view=proxy&u='+val;
+				});
+			});
+		}
 		var nav = document.createElement("ul");
 		nav.className = "wdn_pagination";
 		var search_name = 'unl_search';
-- 
GitLab