Steps To Create Custom Callouts In SharePoint 2013

Introduction

SharePoint 2013 has introduced a new framework to create Callouts that are displayed only for specific Lists and Libraries. Callouts provide a rich and lightweight detailed experience for the users to displays a limited and important information about an item. Callout was not present in earlier versions of SharePoint. In this article, I will explain how to create custom Callouts in SharePoint 2013.

Pre-Requisites

  1. Go to SharePoint 2013 Central Administration site.

  2. Create new publishing portal site collection.

    collection

  3. Go the Site Action -> Site Settings -> “Manage site features” under Site Actions.
    collection
  4. Activate “Team Collaboration Lists” feature.

    collection

  5. Go the Site Action -> Site Content -> Add an App.

    collection
  6. Add new announcement list named as “MyAnnouncements” and add some announcement in it for adding the Callouts for this list.

    collection

  7. Add items to the announcement list.

    collection

Points to remember about CallOut

  1. JavaScript file named “CallOut.js” was added in 15 hive folder, located in C:\Program Files\Common Files\Microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS.

    collection

  2. Callout.js contains all the methods and classes for creating callout popup. Make sure this file is loaded on the page before calling Callout popup.
    1. SP.SOD.executeFunc(“callout.js”, “CalloutFunction”, function () {   
    2. });   
  3. Callout.js not present in early versions of SharePoint.

  4. External content will not be displayed in the callout.

  5. Callout popups are displayed by default for Lists & Libraries like page library, document library, image library, etc.
    collection
  6. Calendar, Announcement, Discussion and custom list does not display the callout by default.

  7. To change the appearance of the existing callout in lists and library, by changing the respective search callout display template “Item_Word_HoverPanel.html”.

    collection

    collection

  8. The property “beakOrientation” needs to be set for callout popups can be displayed in either “Top to Bottom (topBottom)” or “Left to Right (leftRight)” direction.

Create Custom CallOut

  1. Open SharePoint publishing site that we created.

  2. Go to page library and create new blank web part page.

    collection
  3. Edit the newly created page and add the script editor webpart.

    collection

  4. Click on “Edit Snippet” in the script editor webpart.

    collection

  5. "Embed" popup appears for the script editor webpart.

    collection

  6. Add the following code snippet to get the Callout for announcement “MyAnnouncements” list.

    collection
    1. <script src="/_layouts/15/callout.js" type="text/javascript"></script>  
    2.   
    3. <script type="text/javascript">  
    4.     SP.SOD.executeFunc("callout.js""Callout"function()  
    5.   
    6.         {  
    7.   
    8.             var Url = "http://siteURL/sites/Ramesh/_vti_bin/ListData.svc/MyAnnouncements";  
    9.   
    10.             var request = new Sys.Net.WebRequest();  
    11.   
    12.             request.set_httpVerb("GET");  
    13.   
    14.             request.set_url(Url);  
    15.   
    16.             request.get_headers()["Accept"] = "application/json";  
    17.   
    18.             request.add_completed(onSuccessFunction);  
    19.   
    20.             request.invoke();  
    21.   
    22.         });  
    23.   
    24.     function onSuccessFunction(response, eventArgs) {  
    25.         var announcements = eval("(" + response.get_responseData() + ")");  
    26.   
    27.         var newAnnouncement = document.createElement("div");  
    28.   
    29.         for (var i = 0; i < announcements.d.results.length; i++) {  
    30.   
    31.             announTitle = announcements.d.results[i].Title;  
    32.   
    33.             _announID = announcements.d.results[i].Id;  
    34.   
    35.             _announBody = announcements.d.results[i].Body;  
    36.   
    37.             anniDiv.appendChild(newAnnouncement);  
    38.   
    39.             var calloutLink = document.createElement("div");  
    40.   
    41.             calloutLink.id = _announID;  
    42.   
    43.             calloutLink.onmouseover = function() {  
    44.   
    45.                 curListUrl = this.id;  
    46.   
    47.             }  
    48.   
    49.             calloutLink.innerHTML = "<div class=\"ms-commandLink\" style=\"text-align: left;font-size: 14px;\"><b>" + _announTitle + "</b><br/><br/></div>";  
    50.   
    51.             anniDiv.appendChild(calloutLink);  
    52.   
    53.             var listCallout = CalloutManager.createNew({  
    54.   
    55.                 launchPoint: calloutLink,  
    56.   
    57.                 beakOrientation: "leftRight",  
    58.   
    59.                 ID: _announID,  
    60.   
    61.                 title: _announTitle,  
    62.   
    63.                 content: "<div class=\"ms-soften\" style=\"margin-top:13px;\">"  
    64.   
    65.                     +  
    66.                     "<hr/></div>"  
    67.   
    68.                     +  
    69.                     "<div class=\"callout-section\" style=\"margin-top:13px;\">" + _announBody + "</div>",  
    70.   
    71.             });  
    72.   
    73.         }  
    74.   
    75.     }  
    76.   
    77.     /script>   
    78.   
    79.     <  
    80.     div id = "anniDiv" > < /div>  
  7. CalloutManager.createNew function will create the new callout popup.

  8. Parameter set for the above function, is as follows.

    • launchPoint: calloutLink It will set where callout should come.
    • beakOrientation: "leftRight" It will set which direction callout should come.
    • ID: announID ID of callout popup.
    • title: announTitle Title for callout popup.
    • Content What content should add to the popup.

  9. The above script will fetch the “MyAnnouncements” list item and add the page with callout.

  10. Save and publish the page.

    collection

  11. Callout comes on hovering over the announcement title.

    collection

Summary

Thus, you have learned how to create custom Callout in SharePoint 2013.