PageSourceSearch

https://www.gatewayfarmexpo.org/Events/JS/widgets/rotatingContent.js?sv=8.6.3

js gatewayfarmexpo.org collected 2026-10-05 09:47:49 UTC 8,936 bytes, 253 lines download raw bytes

1/*Rotating Content Widget*/
2
3
4(function ($) {
5
6    //Data service for the widget
7    function widgetDataService() {
8
9        this.getWidgetData = function (servicePath, widgetModuleItemID, successCallback, errorCallback) {
10            $.ajax({
11                type: "POST",
12                url: servicePath,
13                data: "{'widgetModuleItemID':" + widgetModuleItemID + "}",
14                contentType: "application/json; charset=utf-8",
15                dataType: "json",
16                success: successCallback,
17                error: errorCallback
18            });
19        };
20    };
21
22    //Global variable for the widget function
23    var widgetModuleItemID = 0;
24    var widgetData = null;
25
26    var hnm = location.hostname;
27    hnm = hnm.replace('www.', '');
28    var detectIpad = false;
29    var imageWidth, imageHeight, showItems, timing;
30    var randomize = false;
31    var rotatingContentLoaded = function(){};
32    var hasImages = true;
33    var beforeChange = function(){};
34    var afterChange = function(){};
35    var delayBeforeChange = 0;
36    var showDescription = false;
37    var tracking = {
38      present: false,
39      event: '',
40      gaObj: {
41        eventCategory: '',
42        eventAction: '',
43        eventLabel: '',
44        eventValue: ''
45      }
46    };
47
48
49
50    //Constructor for the wiget
51    $.fn.rotatingContent = function (options) {
52
53        var opts = $.extend({}, $.fn.rotatingContent.defaultOptions, options);
54
55        widgetContainer = this;
56        widgetModuleItemID = opts.currentWidgetModuleItemID;
57        imageWidth = opts.imageWidth;
58        imageHeight = opts.imageHeight;
59        showItems = opts.showItems;
60        timing = opts.timing;
61        randomize = opts.randomize;
62        rotatingContentLoaded = opts.rotatingContentLoaded;
63        hasImages = opts.hasImages;
64        beforeChange = opts.beforeChange;
65        afterChange = opts.afterChange;
66        delayBeforeChange = opts.delayBeforeChange;
67        showDescription = opts.showDescription;
68        imageIsBackground = opts.imageIsBackground;
69        tracking = opts.tracking;
70
71
72        var widgetDataAdapter = new widgetDataService();
73
74        widgetDataAdapter.getWidgetData(opts.scriptPath, opts.currentWidgetModuleItemID, getWidgetDataSuccess, getWidgetDataError);
75
76    };
77
78    //Default options for the constructor to be merged with send constructor data
79    $.fn.rotatingContent.defaultOptions = {
80        scriptPath: "services/eventsservice.asmx"
81        , currentWidgetModuleItemID: 0
82        , imageWidth: 250
83        , imageHeight: 250
84        , showItems: 4
85        , timing: 5000
86        , randomize: false
87        , rotatingContentLoaded: function(){}
88        , hasImages: true
89        , beforeChange: function(){}
90        , afterChange: function(){}
91        , delayBeforeChange: 0
92        , showDescription: false
93        , imageIsBackground: false
94        , tracking: {
95          present: false,
96          event: '',
97          gaObj: {
98            eventCategory: '',
99            eventAction: '',
100            eventLabel: '',
101            eventValue: ''
102          }
103        }
104    };
105
106    //service call worked
107    var getWidgetDataSuccess = function (data) {
108
109        widgetData = data.d;
110        initialize();
111
112            rotatingContentLoaded();
113    };
114
115
116
117
118    //service call has failed
119    var getWidgetDataError = function (data) {
120
121        console.log('Rotating Content failed to load'
122        , '\n' + 'Status: ' + data.status + ' ' + data.statusText
123        , '\n' + data.responseText);
124    };
125
126
127    //set up the ui
128    function initialize() {
129
130            var widgetArray = [];
131            var i = 0;
132            var hasSlides = widgetData.Slides.length;
133
134            if(hasSlides){
135                $('body').addClass('rotatingContentHasSlides');
136            } else {
137                $('body').addClass('rotatingContentDoesNotHaveSlides');
138            }
139
140            $(widgetData.Slides).each(function(){
141                var itemStyle;
142                var gA;
143                var target = widgetData.Slides[i].URLOpenInANewWindow;
144                if(target == true){
145                    target = ' target="_blank"';
146                } else {
147                    target = '';
148                }
149                var description = '';
150                if(showDescription){
151                    description = '<span class="rotatingContentDescription">'+widgetData.Slides[i].Description+'</span>'
152                }
153
154                var link = widgetData.Slides[i].URL;
155                if(link == '' || link == undefined || link == null){
156                    link = 'javascript:void(0)';
157                    itemStyle = ' style="cursor:default;"'
158                } else {
159                    itemStyle = '';
160                }
161                var imagePath = widgetData.Slides[i].ImageWithPath;
162                // convert image links to SSL if the page is encrypted
163      					PAGESSL ? convertSources() : null;
164      					function convertSources() {
165      						if(imagePath) {
166      							var makeHTTPS = imagePath.replace(/^http:\/\//i, 'https://');
167      							imagePath = makeHTTPS;
168      						}
169      		      }
170                var title = widgetData.Slides[i].Title;
171                if (tracking.present) {
172                  tracking.gaObj.eventLabel = title;
173                  var str = JSON.stringify(tracking.gaObj).replace(/"/g, '\'');
174                  gA = 'onclick="ga(\'send\', \'' + tracking.event + '\', ' + str + ')"'
175                } else {
176                  gA = '';
177                }
178
179                var imageAlternateText = "";
180
181                if (widgetData.Slides[i].ImageAlternateText != null) {
182                    imageAlternateText = (widgetData.Slides[i].ImageAlternateText);
183                }
184
185
186                if(hasImages){
187                    if (imageIsBackground) {
188                        widgetArray.push('<a href="'+link+'"'+itemStyle+''+target+' class="rotatingContentWidgetItem'+i+'" ' + gA + 'data-title="'+title+'"><div class="image-container" style="background-image:url('+ imagePath +');"><span class="rotatingContentTitle">'+title+'</span>'+description+'</div></a>');
189                    } else {
190                        widgetArray.push('<a href="' + link + '"' + itemStyle + '' + target + ' class="rotatingContentWidgetItem' + i + '" ' + gA + 'data-title="' + title + '"><img src="' + imagePath + '&w=' + imageWidth + '&h=' + imageHeight + '" alt="' + imageAlternateText + '" /></a>');
191                    }
192                } else {
193                    widgetArray.push('<a href="'+link+'"'+itemStyle+''+target+' class="rotatingContentWidgetItem'+i+'" ' + gA + 'data-title="'+title+'"><span class="rotatingContentTitle">'+title+'</span>'+description+'</a>');
194                }
195
196                i++;
197
198            });
199
200            if(randomize){
201                function shuffle(o){
202                    for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
203                    return o;
204                };
205                widgetArray = shuffle(widgetArray);
206            }
207
208            i = 0;
209
210            //first set of items
211            for(i=showItems; i>0; i--){
212                var num = i-1;
213                var checkNum = widgetArray[num];
214                if(checkNum != undefined){
215                    $('#rotatingContentWidget').prepend('<div class="rotatingContentWidgetItemContainer rotatingContentWidgetItemContainer'+i+'">'+widgetArray[num]+'</div>');
216                }
217            }
218
219            if(timing > 0){
220                var nextItem = showItems;
221                var switchItem = 1;
222                // rotate in further items
223                if(widgetData.Slides.length > showItems){
224                    var tempInt = setInterval(function(){
225                        beforeChange();
226                        setTimeout(function(){
227                            $('.rotatingContentWidgetItemContainer'+switchItem).html('');
228                            $('.rotatingContentWidgetItemContainer'+switchItem).html(widgetArray[nextItem]);
229
230                            if(switchItem >= showItems){
231                                switchItem = 1;
232                            } else {
233                                switchItem++;
234                            }
235
236                            if(nextItem >= (widgetData.Slides.length-1)){
237                                nextItem = 0;
238                            } else {
239                                nextItem++;
240                            }
241
242                            afterChange();
243                        }, delayBeforeChange);
244
245                    }, timing);
246                }
247            }
248
249
250
251    }
252
253})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.