﻿function surveyRun() { if (settings.enable == false) return false; if (performTimerValidation() == false) return false; debug("after timer"); if (performCountryValidation() == false) return false; debug("after country"); if (performIPValidation() == false) return false; debug("after ip"); var a = settings.cookie.enable; var b = a == true ? $.cookie(settings.cookie.name) : null; if (b == null) { $.get(settings.popupUrl, function (a) { $.blockUI({ message: a }); loadLanguage(); attachTemplateResponseEvents(); attachTemplateTheme() }) } } function surveyInit(a, b) { $.holdReady(true); execute = b == null ? true : b; path = a; loadSettings(); performTimerDetection(); performCountryDetection(); performIPDetection(); $.holdReady(false) } function performExitDomainDetection() { if (settings.onExitDomain == true) { $().onUserExit({ execute: function () { var a = settings.cookie.enable; var b = a == true ? $.cookie(settings.cookie.name) : null; if (a == true) { if (b != null && b == "true") { popup(settings.surveyUrl, settings.width, settings.height); $.cookie(settings.cookie.name, "complete", { expires: 1, path: "/" }) } } else popup(settings.surveyUrl, settings.width, settings.height) }, internalURLs: settings.internalDomains }) } } function performIPDetection() { if (settings.ipDetection.enable == true && (settings.ipDetection.allowedIPs != "-1" || settings.ipDetection.deniedIPs != "-1")) { $.holdReady(true); $.getJSON("http://jsonip.appspot.com?callback=?", function (a) { var b = a.ip; saveIP(b) }).complete(function () { $.holdReady(false) }) } } function saveIP(a) { clientIP = a } function performCountryDetection() { if (settings.countryDetection.enable == true && settings.countryDetection.locations != "-1") { $.holdReady(true); $.getJSON("http://api.wipmania.com/jsonp?callback=?", function (a) { var b = a.address.country_code; saveCountry(b) }).complete(function () { $.holdReady(false) }) } } function saveCountry(a) { clientCountry = a } function performTimerDetection() { if (settings.timer.enable == true) { $.holdReady(true); var a = "http://json-time.appspot.com/time.json?tz=" + settings.timer.timezone + "&callback=?"; $.getJSON(a, function (a) { var b = a; if (b.error == true) saveTime(null); else saveTime(b.datetime) }).complete(function () { $.holdReady(false) }) } } function saveTime(a) { clientDateTime = a } function readyLock() { if (settings.countryDetection.enable == true && settings.countryDetection.locations != "-1" || settings.ipDetection.enable == true || settings.timer.enable == true) $.holdReady(true) } function loadSettings() { $.ajax({ type: "GET", url: path, dataType: "JSON", async: false, success: function (a) { settings = a }, error: function (a, b, c) { alert(b) }, complete: function () { } }) } function attachTemplateTheme() { var a = settings.theme.color; if (a == "-1") return false; $("#surveyBG .color").css("color", a).removeClass("color"); $("#surveyBG .bgColor").css("background-color", a).removeClass("bgColor") } function attachTemplateResponseEvents() { $("#surveyYes").click(function () { var a = settings.cookie.enable; if (a == true) $.cookie(settings.cookie.name, "true", { expires: 1, path: "/" }); if (settings.onExitDomain == false) { if (a == true) { $.cookie(settings.cookie.name, "complete", { expires: 1, path: "/" }) } popup(settings.surveyUrl, settings.width, settings.height) } $.unblockUI() }); $("#surveyNo, #surveyClose").click(function () { var a = settings.cookie.enable; if (a == true) $.cookie(settings.cookie.name, "false", { expires: 1, path: "/" }); $.unblockUI(); return false }) } function loadLanguage() { var a = settings.languageUrl; $.ajax({ type: "GET", url: a, dataType: "JSON", async: false, success: function (a) { $("#surveyContent #surveyHeading").text(a.heading); $("#surveyContent #surveyBody").text(a.body); $("#surveyContent #surveyAsk").text(a.question); $("#surveyContent #surveyYes").val(a.yes); $("#surveyContent #surveyNo").val(a.no) }, error: function (a, b, c) { alert("invalid language") } }) } function performIPValidation() { debug("clientIP is " + clientIP); if (clientIP == null) return true; var a = settings.ipDetection.allowedIPs; var b = settings.ipDetection.deniedIPs; var c = true; if (a != "-1" || b != "-1") { if (a != "-1") a = trimAll(a); if (b != "-1") b = trimAll(b); if (a != "-1") { if (!ipFoundInList(clientIP, a)) c = false } if (b != "-1") { if (ipFoundInList(clientIP, b)) c = false } } return c } function ipFoundInList(a, b) { var c = false; var d = b.split("|"); for (var e = 0; e < d.length; e++) { if (matchesIPOrMask(a, d[e])) c = true } return c } function matchesIPOrMask(a, b) { var c = true; var d, e; if (a.length > 0 && b.length > 0) { d = a.split("."); e = b.split("."); if (d.length == e.length) { for (var f = 0; f < d.length; f++) { if (d[f] != e[f] && e[f] != "*") { c = false; break } } } else c = false } return c } function performCountryValidation() { debug("clientCountry is " + clientCountry); if (clientCountry == null) return true; var a = trimAll(settings.countryDetection.locations).split("|"); var b = $.inArray(clientCountry, a) > -1; return b } function performTimerValidation() { debug("clientDateTime is " + clientDateTime); if (clientDateTime == null) return true; var a = false; var b = new Date(clientDateTime), c = new Date(clientDateTime), d = new Date(clientDateTime); var e, f; var g, h, i, j; var k = settings.timer.intervals; var l = trimAll(k).split("|"); var m, n, o; try { for (var p = 0; p < l.length; p++) { m = l[p].split("-"); n = m[0]; o = m[1]; e = n.split(":"); g = parseInt(e[0]); h = parseInt(e[1]); f = o.split(":"); i = parseInt(o.split(":")[0]); j = parseInt(o.split(":")[1]); c.setHours(g, h); d.setHours(i, j); if (b.getTime() >= c.getTime() && b.getTime() <= d.getTime()) { a = true; break } } return a } catch (q) { debug("exception caught in performTimerValidation()..." + q); return a } } function popup(a, b, c) { var b = b; var c = c; var d = (screen.width - b) / 2; var e = (screen.height - c) / 2; var f = "width=" + b + ", height=" + c; f += ", top=" + e + ", left=" + d; f += ", directories=0"; f += ", location=0"; f += ", menubar=0"; f += ", resizable=1"; f += ", scrollbars=1"; f += ", status=1"; f += ", toolbar=0"; var g = window.open(a, "survey", f); if (window.focus()) window.blur(); if (g != null) g.focus(); return false } function debug(a) { if (mode) try { window.console.debug(a) } catch (b) { window.console.log(a) } } function trimAll(a) { return a.replace(/\s/g, "") } var mode = false; var path = "settings.json"; var settings = null; var clientDateTime = null; var clientCountry = null; var clientIP = null; var execute = false; $.blockUI.defaults.css = { padding: 0, margin: 0, width: "", top: "25%", left: "35%", textAlign: "center", color: "", border: "none", backgroundColor: "transparent", cursor: "default" }; $.blockUI.defaults.overlayCSS = { backgroundColor: "#FFF", opacity: .5, cursor: "default" }; $(function () { if (execute == true) surveyRun(); if (settings != null) performExitDomainDetection() })
