define("discourse/plugins/poll/components/poll-breakdown-chart",["exports","@ember/component","I18n","discourse/plugins/poll/controllers/poll-ui-builder","discourse-common/utils/decorators","discourse/plugins/poll/lib/chart-colors","@ember/template","@ember/object/computed"],(function(t,e,l,o,n,i,r,s){"use strict";var a,u,p;function c(t,e,l,o,n){var i={};return Object.keys(o).forEach((function(t){i[t]=o[t]})),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=l.slice().reverse().reduce((function(l,o){return o(t,e,l)||l}),i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var d=e.default.extend((a=(0,n.default)("optionColors","index"),u=(0,n.default)("data","displayMode"),p={group:null,options:null,displayMode:null,highlightedOption:null,setHighlightedOption:null,classNames:"poll-breakdown-chart-container",_optionToSlice:null,_previousHighlightedSliceIndex:null,_previousDisplayMode:null,data:(0,s.mapBy)("options","votes"),init:function(){this._super.apply(this,arguments),this._optionToSlice={}},didInsertElement:function(){this._super.apply(this,arguments);var t=this.element.querySelector("canvas");this._chart=new window.Chart(t.getContext("2d"),this.chartConfig)},didReceiveAttrs:function(){this._super.apply(this,arguments),this._chart&&(this._updateDisplayMode(),this._updateHighlight())},willDestroy:function(){this._super.apply(this,arguments),this._chart&&this._chart.destroy()},colorStyle:function(t,e){return(0,r.htmlSafe)("background: ".concat(t[e],";"))},chartConfig:function(t,e){var n=this,r=[],s=0;this._optionToSlice={},t.forEach((function(t,e){t>0&&(r.push(t),n._optionToSlice[e]=s++)}));var a=r.reduce((function(t,e){return t+e}),0),u=(0,i.getColors)(t.length).filter((function(e,l){return t[l]>0}));return{type:o.PIE_CHART_TYPE,plugins:[window.ChartDataLabels],data:{datasets:[{data:r,backgroundColor:u,hoverBorderColor:"#fff"}]},options:{plugins:{datalabels:{color:"#333",backgroundColor:"rgba(255, 255, 255, 0.5)",borderRadius:2,font:{family:getComputedStyle(document.body).fontFamily,size:16},padding:{top:2,right:6,bottom:2,left:6},formatter:function(t){if("percentage"!==e)return t;var o=l.default.toNumber(t/a*100,{precision:1});return"".concat(o,"%")}}},responsive:!0,aspectRatio:1.1,animation:{duration:0},tooltips:!1,onHover:function(t,e){if(e.length){var l=e[0]._index,o=Object.keys(n._optionToSlice).find((function(t){return n._optionToSlice[t]===l}));e.length=0,n.setHighlightedOption(Number(o))}else n.setHighlightedOption(null)}}}},_updateDisplayMode:function(){if(this.displayMode!==this._previousDisplayMode){var t=this.chartConfig;this._chart.data.datasets=t.data.datasets,this._chart.options=t.options,this._chart.update(),this._previousDisplayMode=this.displayMode}},_updateHighlight:function(){var t=this._chart.getDatasetMeta(0);if(null!==this._previousHighlightedSliceIndex){var e=t.data[this._previousHighlightedSliceIndex];t.controller.removeHoverStyle(e),this._chart.draw()}if(null!==this.highlightedOption){var l=this._optionToSlice[this.highlightedOption];if(void 0!==l){var o=t.data[l];this._previousHighlightedSliceIndex=l,t.controller.setHoverStyle(o),this._chart.draw()}else this._previousHighlightedSliceIndex=null}else this._previousHighlightedSliceIndex=null}},c(p,"colorStyle",[a],Object.getOwnPropertyDescriptor(p,"colorStyle"),p),c(p,"chartConfig",[u],Object.getOwnPropertyDescriptor(p,"chartConfig"),p),p));t.default=d})),define("discourse/plugins/poll/components/poll-breakdown-option",["exports","@ember/component","I18n","@ember/object","discourse-common/utils/decorators","@ember/object/computed","discourse/plugins/poll/lib/chart-colors","@ember/template","discourse/lib/computed"],(function(t,e,l,o,n,i,r,s,a){"use strict";var u,p,c,d,f;function h(t,e,l,o,n){var i={};return Object.keys(o).forEach((function(t){i[t]=o[t]})),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=l.slice().reverse().reduce((function(l,o){return o(t,e,l)||l}),i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var m=e.default.extend((u=(0,n.default)("option.votes","totalVotes"),p=(0,n.default)("optionsCount"),c=(0,n.default)("highlighted"),d=(0,n.default)("highlighted","optionColors","index"),h(f={option:null,index:null,totalVotes:null,optionsCount:null,displayMode:null,highlightedOption:null,onMouseOver:null,onMouseOut:null,tagName:"",highlighted:(0,a.propertyEqual)("highlightedOption","index"),showPercentage:(0,i.equal)("displayMode","percentage"),percent:function(t,e){return l.default.toNumber(t/e*100,{precision:1})},optionColors:function(t){return(0,r.getColors)(t)},colorBackgroundStyle:function(t){if(t)return(0,s.htmlSafe)("background: rgba(0, 0, 0, 0.1);")},colorPreviewStyle:function(t,e,l){var o=t?window.Chart.helpers.getHoverColor(e[l]):e[l];return(0,s.htmlSafe)("background: ".concat(o,";"))},onHover:function(t){t?this.onMouseOver():this.onMouseOut()}},"percent",[u],Object.getOwnPropertyDescriptor(f,"percent"),f),h(f,"optionColors",[p],Object.getOwnPropertyDescriptor(f,"optionColors"),f),h(f,"colorBackgroundStyle",[c],Object.getOwnPropertyDescriptor(f,"colorBackgroundStyle"),f),h(f,"colorPreviewStyle",[d],Object.getOwnPropertyDescriptor(f,"colorPreviewStyle"),f),h(f,"onHover",[o.action],Object.getOwnPropertyDescriptor(f,"onHover"),f),f));t.default=m})),define("discourse/plugins/poll/controllers/poll-breakdown",["exports","@ember/controller","I18n","discourse/mixins/modal-functionality","@ember/object","discourse/lib/ajax","@ember/string","discourse-common/utils/decorators","@ember/template","discourse/lib/load-script","discourse/lib/ajax-error"],(function(t,e,l,o,n,i,r,s,a,u,p){"use strict";var c,d,f,h;function m(t,e,l,o,n){var i={};return Object.keys(o).forEach((function(t){i[t]=o[t]})),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=l.slice().reverse().reduce((function(l,o){return o(t,e,l)||l}),i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var b=e.default.extend(o.default,(c=(0,s.default)("model.poll.title","model.post.topic.title"),d=(0,s.default)("model.groupableUserFields"),f=(0,s.default)("model.poll.options"),m(h={model:null,charts:null,groupedBy:null,highlightedOption:null,displayMode:"percentage",title:function(t,e){return t?(0,a.htmlSafe)(t):e},groupableUserFields:function(t){return t.map((function(t){var e=t.split("_").filter(Boolean);return e.length>1&&(e[0]=(0,r.classify)(e[0])),{id:t,label:e.join(" ")}}))},totalVotes:function(t){return t.reduce((function(t,e){return t+e.votes}),0)},onShow:function(){var t=this;this.set("charts",null),this.set("displayMode","percentage"),this.set("groupedBy",this.model.groupableUserFields[0]),(0,u.default)("/javascripts/Chart.min.js").then((function(){return(0,u.default)("/javascripts/chartjs-plugin-datalabels.min.js")})).then((function(){window.Chart.plugins.unregister(window.ChartDataLabels),t.fetchGroupedPollData()}))},fetchGroupedPollData:function(){var t=this;return(0,i.ajax)("/polls/grouped_poll_results.json",{data:{post_id:this.model.post.id,poll_name:this.model.poll.name,user_field_name:this.groupedBy}}).catch((function(t){t?(0,p.popupAjaxError)(t):bootbox.alert(l.default.t("poll.error_while_fetching_voters"))})).then((function(e){t.isDestroying||t.isDestroyed||t.set("charts",e.grouped_results)}))},setGrouping:function(t){this.set("groupedBy",t),this.fetchGroupedPollData()},onSelectPanel:function(t){this.set("displayMode",t.id)}},"title",[c],Object.getOwnPropertyDescriptor(h,"title"),h),m(h,"groupableUserFields",[d],Object.getOwnPropertyDescriptor(h,"groupableUserFields"),h),m(h,"totalVotes",[f],Object.getOwnPropertyDescriptor(h,"totalVotes"),h),m(h,"setGrouping",[n.action],Object.getOwnPropertyDescriptor(h,"setGrouping"),h),m(h,"onSelectPanel",[n.action],Object.getOwnPropertyDescriptor(h,"onSelectPanel"),h),h));t.default=b})),define("discourse/plugins/poll/controllers/poll-ui-builder",["exports","@ember/controller","@ember/object","@ember/object/computed","@ember/runloop","discourse-common/utils/decorators","discourse/mixins/modal-functionality","I18n"],(function(t,e,l,o,n,i,r,s){"use strict";var a,u,p,c,d,f,h,m,b,g,v,_,y;function O(t){return function(t){if(Array.isArray(t))return w(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return w(t,e);var l=Object.prototype.toString.call(t).slice(8,-1);"Object"===l&&t.constructor&&(l=t.constructor.name);if("Map"===l||"Set"===l)return Array.from(t);if("Arguments"===l||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(l))return w(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var l=0,o=new Array(e);l0})).length},siteGroups:function(t){return t.filter((function(t){return 0!==t.id}))},isPie:function(t,e){return e!==j&&"pie"===t},canRemoveOption:(0,o.gt)("pollOptions.length",1),_setPollMinMax:function(){this.isMultiple?((this.pollMin<=0||this.pollMin>=this.pollMax||this.pollMin>=this.pollOptionsCount)&&this.set("pollMin",this.pollOptionsCount>0?1:0),(this.pollMax<=0||this.pollMin>=this.pollMax||this.pollMax>this.pollOptionsCount)&&this.set("pollMax",this.pollOptionsCount)):this.isNumber&&this.set("pollMax",this.siteSettings.poll_maximum_options)},pollOutput:function(t,e,l,o,n,i,r,s,a,u,p){var c="[poll",d="",f=this.toolbarEvent.getText().match(/\[poll(\s+name=[^\s\]]+)*.*\]/gim);f&&(c+=" name=poll".concat(f.length+1));var h=s;return h<1&&(h=1),t&&(c+=" type=".concat(t)),e&&(c+=" results=".concat(e)),i&&t!==M&&(c+=" min=".concat(i)),r&&t!==M&&(c+=" max=".concat(r)),t===j&&(c+=" step=".concat(h)),l&&(c+=" public=true"),p&&t!==j&&(c+=" chartType=".concat(p)),a&&a.length>0&&(c+=" groups=".concat(a)),u&&(c+=" close=".concat(u.toISOString())),d+="".concat(c+="]","\n"),o&&(d+="# ".concat(o.trim(),"\n")),n.length>0&&t!==j&&n.forEach((function(t){t.value.length>0&&(d+="* ".concat(t.value.trim(),"\n"))})),d+="[/poll]\n"},minNumOfOptionsValidation:function(t,e){if(!t){if(e<1)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.options_min_count")});if(e>this.siteSettings.poll_maximum_options)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.options_max_count",{count:this.siteSettings.poll_maximum_options})})}return l.default.create({ok:!0})},showMinNumOfOptionsValidation:function(t){return 1!==t.length||""!==t[0].value},minMaxValueValidation:function(t,e,o,n,i,r){if(n=parseInt(n,10)||0,i=parseInt(i,10)||0,r=parseInt(r,10)||0,n<0)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.invalid_min_value")});if(i<0||t&&i>e)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.invalid_max_value")});if(n>i)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.invalid_values")});if(o){if(r<1)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.min_step_value")});var a=(i-n+1)/r;if(a<1)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.options_min_count")});if(a>this.siteSettings.poll_maximum_options)return l.default.create({failed:!0,reason:s.default.t("poll.ui_builder.help.options_max_count",{count:this.siteSettings.poll_maximum_options})})}return l.default.create({ok:!0})},disableInsert:function(t,e){return!t.ok||!e.ok},_comboboxOptions:function(t,e){return O(Array(e-t).keys()).map((function(e){return{value:e+t,name:e+t}}))},onOptionsTextChange:function(t){var e=0;this.set("pollOptions",t.target.value.split("\n").map((function(t){return l.default.create({idx:e++,value:t})})))},insertPoll:function(){this.toolbarEvent.addText(this.pollOutput),this.send("closeModal")},toggleAdvanced:function(){this.toggleProperty("showAdvanced"),this.showAdvanced&&this.set("pollOptionsText",this.pollOptions.map((function(t){return t.value})).join("\n"))},addOption:function(t,e,o){if(""!==e){var i=this.pollOptions.indexOf(t)+1,r=l.default.create({value:""});this.pollOptions.insertAt(i,r);var s=0;this.pollOptions.forEach((function(t){return t.set("idx",s++)})),(0,n.next)((function(){var t=document.getElementsByClassName("poll-options");if(t){var e=t[0].getElementsByTagName("input");r.idx=e))},actions:{showPollBuilder:function(){(0,l.default)("poll-ui-builder").set("toolbarEvent",this.toolbarEvent)}}},r="canBuildPoll",s=[o],a=Object.getOwnPropertyDescriptor(n,"canBuildPoll"),u=n,p={},Object.keys(a).forEach((function(t){p[t]=a[t]})),p.enumerable=!!p.enumerable,p.configurable=!!p.configurable,("value"in p||p.initializer)&&(p.writable=!0),p=s.slice().reverse().reduce((function(t,e){return e(i,r,t)||t}),p),u&&void 0!==p.initializer&&(p.value=p.initializer?p.initializer.call(u):void 0,p.initializer=void 0),void 0===p.initializer&&(Object.defineProperty(i,r,p),p=null),n)),t.addToolbarPopupMenuOptionsCallback((function(){return{action:"showPollBuilder",icon:"chart-bar",label:"poll.ui_builder.title",condition:"canBuildPoll"}}))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i={name:"add-poll-ui-builder",initialize:function(){(0,o.withPluginApi)("0.8.7",n)}};t.default=i})),define("discourse/plugins/poll/initializers/extend-for-poll",["exports","@ember/object","discourse/widgets/glue","discourse-common/lib/get-owner","discourse-common/utils/decorators","discourse/lib/plugin-api"],(function(t,e,l,o,n,i){"use strict";function r(t){var i,r,s=(0,o.getRegister)(t);t.modifyClass("controller:topic",{subscribe:function(){var t=this;this._super.apply(this,arguments),this.messageBus.subscribe("/polls/"+this.get("model.id"),(function(e){var l=t.get("model.postStream").findLoadedPost(e.post_id);l&&l.set("polls",e.polls)}))},unsubscribe:function(){this.messageBus.unsubscribe("/polls/*"),this._super.apply(this,arguments)}});var a,u,p,c,d,f,h=[],m=null;function b(){h.forEach((function(t){return t.queueRerender()}))}t.modifyClass("model:post",(i=(0,n.observes)("polls"),a=r={_polls:null,pollsObject:null,pollsChanged:function(){var t=this,l=this.polls;l&&(this._polls=this._polls||{},l.forEach((function(l){t._polls[l.name]?t._polls[l.name].setProperties(l):t._polls[l.name]=e.default.create(l)})),this.set("pollsObject",this._polls),b())}},u="pollsChanged",p=[i],c=Object.getOwnPropertyDescriptor(r,"pollsChanged"),d=r,f={},Object.keys(c).forEach((function(t){f[t]=c[t]})),f.enumerable=!!f.enumerable,f.configurable=!!f.configurable,("value"in f||f.initializer)&&(f.writable=!0),f=p.slice().reverse().reduce((function(t,e){return e(a,u,t)||t}),f),d&&void 0!==f.initializer&&(f.value=f.initializer?f.initializer.call(d):void 0,f.initializer=void 0),void 0===f.initializer&&(Object.defineProperty(a,u,f),f=null),r)),t.includePostAttributes("polls","polls_votes"),t.decorateCooked((function(o,n){var i=$(".poll",o);if(i.length&&n){var r=n.getModel();t.preventCloak(r.id),r.pollsChanged();var a=r.pollsObject||{},u=r.polls_votes||{};m=m||setInterval(b,3e4),i.each((function(o,n){var i=$(n),p=i.data("poll-name"),c=a[p],d=r,f=u[p]||[],m=i.parent(".expanded-quote").data("post-id");if(m&&r.quoted[m]&&(d=r.quoted[m],d=e.default.create(d),c=e.default.create(d.polls.find((function(t){return t.name===p}))),f=(f=d.polls_votes||{})[p]||[]),c){var b=n.querySelector(".poll-title"),g={id:"".concat(p,"-").concat(d.id),post:d,poll:c,vote:f,titleHTML:b&&b.outerHTML,groupableUserFields:(t.container.lookup("site-settings:main").poll_groupable_user_fields||"").split("|").filter(Boolean)},v=new l.default("discourse-poll",s,g);v.appendTo(n),h.push(v)}}))}}),{onlyStream:!0,id:"discourse-poll"}),t.cleanupStream((function(){m&&(clearInterval(m),m=null),h.forEach((function(t){return t.cleanUp()})),h=[]}))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s={name:"extend-for-poll",initialize:function(){(0,i.withPluginApi)("0.8.7",r)}};t.default=s})),define("discourse/plugins/poll/lib/discourse-markdown/poll",["exports","I18n"],(function(t,e){"use strict";function l(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return o(t,e);var l=Object.prototype.toString.call(t).slice(8,-1);"Object"===l&&t.constructor&&(l=t.constructor.name);if("Map"===l||"Set"===l)return Array.from(t);if("Arguments"===l||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(l))return o(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var l=0,o=new Array(e);l * http://www.myersdaily.org/joseph/javascript/md5-text.html * http://pajhome.org.uk/crypt/md5 * * Released under the BSD license * http://www.opensource.org/licenses/bsd-license */;var n="data-poll-",i=["close","max","min","name","order","public","results","chartType","groups","status","step","type"];function r(t,e){t.push("text","",0).content="[/"+e+"]"}var s={tag:"poll",before:function(t,e,l){var o=t.push("text","",0);o.content=l,o.bbcode_attrs=e.attrs,o.bbcode_type="poll_open"},after:function(t,o,s){var u=function(t,e){var l=t.indexOf(e);if(-1!==l){var o=t.slice(l),n=o.findIndex((function(t){return"heading_open"===t.type})),i=o.findIndex((function(t){return"heading_close"===t.type}));if(-1!==n&&-1!==i){var r=o.slice(n+1,i);return t.splice(l+n,i-n+1),r}}}(t.tokens,o),p=function(t,e){for(var l=t.length-1,o=[],n=[];t[l]!==e;l--){if(0===l)return;var i=t[l];if(0===i.level&&"ol"!==i.tag&&"ul"!==i.tag)return;if(1===i.level&&1===i.nesting){if("li"!==i.tag)return;o.push([i,n.reverse().join(" ")])}1===i.level&&1===i.nesting&&"li"===i.tag?n=[]:"text"!==i.type&&"inline"!==i.type||n.push(i.content)}return o.reverse()}(t.tokens,o);if(!p)return r(t,s);var c=o.bbcode_attrs,d=[["class","poll"]];c.status||d.push(["data-poll-status","open"]),i.forEach((function(t){c[t]&&d.push([n+t,c[t]])})),c.name||d.push(["data-poll-name","poll"]);var f=parseInt(c.min,10),m=parseInt(c.max,10),g=parseInt(c.step,10);g<1&&(g=1);var v=[],_=new t.Token("poll_open","div",1);if(_.block=!0,_.attrs=d,v.push(_),(_=new t.Token("poll_open","div",1)).block=!0,v.push(_),(_=new t.Token("poll_open","div",1)).attrs=[["class","poll-container"]],v.push(_),u&&((_=new t.Token("title_open","div",1)).attrs=[["class","poll-title"]],v.push(_),v.push.apply(v,l(u)),_=new t.Token("title_close","div",-1),v.push(_)),"number"===c.type){if(isNaN(f)&&(f=1),isNaN(m)&&(m=t.md.options.discourse.pollMaximumOptions),isNaN(g)&&(g=1),p.length>0)return r(t,s);_=new t.Token("bullet_list_open","ul",1),v.push(_);for(var y=f;y<=m;y+=g)_=new t.Token("list_item_open","li",1),p.push([_,String(y)]),v.push(_),(_=new t.Token("text","",0)).content=String(y),v.push(_),_=new t.Token("list_item_close","li",-1),v.push(_);_=new t.Token("bullet_item_close","",-1),v.push(_)}for(var O=0;O>2]|=t.charCodeAt(e)<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(a(o,n),e=0;e<16;e++)n[e]=0;return n[14]=8*l,a(o,n),o}(JSON.stringify([w])));_.attrs.push(["data-poll-option-id",x])}!function(t,e,o){var n=t.indexOf(e),i=t[n].level;for(t.splice.apply(t,[n,1].concat(l(o))),o[0].map=e.map;n0&&i++}}(t.tokens,o,v),t.level=t.tokens[t.tokens.length-1].level,t.push("poll_close","div",-1),(_=t.push("poll_open","div",1)).attrs=[["class","poll-info"]],t.push("paragraph_open","p",1),(_=t.push("span_open","span",1)).block=!1,_.attrs=[["class","info-number"]],(_=t.push("text","",0)).content="0",t.push("span_close","span",-1),(_=t.push("span_open","span",1)).block=!1,_.attrs=[["class","info-label"]],(_=t.push("text","",0)).content=e.default.t("poll.voters",{count:0}),t.push("span_close","span",-1),t.push("paragraph_close","p",-1),t.push("poll_close","div",-1),t.push("poll_close","div",-1),t.push("poll_close","div",-1)}};function a(t,e){var l=t[0],o=t[1],n=t[2],i=t[3];l=p(l,o,n,i,e[0],7,-680876936),i=p(i,l,o,n,e[1],12,-389564586),n=p(n,i,l,o,e[2],17,606105819),o=p(o,n,i,l,e[3],22,-1044525330),l=p(l,o,n,i,e[4],7,-176418897),i=p(i,l,o,n,e[5],12,1200080426),n=p(n,i,l,o,e[6],17,-1473231341),o=p(o,n,i,l,e[7],22,-45705983),l=p(l,o,n,i,e[8],7,1770035416),i=p(i,l,o,n,e[9],12,-1958414417),n=p(n,i,l,o,e[10],17,-42063),o=p(o,n,i,l,e[11],22,-1990404162),l=p(l,o,n,i,e[12],7,1804603682),i=p(i,l,o,n,e[13],12,-40341101),n=p(n,i,l,o,e[14],17,-1502002290),l=c(l,o=p(o,n,i,l,e[15],22,1236535329),n,i,e[1],5,-165796510),i=c(i,l,o,n,e[6],9,-1069501632),n=c(n,i,l,o,e[11],14,643717713),o=c(o,n,i,l,e[0],20,-373897302),l=c(l,o,n,i,e[5],5,-701558691),i=c(i,l,o,n,e[10],9,38016083),n=c(n,i,l,o,e[15],14,-660478335),o=c(o,n,i,l,e[4],20,-405537848),l=c(l,o,n,i,e[9],5,568446438),i=c(i,l,o,n,e[14],9,-1019803690),n=c(n,i,l,o,e[3],14,-187363961),o=c(o,n,i,l,e[8],20,1163531501),l=c(l,o,n,i,e[13],5,-1444681467),i=c(i,l,o,n,e[2],9,-51403784),n=c(n,i,l,o,e[7],14,1735328473),l=d(l,o=c(o,n,i,l,e[12],20,-1926607734),n,i,e[5],4,-378558),i=d(i,l,o,n,e[8],11,-2022574463),n=d(n,i,l,o,e[11],16,1839030562),o=d(o,n,i,l,e[14],23,-35309556),l=d(l,o,n,i,e[1],4,-1530992060),i=d(i,l,o,n,e[4],11,1272893353),n=d(n,i,l,o,e[7],16,-155497632),o=d(o,n,i,l,e[10],23,-1094730640),l=d(l,o,n,i,e[13],4,681279174),i=d(i,l,o,n,e[0],11,-358537222),n=d(n,i,l,o,e[3],16,-722521979),o=d(o,n,i,l,e[6],23,76029189),l=d(l,o,n,i,e[9],4,-640364487),i=d(i,l,o,n,e[12],11,-421815835),n=d(n,i,l,o,e[15],16,530742520),l=f(l,o=d(o,n,i,l,e[2],23,-995338651),n,i,e[0],6,-198630844),i=f(i,l,o,n,e[7],10,1126891415),n=f(n,i,l,o,e[14],15,-1416354905),o=f(o,n,i,l,e[5],21,-57434055),l=f(l,o,n,i,e[12],6,1700485571),i=f(i,l,o,n,e[3],10,-1894986606),n=f(n,i,l,o,e[10],15,-1051523),o=f(o,n,i,l,e[1],21,-2054922799),l=f(l,o,n,i,e[8],6,1873313359),i=f(i,l,o,n,e[15],10,-30611744),n=f(n,i,l,o,e[6],15,-1560198380),o=f(o,n,i,l,e[13],21,1309151649),l=f(l,o,n,i,e[4],6,-145523070),i=f(i,l,o,n,e[11],10,-1120210379),n=f(n,i,l,o,e[2],15,718787259),o=f(o,n,i,l,e[9],21,-343485551),t[0]=g(l,t[0]),t[1]=g(o,t[1]),t[2]=g(n,t[2]),t[3]=g(i,t[3])}function u(t,e,l,o,n,i){return e=g(g(e,t),g(o,i)),g(e<>>32-n,l)}function p(t,e,l,o,n,i,r){return u(e&l|~e&o,t,e,n,i,r)}function c(t,e,l,o,n,i,r){return u(e&o|l&~o,t,e,n,i,r)}function d(t,e,l,o,n,i,r){return u(e^l^o,t,e,n,i,r)}function f(t,e,l,o,n,i,r){return u(l^(e|~o),t,e,n,i,r)}function h(t){var e,l=[];for(e=0;e<64;e+=4)l[e>>2]=t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24);return l}var m="0123456789abcdef".split("");function b(t){for(var e="",l=0;l<4;l++)e+=m[t>>8*l+4&15]+m[t>>8*l&15];return e}function g(t,e){return t+e&4294967295}})),define("discourse/plugins/poll/lib/chart-colors",["exports"],(function(t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getColors=function(t,e){var l;switch(e=e||"cool"){case"cool":l={0:[255,255,255],25:[220,237,200],50:[66,179,213],75:[26,39,62],100:[0,0,0]};break;case"warm":l={0:[255,255,255],25:[254,235,101],50:[228,82,27],75:[77,52,47],100:[0,0,0]}}for(var o,n,i=Object.keys(l),r=[],s=0;s=i[u]&&or&&(s=a,r=l[a]);if(++t[s],l[s]=0,e(t))break}return t.map((function(t){return Math.floor(t)}))}})),define("discourse/plugins/poll/widgets/discourse-poll",["exports","I18n","discourse/plugins/poll/controllers/poll-ui-builder","discourse/widgets/raw-html","discourse/lib/ajax","discourse/widgets/post","discourse/widgets/widget","discourse/plugins/poll/lib/even-round","discourse/plugins/poll/lib/chart-colors","virtual-dom","discourse-common/lib/icon-library","discourse/lib/load-script","discourse/lib/ajax-error","discourse/lib/formatter","discourse/lib/round","discourse/lib/show-modal"],(function(t,e,l,o,n,i,r,s,a,u,p,c,d,f,h,m){"use strict";function b(t){return function(t){if(Array.isArray(t))return g(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return g(t,e);var l=Object.prototype.toString.call(t).slice(8,-1);"Object"===l&&t.constructor&&(l=t.constructor.name);if("Map"===l||"Set"===l)return Array.from(t);if("Arguments"===l||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(l))return g(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var l=0,o=new Array(e);l".concat(t.html,""));return e.find(".discourse-local-date").each((function(t,e){$(e).applyLocalDates()})),new o.default({html:"".concat(e.html(),"")})}function _(t){return new o.default({html:''.concat(t,"")})}function y(t){return(0,n.ajax)("/polls/voters.json",{data:t}).catch((function(t){t?(0,d.popupAjaxError)(t):bootbox.alert(e.default.t("poll.error_while_fetching_voters"))}))}function O(t,e){var l=e&&e.groups&&e.groups.split(",").map((function(t){return t.toLowerCase()}));if(!l)return!0;var o=t&&t.groups&&t.groups.map((function(t){return t.name.toLowerCase()}));return o&&l.some((function(t){return o.includes(t)}))}function w(t){return(new DOMParser).parseFromString(t,"text/html").body.textContent||""}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,(0,r.createWidget)("discourse-poll-option",{tagName:"li",buildAttributes:function(t){return{tabindex:0,"data-poll-option-id":t.option.id}},html:function(t){var e=[],l=t.option,o=t.vote.includes(l.id);return t.isMultiple?e.push((0,p.iconNode)(o?"far-check-square":"far-square")):e.push((0,p.iconNode)(o?"circle":"far-circle")),e.push(" "),e.push(v(l)),e},click:function(t){0===$(t.target).closest("a").length&&this.sendWidgetAction("toggleOption",this.attrs.option)},keyDown:function(t){13===t.keyCode&&this.click(t)}}),(0,r.createWidget)("discourse-poll-load-more",{tagName:"div.poll-voters-toggle-expand",buildKey:function(t){return"load-more-".concat(t.optionId)},defaultState:function(){return{loading:!1}},html:function(t,e){return e.loading?(0,u.h)("div.spinner.small"):(0,u.h)("a",(0,p.iconNode)("chevron-down"))},click:function(){var t=this.state;if(!t.loading)return t.loading=!0,this.sendWidgetAction("loadMore").finally((function(){return t.loading=!1}))}}),(0,r.createWidget)("discourse-poll-voters",{tagName:"ul.poll-voters-list",buildKey:function(t){return"poll-voters-".concat(t.optionId)},defaultState:function(){return{loaded:"new",voters:[],page:1}},fetchVoters:function(){var t=this,e=this.attrs,l=this.state;if("loading"!==l.loaded)return l.loaded="loading",y({post_id:e.postId,poll_name:e.pollName,option_id:e.optionId,page:l.page}).then((function(o){l.loaded="loaded",l.page+=1;var n="number"===e.pollType?o.voters:o.voters[e.optionId],i=new Set(l.voters.map((function(t){return t.username})));n.forEach((function(t){i.has(t.username)||(i.add(t.username),l.voters.push(t))})),t.scheduleRerender()}))},loadMore:function(){return this.fetchVoters()},html:function(t,e){t.voters&&"new"===e.loaded&&(e.voters=t.voters);var l=e.voters.map((function(t){return(0,u.h)("li",[(0,i.avatarFor)("tiny",{username:t.username,template:t.avatar_template})," "])}));return e.voters.length".concat(a,"")}))];return n.get("public")&&(l.loaded||(l.voters=n.get("preloaded_voters"),l.loaded=!0),p.push(this.attach("discourse-poll-voters",{totalVotes:n.get("voters"),voters:l.voters||[],postId:t.post.id,pollName:n.get("name"),pollType:n.get("type")}))),p}}),(0,r.createWidget)("discourse-poll-container",{tagName:"div.poll-container",html:function(t){var n=this,i=t.poll,r=i.get("options");if(t.showResults){var s=[];t.titleHTML&&s.push(new o.default({html:t.titleHTML}));var a="number"===i.get("type")?"number":"standard",p="number"===a||t.poll.chart_type!==l.PIE_CHART_TYPE?"discourse-poll-".concat(a,"-results"):"discourse-poll-pie-chart";return s.push(this.attach(p,t)),s}if(r){var c=[];return t.titleHTML&&c.push(new o.default({html:t.titleHTML})),O(this.currentUser,i)||c.push((0,u.h)("div.alert.alert-danger",e.default.t("poll.results.groups.title",{groups:i.groups}))),c.push((0,u.h)("ul",r.map((function(e){return n.attach("discourse-poll-option",{option:e,isMultiple:t.isMultiple,vote:t.vote})})))),c}}}),(0,r.createWidget)("discourse-poll-info",{tagName:"div.poll-info",multipleHelpText:function(t,l,o){if(l>0)if(t===l){if(t>1)return e.default.t("poll.multiple.help.x_options",{count:t})}else{if(t>1)return l2&&void 0!==arguments[2]?arguments[2]:{},n="aspectRatio"in o?o.aspectRatio:2.2,i=e.map((function(t){return w(t)}));return{type:l.PIE_CHART_TYPE,data:{datasets:[{data:t,backgroundColor:(0,a.getColors)(t.length)}],labels:i},options:{responsive:!0,aspectRatio:n,animation:{duration:0},legend:{display:!1},legendCallback:function(t){for(var l="",o=0;o').concat(e[o],"");return l}}}}(t.poll.options.mapBy("votes"),t.poll.options.mapBy("html")),o=document.getElementById("poll-results-chart-".concat(t.id)),n=new Chart(o.getContext("2d"),e);document.getElementById("poll-results-legend-".concat(t.id)).innerHTML=n.generateLegend()}))},buildAttributes:function(t){return{id:"poll-results-chart-".concat(t.id)}}}),(0,r.createWidget)("discourse-poll-pie-chart",{tagName:"div.poll-results-chart",html:function(t){var e,l,o=[];if(!t.showResults)return e=t.id,(l=document.querySelector("#poll-results-chart-".concat(e)))&&l.parentNode.removeChild(l),o;var n=this.attach("discourse-poll-pie-canvas",t);return o.push(n),o.push((0,u.h)("div#poll-results-legend-".concat(t.id,".pie-chart-legends"))),o}}),(0,r.createWidget)("discourse-poll-buttons",{tagName:"div.poll-buttons",html:function(t){var l=[],n=t.poll,i=t.post,r=i.get("topic.archived"),s=t.isClosed,a="staff_only"===n.results,u=this.currentUser&&this.currentUser.staff,p=this.currentUser&&this.currentUser.admin,c=this.currentUser&&i.user_id===this.currentUser.id,d=this.siteSettings.data_explorer_enabled,h=!a&&(s||r),m=this.siteSettings.poll_export_data_explorer_query_id;if(t.isMultiple&&!h){var b=!t.canCastVotes;l.push(this.attach("button",{className:"cast-votes ".concat(b?"btn-default":"btn-primary"),label:"poll.cast-votes.label",title:"poll.cast-votes.title",disabled:b,action:"castVotes"})),l.push(" ")}if(t.showResults||h?l.push(this.attach("button",{className:"btn-default toggle-results",label:"poll.hide-results.label",title:"poll.hide-results.title",icon:"far-eye-slash",disabled:h,action:"toggleResults"})):"on_vote"!==n.get("results")||t.hasVoted||c?"on_close"!==n.get("results")||s?"staff_only"!==n.results||u?l.push(this.attach("button",{className:"btn-default toggle-results",label:"poll.show-results.label",title:"poll.show-results.title",icon:"far-eye",disabled:0===n.get("voters"),action:"toggleResults"})):l.push(_(e.default.t("poll.results.staff.title"))):l.push(_(e.default.t("poll.results.closed.title"))):l.push(_(e.default.t("poll.results.vote.title"))),t.groupableUserFields.length&&n.voters>0){var g=this.attach("button",{className:"btn-default poll-show-breakdown",label:"poll.group-results.label",title:"poll.group-results.title",icon:"far-eye",action:"showBreakdown"});l.push(g)}if(p&&d&&n.voters>0&&m&&l.push(this.attach("button",{className:"btn btn-default export-results",label:"poll.export-results.label",title:"poll.export-results.title",icon:"download",disabled:0===n.voters,action:"exportResults"})),n.get("close")){var v=moment(n.get("close"));if(v.isValid()){var y,O=v.format("LLL");if(t.isAutomaticallyClosed){var w=(0,f.relativeAge)(v.toDate(),{addAgo:!0});y=e.default.t("poll.automatic_close.age",{age:w})}else{var x=moment().to(v,!0);y=e.default.t("poll.automatic_close.closes_in",{timeLeft:x})}l.push(new o.default({html:'').concat(y,"")}))}}return!this.currentUser||this.currentUser.get("id")!==i.get("user_id")&&!u||r||(s?t.isAutomaticallyClosed||l.push(this.attach("button",{className:"btn-default toggle-status",label:"poll.open.label",title:"poll.open.title",icon:"unlock-alt",action:"toggleStatus"})):l.push(this.attach("button",{className:"toggle-status btn-danger",label:"poll.close.label",title:"poll.close.title",icon:"lock",action:"toggleStatus"}))),l}});var x=(0,r.createWidget)("discourse-poll",{tagName:"div",buildKey:function(t){return"poll-".concat(t.id)},buildAttributes:function(t){var e="poll";return t.poll.chart_type===l.PIE_CHART_TYPE&&(e+=" pie"),{class:e,"data-poll-name":t.poll.get("name"),"data-poll-type":t.poll.get("type")}},defaultState:function(t){var e=t.post,l=t.poll,o="staff_only"===t.poll.results;return{loading:!1,showResults:e.get("topic.archived")&&!o||this.isClosed()&&!o||"on_close"!==l.results&&this.hasVoted()&&!o}},html:function(t,e){var l="staff_only"===t.poll.results,o=e.showResults||t.post.get("topic.archived")&&!l||this.isClosed()&&!l,n=jQuery.extend({},t,{canCastVotes:this.canCastVotes(),hasVoted:this.hasVoted(),isAutomaticallyClosed:this.isAutomaticallyClosed(),isClosed:this.isClosed(),isMultiple:this.isMultiple(),max:this.max(),min:this.min(),showResults:o});return(0,u.h)("div",[this.attach("discourse-poll-container",n),this.attach("discourse-poll-info",n),this.attach("discourse-poll-buttons",n)])},min:function(){var t=parseInt(this.attrs.poll.get("min"),10);return(isNaN(t)||t<0)&&(t=0),t},max:function(){var t=parseInt(this.attrs.poll.get("max"),10),e=this.attrs.poll.get("options.length");return(isNaN(t)||t>e)&&(t=e),t},isAutomaticallyClosed:function(){var t=this.attrs.poll;return t.get("close")&&moment.utc(t.get("close"))<=moment()},isClosed:function(){return"closed"===this.attrs.poll.get("status")||this.isAutomaticallyClosed()},isMultiple:function(){return"multiple"===this.attrs.poll.get("type")},hasVoted:function(){var t=this.attrs.vote;return t&&t.length>0},canCastVotes:function(){var t=this.state,e=this.attrs;if(this.isClosed()||t.showResults||t.loading)return!1;var l=e.vote.length;return this.isMultiple()?l>=this.min()&&l<=this.max():l>0},toggleStatus:function(){var t=this,l=this.state,o=this.attrs,i=o.post,r=o.poll;this.isAutomaticallyClosed()||bootbox.confirm(e.default.t(this.isClosed()?"poll.open.confirm":"poll.close.confirm"),e.default.t("no_value"),e.default.t("yes_value"),(function(o){if(o){l.loading=!0;var s=t.isClosed()?"open":"closed";(0,n.ajax)("/polls/toggle_status",{type:"PUT",data:{post_id:i.get("id"),poll_name:r.get("name"),status:s}}).then((function(){r.set("status",s),"on_close"===r.get("results")&&(l.showResults="closed"===s),t.scheduleRerender()})).catch((function(t){t?(0,d.popupAjaxError)(t):bootbox.alert(e.default.t("poll.error_while_toggling_status"))})).finally((function(){l.loading=!1}))}}))},toggleResults:function(){this.state.showResults=!this.state.showResults},exportResults:function(){var t=this.attrs,l=this.siteSettings.poll_export_data_explorer_query_id;(0,n.ajax)("/admin/plugins/explorer/queries/".concat(l,"/run.csv"),{type:"POST",data:{params:JSON.stringify({poll_name:t.poll.name,post_id:t.post.id.toString()}),explain:!1,limit:1e6,download:1}}).then((function(e){var l=document.createElement("a"),o=new Blob([e],{type:"text/csv;charset=utf-8;"});l.href=URL.createObjectURL(o),l.setAttribute("download","poll-export-".concat(t.poll.name,"-").concat(t.post.id,".csv")),l.click(),l.remove()})).catch((function(t){t?(0,d.popupAjaxError)(t):bootbox.alert(e.default.t("poll.error_while_exporting_results"))}))},showLogin:function(){this.register.lookup("route:application").send("showLogin")},_toggleOption:function(t){var e=this.attrs.vote,l=e.indexOf(t.id);-1!==l?e.splice(l,1):e.push(t.id)},toggleOption:function(t){var e=this,l=this.attrs;if(!this.isClosed()){if(!this.currentUser)return this.showLogin();if(O(this.currentUser,this.attrs.poll)){var o=l.vote;return this.isMultiple()||(o.length=0),this._toggleOption(t),this.isMultiple()?void 0:this.castVotes().catch((function(){return e._toggleOption(t)}))}}},castVotes:function(){var t=this;if(this.canCastVotes()){if(!this.currentUser)return this.showLogin();var l=this.attrs,o=this.state;return o.loading=!0,(0,n.ajax)("/polls/vote",{type:"PUT",data:{post_id:l.post.id,poll_name:l.poll.get("name"),options:l.vote}}).then((function(e){var n=e.poll;l.poll.setProperties(n),t.appEvents.trigger("poll:voted",n,l.post,l.vote),"on_close"!==l.poll.get("results")&&(o.showResults=!0),"staff_only"===l.poll.results&&(t.currentUser&&t.currentUser.get("staff")?o.showResults=!0:o.showResults=!1)})).catch((function(t){t?(0,d.popupAjaxError)(t):bootbox.alert(e.default.t("poll.error_while_casting_votes"))})).finally((function(){o.loading=!1}))}},showBreakdown:function(){(0,m.default)("poll-breakdown",{model:this.attrs,panels:[{id:"percentage",title:"poll.breakdown.percentage"},{id:"count",title:"poll.breakdown.count"}]})}});t.default=x})); //# sourceMappingURL=/assets/plugins/poll-752dadfc5017172081b079c7c6b1392a46420ea148d399f83683c07d36f64509.js.map