/* Vboost widget ver. 1.04 07/07/2017 */ "use strict"; (function() { const ver = '1.05'; //const debug = true; const companyID = 543; const companyName = "Earnhardt Auto Centers"; const widgetHost = ''; const coverImage = "https://vboostlive.com/media/gallery/images/Earnhardt_Auto_Centers_-_header_2020.jpg"; const scriptMask = "script[src='https://vboostlive.com/widget/widget-088749aa-fe0f-413f-a78c-8035fd6b21a6.js']"; const staticPath = (typeof debug == 'undefined') ? "https://vboostlive.com/static/live/widget/" : "http://localhost/rm/home/vboost/vbo/live/static/live/widget/"; const staticSuffix = "?" + ver; const jQueryPath = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js" const widgetApiRootUrl = (typeof debug == 'undefined') ? "" : 'http://vboostoffice.criterion-dev.net/api/v1/live/'; const packagesAPI = 'https://vboostlive.com/api/v1/live/packages/'; const montageAPI = 'https://vboostlive.com/api/v1/live/montage/'; const pageLimit = 12; let curPage, overlayDiv, innerDiv; function pButton(symbol, display, toPage) { // display pagination button if (display == false) return ''; if (toPage != false) return ' ' + symbol + ''; return '' + symbol + ''; } function disableOverlay() { overlayDiv.hide(); innerDiv.css('opacity', 1); } const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; const monthNamesShort = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; function formatUTCTime(time) { time = new Date(time); let hours = time.getHours(); let pm = (hours >= 12); hours %= 12; if (hours == 0) hours = 12; return (monthNames[time.getMonth()] + ' ' + time.getDate() + ', ' + time.getFullYear() + ', ' + hours + ':' + (time.getMinutes()<10?'0':'') + time.getMinutes() + ' ' + (pm ? 'p.m.' : 'a.m.')); } function loadSidebar() { // get sidebar data from API $.ajax({ url: montageAPI + companyID + "/", type: "GET", crossDomain: true, success: function(data) { let html = ''; for (var i in data) { if (!data[i].image) continue; let d = data[i].date.split('-'); if (d.length == 3) data[i].date = monthNamesShort[parseInt(d[1]) - 1] + '. ' + d[2] + ', ' + d[0]; html += '' + '' + '' + data[i].date + '' + ((i > 0) ? '' : 'Monthly slide show') + '' + companyName + '' + '
' + '
'; } $('div.VboostWidget div.dynamicSidebar').html(html); }, error: function(){ alert('AJAX error geting data from montage API.'); } }); } function goToPage(ptr) { // CSS and jQuery are loaded curPage = ptr; overlayDiv.show(); innerDiv.css('opacity', 0.5); // prepare API parameters let url = packagesAPI + companyID + "/" + "?limit=" + pageLimit + "&offset=" + ((curPage - 1) * pageLimit); // get data from API $.ajax({ url: url, type: "GET", crossDomain: true, success: function(data) { let count = data.count || 0; let results = data.results || []; let html = ''; for (var i in results) { let res = results[i]; // ISO => March 14, 2017, 4:58 p.m. let time = formatUTCTime(res.last_mailed); html += '' + '' + '
' + time + '
' + '

Ask for: ' + res.contact + '' + '

' + '
'; } if (count) { // pagination let lastPage = parseInt((count + pageLimit - 1) / pageLimit); if (curPage > lastPage) curPage = lastPage; if (curPage < 1) curPage = 1; html += ''; } // update data $('div.VboostWidget div.cellContainer').html(html); disableOverlay(); // bink click let pagDiv = innerDiv.find('div.pagination'); pagDiv.find('span.link').click(function(e){ pagDiv.find('span.regular').removeClass('regular').addClass('ellipsis'); e = $(e.target); e.removeClass('link').addClass('regular'); $('html, body').animate({scrollTop:0}, 'slow'); goToPage(e.data('to')); }); }, error: function(){ disableOverlay(); alert('AJAX error geting data from packages API.'); } }); } function startWidget() { // CSS and jQuery are loaded // jQuery is ready now $.noConflict = true; let script = $(scriptMask); if (!script.length) { alert('Cannot find script by mask.'); return; } // create main
after self