
(function() {(function() {var l = document.createElement("link");l.rel = "stylesheet";l.type = "text/css";l.href = "https:\/\/civicscience-jspoll-styles.s3.amazonaws.com\/3120\/style.css";(document.getElementsByTagName('head')[0] || document.documentElement).appendChild(l);})();var init = (function(widgetElementId, widgetHtml, widgetPageUrl, widgetCallback) {var DMODE_DESKTOP = "click";var DMODE_MOBILE = "touch";var JQUERY_VERSION = "1.10.2";var PAGE_URL = widgetPageUrl;if (PAGE_URL == "") {(function() {var w;for (w = window; w.parent != w; w = w.parent);try {PAGE_URL = w.location.href;} catch (e) {PAGE_URL = window.document.referrer;}})();}var $ = window.jQuery;function requestJSONP(url, handler) {var deferred = $.Deferred().done(function(resp) {if (handler) {handler(resp.data);}});(function(d) {$.ajax({url: url,
dataType: "jsonp",
crossDomain: true,
jsonp: "responseHandler"
})
.done(function(resp) {d.resolve(resp);});})(deferred);return deferred;}var Widget = function(containerElt) {var THIS = this;var $container = $(containerElt);var deviceMode = $container.find("div:first").hasClass(DMODE_MOBILE)
? DMODE_MOBILE
: DMODE_DESKTOP;this.getDeviceMode = function() {return deviceMode;};var $body = $container.find(".poll_body");this.$getBody = function() {return $body;};var $ballotbox = $container.find(".ballotbox");this.setProgress = function(current, total) {$.each(
$ballotbox[0].className.split(/\s+/),
function(i, c) {if (/^(question|total)_/.test(c)) {$ballotbox.removeClass(c);}});if (current >= 0 && total >= 0) {$ballotbox
.addClass("question_" + current)
.addClass("total_" + total);}};this.setBodyIsLoading = function(loading) {$body.toggleClass("loading", !!loading);};this.getQuestionsUrl = "";this.getResultsUrl = "";this.putResponsesUrl = "";this.editableUrl = "";this.isOptOutUser = false;var receivedQidList = [];this.getReceivedQidList = function() {return receivedQidList;}; function receivedQuestion(qid) {receivedQidList.unshift(qid);var i;for (i = 1; i < receivedQidList.length; i++) {if (receivedQidList[i] == qid) { receivedQidList.splice(i--, 1);}}if (receivedQidList.length > 30) {receivedQidList.pop();}} function askedQuestion(qid) {if (qid == null) {$ballotbox.removeAttr("data-qid");} else {$ballotbox.attr("data-qid", qid);}}askedQuestion(null);THIS.askedQuestion = askedQuestion;var LOCAL_NAME = "__iqpbb";function getLocalId() {var id = null;if (!THIS.isOptOutUser) {try {if ("localStorage" in window) {var storage = window["localStorage"];if (storage != null) {id = storage.getItem(LOCAL_NAME);if (id == null) {function r() {return Math.floor(Math.random() * 4294967296);}id = r() + "." + r();storage.setItem(LOCAL_NAME, id);}}}} catch (e) {}}return id;} var wroteCss = false;function start() {if (!THIS.getQuestionsUrl) {return;}if (!wroteCss) {try {var css = /^\d/.test(widgetElementId)
? ("[id='" + widgetElementId + "']") : ("#" + widgetElementId);css += " .submit[disabled] { cursor: default; opacity: .5; }";$("<style>")
.attr("type", "text/css")
.text(css)
.appendTo($container);} catch (e) {}wroteCss = true;}var params = [];var id = getLocalId();if (id) {params.push("al=" + encodeURIComponent(id));}if (PAGE_URL) {params.push("pgurl=" + encodeURIComponent(PAGE_URL));}params.push("elt=" + widgetElementId);params.push("elth=" + Math.round($container.height()));params.push("elty=" + Math.round($container.offset().top));params.push("winh=" + Math.round($(window).height()));params.push("winy=" + Math.round($(window).scrollTop()));if (params.length > 0) {THIS.getQuestionsUrl
+= (THIS.getQuestionsUrl.indexOf("?") == -1 ? "?" : "&")
+ params.join("&");}var qp = new QuestionPager(THIS);qp.addReceivedQuestionListener(receivedQuestion);qp.addFinishListener(showResults);qp.run();} var isRunning = false;this.run = function() {if (isRunning) {return;}isRunning = true;var $win = $(window);var interval = null;function startIfNearlyVisible() {if ($container.offset().top
< $win.scrollTop() + $win.height() + 200) {$win.off("resize scroll", startIfNearlyVisible);clearInterval(interval);start();if (THIS.editableUrl) {var url = THIS.editableUrl;if (PAGE_URL) {url += url.indexOf("?") == -1 ? "?" : "&";url += "url=" + encodeURIComponent(PAGE_URL); 
}$.getScript(url);}}}$win.on("resize scroll", startIfNearlyVisible);interval = setInterval(startIfNearlyVisible, 5000);startIfNearlyVisible();}; this.restart = function() {if (isRunning) { var qurl = this.getQuestionsUrl;qurl += qurl.indexOf("?") == -1 ? "?" : "&";qurl += "restart=1";this.getQuestionsUrl = qurl;this.getResultsUrl = "";this.putResponsesUrl = "";start();}}; var showResults = function() {if (THIS.getResultsUrl) {var url = THIS.getResultsUrl;THIS.setBodyIsLoading(true);requestJSONP(url, function(response) {THIS.setBodyIsLoading(false);if (response.results) {var pobjList = response.results.pages;if (pobjList) {var first = null;var prev = null;var i;for (i = 0; i < pobjList.length; i++) {var pobj = pobjList[i];if (pobj.html) {prev = new ResultsPage(THIS, pobj.id, pobj.html, prev);if (first == null) {first = prev;}}}if (first == null) {$body.empty();} else {first.show();}}}});}}; };var QuestionPager = function(widget) {var THIS = this;var MAX_PAGE_SIZE = 1;var qobjList = [];var qobjIndex = 0;var askedList = [];var isVoting = false;var receivedQuestionListeners = [];this.addReceivedQuestionListener = function(f) {if (typeof f == "function") {receivedQuestionListeners.push(f);}}; var putResponsesDeferreds = [];function waitForPutResponses() {var when =
$.when.apply($, putResponsesDeferreds)
.done(function() {putResponsesDeferreds = [];});(function(deferreds) {setTimeout(function() {$.each(deferreds, function(i, d) {d.resolve();});}, 5000);})(putResponsesDeferreds);return when;}var run = function() {var origIndex = qobjIndex;widget.$getBody().empty();askedList = [];while (qobjIndex < qobjList.length) {var qobjMax = Math.min(qobjList.length, qobjIndex + MAX_PAGE_SIZE);while (qobjIndex < qobjMax) {var qobj = qobjList[qobjIndex++];var question = null;switch (qobj.type) {case "radio":question = new RadioQuestion(widget, THIS, qobj.html);break;case "checkbox":question = new CheckboxQuestion(widget, THIS, qobj.html);break;case "star-group":question = new StarRatingQuestion(widget, THIS, qobj.html);break;}if (question != null) {if (MAX_PAGE_SIZE == 1) {widget.setProgress(qobjIndex, qobjList.length);}question.ask();askedList.push(question);widget.askedQuestion(qobj.id);}}if (askedList.length > 0) {isVoting = false;return;}}if (MAX_PAGE_SIZE == 1) {widget.setProgress(-1, -1);}if (origIndex == 0 && qobjList.length != 0) {finish();} else if (widget.getQuestionsUrl) {var url = widget.getQuestionsUrl;var xqids = widget.getReceivedQidList();if (xqids.length > 0) {url += url.indexOf("?") == -1 ? "?" : "&";url += "xq=." + xqids.join(".");}widget.setBodyIsLoading(true);waitForPutResponses()
.done(function() {requestJSONP(url, function(response) {widget.setBodyIsLoading(false);qobjList = response.questions || [];if (response.session) {widget.getQuestionsUrl = response.session.getQuestionsUrl;widget.getResultsUrl = response.session.getResultsUrl;widget.putResponsesUrl = response.session.putResponsesUrl;}if (qobjList.length == 0) {finish();} else {var i;for (i = 0; i < receivedQuestionListeners.length; i++) {var j;for (j = 0; j < qobjList.length; j++) {receivedQuestionListeners[i](qobjList[j].id);}}qobjIndex = 0;run();}});});}}; this.run = run;function vote() {if (!isVoting && widget.putResponsesUrl) {var params = "";var i;for (i = 0; i < askedList.length && askedList[i].isVotable(); i++) {if (params) {params += "&";}params += askedList[i].getUrlParams();}if (i == askedList.length) {var url = widget.putResponsesUrl;if (params != "") {url += url.indexOf("?") == -1 ? "?" : "&";url += params;}putResponsesDeferreds.push(requestJSONP(url, null));run();}}} this.vote = vote;var finishListeners = [];this.addFinishListener = function(f) {if (typeof f == "function") {finishListeners.push(f);}};var finish = function() {widget.askedQuestion(null);var i;for (i = 0; i < finishListeners.length; i++) {finishListeners[i].apply(THIS, []);}}; }; var Question = function(widget, pager, html) {var $root = $("<div>").html(html);this.$getRoot = function() {return $root;};this.getUrlParams = function() {return "";};this.isVotable = function() {return false;};this.ask = function() {widget.$getBody().append($root);};}; var RadioQuestion = function(widget, pager, html) {Question.apply(this, [widget, pager, html]);var THIS = this;var $root = this.$getRoot();var $radio = $root.find("input[type='radio']");var $submitBtn = $root.find("input[type='button'].submit");var $submit = $submitBtn;if (widget.getDeviceMode() == DMODE_MOBILE) {$submit = $submit.add($radio);}$submit.click(function() {pager.vote();});this.getUrlParams = function() {var $r = $radio.filter(":checked");return $r.length == 0
? ""
: $r.val();};this.isVotable = function() {return $radio.filter(":checked").length > 0;};function updateSubmit() {$submitBtn.prop("disabled", !THIS.isVotable());}$radio.click(updateSubmit);updateSubmit();}; var CheckboxQuestion = function(widget, pager, html) {Question.apply(this, [widget, pager, html]);var THIS = this;var $root = this.$getRoot();var $allCheckboxes = $root.find("input[type='checkbox']");var $none = $allCheckboxes.filter("[data-none]");var $checkboxes = $allCheckboxes.not($none);$checkboxes.click(function() {if ($checkboxes.filter(":checked").length > 0) {$none.prop("checked", false);}});$none.change(function() {$checkboxes.prop("checked", false);$none.prop("checked", false);$(this).prop("checked", true);});var $ul = $root.find("ul.checkbox.answer_options");var minBoxes = $ul.data("min-checks") || 0;var maxBoxes = $ul.data("max-checks") || $checkboxes.length;this.isVotable = function() {if ($none.is(":checked")) {return true;}var n = $checkboxes.filter(":checked").length;return n >= minBoxes && n <= maxBoxes;};var $submit = $root.find("input[type='button'].submit");$submit.click(function() {pager.vote();});this.getUrlParams = function() {var p = [];$allCheckboxes.filter(":checked").each(function() {p.push($(this).val());});$allCheckboxes.filter(":not(:checked)").each(function() {var $unchecked = $root.find("input[type='hidden'][name='unchecked_" + this.name + "']");if ($unchecked.length != 0) {p.push($unchecked.val());}});return p.join("&");};function updateSubmit() {$submit.prop("disabled", !THIS.isVotable());}$checkboxes.click(updateSubmit);$none.change(updateSubmit);updateSubmit();}; var StarRatingQuestion = function(widget, pager, html) {Question.apply(this, [widget, pager, html]);var THIS = this;var $root = this.$getRoot();var questions = [];$root.find(".answer_options").each(function(i, elt) {questions.push(new StarQuestion($(elt)));});this.isVotable = function() {for (var i = 0; i < questions.length; i++) {if (!questions[i].isAnswered()) {return false;}}return true;};this.getUrlParams = function() {var p = [];for (var i = 0; i < questions.length; i++) {p.push(questions[i].getParam());}return p.join("&");};function updateSubmit() {$submit.prop("disabled", !THIS.isVotable());}var $submit = $root.find("input[type='button'].submit");$submit.click(function() {pager.vote();});updateSubmit();function StarQuestion($containerElt) {var wrapperClasses = [
"never", "hate", "dislike", "indifferent", "like", "love"
];var $starWrapperElt = $containerElt.find(".civsci-star-wrapper");var $starLabelElt = $containerElt.find(".civsci-star-answer");var $options = $containerElt.find("li");var isAnswered = false;var qid = $containerElt.data("qid");var selectedParam = null;var selectedOptionText = null;function removeWrapperClasses() {for (var i = 0; i < wrapperClasses.length; i++) {$starWrapperElt.removeClass("civsci-selected-" + wrapperClasses[i]);}}this.isAnswered = function() {return isAnswered;};this.getQuestionId = function() {return qid;};this.getParam = function() {return selectedParam;};$options.click(function() {var $this = $(this);removeWrapperClasses();var c = $this.attr("class");c = c.split("-");var wrapperClass = c[0] + "-selected-" + c[1];$starWrapperElt.addClass(wrapperClass);var optionText = $this.data("option-text");selectedOptionText = optionText;$starLabelElt.html(optionText);selectedParam = $this.data("param");isAnswered = true;updateSubmit();});$options.hover(function() {var optionText = $(this).data("option-text");$starLabelElt.html(optionText);}, function() {var optionText = selectedOptionText ? selectedOptionText: "";$starLabelElt.html(optionText);});removeWrapperClasses();}}; var ResultsPage = function(widget, qid, html, prevPage) {var THIS = this;this.prevPage = prevPage;this.nextPage = null;if (prevPage != null) {prevPage.nextPage = this;} else {ResultsPage.questionTotal = 0;}var $root = $("<div>").html(html);this.questionIndex = -1;(function() {if ($root.find(".question_text").length) {var p = prevPage;for ( ; p != null && p.questionIndex == -1; p = p.prevPage);if (p == null) {THIS.questionIndex = 1;} else {THIS.questionIndex = p.questionIndex + 1;}ResultsPage.questionTotal = THIS.questionIndex;}})();this.show = function() {widget.$getBody().empty().append($root);widget.askedQuestion(qid);if (ResultsPage.questionTotal && this.questionIndex >= 0) {widget.setProgress(this.questionIndex, ResultsPage.questionTotal);} else {widget.setProgress(-1, -1);}};$root.find(".previous").click(function() {if (THIS.prevPage) {$root.detach();THIS.prevPage.show();}});$root.find(".next").click(function() {if (THIS.nextPage) {$root.detach();THIS.nextPage.show();} else {widget.restart();}});}; function ensureJQuery(callback) {if ($ == undefined || $.fn.jquery != JQUERY_VERSION) {(function() {var done = false;var s = document.createElement("script");s.src = "https:/" + "/ajax.googleapis.com/ajax/libs/jquery/" + JQUERY_VERSION + "/jquery.min.js";s.onload = s.onreadystatechange = function() {if (!done) {var r = this.readyState;if (!r || r == "complete" || r == "loaded") {done = true;$ = window.jQuery.noConflict(true);callback();}}};(document.getElementsByTagName('head')[0] || document.documentElement).appendChild(s);})();} else {callback();}}ensureJQuery(function() {$(document).ready(function() {var $container = $("#" + widgetElementId);if ($container.length) {$container.html(widgetHtml);widgetCallback(new Widget($container[0]));}});});});;init(
"civsci-2100675583",
"<div class=\"civicscience ballotbox click\">\n    <div class=\"header\">What do you think?<\/div>\n    <div class=\"poll_body\"><\/div>\n    <div class=\"progress_bar\"><\/div>\n    <div class=\"footer\"><\/div>\n<\/div>",
"",
function(widget) {widget.isOptOutUser = false;widget.getQuestionsUrl = "https:\/\/www.civicscience.com\/widget\/jspoll\/getQuestions?tgt=3120&device=click";widget.editableUrl = "https:\/\/www.civicscience.com\/widget\/EditableWidget?tgt=3120&elt=civsci-2100675583";widget.run();});})();