Current section
Files
Jump to
Current section
Files
priv/www/nitrogen.min.js
var nitrogen_jqm_loaded=!1;let WebSocketStatus={NOT_ATTEMPTED:-2,TRYING_TO_CONNECT:-1,NOT_ENABLED:0,CONNECTED:1};class NitrogenDeferredPromise{constructor(){this._promise=new Promise((resolve,reject)=>{this.resolve=resolve,this.reject=reject}),this.then=this._promise.then.bind(this._promise),this.catch=this._promise.catch.bind(this._promise),this.finally=this._promise.finally.bind(this._promise),this[Symbol.toStringTag]="Promise"}}function NitrogenClass(o){return this.$url=document.location.href,this.$div=document,this.$sleep_check_interval=2e3,this.$last_sleep_time=null,this.$ping_sent=null,this.$ping_timeout=3e3,this.$ping_test_running=!1,this.$websocket_reconnect_interval=25,this.$websocket_reconnect_timer_start=null,this.$current_websocket_reconnect_interval=25,this.$max_websocket_reconnect_interval=3e4,this.$websocket_closing_timeout=1e3,this.$websocket_closing_timer=null,this.$websocket_inactivity_interval=3e4,this.$websocket_connecting_start=0,this.$last_websocket_received=0,this.$anchor_root_path=document,this.$params=new Object,this.$event_queue=new Array,this.$event_is_running=!1,this.$event_success_fun=null,this.$event_error_fun=null,this.$event_data_type="text",this.$event_obj=null,this.$event_timeout=null,this.$system_event_queue=new Array,this.$system_event_is_running=!1,this.$system_event_obj=null,this.$system_event_timeout=null,this.$system_reconnection_events=Array(),this.$last_system_event=null,this.$going_away=!1,this.$maybe_going_away=!1,this.$validation_data_field="nitrogen_validation_field",this.$validation_msg_class="nitrogen_validation_failed",this.$before_postback_list=new Array,this.$js_triggers=new Array,this.$websocket=null,this.$websockets_enabled=!1,this.$websocket_status=WebSocketStatus.NOT_ATTEMPTED,this.$websockets_ever_succeeded=!1,this.$websocket_reconnect_timer=null,this.$websocket_handlers=new Array,this.$validation_system=null,this.$disconnected=!1,this.$allow_redirect=!0,this.$redirect_prompt="Are you sure you want to leave?",this}function obj(path,anchor){return objs(path,anchor).get(0)}function objs(path,anchor){if("string"!=typeof path)throw{invalid_path_in_objs:path};if(path=jQuery.trim(path),anchor=anchor?Nitrogen.$path_alias(anchor):Nitrogen.$anchor_path,-1!=path.indexOf(",")){for(var paths=path.split(","),a=$(),i=0;i<paths.length;i++)a=a.add(objs(paths[i],anchor));return a}if("page"==path||".page"==path)return jQuery(document);if(-1==(path=(path=path.replace(/##/g,".wfid_")).replace(/\bme\b/g,anchor)).indexOf(" ")&&-1==path.indexOf(".")&&-1==path.indexOf("#")){if(0<(results=objs(".wfid_"+path,anchor)).length)return results;if(0==results.length&&-1==jQuery.inArray(path.toLowerCase(),Nitrogen.$valid_elements))return jQuery()}var re=new RegExp(/^body\b/);if(!re.test(path)){re=jQuery(Nitrogen.$anchor_root_path).find(anchor);if(0<(results=re.find(path)).length)return results;for(var results=re.parentsUntil(Nitrogen.$anchor_root_path),i=0;i<results.length;i++){var results2=jQuery(results.get(i)).find(path);if(0<results2.length)return results2}}return jQuery(path)}NitrogenClass.prototype.$eval=function(data){return eval(data)},NitrogenClass.prototype.$path_alias=function(path){return"page"===path?document:path},NitrogenClass.prototype.$anchor=function(anchor,target){this.$anchor_path=this.$path_alias(anchor),this.$target_path=this.$path_alias(target)},NitrogenClass.prototype.$anchor_root=function(anchor_root){this.$anchor_root_path=anchor_root},NitrogenClass.prototype.$set_param=function(key,value){this.$params[key]=value},NitrogenClass.prototype.$destroy=function(){document.comet_started=!1,this.$going_away=!0,this.$system_event_queue=new Array,null!==this.$system_event_obj&&this.$system_event_obj.abort(),this.$websocket&&this.$websocket.close(),this.$system_event_is_running=!1},NitrogenClass.prototype.$queue_event=function(vessel,validationGroup,onInvalid,eventContext,extraParam,ajaxSettings){this.$event_queue.push({vessel:vessel,validationGroup:validationGroup,onInvalid:onInvalid,eventContext:eventContext,extraParam:extraParam,ajaxSettings:ajaxSettings})},NitrogenClass.prototype.$queue_system_event=function(eventContext){this.$system_event_queue.push({eventContext:eventContext})},NitrogenClass.prototype.$requeue_last_system_event=function(){this.$system_event_queue.unshift(this.$last_system_event)},NitrogenClass.prototype.$requeue_last_event=function(){this.$event_queue.unshift(this.$last_event)},NitrogenClass.prototype.$is_disconnected=function(){return this.$disconnected},NitrogenClass.prototype.$set_disconnected_no_notice=function(disconnected){this.$disconnected=disconnected},NitrogenClass.prototype.$set_disconnected=function(disconnected){var n;this.$set_disconnected_no_notice(disconnected),disconnected?((n=this).$console_log("We're disconnected, and if we're not reconnected within 2 seconds, we'll show the disconnected bar"),setTimeout(function(){n.$disconnected&&(n.$console_log("It has been 2 seconds. Time to show the disconnected bar."),n.$show_disconnected_notice())},2e3)):this.$hide_disconnected_notice_worked()},NitrogenClass.prototype.$register_system_reconnection_event=function(tag,fun){this.$system_reconnection_events.push({tag:tag,fun:fun})},NitrogenClass.prototype.$cancel_system_reconnection_event=function(tag){for(var i=0;i<this.$system_reconnection_events.length;i++)if(this.$system_reconnection_events[i].tag==tag)return void this.$system_reconnection_events.splice(i,1)},NitrogenClass.prototype.$reconnect_system=function(){if(this.$is_disconnected()){for(var i=0;i<this.$system_reconnection_events.length;i++)this.$system_reconnection_events[i].fun();this.$set_disconnected(!1),this.$system_reconnection_events=[]}},NitrogenClass.prototype.$event_loop=function(){var o,this2=this,now=this.$get_time();if(this.$system_event_is_running&&null!==this.$system_event_obj&&now>this.$system_event_started+2e4&&this.$cancel_system_event(),this.$event_is_running&&null!==this.$event_obj&&now>this.$event_started+2e4&&this.$cancel_event(),[WebSocketStatus.NOT_ENABLED,WebSocketStatus.CONNECTED].includes(this.$websocket_status)&&(!this.$system_event_is_running&&0<this.$system_event_queue.length&&(o=this.$system_event_queue.shift(),this.$last_system_event=o,this.$system_event_started=now,this.$do_system_event(o.eventContext)),!this.$event_is_running)&&0<this.$event_queue.length&&(o=this.$event_queue.shift(),this.$last_event=o,this.$event_started=now,this.$do_event(o.vessel,o.validationGroup,o.onInvalid,o.eventContext,o.extraParam,o.ajaxSettings)),0==this.$system_event_queue.length||0==this.$event_queue.length)return this.$going_away?void 0:void setTimeout(function(){this2.$event_loop()},50);this.$event_is_running||this.$system_event_is_running?setTimeout(function(){this2.$event_loop()},10):setTimeout(function(){this2.$event_loop()},1)},NitrogenClass.prototype.$show_notice_bar=function(notice_type,msg){var notice_bar=document.getElementById("nitrogen-notice-bar");null===notice_bar&&((notice_bar=document.createElement("div")).setAttribute("id","nitrogen-notice-bar"),document.body.insertBefore(notice_bar,document.body.firstChild)),notice_bar.setAttribute("class","visible is-"+notice_type),notice_bar.innerHTML=msg},NitrogenClass.prototype.$hide_notice_bar=function(){var notice_bar=document.getElementById("nitrogen-notice-bar");null!==notice_bar&&(notice_bar.removeAttribute("class"),notice_bar.innerHTML="")},NitrogenClass.prototype.$show_disconnected_notice=function(){this.$going_away||this.$maybe_going_away||this.$show_notice_bar("error","⚡ Connection Broken! Attempting to reconnect... ⚡")},NitrogenClass.prototype.$hide_disconnected_notice=function(){this.$hide_notice_bar()},NitrogenClass.prototype.$hide_disconnected_notice_worked=function(){var notice_bar=document.getElementById("nitrogen-notice-bar");null!==notice_bar&&0<notice_bar.clientHeight&&(this.$show_notice_bar("ok","Reconnected!"),this.$hide_disconnected_notice())},NitrogenClass.prototype.$before_postback=function(f){this.$before_postback_list.push(f)},NitrogenClass.prototype.$execute_before_postbacks=function(){for(var before_list=this.$before_postback_list,i=0;i<before_list.length;i++)try{before_list[i]()}catch(ex){}},NitrogenClass.prototype.$validate_and_serialize=function(vessel,validationGroup){var is_valid=!0,params={},n=this,vessel=(this.$execute_before_postbacks(),vessel=null==vessel?jQuery(":input"):jQuery(vessel).find(":input"),jQuery(vessel).not(".no_postback"));return jQuery(vessel).each(function(i){var id,val;n.$validate_element(this,validationGroup)?n.$ignore_element(this)||""!=(id=n.$make_id(this))&&(val=$(this).val(),params[id]=val=null==val?"":val):is_valid=!1}),is_valid&¶ms||null},NitrogenClass.prototype.$ignore_element=function(element){return this.$is_unchecked(element)||this.$is_empty_multiselect(element)||this.$is_button(element)||!this.$is_nitrogen_element(element)},NitrogenClass.prototype.$is_unchecked=function(element){return("radio"==element.type||"checkbox"==element.type)&&!element.checked},NitrogenClass.prototype.$is_empty_multiselect=function(element){return"select-multiple"==element.type&&(null==$(element).val()||0==$(element).val().length)},NitrogenClass.prototype.$is_button=function(element){return"button"==element.type||"submit"==element.type},NitrogenClass.prototype.$is_nitrogen_element=function(element){return""!=this.$make_id(element)},NitrogenClass.prototype.$init_validation=function(element,group,args){this.$register_trigger("validation_system_loaded",function(){Nitrogen.$init_validation(element,group,args)})},NitrogenClass.prototype.$get_validation=function(element){throw"validation not loaded"},NitrogenClass.prototype.$set_validation=function(element,data){throw"validation not loaded"},NitrogenClass.prototype.$validate_element=function(element){throw"validation not loaded"},NitrogenClass.prototype.$add_validation=function(element,fun){this.$register_trigger("validation_system_loaded",function(){Nitrogen.$add_validation(element,fun)})},NitrogenClass.prototype.$remove_validation_artifacts=function(element){},NitrogenClass.prototype.$is_validation_loaded=function(){return this.$is_trigger_loaded("validation_system_loaded")},NitrogenClass.prototype.$set_validation_loaded=function(systemName){this.$validation_system=systemName,this.$set_trigger_loaded("validation_system_loaded"),this.$execute_triggers("validation_system_loaded")},NitrogenClass.prototype.$get_validation_system=function(){return this.$validation_system},NitrogenClass.prototype.$destroy_specific_validation=async function(trigger,target){(await this.$get_validation)(target).group==trigger&&this.$destroy_target_validation(target)},NitrogenClass.prototype.$destroy_target_validation=function(element){this.$get_validation(element)&&$(element).data(this.$validation_data_field,null)},NitrogenClass.prototype.$destroy_validation_group=function(validationGroup){var this2=this;jQuery(":input").not(".no_postback").each(function(i){var LV=this2.$get_validation(this);LV&&LV.group==validationGroup&&this2.$destroy_target_validation(this)})},NitrogenClass.prototype.$destroy_all_validation=function(){var this2=this;$("*").each(function(){this2.$destroy_target_validation(this)})},NitrogenClass.prototype.$make_id=function(element){var a=[];for(new RegExp(".wfid_(.[^\\s]*)","g");element&&element.className;){var matches=element.className.match(/wfid_([^\s])+/g);matches&&a.unshift.apply(a,matches),element=element.parentNode}return a.join(".")},NitrogenClass.prototype.$show_spinner=function(){$("div.spinner").show()},NitrogenClass.prototype.$hide_spinner=function(){$("div.spinner").hide()},NitrogenClass.prototype.$do_event=function(vessel,validationGroup,onInvalid,eventContext,extraParam,ajaxSettings){var n=this,vessel=(this.$event_is_running=!0,this.$show_spinner(),this.$validate_and_serialize(vessel,validationGroup));this.$hide_spinner(),null==vessel?(this.$event_is_running=!1,this.$event_started=null,onInvalid&&onInvalid()):(validationGroup=jQuery.extend({},n.$params,vessel,extraParam,{eventContext:eventContext}),onInvalid=jQuery.extend({dataType:"text",cache:!1,success:null,error:null},ajaxSettings),this.$event_data_type=onInvalid.dataType,this.$event_success_fun=onInvalid.success,this.$event_error_fun=onInvalid.error,this.$show_spinner(),this.$websockets_enabled?(delete validationGroup.pageContext,vessel=Bert.encode_to_bytearray(Bert.tuple(Bert.atom("nitrogen_postback"),validationGroup)),this.$ws_send(vessel.buffer)):this.$event_obj=jQuery.ajax({url:this.$url,type:"post",data:jQuery.param(validationGroup),dataType:onInvalid.dataType,cache:onInvalid.cache,timeout:18e3,success:function(data,textStatus){n.$event_success(data,textStatus)},error:function(XHR,textStatus,errorThrown){n.$event_error(XHR,textStatus,errorThrown)}}))},NitrogenClass.prototype.$cancel_event=function(){this.$event_is_running&&(null!==this.$event_obj&&(this.$event_obj.abort(),this.$event_obj=null),this.$event_started=null,this.$console_log("Running event was cancelled due to taking too long"),this.$set_disconnected(!0),this.$event_is_running=!1,this.$hide_spinner())},NitrogenClass.prototype.$event_success=function(data,textStatus){this.$event_is_running=!1,this.$event_started=null,this.$last_event=null,this.$hide_spinner(),this.$is_disconnected()&&this.$reconnect_system(),"function"==typeof this.$event_success_fun?this.$event_success_fun(data,textStatus):this.$eval(data)},NitrogenClass.prototype.$event_error=function(XHR,textStatus,errorThrown){var n=this;this.$event_started=null,this.$hide_spinner(),"timeout"==textStatus&&(this.$console_log("System Event timed out"),n.$set_disconnected(!0)),"timeout"!=textStatus&&"error"!=textStatus||(this.$console_log("Event Error: ("+textStatus+"): "+errorThrown),setTimeout(function(){n.$requeue_last_event()},500)),this.$event_is_running=!1,"function"==typeof this.$event_error_fun&&this.$event_error_fun(XHR,textStatus,errThrown)},NitrogenClass.prototype.$do_system_event=function(eventContext){var bertified,n=this,eventContext=(n.$system_event_is_running=!0,jQuery.extend({},n.$params,{eventContext:eventContext,is_system_event:1}));this.$websockets_enabled?(delete eventContext.pageContext,bertified=Bert.encode_to_bytearray(Bert.tuple(Bert.atom("nitrogen_postback"),eventContext)),n.$ws_send(bertified.buffer)):n.$system_event_obj=$.ajax({url:this.$url,type:"post",data:jQuery.param(eventContext),dataType:"text",cache:!1,timeout:18e3,success:function(data,textStatus){n.$system_event_success(data)},error:function(XHR,textStatus,errorThrown){n.$system_event_error(XHR,textStatus,errorThrown)}})},NitrogenClass.prototype.$cancel_system_event=function(){this.$system_event_is_running&&(this.$system_event_obj.abort(),this.$system_event_started=null,this.$console_log("Canceling system event for taking too long"),this.$set_disconnected(!0),this.$system_event_is_running=!1)},NitrogenClass.prototype.$system_event_success=function(data){var n=this,pc=(n.$is_disconnected()&&n.$reconnect_system(),n.$system_event_is_running=!1,n.$system_event_obj=null,n.$system_event_started=null,n.$last_system_event=null,n.$params.pageContext);n.$eval(data),n.$set_param("pageContext",pc)},NitrogenClass.prototype.$system_event_error=function(XHR,textStatus,errorThrown){var n=this;this.$system_event_started=null,"timeout"==textStatus&&n.$set_disconnected(!0),"timeout"!=textStatus&&"error"!=textStatus||(this.$console_log("System Event Error: ("+textStatus+"): "+errorThrown),setTimeout(function(){n.$requeue_last_system_event()},5e3)),this.$system_event_is_running=!1,this.$system_event_obj=null},NitrogenClass.prototype.$send_pending_files=function(form,input){var file=null;if("object"==typeof form.$nitrogen_pending_files)for(;file=form.$nitrogen_pending_files.shift();)file.submit()},NitrogenClass.prototype.$recalculate_upload_dimensions=function(form){"string"==typeof form&&(form=objs(form));var fakeinput=$(form).find(".upload-button"),w=$(fakeinput).outerWidth(!0),fakeinput=$(fakeinput).outerHeight(!0);$(form).find(".upload-content:visible").width(w).height(fakeinput)},NitrogenClass.prototype.$attach_upload_handle_dragdrop=function(form,input,settings){var thisNitro=this;void 0===settings&&(settings={}),void 0===form.$nitrogen_pending_files&&(form.$nitrogen_pending_files=[]),thisNitro.$dependency_register_function("/nitrogen/jquery.fileupload.min.js",function(){var dropzone=$(form).children(".upload_drop");$(input).fileupload({dropZone:settings.droppable?dropzone:null,singleFileUploads:!0,sequentialUploads:!0,url:thisNitro.$url,paramName:"file",formData:function(){return form.elements.pageContext.value=thisNitro.$params.pageContext,$(form).serializeArray()},start:function(e,data){form.pageContext.value=thisNitro.$params.pageContext,settings.overall_progress&&$(form).children(".upload_overall_progress").progressbar({}).slideDown()},progressall:function(e,data){settings.overall_progress&&($(form).children(".upload_overall_progress").progressbar("option","value",data.loaded).progressbar("option","max",data.total),data.loaded==data.total)&&$(form).children(".upload_overall_progress").slideUp()},progress:function(e,data){var loaded=data.loaded;$.each(data.files,function(i,f){$('li[filename="'+f.name+'"] .upload_progress').progressbar("option","value",loaded)})},send:function(e,data){},stop:function(e,data){},always:function(e,data){},fail:function(e,data,options){thisNitro.$increment_pending_upload_counter(form,-1)},add:function(e,data){if(!settings.multiple){if(1<data.files.length)return void window.alert("Sorry, you can only upload single files with this element");0<form.$nitrogen_pending_files.length&&(form.$nitrogen_pending_files=[],$(form).children(".upload_droplist").html(""))}$.each(data.files,function(i,f){$(form).children(".upload_droplist").prepend($("<li></li>").attr("filename",f.name).prepend([$("<span>").text(f.name+" ("+thisNitro.$format_filesize(f.size)+")"),$("<a>").attr("href","javascript:;").addClass("upload_delete_file").bind("click",function(){$('li[filename="'+f.name+'"]').slideUp(),thisNitro.$delete_pending_file(form,f.name)}).html("×"),$("<div>").addClass("upload_progress").progressbar({max:f.size,value:0})])),Nitrogen.$increment_pending_upload_counter(form,1)}),settings.autoupload?data.submit():settings.multiple||0==form.$nitrogen_pending_files.length?form.$nitrogen_pending_files.push(data):form.$nitrogen_pending_files[0]=data},done:function(e,data){data="string"==typeof data.result?data.result:"object"==typeof data.result?data.result[0].body.innerHTML:"",$.globalEval(data),Nitrogen.$increment_pending_upload_counter(form,-1)}})})},NitrogenClass.prototype.$delete_pending_file=function(form,name){for(var i=0;i<form.$nitrogen_pending_files.length;i++)for(var j=0;j<form.$nitrogen_pending_files[i].files.length;j++)if(form.$nitrogen_pending_files[i].files[j].name==name)return form.$nitrogen_pending_files[i].files.splice(j,1),void(0==form.$nitrogen_pending_files[i].files.length&&form.$nitrogen_pending_files.splice(i,1))},NitrogenClass.prototype.$format_filesize=function(size){return 1e9<size?(size/1e9).toFixed(1)+" GB":1e6<size?(size/1e6).toFixed(1)+" MB":1e3<size?(size/1e3).toFixed(1)+" KB":size+" B"},NitrogenClass.prototype.$increment_pending_upload_counter=function(form,incrementer){var counter=$(form).data("pending_uploads");void 0===counter&&(counter=0),counter+=incrementer,$(form).data("pending_uploads",counter),0==counter&&Nitrogen.$alert_unfinished_files(form)},NitrogenClass.prototype.$upload_finished=function(Name){$(".upload_droplist").children('li[filename="'+Name+'"]').css("text-decoration","line-through").addClass("upload_successful").fadeOut()},NitrogenClass.prototype.$alert_unfinished_files=function(form){var files=$(form).find(".upload_droplist li:not(.upload_successful):visible");0<files.length&&($(form).find(".upload_droplist li:not(.upload_successful)").css("color","red").fadeOut("slow"),form=$(files).get().map(function(f){return $(f).text()}).join("\r\n"),window.alert("There was an error uploading the following file(s):\r\n"+form+"\r\n\r\nThis is likely due to the file(s) being too large or a misconfiguration on the server"))},NitrogenClass.prototype.$valid_elements=["a","abbr","acronym","address","applet","area","b","base","basefont","bdo","big","blockquote","body","br","button","caption","center","cite","code","col","colgroup","dd","del","dfn","dir","div","dl","dt","em","fieldset","font","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","hr","html","i","iframe","img","input","ins","isindex","kbd","label","legend","li","link","map","menu","meta","noframes","noscript","object","ol","optgroup","option","p","param","pre","q","s","samp","script","select","small","span","strike","strong","style","sub","sup","table","tbody","td","textarea","tfoot","th","thead","title","tr","tt","u","ul","var"],NitrogenClass.prototype.$observe_event=function(anchor,path,type,func){objs(path,anchor).bind(type,func)},NitrogenClass.prototype.$update=function(anchor,path,html){objs(path,anchor).html(html)},NitrogenClass.prototype.$replace=function(anchor,path,html){objs(path,anchor).replaceWith(html)},NitrogenClass.prototype.$insert_top=function(anchor,path,html){objs(path,anchor).prepend(html)},NitrogenClass.prototype.$insert_bottom=function(anchor,path,html){objs(path,anchor).append(html)},NitrogenClass.prototype.$insert_before=function(anchor,path,html){objs(path,anchor).before(html)},NitrogenClass.prototype.$insert_after=function(anchor,path,html){objs(path,anchor).after(html)},NitrogenClass.prototype.$remove=function(anchor,path){path=objs(path,anchor);this.$remove_validation_artifacts(path),path.remove()},NitrogenClass.prototype.$dependency_register_function=function(dependency,fun){this.$is_dependency_loaded(dependency)?fun():(this.$load_js_dependency(dependency),dependency=this.$dep_to_trigger(dependency),this.$js_triggers[dependency].pending_calls.push(fun))},NitrogenClass.prototype.$register_trigger=function(trigger,fun){this.$is_trigger_loaded(trigger)?fun():(this.$init_trigger_if_needed(trigger),this.$js_triggers[trigger].pending_calls.push(fun))},NitrogenClass.prototype.$load_js_dependency=function(url){var n=this;n.$is_dependency_loaded(url)||(n.$init_dependency_if_needed(url),$.ajax({url:url,dataType:"script",success:function(data,textStatus,jqxhr){n.$set_dependency_loaded(url),n.$execute_dependency_triggers(url)},error:function(jqxhr,textStatus,errorThrown){n.$console_log({error_loading_file:url,error:textStatus,errorThrown:errorThrown})}}))},NitrogenClass.prototype.$dep_to_trigger=function(dep){return"dependency::"+dep},NitrogenClass.prototype.$init_trigger_if_needed=function(trigger){void 0===this.$js_triggers[trigger]&&(this.$js_triggers[trigger]={loaded:!1,pending_calls:[]})},NitrogenClass.prototype.$init_dependency_if_needed=function(dependency){dependency=this.$dep_to_trigger(dependency);return this.$init_trigger_if_needed(dependency)},NitrogenClass.prototype.$is_trigger_initialized=function(trigger){return void 0!==this.$js_triggers[trigger]},NitrogenClass.prototype.$is_dependency_initialized=function(dependency){dependency=this.$dep_to_trigger(dependency);return this.$is_trigger_initialized(dependency)},NitrogenClass.prototype.$is_trigger_loaded=function(trigger){return!!this.$is_trigger_initialized(trigger)&&this.$js_triggers[trigger].loaded},NitrogenClass.prototype.$set_trigger_loaded=function(trigger){this.$init_trigger_if_needed(trigger),this.$js_triggers[trigger].loaded=!0},NitrogenClass.prototype.$set_dependency_loaded=function(dependency){dependency=this.$dep_to_trigger(dependency);this.$js_triggers[dependency].loaded=!0},NitrogenClass.prototype.$is_dependency_loaded=function(dependency){dependency=this.$dep_to_trigger(dependency);return this.$is_trigger_loaded(dependency)},NitrogenClass.prototype.$execute_triggers=function(trigger){for(var fun;fun=this.$js_triggers[trigger].pending_calls.shift();)fun()},NitrogenClass.prototype.$execute_dependency_triggers=function(dependency){dependency=this.$dep_to_trigger(dependency);return this.$execute_triggers(dependency)},NitrogenClass.prototype.$console_log=function(data){try{var dt=new Date;"string"==typeof data?console.log(dt+": "+data):console.log({date:dt,log:data})}catch(e){}},NitrogenClass.prototype.$return_false=function(value,args){return!1},NitrogenClass.prototype.$is_key_code=function(event,keyCode,shiftKey){return event&&event.keyCode==keyCode&&event.shiftKey==shiftKey},NitrogenClass.prototype.$go_next=function(controlID){controlID=obj(controlID);controlID.focus&&controlID.focus(),controlID.select&&controlID.select()},NitrogenClass.prototype.$disable_selection=function(element){element.onselectstart=function(){return!1},element.unselectable="on",element.style.MozUserSelect="none",element.style.cursor="default"},NitrogenClass.prototype.$set_value=function(anchor,element,value,optional_label){var n=this;(element=element.id?element:objs(element)).each(function(index,el){null!=el.value?$(el).val(value):null!=el.checked?el.checked=value:null!=el.src?el.src=value:$(el).hasClass("ui-progressbar")?n.$set_progress_bar_value(el,value,optional_label):$(el).hasClass("wf_mermaid")?n.$mermaid(el,value):$(el).html(value)})},NitrogenClass.prototype.$set_values=function(anchor,element,values){(element=element.id?element:objs(element)).each(function(index,el){var to_check;"select-multiple"==el.type?$(el).val(values):"checkbox"==el.type&&(to_check=-1!=$.inArray(el.value,values),el.checked=to_check)})},NitrogenClass.prototype.$get_value=function(anchor,element){var el;return(element="string"==typeof(element=null==element?anchor:element)?objs(element):element)instanceof HTMLElement?el=element:element instanceof jQuery&&(el=element.get(0)),null!=el.value?el.value:null!=el.checked?el.checked:null!=el.src?el.src:$(el).hasClass("ui-progressbar")?void n.$get_progress_bar_value(el):$(el).html()},NitrogenClass.prototype.$normalize_param=function(key,value){return key+"&"+value},NitrogenClass.prototype.$encode_arguments_object=function(Obj){if(Bert){Bert.assoc_array_key_encoding("binary");for(var a=new Array,i=0;i<Obj.length;i++)a.push(Obj[i]);return{args:Bert.encode_to_base64(a)}}window.alert("Bert.js library not included in template.")},NitrogenClass.prototype.$urlencode=function(str){return escape(str).replace(/\+/g,"%2B").replace(/%20/g,"+").replace(/\*/g,"%2A").replace(/\//g,"%2F").replace(/@/g,"%40")},NitrogenClass.prototype.$set_cookie=function(cookie,value,path,minutes_to_live){var date,minutes_to_live=minutes_to_live?(minutes_to_live=60*minutes_to_live*1e3,(date=new Date).setTime(this.$get_time()+minutes_to_live),"; expires="+date.toUTCString()):"";document.cookie=[encodeURIComponent(cookie),"=",encodeURIComponent(value),minutes_to_live,"; path=",path].join("")},NitrogenClass.prototype.$datepicker=function(pickerObj,pickerOptions){jQuery(pickerObj).datepicker(pickerOptions)},NitrogenClass.prototype.$autocomplete=function(path,autocompleteOptions,enterPostbackInfo,selectPostbackInfo){var n=this;jQuery.extend(autocompleteOptions,{select:function(ev,ui){var val=ui.item.value.replace(/"/g,'\\"'),ui=ui.item&&'{"id":"'+ui.item.id+'","value":"'+val+'"}'||"";n.$queue_event(null,null,null,selectPostbackInfo,{select_item:ui})},source:function(req,res){n.$queue_event(null,null,null,enterPostbackInfo,{search_term:req.term},{dataType:"json",success:function(data){res(data)}})}}),jQuery(path).autocomplete(autocompleteOptions)},NitrogenClass.prototype.$draggable=function(path,dragOptions,dragTag){objs(path).each(function(index,el){el.$drag_tag=dragTag,jQuery(el).draggable(dragOptions)})},NitrogenClass.prototype.$droppable=function(path,dropOptions,dropPostbackInfo){var n=this;dropOptions.drop=function(ev,ui){ui=ui.draggable[0].$drag_tag;n.$queue_event(null,null,null,dropPostbackInfo,{drag_item:ui})},objs(path).each(function(index,el){jQuery(el).droppable(dropOptions)})},NitrogenClass.prototype.$sortitem=function(el,sortTag){el=obj(el);el.$sort_tag=sortTag,el.$drag_tag=sortTag},NitrogenClass.prototype.$sortblock=function(el,sortOptions,sortPostbackInfo){var n=this;sortOptions.update=function(){for(var sortItems="",i=0;i<this.childNodes.length;i++){var childNode=this.childNodes[i];""!=sortItems&&(sortItems+=","),childNode.$sort_tag&&(sortItems+=childNode.$sort_tag)}n.$queue_event(null,null,null,sortPostbackInfo,{sort_items:sortItems})},objs(el).sortable(sortOptions)},NitrogenClass.prototype.$trap_tabs=function(selector){selector=document.querySelector(selector);null!==selector&&selector.addEventListener("keydown",function(e){if(9==e.keyCode)return document.execCommand("insertText",!1,"\t"),e.preventDefault(),!1})},NitrogenClass.prototype.$from_alien=function(nativeID){var input=$("input#"+nativeID).val();objs(nativeID).val(input)},NitrogenClass.prototype.$init_progress_bar=function(el,value,max,color){objs(el).progressbar({value:value,max:max}),color=this.$normalize_color(color),objs(el).find(".ui-progressbar-value").css("background",color).css("border-color",color)},NitrogenClass.prototype.$normalize_color=function(color){return!color.match(/^#/)&&color.match(/^[0-9a-fA-F]{3,6}$/)?"#"+color:color},NitrogenClass.prototype.$set_progress_bar_value=function(el,value,label){var percent_label,newlabel="";el=("object"==typeof el?$:objs)(el),"string"==typeof value&&(value=parseInt(value)),el.progressbar("option","value",value),el.hasClass("progressbar-label-string")?newlabel=label:el.hasClass("progressbar-label-none")?newlabel="":!1!==value&&(label=el.progressbar("option","max"),percent_label=Math.floor(100*value/label)+"%",value=value+"/"+label,el.hasClass("progressbar-label-percent")?newlabel=percent_label:el.hasClass("progressbar-label-ratio")?newlabel=value:el.hasClass("progressbar-label-both")&&(newlabel=percent_label+" ("+value+")")),el.find(".progressbar-label").text(newlabel)},NitrogenClass.prototype.$get_progress_bar_max=function(el){return objs(el).progressbar("option","max")},NitrogenClass.prototype.$get_progress_bar_value=function(el){return objs(el).progressbar("option","value")},NitrogenClass.prototype.$mermaid=function(el,mermaidCode){id="object"==typeof el?(element=$(el),"wf_mermaid"):(element=objs(el),el),element.hasClass("wf_mermaid")&&mermaid.mermaidAPI.render(id,mermaidCode,function(svgCode,bindFunctions){element.html(svgCode)})},NitrogenClass.prototype.$ws_send=function(data){var n;return this.$websocket.readyState==this.$websocket.OPEN?(this.$websockets_enabled&&"ping"!=data&&this.$older_than(this.$last_websocket_received,1e4)&&this.$ping_test(),this.$websocket.send(data),"ok"):this.$websocket.readyState==this.$websocket.OPENING?(n=this,setTimeout(function(){n.$ws_send(data)},100),"ok"):(this.$console_log("Unable to send message. Websocket is in an unsendable state (readyState="+this.$websocket.readyState+"). Force-closing websocket."),this.$close_websocket(),"closed")},NitrogenClass.prototype.$enable_websockets=function(){this.$console_log("Websockets Enabled (instance_id = "+this.$websocket.instance_id+")"),this.$websockets_enabled=!0,this.$websockets_ever_succeeded=!0,this.$websocket_status=WebSocketStatus.CONNECTED,this.$flush_switchover_comet_actions()},NitrogenClass.prototype.$flush_switchover_comet_actions=function(){var bertified=Bert.encode_to_bytearray(Bert.atom("flush_switchover_comet_actions"));this.$ws_send(bertified)},NitrogenClass.prototype.$disable_websockets=function(){var n=this;n.$console_log("Websockets disabled or disconnected"),n.$websockets_enabled=!1,n.$websocket_status=WebSocketStatus.NOT_ENABLED,clearTimeout(n.$websocket_closing_timer),n.$websocket_closing_timer=null,n.$websocket=null,n.$current_websocket_instance_id=null,navigator.onLine&&n.$websockets_ever_succeeded&&(n.$older_than(n.$last_websocket_received,15e3)&&(n.$console_log("Last Websocket message received more than 15 seconds ago. Marking Disconnected"),n.$set_disconnected(!0)),null!=n.$websocket_reconnect_timer&&clearTimeout(n.$websocket_reconnect_timer),null==n.$websocket_reconnect_timer_start||n.$older_than(n.$websocket_reconnect_timer_start,n.$current_websocket_reconnect_interval-10)?n.$current_websocket_reconnect_interval+=Math.min(n.$current_websocket_reconnect_interval,5e3):n.$console_log("It seems the reconnect timer happened too quickly. So we'll repeat the reconnection interval we just used."),n.$current_websocket_reconnect_interval>n.$max_websocket_reconnect_interval&&(n.$current_websocket_reconnect_interval=n.$max_websocket_reconnect_interval),n.$websocket_reconnect_timer_start=n.$get_time(),n.$console_log("Attempting reconnect in "+n.$current_websocket_reconnect_interval+" ms"),n.$websocket_reconnect_timer=setTimeout(function(){n.$ws_init()},n.$current_websocket_reconnect_interval))},NitrogenClass.prototype.$ws_init=function(){try{var ws_url,this2;null!=this.$websocket&&this.$websocket.readyState==this.$websocket.OPEN?(this.$set_disconnected(!1),this.$console_log("The connection is already open")):null!=this.$websocket&&this.$websocket.readyState==this.$websocket.OPENING?this.$older_than(this.$websocket_connecting_start,5e3)?(this.$console_log("The connection is taking too long to open. Canceling this request"),this.$disable_websockets()):this.$console_log("Currently attempting to connect to websockets. This is a duplicate request to connect. Skipping..."):(this.$websocket_status=WebSocketStatus.TRYING_TO_CONNECT,Bert.assoc_array_key_encoding("binary"),new Error,ws_url=this.$ws_url(location.href.split("#")[0]),this.$websocket=new WebSocket(ws_url),this.$websocket.instance_id=Math.trunc(Math.random()*Number.MAX_SAFE_INTEGER),this.$websocket_connecting_start=this.$get_time(),this.$websocket.binaryType="arraybuffer",(this2=this).$websocket.onopen=function(evt){this2.$websocket.instance_id==evt.target.instance_id?(this2.$last_sleep_time=this2.$get_time(),this2.$current_websocket_instance_id=this2.$websocket.instance_id,this2.$ws_open()):(evt.target.close(),this2.$console_log("An older websocket attempt connected. Closing it to avoid conflicts."))},this.$websocket.onclose=function(evt){this2.$handle_websocket_close(evt)},this.$websocket.onmessage=function(evt){this2.$ws_message(evt.data)},this.$websocket.onerror=function(evt){this2.$handle_websocket_close(evt),this2.$ws_close()},setTimeout(function(){null!=this2.$websocket&&this2.$websocket.readyState==this2.$websocket.OPEN||(this2.$console_log("Websockets timed out. Falling back to AJAX for postbacks."),this2.$disable_websockets())},5e3))}catch(ex){this.$disable_websockets()}},NitrogenClass.prototype.$handle_websocket_close=function(evt){evt.target.instance_id==this.$current_websocket_instance_id?(this.$console_log("The current websocket (instance_id = "+evt.target.instance_id+") has closed with type ("+evt.type+"). Doing some clean-up."),this.$ws_close()):this.$console_log("The stale websocket (instance_id = "+evt.target.instance_id+") has closed with type ("+evt.type+"). Nothing to clean up.")},NitrogenClass.prototype.$ws_url=function(url){return url.replace(/^http/,"ws")},NitrogenClass.prototype.$ws_open=function(){this.$current_websocket_reconnect_interval=this.$websocket_reconnect_interval,this.$websocket_last_time=this.$get_time(),this.$send_pagecontext()},NitrogenClass.prototype.$send_pagecontext=function(){var pageContext=this.$params.pageContext,pageContext=Bert.encode_to_bytearray(Bert.tuple(Bert.atom("page_context"),Bert.binary(pageContext)));this.$ws_send(pageContext)},NitrogenClass.prototype.$ws_close=function(){this.$console_log("The websocket has closed"),this.$system_event_is_running&&this.$requeue_last_system_event(),this.$event_is_running&&this.$requeue_last_event(),this.$disable_websockets()},NitrogenClass.prototype.$ws_message=function(data){var matches,response_data,response_data;this.$last_websocket_received=this.$get_time(),"string"==typeof data?"pong"==data?this.$pong_received():(matches=null,(matches=data.match(/^nitrogen_system_event:([\s\S]*)/))?this.$system_event_success(matches[1]):(matches=data.match(/^nitrogen_event:([\s\S]*)/))?(response_data=null,response_data="json"==this.$event_data_type?eval(matches[1]):matches[1],this.$event_data_type=null,this.$event_success(response_data)):this.$run_registered_ws_handlers(data)):this.$run_registered_ws_handlers(data)},NitrogenClass.prototype.$register_ws_handler=function(id,handler){for(var i=0;i<this.$websocket_handlers.length;i++)if(this.$websocket_handlers[i].id==id)return void(this.$websocket_handlers[i].fun=handler);this.$websocket_handlers.push({id:id,fun:handler})},NitrogenClass.prototype.$unregister_ws_handler=function(id){for(var i=0;i<this.$websocket_handlers.length;i++)if(this.$websocket_handlers[i].id==id)return void this.$websocket_handlers.splice(i,1)},NitrogenClass.prototype.$run_registered_ws_handlers=function(data){return this.$websocket_handlers.forEach(function(e){if(e.fun(data))return!0}),this.$console_log({error:"Received a websocket message that was not handled.",message:data}),!1},NitrogenClass.prototype.$listen_for_online=function(){var n=this;window.addEventListener("offline",function(){n.$console_log("'offline' event has posted to the browser."),n.$kill_reconnect_loop(),n.$set_disconnected(!0)}),window.addEventListener("online",function(){n.$console_log("Browser is back online. Running the reconnect loop"),n.$attempt_websockets(),n.$init_reconnect_loop()})},NitrogenClass.prototype.$attempt_websockets=function(){var n=this;$(document).ready(function(){"object"==typeof Bert?n.$ws_init():(n.$console_log("Bert not linked from template. Attempting to load dynamically."),this.$set_disconnected_no_notice(!1),n.$dependency_register_function("/nitrogen/bert.js",function(){n.$console_log("Bert successfully loaded"),n.$ws_init()}))})},NitrogenClass.prototype.$init_reconnect_loop=function(){var n=this;this.$reconnect_timeout||(this.$reconnect_timeout=setTimeout(function(){n.$reconnect_timeout=void 0,navigator.onLine&&(n.$reconnect_loop(),n.$init_reconnect_loop())},n.$sleep_check_interval))},NitrogenClass.prototype.$kill_reconnect_loop=function(){this.$reconnect_timeout&&(this.$console_log("Killing the reconnect loop while browser is offline"),clearTimeout(this.$reconnect_timeout),this.$reconnect_timeout=void 0)},NitrogenClass.prototype.$reconnect_loop=function(){var currentTime;this.$websocket_status===WebSocketStatus.CONNECTED&&(currentTime=this.$get_time(),this.$older_than(this.$last_sleep_time,2*this.$sleep_check_interval)?(this.$console_log("Potential Sleep Detected. Checking websocket status with a ping"),this.$ping_test()):this.$older_than(this.$last_websocket_received,this.$websocket_inactivity_interval)&&(this.$console_log("No message received for a while. Pinging the server, just to be sure we're still connected"),this.$ping_test()),this.$last_sleep_time=currentTime)},NitrogenClass.prototype.$older_than=function(comparison_time,age_in_ms){return null==comparison_time||comparison_time+age_in_ms<this.$get_time()},NitrogenClass.prototype.$ping_test=function(){var n;this.$ping_test_running?this.$console_log("Ping test is still running. Skipping"):(this.$ping_sent=this.$get_time(),"ok"==this.$ws_send("ping")&&(this.$ping_test_running=!0,(n=this).$console_log("Ping test sent"),this.$ping_timer=setTimeout(function(){n.$pong_not_received()},this.$ping_timeout)))},NitrogenClass.prototype.$pong_received=function(){var pingtime=this.$get_time()-this.$ping_sent;this.$ping_test_running=!1,clearTimeout(this.$ping_timer),this.$ping_timer=null,this.$console_log("Websocket still connected. Ping: "+pingtime+"ms")},NitrogenClass.prototype.$pong_not_received=function(){this.$console_log("Websocket does not appear to be connected. Triggering reconnect..."),this.$ping_test_running=!1,this.$close_websocket()},NitrogenClass.prototype.$close_websocket=function(){var n=this;try{n.$websocket_closing_timer=setTimeout(function(){null!=n.$websocket_closing_timer&&n.$console_log("Websockets still trying to disconnect. Short-circuiting..."),n.$disable_websockets()},n.$websocket_closing_timeout),n.$websocket.close()}catch(ex){n.$console_log(["Closing the websocket failed with this error message",ex]),n.$disable_websockets()}},NitrogenClass.prototype.$get_time=function(){return(new Date).getTime()},NitrogenClass.prototype.$is_integer=function(v){return"number"==typeof v?Number.isInteger(v):"string"==typeof v&&/^-?\d+$/.test(v)},NitrogenClass.prototype.$is_float=function(v){return"number"==typeof v?Number.isFloat(v):"string"==typeof v&&/^-?\d+(\.\d+)?$/.test(v)},NitrogenClass.prototype.$is_number=function(v){return this.$is_integer(v)||this.$is_float(v)};var page=document,Nitrogen=new NitrogenClass;window.addEventListener("beforeunload",function(){if(!Nitrogen.$allow_redirect)return Nitrogen.$redirect_prompt;Nitrogen.$maybe_going_away=!0,setTimeout(function(){Nitrogen.$maybe_going_away=!1},1e3)}),document.addEventListener("readystatechange",function(){"complete"!==document.readyState||nitrogen_jqm_loaded||(Nitrogen.$attempt_websockets(),Nitrogen.$init_reconnect_loop(),Nitrogen.$event_loop(),Nitrogen.$listen_for_online())});