/*
Vboost widget
ver. 1.04
07/07/2017
*/
"use strict";
(function() {
const ver = '1.05';
//const debug = true;
const companyID = 675;
const companyName = "Coastal Chevrolet";
const widgetHost = '';
const coverImage = "https://vboostlive.com/media/gallery/images/Coastal_Chevrolet_-_header.png";
const scriptMask = "script[src='https://vboostlive.com/widget/widget-e16c46ad-5328-4007-83b4-a83530f294de.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 +=
''
+ ''
+ '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 += '