Check out the whole SharePoint 2013 Solution Series
New Titles Added Weekly!
In my previous post on Enhancing Video Results, I demonstrated how to display Video results in a horizontal fashion using the out-of-the-box Video horizontal template. However, this display does not incorporate a hover panel and thus nothing pops up when mousing over the results. No problem. I figured out how to add a hover panel to the template in just a few easy steps.
First, navigate to the Search Center display templates via SharePoint Designer 2013, similiar to the process explained in this post. For simplicity I am going to modify the display template file in-place but the recommended approach would be to make a copy and use that.
Locate the Item_Video_CompactHorizontal.html file, right-click, and select Edit File in Advanced Mode:
Paste this code at the top as shown in the image below:
var id = ctx.ClientControl.get_nextUniqueId();
var itemId = id + Srch.U.Ids.item;
var hoverId = id + Srch.U.Ids.hover;
var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Video_HoverPanel.js";
$setResultItem(itemId, ctx.CurrentItem);
ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
var itemId = id + Srch.U.Ids.item;
var hoverId = id + Srch.U.Ids.hover;
var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Video_HoverPanel.js";
$setResultItem(itemId, ctx.CurrentItem);
ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
Notice I am using the out-of-the-box Item_Video_HoverPanel .
Next, scroll down to the main <div> and change the id to use _#= $htmlEncode(itemId) =#_
![]() |
| (Click on image to display larger) |
onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_"
onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_"
![]() |
| (Click on image for larger view) |
Now add the following <div> after the first <div>:
<div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
Save the changes to the template. Navigate to your Search Center and perform a search that returns Video results:
Hovering over the results shows the hover panel preview!!!





























