Skip to content

Instantly share code, notes, and snippets.

@Sinetheta
Created May 16, 2012 17:28
Show Gist options
  • Save Sinetheta/2712413 to your computer and use it in GitHub Desktop.
Save Sinetheta/2712413 to your computer and use it in GitHub Desktop.
JS: jQuery Sharepoint search replacement
/**********************************************************************
OOTB Search control looks something like this:
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4"/>
</asp:ContentPlaceHolder>
We can replace it with either static inputs:
<div id="siteSearch" class="s4-notdlg noindex">
<select id="searchScope" class="ms-sbscopes">
<option selected="selected">Scope 1</option>
<option>Scope 2</option>
<option>Scope 3</option>
</select>
<input id="searchBox" type="text">
<a id="searchGo" href="#">Search</a>
</div>
Or you could grab the scopes dynamically with a SOAP service like GetPortalSearchInfo
https://github.com/Sinetheta/JS--SharePoint-web-services/blob/master/search/GetPortalSearchInfo.js
You will still need to include the "dud" search control somewhere in your master page though:
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
***********************************************************************/
(function($){
function search(){
var query = $('#searchBox').val(),
scope = $('#searchScope').val();
window.location = 'https://yourserver/SitePages/searchresults.aspx?k=' + query + '&s=' + scope;
};
$('#searchGo').on('click', search);
$('#searchBox').placeholder().keydown(function(e) {
var query = $(this).val(), scope;
if ((e.which=== 13) && (query !== '')) {
search();
}
})
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment