/*
Vboost widget
ver. 1.04
07/07/2017
*/
"use strict";
(function() {
const ver = '1.05';
//const debug = true;
const companyID = 588;
const companyName = "Lindsay Ford of Wheaton";
const widgetHost = '';
const coverImage = "https://vboostlive.com/media/gallery/images/Lindsay_Ford_-_header.jpg";
const scriptMask = "script[src='https://vboostlive.com/widget/widget-12e7dfb3-07ab-4183-98f1-7378ed7221a8.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 += '