Skip to content

Instantly share code, notes, and snippets.

@BigRaj
Created January 17, 2019 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRaj/d9eb15cb7711a8f2cca81238d44eb647 to your computer and use it in GitHub Desktop.
Save BigRaj/d9eb15cb7711a8f2cca81238d44eb647 to your computer and use it in GitHub Desktop.
Adds hotkeys for SharePoint Search: "Ctrl+Shift+F" and "F3"
/*
* Created by Rajiv Gomer
* Released under the MIT license
* Date: 2019-01-17
* Tested using SharePoint 2013 On-Prem
* Usage: 1. Add to MasterPage as site level custom action.
* 2. Activate Search by pressing "Ctrl+Shift+F" OR "F3"
* 3. Deactivate Search bar by clicking out of window or Escape key.
*/
var SPSearch = function(){
// GLOBAL VARIABLES
var dphsa = document.getElementById('DeltaPlaceHolderSearchArea');
var sib = document.getElementById('searchInputBox');
var smallsib = document.querySelector('#SearchBox > div[id*="PlaceHolderSearchArea_SmallSearchInputBox"]');
var sibinput = document.querySelector('div[id*="PlaceHolderSearchArea_SmallSearchInputBox"] > input');
var siba = document.querySelector('div[id*="PlaceHolderSearchArea_SmallSearchInputBox"] > a');
var carat = document.getElementById('Suite_ActiveLinkIndicator');
var pF = {
searchEnabled:false
};
// Apply styling for search transitions
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = ".dphsa,.sib{position:absolute !important}.dphsa{width:100% !important;height:100% !important;top:0 !important;left:0 !important;z-index:1000 !important;background-color:rgba(0,0,0,.7) !important;transition: background-color 0.3s !important}.sib{opacity:1 !important;background-color:#fff !important;top:50% !important;left:50% !important;transform:translateX(-25%) translateY(-25%) !important;width:25% !important}.smallsib{width:100% !important;border:none !important}.sibinput{width:93% !important;color:#777 !important}.siba{float:right !important;margin-left:-5px !important}.ui-accordion .ui-accordion-header{position:inherit !important}#s4-workspace{position:inherit !important}";
// intelshare specific styles
style.innerHTML = style.innerHTML + "#intelinkStandardHeader,#ishMenuBar{position:inherit !important}";
document.getElementsByTagName('head')[0].appendChild(style);
// Add elements for transition to dphsa
dphsa.style.backgroundColor = 'inherit';
dphsa.style.transition = 'background-color 1.5s';
dphsa.style.height = 'inherit';
dphsa.style.width = '260px';
var clickDisable = function(e){
if(e.target !== sibinput){
disableSearch();
}
}
var enableSearch = function(){
pF.searchEnabled = !pF.searchEnabled;
dphsa.classList.add('dphsa');
sib.classList.add('sib');
smallsib.classList.add('smallsib');
sibinput.classList.add('sibinput');
siba.classList.add('siba');
carat.style.display = 'none';
dphsa.addEventListener('click', clickDisable);
}
var disableSearch = function(){
pF.searchEnabled = !pF.searchEnabled;
dphsa.classList.remove('dphsa');
sib.classList.remove('sib');
smallsib.classList.remove('smallsib');
sibinput.classList.remove('sibinput');
siba.classList.remove('siba');
carat.style.display = 'inline-block';
dphsa.removeEventListener('click',clickDisable);
}
// REGISTER INITIAL SEARCH HOT KEYS
window.addEventListener("keydown",function (e) {
if (e.keyCode === 114 || (e.ctrlKey && e.shiftKey && e.keyCode === 70)) {
e.preventDefault();
enableSearch();
}
if ((e.keycode === 27 || e.keyCode === 114) && SPSearch.searchEnabled){
disableSearch();
}
});
return pF;
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment