function clxReviewWidget(v) {
this.c = document.getElementById('clx_rev_url');
if (this.c === null)
return false;
this.options = {
headline: 'CYLEX Reviews',
borderColor: '#2d7681',
backgroundColor: '#FFF',
textColor: '#000',
showAvatar: true,
showStars: true,
showUsername: true,
showAskReview: true,
showRichSearchResults: true,
lkz: 'd',
fir_nr: 0,
city: '',
interval: 5000,
speed: 500,
domain: '',
language: ''
};
inst = this;
this.item = -1;
this.clx_review_text = '';
this.head = document.getElementsByTagName("head")[0];
this.options = this.mergeDefaults(v);
this.start();
}
clxReviewWidget.prototype = {
start: function () {
this.injectCss();
this.injectCss1();
this.applyConfig();
this.getReviews();
},
mergeDefaults: function (c) {
c.merge = function (k, dV) {
if (typeof (k) === 'undefined') c[x] = dV;
};
for (var x in this.options) {
c.merge(c[x], this.options[x]);
}
return c;
},
getReviews: function () {
//add review widget
js = document.createElement('script');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', this.options.domain.replace('fr.', '') + '/js/globalVariables.' + this.options.language + '.js');
this.head.appendChild(js);
//--
js = document.createElement('script');
js.setAttribute('type', 'text/javascript');
var isFromSS = 'false';
if (typeof clxprevWidget !== 'undefined' || (typeof clxprevWidget !== 'undefined' && clxprevWidget === null))
isFromSS = 'true';
if (this.options.fir_nr > 0) {
var refURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
js.setAttribute('src', this.options.domain.replace('fr.', '') + '/ReviewsWidget/reviewsinfo.aspx?d=' + this.options.domain.replace('http://admin.', '').replace('https://admin.', '') + '&lkz=' + this.options.lkz + '&fir_nr=' + this.options.fir_nr + '&from_ss=' + isFromSS + '&widgetref=' + encodeURIComponent(refURL));
}
this.head.appendChild(js);
js.onreadystatechange = function () {
if (js.readyState === 'complete' || js.readyState === 'loaded') {
inst.clxWriteReviews();
}
};
js.onload = function () {
inst.clxWriteReviews();
};
},
next: function () {
this.item++;
if (this.item >= this.dN.length)
this.item = 0;
var showNegs=true;
//if (typeof clxprevWidget !== 'undefined'&& clxprevWidget!=null) {
// showNegs = clxprevWidget.options.showNegativs;
//} else {
// showNegs = this.options.showNegativs;
//}
while (this.item < this.dN.length && !showNegs && this.dN[this.item].className === "clx_rev_element") {
this.item++;
}
if (this.dN[this.item]) {
this.cH = this.dN[this.item].offsetHeight;
this.cT = parseInt(this.options.speed / this.cH);
this.slide(0);
aktiv = window.setInterval("inst.slide(inst.x)", inst.cT);
}
},
slide: function (x) {
this.x = x;
if (x < this.cH) {
this.x = this.x + 2;
this.dN[this.item].style.marginTop = -x + 'px';
} else {
inst.dN2.appendChild(this.dN[this.item]);
this.dN[this.item].style.marginTop = 0;
window.clearInterval(aktiv);
window.setTimeout("inst.next(inst.item)", inst.options.interval);
}
},
clxWriteReviews: function () {
if (this.wR === true)
return;
this.wR = true;
this.dN2 = document.createElement('div');
this.dN2.id = "clxReviews";
this.dN = [];
for (j = 0; j < clx_reviews.review.length; ++j) {
console.log(clx_reviews.review[j].avatar);
this.clx_review_text += '';
this.clx_review_text += '
' + clx_reviews.review[j].title + '
';
if (this.options.showStars)
this.clx_review_text += '
';
this.clx_review_text += '
' + clx_lang.from + ' ' + clx_reviews.review[j].user + ' ' + clx_lang.dateTime.replace(/{date}/, clx_reviews.review[j].date).replace(/{time}/, clx_reviews.review[j].time) + '
';
this.clx_review_text += '
' + clx_reviews.review[j].text + '
';
this.clx_review_text += '
' + (clx_reviews.review[j].tags === '' ? '' : clx_lang.tags + ': ') + clx_reviews.review[j].tags + '
';
this.clx_review_text += '
';
this.dN[j] = document.createElement('div');
if (clx_reviews.review[j].stars < 3) {
this.dN[j].className = 'clx_rev_element';
var showNegs = true;
//if (typeof clxprevWidget !== 'undefined' && clxprevWidget!=null)
// showNegs = clxprevWidget.options.showNegativs;
//else
// showNegs = this.options.showNegativs;
if (showNegs)
this.dN[j].style.display = 'block';
else
this.dN[j].style.display = 'none';
}
this.dN[j].innerHTML = this.clx_review_text;
this.dN2.appendChild(this.dN[j]);
this.clx_review_text = '';
}
this.dN1 = document.createElement('div');
if (this.options.showAskReview === true) {
//add review widget
stars = '';
for (x = 1; x < 6; x++)
stars += '' + x + '';
this.dN1.innerHTML = '';
//--
}
else
this.dN1.innerHTML = '';
this.dN1.innerHTML = this.dN1.innerHTML + '' + this.options.headline + '
';
this.dN1.id = "clxReviewWidget";
this.dN1.appendChild(this.dN2);
f = document.createElement('div');
f.id = 'clx_foot';
f.innerHTML = '';
this.dN1.appendChild(f);
this.c.parentNode.appendChild(this.dN1);
f.appendChild(this.c);
var companyUrl = window.location.host;
var utmParamsForLogo = '?utm_campaign=review+widget&utm_source=' + encodeURIComponent(companyUrl) + '&utm_medium=widget&utm_content=logo+link';
var logolink = document.getElementById('clx_logo_url');
if (typeof (clxprevWidget) === 'undefined') {
logolink.href += utmParamsForLogo;
}
if (typeof (clx_data) !== 'undefined' && this.options.showRichSearchResults == true) {
var JRText = '{"@context":"http:\/\/schema.org", ' +
' "@type":"LocalBusiness", ' +
' "@id":"' + clx_data.id + '", ' +
' "name":"' + clx_data.companyName + '", ' +
' "url":"' + this.c.href.split('?')[0] + '", ' +
' "image": [ ' +
'"' + clx_data.img1 + '",' +
'"' + clx_data.img2 + '"' +
'],' +
' "aggregateRating": { ' +
' "@type":"AggregateRating", ' +
' "worstRating":"1", ' +
' "bestRating":"5", ' +
' "ratingValue":"' + clx_data.revAvg + '", ' +
' "reviewCount":"' + clx_data.revCount + '", ' +
' "sameAs":"' + this.c.href.split('?')[0] + '" }}';
var script = document.createElement("script");
script.setAttribute("id", "CylexJSONLd");
script.type = "application/ld+json";
script.appendChild(document.createTextNode(JRText));
document.head.appendChild(script);
}
window.setTimeout("inst.next(inst.item)", inst.options.interval);
},
injectCss: function () {
this.clxCssNode = document.createElement('link');
this.clxCssNode.type = 'text/css';
this.clxCssNode.rel = 'stylesheet';
this.clxCssNode.href = this.options.domain.replace('fr.', '') + '/css/widget/rateWidgetMerged.css';
this.head.appendChild(this.clxCssNode);
},
injectCss1: function () {
this.clxCssNode = document.createElement('link');
this.clxCssNode.type = 'text/css';
this.clxCssNode.rel = 'stylesheet';
this.clxCssNode.href = this.options.domain.replace('fr.', '') + '/css/widget/reviewWidget.css';
this.head.appendChild(this.clxCssNode);
},
applyConfig: function () {
px = isNaN(this.options.width) ? '' : 'px';
css = 'div#clxReviewWidget {width:' + this.options.width + 'px; border-color:' + this.options.borderColor + '; }\n' +
'div#clxReviewWidget h2 {color:' + this.options.backgroundColor + '; background-color:' + this.options.borderColor + ';}\n' +
'div#clxReviewWidget div#clxReviews {background-color:' + this.options.backgroundColor + '; height: ' + this.options.height + 'px;}\n' +
'div#clxReviewWidget div#clxReviews div {border-color:' + this.options.borderColor + ';}\n' +
'div#clxReviewWidget div#clxReviews div h3 {color:' + this.options.borderColor + ';}\n' +
'div#clxReviewWidget div#clxReviews div p.clx_meta {color:' + this.options.textColor + ';}\n' +
'div#clxReviewWidget div#clxReviews img.clx_avatar {border: 1px solid ' + this.options.borderColor + ' !important;}\n' +
'div#clxReviewWidget div#clx_foot {border-color:' + this.options.borderColor + '; background-color:' + this.options.borderColor + ';}\n' +
'div#clxReviewWidget div#clx_foot a#clx_rev_url {color:' + this.options.backgroundColor + ';}\n' +
'div#clxReviewWidget div#clxReviews p {color:' + this.options.textColor + ';}\n' +
'div#clxReviewWidget div#clxRateWidget span { color:' + this.options.borderColor + '; }\n' +
'div#clxReviewWidget div#clxRateWidget a { color:' + this.options.borderColor + '; }\n';
clxCssNode2 = document.createElement('style');
clxCssNode2.type = 'text/css';
clxCssNode2.title = 'CylexReviewWidget';
if (clxCssNode2.styleSheet) {
//IE only
clxCssNode2.styleSheet.cssText = css;
} else {
//W3C
var clxCssNode2Content = document.createTextNode(css);
clxCssNode2.appendChild(clxCssNode2Content);
}
this.head.appendChild(clxCssNode2);
},
vote: function (v) {
var openedWindow;
var utmParamsForPost = '&utm_campaign=review+widget&utm_source=' + encodeURIComponent(window.location.host) + '&utm_medium=widget&utm_content=offsite+review+writing';
//var openedLink = clx_lang.baseUrl + '/reviews/postreview.aspx?fir_nr=' + this.options.fir_nr + '&anon=1&stars=' + v + '&decided=a';
var openedLink = clx_lang.baseUrl + '/reviews/reviewhandler.ashx?firnr=' + this.options.fir_nr + '&rating=' + v + '&source=widget';
if (typeof (clxprevWidget) === 'undefined') {
openedLink += utmParamsForPost;
}
openedWindow = window.open(openedLink, "_blank", "width=600,height=600,resizable=yes");
}
}