{"id":1207,"date":"2014-04-08T21:03:26","date_gmt":"2014-04-09T04:03:26","guid":{"rendered":"https:\/\/mmman.itgroove.net\/?p=1207"},"modified":"2023-02-24T21:48:32","modified_gmt":"2023-02-24T21:48:32","slug":"an-alternative-photo-rotator-solution","status":"publish","type":"post","link":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/","title":{"rendered":"An Alternative Photo Rotator Solution"},"content":{"rendered":"<p>A customer of ours had an issue with the out of the box photo rotator in SharePoint \u2013 every few minutes it kept prompting them for credentials.&nbsp; After some inspection, I noticed that pretty much every rotator solution would always change the image by swapping between two &lt;img&gt; elements, and changing the URL of the one not currently in focus.&nbsp; As this was ultimately causing the browser to fetch new content every few seconds, I decided to write my own rotator which instead does a one time pull of all the images, and iterates between the collection.<\/p>\n<p>Many thanks to Bill Simser for much of the code for querying the lists in this article <a href=\"http:\/\/weblogs.asp.net\/bsimser\/archive\/2011\/09\/10\/jquery-sharepoint-picture-libraries-and-automatic-thumbnails.aspx\">here<\/a>.<\/p>\n<p>First off, get a copy of a jQuery library and store it somewhere on your site.&nbsp; Next, create a picture library, and name it \u201cRotator Images\u201d.&nbsp; <\/p>\n<p>After you\u2019ve got those in place, put this code into a content editor (using edit HTML source), and your rotator should come alive.<\/p>\n<p>Here\u2019s the code, enjoy!<\/p>\n<p>\n[code language=&#8221;html&#8221;]<br \/>\n&lt;div id=&quot;RotatorCont&quot;&gt;&lt;\/div&gt;<br \/>\n&lt;style type=&quot;text\/css&quot;&gt;<br \/>\n.pictureWrapperDiv<br \/>\n{<br \/>\n\tmargin: 0px;<br \/>\n\tpadding: 0px;<br \/>\n\tborder: 0px;<br \/>\n}<br \/>\n.pictureGallery<br \/>\n{<br \/>\n\tmargin: 0px;<br \/>\n\tpadding: 0px;<br \/>\n\tborder: 0px;<br \/>\n}<br \/>\n&lt;\/style&gt;<\/p>\n<p>&lt;script type=&quot;text\/javascript&quot; src=&quot;\/Style%20Library\/Branding\/Scripts\/jQuery-1.7.1.js&quot;&gt;&lt;\/script&gt;<br \/>\n&lt;script type=&quot;text\/javascript&quot;&gt;<\/p>\n<p>\/\/Globals for # of secs between images, max width and height, and the name of the picture library (must be local to this web site)<br \/>\n\/\/You can modify these as necessary<br \/>\nvar itgLoadTimeSecs = 8;<br \/>\nvar itgImgHeight = 296;<br \/>\nvar itgImgWidth = 390;<br \/>\nvar itgRotatorLibraryTitle = &quot;Rotator Images&quot;;<\/p>\n<p>\/\/Globals for internal use only (don&#8217;t change these)<br \/>\nvar itgImgRotCount = 0;<br \/>\nvar itgImgRotIter = 0;<br \/>\nvar picid = &quot;itgDynaImg&quot;;<br \/>\nvar itgLoadTime = itgLoadTimeSecs * 1000;<\/p>\n<p>$(document).ready(function(){<br \/>\n    \/\/start your engines<br \/>\n\tpageonload();<\/p>\n<p>\t\/\/Set a slight delay before kicking off the query (just for good measure)<br \/>\n\tsetTimeout(loadSharePointPictures, 250);<br \/>\n});<\/p>\n<p>function pageonload()<br \/>\n{<br \/>\n\tvar rota = $(&quot;#RotatorCont&quot;);<br \/>\n\trota.css(&quot;display&quot;, &quot;inline-block&quot;);<br \/>\n}<\/p>\n<p>function loadSharePointPictures()<br \/>\n{<br \/>\n\t\/\/fetch the list of items using the client object model<br \/>\n\tvar context = new SP.ClientContext.get_current();<\/p>\n<p>\t\/\/get the current website<br \/>\n\tvar web = context.get_web();<\/p>\n<p>\t\/\/get the pictures list<br \/>\n\tvar list = web.get_lists().getByTitle(itgRotatorLibraryTitle);<\/p>\n<p>\t\/\/create the query to get all items<br \/>\n\tvar query = SP.CamlQuery.createAllItemsQuery();<\/p>\n<p>\t\/\/get all items from the query<br \/>\n\tpictures = list.getItems(query);<\/p>\n<p>\t\/\/load the context<br \/>\n\tcontext.load(pictures, &#8216;Include(FileLeafRef,FileDirRef)&#8217;);<\/p>\n<p>\t\/\/execute the query in async mode<br \/>\n\tcontext.executeQueryAsync(<br \/>\n\t\tFunction.createDelegate(this, this.success),<br \/>\n\t\tFunction.createDelegate(this, this.failed)<br \/>\n\t);<br \/>\n}<\/p>\n<p>function success(sender, args)<br \/>\n{<br \/>\n    pictureArray = new Array();<br \/>\n    var pictureCount = 0;<\/p>\n<p>\t\/\/pull the details about each image (directory and filename) out of the result<br \/>\n    var enumerator = this.pictures.getEnumerator();<br \/>\n    while(enumerator.moveNext())<br \/>\n\t{<br \/>\n        var currentItem = enumerator.get_current();<br \/>\n        var filename = currentItem.get_item(&#8216;FileLeafRef&#8217;);<br \/>\n        var dir = currentItem.get_item(&#8216;FileDirRef&#8217;);<br \/>\n        filename = dir + &#8216;\/&#8217; + filename;<br \/>\n        pictureArray[pictureCount++] = filename;<br \/>\n    }<br \/>\n    var newHtml = &#8221;;<\/p>\n<p>\t\/\/set the first image to display<br \/>\n\tvar itgdispval = &quot;block&quot;;<\/p>\n<p>\t\/\/iterate through the result and create HTML code (img with div wrapper) for each picture<br \/>\n    for(var i = 0; i &lt; this.pictureArray.length; i++)<br \/>\n\t{<br \/>\n\t\tif (i &gt; 0)<br \/>\n\t\t{<br \/>\n\t\t\t\/\/set all the additional images to hidden<br \/>\n\t\t\titgdispval = &quot;none&quot;;<br \/>\n\t\t}<br \/>\n        newHtml += &#8216;&lt;div id=&quot;&#8217; + picid + i.toString() + &#8216;&quot; class=&quot;pictureWrapperDiv&quot; style=&quot;height: &#8216; + itgImgHeight + &#8216;px; max-height: &#8216; + itgImgHeight + &#8216;px; width: &#8216; + itgImgWidth + &#8216;px; max-width: &#8216; + itgImgWidth + &#8216;px; display: &#8216; + itgdispval + &#8216;;&quot;&gt;&lt;img class=&quot;pictureGallery&quot; src=&quot;&#8217;;<br \/>\n        newHtml += this.pictureArray[i];<br \/>\n        newHtml += &#8216;&quot; style=&quot;max-height: &#8216; + itgImgHeight + &#8216;px; max-width: &#8216; + itgImgWidth + &#8216;px;&quot;\/&gt;&lt;\/div&gt;&#8217;;<br \/>\n    }<br \/>\n\t\/\/store the number of images<br \/>\n\titgImgRotCount = i;<\/p>\n<p>\t\/\/start the iterator<br \/>\n\titgImgRotIter++;<\/p>\n<p>\t\/\/assign the HTML to the rotator container<br \/>\n    $(&#8216;#RotatorCont&#8217;).html(newHtml);<\/p>\n<p>\t\/\/start the rotator<br \/>\n\tsetTimeout(itgRotateImg, itgLoadTime);<br \/>\n}<\/p>\n<p>function failed(sender, args)<br \/>\n{<br \/>\n\t\/\/alert(&quot;Failure: [&quot; + sender + &quot;] \/ [&quot; + args + &quot;]&quot;);<br \/>\n}<\/p>\n<p>function itgRotateImg()<br \/>\n{<br \/>\n\tvar dynapicid = picid + itgImgRotIter.toString();<br \/>\n\tvar dynalast = 0;<br \/>\n\tif ((itgImgRotCount &gt; 0) &amp;&amp; (itgImgRotIter == 0))<br \/>\n\t{<br \/>\n\t\tdynalast = itgImgRotCount &#8211; 1;<br \/>\n\t}<br \/>\n\telse<br \/>\n\t{<br \/>\n\t\tdynalast = itgImgRotIter &#8211; 1;<br \/>\n\t}<br \/>\n\tvar dynapicidlast = picid + dynalast.toString();<\/p>\n<p>\t\/\/hide the last image to be displayed<br \/>\n\t$(&#8216;#&#8217; + dynapicidlast).css(&quot;display&quot;, &quot;none&quot;);<\/p>\n<p>\t\/\/show (fade in) the next image<br \/>\n\t$(&#8216;#&#8217; + dynapicid).fadeIn(400);<br \/>\n\tif ((itgImgRotIter + 1) &lt; itgImgRotCount)<br \/>\n\t{<br \/>\n\t\titgImgRotIter++;<br \/>\n\t}<br \/>\n\telse<br \/>\n\t{<br \/>\n\t\titgImgRotIter = 0;<br \/>\n\t}<br \/>\n\tsetTimeout(itgRotateImg, itgLoadTime);<br \/>\n}<br \/>\n&lt;\/script&gt;<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer of ours had an issue with the out of the box photo rotator in SharePoint \u2013 every few minutes it kept prompting them for credentials.&nbsp; After some inspection, I noticed that pretty much every rotator solution would always change the image by swapping between two &lt;img&gt; elements, and changing the URL of the &hellip; <a href=\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/\"><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[4,7],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>An Alternative Photo Rotator Solution - Archive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Alternative Photo Rotator Solution - Archive\" \/>\n<meta property=\"og:description\" content=\"A customer of ours had an issue with the out of the box photo rotator in SharePoint \u2013 every few minutes it kept prompting them for credentials.&nbsp; After some inspection, I noticed that pretty much every rotator solution would always change the image by swapping between two &lt;img&gt; elements, and changing the URL of the &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/\" \/>\n<meta property=\"og:site_name\" content=\"Archive\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-09T04:03:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-24T21:48:32+00:00\" \/>\n<meta name=\"author\" content=\"Colin Phillips (Alumni)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Colin Phillips (Alumni)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/\",\"url\":\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/\",\"name\":\"An Alternative Photo Rotator Solution - Archive\",\"isPartOf\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#website\"},\"datePublished\":\"2014-04-09T04:03:26+00:00\",\"dateModified\":\"2023-02-24T21:48:32+00:00\",\"author\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\"},\"breadcrumb\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog Archive\",\"item\":\"https:\/\/regroove.ca\/archive\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"An Alternative Photo Rotator Solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/regroove.ca\/archive\/#website\",\"url\":\"https:\/\/regroove.ca\/archive\/\",\"name\":\"Archive\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/regroove.ca\/archive\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\",\"name\":\"Colin Phillips (Alumni)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"caption\":\"Colin Phillips (Alumni)\"},\"url\":\"https:\/\/regroove.ca\/archive\/author\/cphillips\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An Alternative Photo Rotator Solution - Archive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/","og_locale":"en_US","og_type":"article","og_title":"An Alternative Photo Rotator Solution - Archive","og_description":"A customer of ours had an issue with the out of the box photo rotator in SharePoint \u2013 every few minutes it kept prompting them for credentials.&nbsp; After some inspection, I noticed that pretty much every rotator solution would always change the image by swapping between two &lt;img&gt; elements, and changing the URL of the &hellip;","og_url":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/","og_site_name":"Archive","article_published_time":"2014-04-09T04:03:26+00:00","article_modified_time":"2023-02-24T21:48:32+00:00","author":"Colin Phillips (Alumni)","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Colin Phillips (Alumni)","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/","url":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/","name":"An Alternative Photo Rotator Solution - Archive","isPartOf":{"@id":"https:\/\/regroove.ca\/archive\/#website"},"datePublished":"2014-04-09T04:03:26+00:00","dateModified":"2023-02-24T21:48:32+00:00","author":{"@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b"},"breadcrumb":{"@id":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/regroove.ca\/archive\/2014\/04\/08\/an-alternative-photo-rotator-solution\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Archive","item":"https:\/\/regroove.ca\/archive\/"},{"@type":"ListItem","position":2,"name":"An Alternative Photo Rotator Solution"}]},{"@type":"WebSite","@id":"https:\/\/regroove.ca\/archive\/#website","url":"https:\/\/regroove.ca\/archive\/","name":"Archive","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/regroove.ca\/archive\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b","name":"Colin Phillips (Alumni)","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","caption":"Colin Phillips (Alumni)"},"url":"https:\/\/regroove.ca\/archive\/author\/cphillips\/"}]}},"_links":{"self":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1207"}],"collection":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/comments?post=1207"}],"version-history":[{"count":1,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1879,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1207\/revisions\/1879"}],"wp:attachment":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/media?parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/categories?post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/tags?post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}