Created
February 22, 2011 01:29
-
-
Save mrclay/838059 to your computer and use it in GitHub Desktop.
Workaround for Google Custom Search on HTTPS to avoid mixed content warning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copied from: https://www.google.com/cse/brand?form=cse-search-box&lang=en | |
and patched to be HTTPS-friendly. | |
Bug: http://www.google.com/support/forum/p/customsearch/thread?tid=1bf2598a30df483f&hl=en | |
*/ | |
(function() { | |
// copy this from your branding URL (e.g. &lang=en) | |
var lang = "en"; | |
var f = document.getElementById("cse-search-box"); | |
if(!f) { | |
f = document.getElementById("searchbox_demo") | |
} | |
if(f && f.q) { | |
var q = f.q; | |
var n = navigator; | |
var l = location; | |
var su = function() { | |
var u = document.createElement("input"); | |
var v = document.location.toString(); | |
var existingSiteurl = /(?:[?&]siteurl=)([^&#]*)/.exec(v); | |
if(existingSiteurl) { | |
v = decodeURI(existingSiteurl[1]) | |
} | |
var delimIndex = v.indexOf("://"); | |
if(delimIndex >= 0) { | |
v = v.substring(delimIndex + "://".length, v.length) | |
} | |
u.name = "siteurl"; | |
u.value = v; | |
u.type = "hidden"; | |
f.appendChild(u) | |
}; | |
/* | |
// not necessary | |
if(n.appName == "Microsoft Internet Explorer") { | |
var s = f.parentNode.childNodes; | |
for(var i = 0;i < s.length;i++) { | |
if(s[i].nodeName == "SCRIPT" && s[i].attributes["src"] && s[i].attributes["src"].nodeValue == unescape("http://www.google.com/cse/brand?form=cse-search-box&lang=en")) { | |
su(); | |
break | |
} | |
} | |
}else {*/ | |
su(); | |
//} | |
if(n.platform == "Win32") { | |
q.style.cssText = "border: 1px solid #7e9db9; padding: 2px;" | |
} | |
if(window.history.navigationMode) { | |
window.history.navigationMode = "compatible" | |
} | |
var b = function() { | |
if(q.value == "") { | |
var ga = ("https:" == document.location.protocol ? "https://" : "http://") + "www.google.com/cse/intl/" + lang + "/images/google_custom_search_watermark.gif"; | |
q.style.background = "#FFFFFF url(" + ga + ") left no-repeat" | |
} | |
}; | |
var f = function() { | |
q.style.background = "#ffffff" | |
}; | |
q.onfocus = f; | |
q.onblur = b; | |
if(!/[&?]q=[^&]/.test(l.search)) { | |
b() | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment