Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Created February 2, 2014 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirontoli/8766065 to your computer and use it in GitHub Desktop.
Save mirontoli/8766065 to your computer and use it in GitHub Desktop.
This is a workaround for search center refinements in SharePoint 2013. The bug is that the search center takes the browser language, instead of the default language of the SharePoint farm.
//This is a workaround for search language. Please remove this after the August Patch has been installed (SharePoint 2013, 2013 CU)
//A control for changing the language adds a url fragment: #l=1033 (for English)
// bug #2319
(function() {
var href = window.location.href;
var url = window._tpContextInfo.SearchCenterUrl;
var searchCenter = href.indexOf(url + "/results.aspx") === 0 || href.indexOf(url + "/peopleresults.aspx") === 0;
if (searchCenter) {
var hash = window.location.hash;
var langRegexPattern = "#l=\\d{4}";
var langRegex = new RegExp(langRegexPattern);
var englishRegexPattern = "#l=1033";
var englishRegex = new RegExp(englishRegexPattern);
var hasLangHash = langRegex.test(hash);
var hasEnglishHash = englishRegex.test(hash);
if (!hasLangHash) {
window.location.hash += englishRegexPattern;
} else if (!hasEnglishHash) {
window.location.hash = hash.replace(langRegex, englishRegexPattern);
}
var getParameter = function(key) {
function parseParams() {
var params = {},
e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function(s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);
while (e = r.exec(q))
params[d(e[1])] = d(e[2]);
return params;
}
if (!this.queryStringParams)
this.queryStringParams = parseParams();
return this.queryStringParams[key];
};
//adjust the query string keyword ?k= Copy it to the hash
// if there
if (/k=/.test(window.location.search) && !/#k=/.test(hash)) {
var value = getParameter("k");
window.location.hash += "#k=" + value;
}
}
});//decided not to implement this fix//();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment