Quantcast
Viewing all articles
Browse latest Browse all 21

SharePoint 2013 REST jQuery Slideshow

After the SharePoint 2010 Slideshow I searched for a better solution for SharePoint 2013. I found a lot of Slideshow solutions still using SOAP calls.

The better solution in this case (see announcement below) was creating a solution based on the new SharePoint 2013 REST API.

API sets

“Two API sets are still supported in the SharePoint 2013 framework for backward compatibility, but we recommend that you not use them for new projects: the ASP.NET (asmx) web services, and direct Remote Procedure Calls (RPC) calls to the owssvr.dll file”

With 3 simple steps and minimal code we can create a cool slider.

  • Create a Picture Library

    Create a SharePoint 2013 picture library and name it “Banners”

  • Add code

    Add the REST call and plugin code to your Page Layout

  • Customize

    Style/add content however you want!

This is the slider we want to go for, as seen on http://www.slidesjs.com

Image may be NSFW.
Clik here to view.

Take a look at the following demo:

OK, let’s start!

  • Create a Picture Library

    Create a SharePoint 2013 picture library and name it “Banners”

Add an app > Picture Library > Name it “Banners” > Add some images

The result should be the following:

Image may be NSFW.
Clik here to view.
  • Add code

    Add the REST call and plugin code to your Page Layout

First add the placeholder for the append images code

Image may be NSFW.
Clik here to view.

Now we can add the REST call to the “Banners” Picture Library and run the slidesjs plugin

Image may be NSFW.
Clik here to view.

Copy Paste :)

jQuery(document).ready(function() {
var basePath = "/_api/";
jQuery.ajax({
url: basePath + "lists/GetByTitle('Banners')/items?$select=EncodedAbsUrl,Title",
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {
//script to build UI HERE
jQuery.each(data.d.results, function (index, value) {
jQuery("#slides").append("<img src='" + value.EncodedAbsUrl + "'" + " alt='" + value.Title + "'/>");
});
jQuery(function () {
jQuery('#slides').slidesjs({
play: {
active: true,
auto: true,
interval: 5000,
swap: true
}
});
});
},
error: function (data) {
//output error HERE
alert(data.statusText);
}
});
});
Note

Make sure you download the jquery.slides.min.js from http://www.slidesjs.com or here and reference it before all the other code

Now,

  • Customize

    Style/add content however you want!

Good luck!


Viewing all articles
Browse latest Browse all 21

Trending Articles