-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathnitrogen.min.js
1 lines (1 loc) · 34 KB
/
nitrogen.min.js
1
var nitrogen_jqm_loaded=false;function NitrogenClass(a){this.$url=document.location.href;this.$div=document;this.$sleep_check_interval=2000;this.$last_sleep_time=null;this.$ping_sent=null;this.$ping_timeout=3000;this.$ping_test_running=false;this.$websocket_reconnect_interval=25;this.$websocket_reconnect_timer_start=null;this.$current_websocket_reconnect_interval=25;this.$max_websocket_reconnect_interval=30000;this.$websocket_closing_timeout=1000;this.$websocket_closing_timer=null;this.$websocket_inactivity_interval=30000;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=false;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=false;this.$system_event_obj=null;this.$system_event_timeout=null;this.$system_reconnection_events=Array();this.$last_system_event=null;this.$going_away=false;this.$maybe_going_away=false;this.$live_validation_data_field="LV_live_validation";this.$before_postback_list=new Array();this.$js_dependencies=new Array();this.$websocket=null;this.$websockets_enabled=false;this.$websocket_status=-2;this.$websockets_ever_succeeded=false;this.$websocket_reconnect_timer=null;this.$websocket_handlers=new Array();this.$disconnected=false;this.$allow_redirect=true;this.$redirect_prompt="Are you sure you want to leave?";return this}NitrogenClass.prototype.$eval=function(data){return eval(data)};NitrogenClass.prototype.$path_alias=function(a){if(a==="page"){return document}else{return a}};NitrogenClass.prototype.$anchor=function(a,b){this.$anchor_path=this.$path_alias(a);this.$target_path=this.$path_alias(b)};NitrogenClass.prototype.$anchor_root=function(a){this.$anchor_root_path=a};NitrogenClass.prototype.$set_param=function(a,b){this.$params[a]=b};NitrogenClass.prototype.$destroy=function(){document.comet_started=false;this.$going_away=true;this.$system_event_queue=new Array();if(this.$system_event_obj!==null){this.$system_event_obj.abort()}if(this.$websocket){this.$websocket.close()}this.$system_event_is_running=false};NitrogenClass.prototype.$queue_event=function(f,b,e,c,a,d){this.$event_queue.push({vessel:f,validationGroup:b,onInvalid:e,eventContext:c,extraParam:a,ajaxSettings:d})};NitrogenClass.prototype.$queue_system_event=function(a){this.$system_event_queue.push({eventContext:a})};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(a){this.$disconnected=a};NitrogenClass.prototype.$set_disconnected=function(a){this.$set_disconnected_no_notice(a);if(a){var b=this;b.$console_log("We're disconnected, and if we're not reconnected within 2 seconds, we'll show the disconnected bar");setTimeout(function(){if(b.$disconnected){b.$console_log("It has been 2 seconds. Time to show the disconnected bar.");b.$show_disconnected_notice()}},2000)}else{this.$hide_disconnected_notice_worked()}};NitrogenClass.prototype.$register_system_reconnection_event=function(a,b){this.$system_reconnection_events.push({tag:a,fun:b})};NitrogenClass.prototype.$cancel_system_reconnection_event=function(a){for(var b=0;b<this.$system_reconnection_events.length;b++){if(this.$system_reconnection_events[b].tag==a){this.$system_reconnection_events.splice(b,1);return}}};NitrogenClass.prototype.$reconnect_system=function(){if(this.$is_disconnected()){for(var a=0;a<this.$system_reconnection_events.length;a++){this.$system_reconnection_events[a].fun()}this.$set_disconnected(false);this.$system_reconnection_events=[]}};NitrogenClass.prototype.$event_loop=function(){var a=this;var b=this.$get_time();if(this.$system_event_is_running&&this.$system_event_obj!==null&&b>this.$system_event_started+20000){this.$cancel_system_event()}if(this.$event_is_running&&this.$event_obj!==null&&b>this.$event_started+20000){this.$cancel_event()}if(this.$websocket_status==0||this.$websocket_status==1){if(!this.$system_event_is_running&&this.$system_event_queue.length>0){var c=this.$system_event_queue.shift();this.$last_system_event=c;this.$system_event_started=b;this.$do_system_event(c.eventContext)}if(!this.$event_is_running&&this.$event_queue.length>0){var c=this.$event_queue.shift();this.$last_event=c;this.$event_started=b;this.$do_event(c.vessel,c.validationGroup,c.onInvalid,c.eventContext,c.extraParam,c.ajaxSettings)}}if(this.$system_event_queue.length==0||this.$event_queue.length==0){if(this.$going_away){return}else{setTimeout(function(){a.$event_loop()},50);return}}if(this.$event_is_running||this.$system_event_is_running){setTimeout(function(){a.$event_loop()},10);return}setTimeout(function(){a.$event_loop()},1)};NitrogenClass.prototype.$show_notice_bar=function(b,c){var a=document.getElementById("nitrogen-notice-bar");if(null===a){a=document.createElement("div");a.setAttribute("id","nitrogen-notice-bar");document.body.insertBefore(a,document.body.firstChild)}a.setAttribute("class","visible is-"+b);a.innerHTML=c};NitrogenClass.prototype.$hide_notice_bar=function(){var a=document.getElementById("nitrogen-notice-bar");if(null===a){return}a.removeAttribute("class");a.innerHTML=""};NitrogenClass.prototype.$show_disconnected_notice=function(){if(!this.$going_away&&!this.$maybe_going_away){var a="⚡ Connection Broken! Attempting to reconnect... ⚡";this.$show_notice_bar("error",a)}};NitrogenClass.prototype.$hide_disconnected_notice=function(){this.$hide_notice_bar()};NitrogenClass.prototype.$hide_disconnected_notice_worked=function(){var a=document.getElementById("nitrogen-notice-bar");if(null===a){return}if(a.clientHeight>0){this.$show_notice_bar("ok","Reconnected!");this.$hide_disconnected_notice()}};NitrogenClass.prototype.$before_postback=function(a){this.$before_postback_list.push(a)};NitrogenClass.prototype.$execute_before_postbacks=function(){var c=this.$before_postback_list;for(var b=0;b<c.length;b++){try{c[b]()}catch(a){}}};NitrogenClass.prototype.$validate_and_serialize=function(f,c){var b=true,e={},g=this;this.$execute_before_postbacks();var a;if(f==null){a=jQuery(":input")}else{a=jQuery(f).find(":input")}var d=jQuery(a).not(".no_postback");jQuery(d).each(function(h){var l=Nitrogen.$get_validation(this);if(l&&l.group==c&&!l.validate()){b=false}else{if((this.type=="radio"||this.type=="checkbox")&&!this.checked){return}if(this.type=="select-multiple"&&($(this).val()==null||($(this).val().length==0))){return}if(this.type=="button"||this.type=="submit"){return}var k=g.$make_id(this);if(k==""){return}var j=$(this).val();if(j==null||(this.type=="select-multiple"&&j.length==0)){j=""}e[k]=j}});return b&&e||null};NitrogenClass.prototype.$add_validation=function(b,a){if($(b)){if(!$(b).data(Nitrogen.$live_validation_data_field)){$(b).data(Nitrogen.$live_validation_data_field,new LiveValidation(b,a))}return Nitrogen.$get_validation(b)}else{return null}};NitrogenClass.prototype.$get_validation=function(a){return $(a).data(Nitrogen.$live_validation_data_field)};NitrogenClass.prototype.$destroy_specific_validation=function(b,c){var a=Nitrogen.$get_validation(c);if(a.group==b){Nitrogen.$destroy_target_validation(c)}};NitrogenClass.prototype.$destroy_target_validation=function(b){var a=Nitrogen.$get_validation(b);if(a){a.destroy();$(b).data(Nitrogen.$live_validation_data_field,null)}};NitrogenClass.prototype.$destroy_validation_group=function(a){jQuery(":input").not(".no_postback").each(function(b){var c=Nitrogen.$get_validation(this);if(c&&c.group==a){Nitrogen.$destroy_target_validation(this)}})};NitrogenClass.prototype.$destroy_all_validation=function(){$("*").each(function(){Nitrogen.$destroy_target_validation(this)})};NitrogenClass.prototype.$make_id=function(c){var b=[];var d=new RegExp(".wfid_(.[^\\s]*)","g");while(c&&c.className){var e=c.className.match(/wfid_([^\s])+/g);if(e){b.unshift.apply(b,e)}c=c.parentNode}return b.join(".")};NitrogenClass.prototype.$show_spinner=function(){$("div.spinner").show()};NitrogenClass.prototype.$hide_spinner=function(){$("div.spinner").hide()};NitrogenClass.prototype.$do_event=function(h,d,i,f,b,j){var a=this;this.$event_is_running=true;this.$show_spinner();var g=this.$validate_and_serialize(h,d);this.$hide_spinner();if(g==null){this.$event_is_running=false;this.$event_started=null;if(i){i()}return}var c=jQuery.extend({},a.$params,g,b,{eventContext:f});var k=jQuery.extend({dataType:"text",cache:false,success:null,error:null},j);this.$event_data_type=k.dataType;this.$event_success_fun=k.success;this.$event_error_fun=k.error;this.$show_spinner();if(this.$websockets_enabled){delete c.pageContext;var e=Bert.encode_to_bytearray(Bert.tuple(Bert.atom("nitrogen_postback"),c));this.$ws_send(e.buffer)}else{this.$event_obj=jQuery.ajax({url:this.$url,type:"post",data:jQuery.param(c),dataType:k.dataType,cache:k.cache,timeout:18000,success:function(l,m){a.$event_success(l,m)},error:function(l,o,m){a.$event_error(l,o,m)}})}};NitrogenClass.prototype.$cancel_event=function(){if(this.$event_is_running){if(this.$event_obj!==null){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(true);this.$event_is_running=false;this.$hide_spinner()}};NitrogenClass.prototype.$event_success=function(a,b){this.$event_is_running=false;this.$event_started=null;this.$last_event=null;this.$hide_spinner();if(this.$is_disconnected()){this.$reconnect_system()}if(typeof this.$event_success_fun=="function"){this.$event_success_fun(a,b)}else{this.$eval(a)}};NitrogenClass.prototype.$event_error=function(a,d,b){var c=this;this.$event_started=null;this.$hide_spinner();if(d=="timeout"){this.$console_log("System Event timed out");c.$set_disconnected(true)}if(d=="timeout"||d=="error"){this.$console_log("Event Error: ("+d+"): "+b);setTimeout(function(){c.$requeue_last_event()},500)}this.$event_is_running=false;if(typeof this.$event_error_fun=="function"){this.$event_error_fun(a,d,errThrown)}};NitrogenClass.prototype.$do_system_event=function(a){var d=this;d.$system_event_is_running=true;var b=jQuery.extend({},d.$params,{eventContext:a,is_system_event:1});if(this.$websockets_enabled){delete b.pageContext;var c=Bert.encode_to_bytearray(Bert.tuple(Bert.atom("nitrogen_postback"),b));d.$ws_send(c.buffer)}else{d.$system_event_obj=$.ajax({url:this.$url,type:"post",data:jQuery.param(b),dataType:"text",cache:false,timeout:18000,success:function(e,f){d.$system_event_success(e)},error:function(e,g,f){d.$system_event_error(e,g,f)}})}};NitrogenClass.prototype.$cancel_system_event=function(){if(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(true);this.$system_event_is_running=false}};NitrogenClass.prototype.$system_event_success=function(b){var c=this;if(c.$is_disconnected()){c.$reconnect_system()}c.$system_event_is_running=false;c.$system_event_obj=null;c.$system_event_started=null;c.$last_system_event=null;var a=c.$params.pageContext;c.$eval(b);c.$set_param("pageContext",a)};NitrogenClass.prototype.$system_event_error=function(a,d,b){var c=this;this.$system_event_started=null;if(d=="timeout"){c.$set_disconnected(true)}if(d=="timeout"||d=="error"){this.$console_log("System Event Error: ("+d+"): "+b);setTimeout(function(){c.$requeue_last_system_event()},5000)}this.$system_event_is_running=false;this.$system_event_obj=null};NitrogenClass.prototype.$send_pending_files=function(c,a){var b=null;if(typeof(c.$nitrogen_pending_files)=="object"){while(b=c.$nitrogen_pending_files.shift()){b.submit()}}};NitrogenClass.prototype.$recalculate_upload_dimensions=function(d){if(typeof d=="string"){d=objs(d)}var a=$(d).find(".upload-button");var b=$(a).outerWidth(true);var c=$(a).outerHeight(true);$(d).find(".upload-content:visible").width(b).height(c)};NitrogenClass.prototype.$attach_upload_handle_dragdrop=function(d,b,c){var a=this;if(typeof(c)=="undefined"){c={}}if(typeof(d.$nitrogen_pending_files)=="undefined"){d.$nitrogen_pending_files=[]}a.$dependency_register_function("/nitrogen/jquery.fileupload.min.js",function(){var e=$(d).children(".upload_drop");$(b).fileupload({dropZone:(c.droppable?e:null),singleFileUploads:true,sequentialUploads:true,url:a.$url,paramName:"file",formData:function(){d.elements.pageContext.value=a.$params.pageContext;var f=$(d).serializeArray();return f},start:function(g,f){d.pageContext.value=a.$params.pageContext;if(c.overall_progress){$(d).children(".upload_overall_progress").progressbar({}).slideDown()}},progressall:function(g,f){if(c.overall_progress){$(d).children(".upload_overall_progress").progressbar("option","value",f.loaded).progressbar("option","max",f.total);if(f.loaded==f.total){$(d).children(".upload_overall_progress").slideUp()}}},progress:function(h,g){var f=g.loaded;$.each(g.files,function(j,k){$('li[filename="'+k.name+'"] .upload_progress').progressbar("option","value",f)})},send:function(g,f){},stop:function(g,f){},always:function(g,f){},fail:function(h,g,f){Nitrogen.$increment_pending_upload_counter(d,-1)},add:function(g,f){if(!c.multiple){if(f.files.length>1){window.alert("Sorry, you can only upload single files with this element");return}else{if(d.$nitrogen_pending_files.length>0){d.$nitrogen_pending_files=[];$(d).children(".upload_droplist").html("")}}}$.each(f.files,function(h,j){$(d).children(".upload_droplist").prepend($("<li></li>").attr("filename",j.name).prepend([$("<span>").text(j.name+" ("+a.$format_filesize(j.size)+")"),$("<a>").attr("href","javascript:;").addClass("upload_delete_file").bind("click",function(){$('li[filename="'+j.name+'"]').slideUp();a.$delete_pending_file(d,j.name)}).html("×"),$("<div>").addClass("upload_progress").progressbar({max:j.size,value:0})]));Nitrogen.$increment_pending_upload_counter(d,1)});if(c.autoupload){f.submit()}else{if(c.multiple||d.$nitrogen_pending_files.length==0){d.$nitrogen_pending_files.push(f)}else{d.$nitrogen_pending_files[0]=f}}},done:function(h,g){if(typeof g.result=="string"){var f=g.result}else{if(typeof g.result=="object"){var f=g.result[0].body.innerHTML}else{var f=""}}$.globalEval(f);Nitrogen.$increment_pending_upload_counter(d,-1)}})})};NitrogenClass.prototype.$delete_pending_file=function(d,b){for(var c=0;c<d.$nitrogen_pending_files.length;c++){for(var a=0;a<d.$nitrogen_pending_files[c].files.length;a++){if(d.$nitrogen_pending_files[c].files[a].name==b){d.$nitrogen_pending_files[c].files.splice(a,1);if(d.$nitrogen_pending_files[c].files.length==0){d.$nitrogen_pending_files.splice(c,1)}return}}}};NitrogenClass.prototype.$format_filesize=function(a){if(a>1000000000){return(a/1000000000).toFixed(1)+" GB"}else{if(a>1000000){return(a/1000000).toFixed(1)+" MB"}else{if(a>1000){return(a/1000).toFixed(1)+" KB"}else{return a+" B"}}}};NitrogenClass.prototype.$increment_pending_upload_counter=function(b,c){var a=$(b).data("pending_uploads");if(typeof(a)=="undefined"){a=0}a+=c;$(b).data("pending_uploads",a);if(a==0){Nitrogen.$alert_unfinished_files(b)}};NitrogenClass.prototype.$upload_finished=function(a){$(".upload_droplist").children('li[filename="'+a+'"]').css("text-decoration","line-through").addClass("upload_successful").fadeOut()};NitrogenClass.prototype.$alert_unfinished_files=function(c){var b=$(c).find(".upload_droplist li:not(.upload_successful):visible");if(b.length>0){$(c).find(".upload_droplist li:not(.upload_successful)").css("color","red").fadeOut("slow");var a=$(b).get().map(function(d){return $(d).text()}).join("\r\n");window.alert("There was an error uploading the following file(s):\r\n"+a+"\r\n\r\nThis is likely due to the file(s) being too large or a misconfiguration on the server")}};function obj(b,a){return objs(b,a).get(0)}function objs(k,e){if(typeof k!="string"){throw {invalid_path_in_objs:k}}k=jQuery.trim(k);if(!e){e=Nitrogen.$anchor_path}else{e=Nitrogen.$path_alias(e)}if(k.indexOf(",")!=-1){var j=k.split(",");var f=$();for(var c=0;c<j.length;c++){f=f.add(objs(j[c],e))}return f}if(k=="page"||k==".page"){return jQuery(document)}k=k.replace(/##/g,".wfid_");k=k.replace(/\bme\b/g,e);if(k.indexOf(" ")==-1&&k.indexOf(".")==-1&&k.indexOf("#")==-1){var d=objs(".wfid_"+k,e);if(d.length>0){return d}if(d.length==0&&jQuery.inArray(k.toLowerCase(),Nitrogen.$valid_elements)==-1){return jQuery()}}var h=new RegExp(/^body\b/);if(h.test(k)){return jQuery(k)}var g=jQuery(Nitrogen.$anchor_root_path).find(e);var d=g.find(k);if(d.length>0){return d}var d=g.parentsUntil(Nitrogen.$anchor_root_path);for(var c=0;c<d.length;c++){var b=jQuery(d.get(c)).find(k);if(b.length>0){return b}}return jQuery(k)}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(a,d,b,c){objs(d,a).bind(b,c)};NitrogenClass.prototype.$update=function(a,c,b){objs(c,a).html(b)};NitrogenClass.prototype.$replace=function(a,c,b){objs(c,a).replaceWith(b)};NitrogenClass.prototype.$insert_top=function(a,c,b){objs(c,a).prepend(b)};NitrogenClass.prototype.$insert_bottom=function(a,c,b){objs(c,a).append(b)};NitrogenClass.prototype.$insert_before=function(a,c,b){objs(c,a).before(b)};NitrogenClass.prototype.$insert_after=function(a,c,b){objs(c,a).after(b)};NitrogenClass.prototype.$remove=function(b,c){var a=objs(c,b).remove();$(a).next(".LV_validation_message").remove();a.remove()};NitrogenClass.prototype.$dependency_register_function=function(b,a){if(this.$is_dependency_loaded(b)){a()}else{this.$load_js_dependency(b);this.$js_dependencies[b].pending_calls.push(a)}};NitrogenClass.prototype.$load_js_dependency=function(a){var b=this;if(!b.$is_dependency_initialized(a)){b.$init_dependency_if_needed(a);$.ajax({url:a,dataType:"script",success:function(c,e,d){b.$js_dependencies[a].loaded=true;b.$execute_dependency_scripts(a)},error:function(d,e,c){b.$console_log({error_loading_file:a,error:e,errorThrown:c})}})}};NitrogenClass.prototype.$init_dependency_if_needed=function(a){if(this.$js_dependencies[a]===undefined){this.$js_dependencies[a]={loaded:false,pending_calls:[]}}};NitrogenClass.prototype.$is_dependency_initialized=function(a){return this.$js_dependencies[a]!==undefined};NitrogenClass.prototype.$is_dependency_loaded=function(a){if(!this.$is_dependency_initialized(a)){return false}else{return this.$js_dependencies[a].loaded}};NitrogenClass.prototype.$execute_dependency_scripts=function(b){var a;while(a=this.$js_dependencies[b].pending_calls.shift()){a()}};NitrogenClass.prototype.$console_log=function(b){try{var a=new Date();if(typeof b=="string"){console.log(a+": "+b)}else{console.log({date:a,log:b})}}catch(c){}};NitrogenClass.prototype.$return_false=function(b,a){return false};NitrogenClass.prototype.$is_key_code=function(b,c,a){return(b&&b.keyCode==c&&b.shiftKey==a)};NitrogenClass.prototype.$go_next=function(a){var b=obj(a);if(b.focus){b.focus()}if(b.select){b.select()}};NitrogenClass.prototype.$disable_selection=function(a){a.onselectstart=function(){return false};a.unselectable="on";a.style.MozUserSelect="none";a.style.cursor="default"};NitrogenClass.prototype.$set_value=function(a,b,d,c){var e=this;if(!b.id){b=objs(b)}b.each(function(f,g){if(g.value!=undefined){$(g).val(d)}else{if(g.checked!=undefined){g.checked=d}else{if(g.src!=undefined){g.src=d}else{if($(g).hasClass("ui-progressbar")){e.$set_progress_bar_value(g,d,c)}else{if($(g).hasClass("wf_mermaid")){e.$mermaid(g,d)}else{$(g).html(d)}}}}}})};NitrogenClass.prototype.$set_values=function(b,c,a){var d=this;if(!c.id){c=objs(c)}c.each(function(f,g){if(g.type=="select-multiple"){$(g).val(a)}else{if(g.type=="checkbox"){var e=($.inArray(g.value,a)!=-1);g.checked=e}}})};NitrogenClass.prototype.$get_value=function(a,b){if(!b.id){b=objs(b)}el=b.get(0);if(el.value!=undefined){return el.value}else{if(el.checked!=undefined){return el.checked}else{if(el.src!=undefined){return el.src}else{if($(el).hasClass("ui-progressbar")){n.$get_progress_bar_value(el)}else{return $(el).html()}}}}};NitrogenClass.prototype.$normalize_param=function(a,c){var b="";if(a){b=a}if(a&&c){b=a+"="+c}return a+"&"+c};NitrogenClass.prototype.$encode_arguments_object=function(d){if(!Bert){window.alert("Bert.js library not included in template.")}else{Bert.assoc_array_key_encoding("binary");var b=new Array();for(var c=0;c<d.length;c++){b.push(d[c])}var e=Bert.encode_to_base64(b);return{args:e}}};NitrogenClass.prototype.$urlencode=function(a){return escape(a).replace(/\+/g,"%2B").replace(/%20/g,"+").replace(/\*/g,"%2A").replace(/\//g,"%2F").replace(/@/g,"%40")};NitrogenClass.prototype.$set_cookie=function(d,f,g,e){var a;if(e){var c=new Date();var b=e*60*1000;c.setTime(this.$get_time()+b);a="; expires="+c.toUTCString()}else{a=""}document.cookie=[encodeURIComponent(d),"=",encodeURIComponent(f),a,"; path=",g].join("")};NitrogenClass.prototype.$datepicker=function(b,a){jQuery(b).datepicker(a)};NitrogenClass.prototype.$autocomplete=function(c,a,b,f){var e=this;var d=null;jQuery.extend(a,{select:function(h,i){var j=i.item.value.replace(/"/g,'\\"');var g=(i.item)&&'{"id":"'+i.item.id+'","value":"'+j+'"}'||"";e.$queue_event(d,null,null,f,{select_item:g})},source:function(h,g){e.$queue_event(d,null,null,b,{search_term:h.term},{dataType:"json",success:function(i){g(i)}})}});jQuery(c).autocomplete(a)};NitrogenClass.prototype.$draggable=function(b,a,c){objs(b).each(function(d,e){e.$drag_tag=c;jQuery(e).draggable(a)})};NitrogenClass.prototype.$droppable=function(c,a,b){var e=this;var d=null;a.drop=function(f,h){var g=h.draggable[0].$drag_tag;e.$queue_event(d,null,null,b,{drag_item:g})};objs(c).each(function(f,g){jQuery(g).droppable(a)})};NitrogenClass.prototype.$sortitem=function(a,c){var b=obj(a);b.$sort_tag=c;b.$drag_tag=c};NitrogenClass.prototype.$sortblock=function(a,e,b){var d=this;var c=null;e.update=function(){var h="";for(var g=0;g<this.childNodes.length;g++){var f=this.childNodes[g];if(h!=""){h+=","}if(f.$sort_tag){h+=f.$sort_tag}}d.$queue_event(c,null,null,b,{sort_items:h})};objs(a).sortable(e)};NitrogenClass.prototype.$trap_tabs=function(a){var b=document.querySelector(a);if(null===b){return}b.addEventListener("keydown",function(c){if(c.keyCode==9){document.execCommand("insertText",false,"\t");c.preventDefault();return false}})};NitrogenClass.prototype.$from_alien=function(a){var b=$("input#"+a).val();objs(a).val(b)};NitrogenClass.prototype.$init_progress_bar=function(c,d,a,b){objs(c).progressbar({value:d,max:a});b=this.$normalize_color(b);objs(c).find(".ui-progressbar-value").css("background",b).css("border-color",b)};NitrogenClass.prototype.$normalize_color=function(a){if(a.match(/^#/)){return a}else{if(a.match(/^[0-9a-fA-F]{3,6}$/)){return"#"+a}else{return a}}};NitrogenClass.prototype.$set_progress_bar_value=function(d,f,c){var g="";if(typeof d=="object"){d=$(d)}else{d=objs(d)}if(typeof f=="string"){f=parseInt(f)}d.progressbar("option","value",f);if(d.hasClass("progressbar-label-string")){g=c}else{if(d.hasClass("progressbar-label-none")){g=""}else{if(f!==false){var a=d.progressbar("option","max");var e=Math.floor(f*100/a)+"%";var b=f+"/"+a;if(d.hasClass("progressbar-label-percent")){g=e}else{if(d.hasClass("progressbar-label-ratio")){g=b}else{if(d.hasClass("progressbar-label-both")){g=e+" ("+b+")"}}}}}}d.find(".progressbar-label").text(g)};NitrogenClass.prototype.$get_progress_bar_max=function(a){return objs(a).progressbar("option","max")};NitrogenClass.prototype.$get_progress_bar_value=function(a){return objs(a).progressbar("option","value")};NitrogenClass.prototype.$mermaid=function(b,a){if(typeof b=="object"){element=$(b);id="wf_mermaid"}else{element=objs(b);id=b}if(element.hasClass("wf_mermaid")){var c=function(d,e){element.html(d)};mermaid.mermaidAPI.render(id,a,c)}};NitrogenClass.prototype.$ws_send=function(a){if(this.$websocket.readyState==this.$websocket.OPEN){if(this.$websockets_enabled&&a!="ping"&&this.$older_than(this.$last_websocket_received,10000)){this.$ping_test()}this.$websocket.send(a);return"ok"}else{if(this.$websocket.readyState==this.$websocket.OPENING){var b=this;setTimeout(function(){b.$ws_send(a)},100);return"ok"}else{this.$console_log("Unable to send message. Websocket is in an unsendable state (readyState="+this.$websocket.readyState+"). Force-closing websocket.");this.$close_websocket();return"closed"}}};NitrogenClass.prototype.$enable_websockets=function(){this.$console_log("Websockets Enabled (instance_id = "+this.$websocket.instance_id+")");this.$websockets_enabled=true;this.$websockets_ever_succeeded=true;this.$websocket_status=1;this.$flush_switchover_comet_actions()};NitrogenClass.prototype.$flush_switchover_comet_actions=function(){var a=Bert.encode_to_bytearray(Bert.atom("flush_switchover_comet_actions"));this.$ws_send(a)};NitrogenClass.prototype.$disable_websockets=function(){var a=this;a.$console_log("Websockets disabled or disconnected");a.$websockets_enabled=false;a.$websocket_status=0;clearTimeout(a.$websocket_closing_timer);a.$websocket_closing_timer=null;a.$websocket=null;a.$current_websocket_instance_id=null;if(navigator.onLine){if(a.$websockets_ever_succeeded){if(a.$older_than(a.$last_websocket_received,15000)){a.$console_log("Last Websocket message received more than 15 seconds ago. Marking Disconnected");a.$set_disconnected(true)}if(a.$websocket_reconnect_timer!=null){clearTimeout(a.$websocket_reconnect_timer)}if(a.$websocket_reconnect_timer_start==null||a.$older_than(a.$websocket_reconnect_timer_start,a.$current_websocket_reconnect_interval-10)){a.$current_websocket_reconnect_interval+=Math.min(a.$current_websocket_reconnect_interval,5000)}else{a.$console_log("It seems the reconnect timer happened too quickly. So we'll repeat the reconnection interval we just used.")}if(a.$current_websocket_reconnect_interval>a.$max_websocket_reconnect_interval){a.$current_websocket_reconnect_interval=a.$max_websocket_reconnect_interval}a.$websocket_reconnect_timer_start=a.$get_time();a.$console_log("Attempting reconnect in "+a.$current_websocket_reconnect_interval+" ms");a.$websocket_reconnect_timer=setTimeout(function(){a.$ws_init()},a.$current_websocket_reconnect_interval)}}};NitrogenClass.prototype.$ws_init=function(){try{if(this.$websocket!=null&&this.$websocket.readyState==this.$websocket.OPEN){this.$set_disconnected(false);this.$console_log("The connection is already open");return}else{if(this.$websocket!=null&&this.$websocket.readyState==this.$websocket.OPENING){if(this.$older_than(this.$websocket_connecting_start,5000)){this.$console_log("The connection is taking too long to open. Canceling this request");this.$disable_websockets()}else{this.$console_log("Currently attempting to connect to websockets. This is a duplicate request to connect. Skipping...")}}else{this.$websocket_status=-1;Bert.assoc_array_key_encoding("binary");var d=new Error();var c=this.$ws_url(location.href.split("#")[0]);this.$websocket=new WebSocket(c);this.$websocket.instance_id=Math.trunc((Math.random()*Number.MAX_SAFE_INTEGER));this.$websocket_connecting_start=this.$get_time();this.$websocket.binaryType="arraybuffer";var a=this;this.$websocket.onopen=function(e){if(a.$websocket.instance_id==e.target.instance_id){a.$last_sleep_time=a.$get_time();a.$current_websocket_instance_id=a.$websocket.instance_id;a.$ws_open()}else{e.target.close();a.$console_log("An older websocket attempt connected. Closing it to avoid conflicts.")}};this.$websocket.onclose=function(e){a.$handle_websocket_close(e)};this.$websocket.onmessage=function(e){a.$ws_message(e.data)};this.$websocket.onerror=function(e){a.$handle_websocket_close(e);a.$ws_close()};setTimeout(function(){if(a.$websocket==null||a.$websocket.readyState!=a.$websocket.OPEN){a.$console_log("Websockets timed out. Falling back to AJAX for postbacks.");a.$disable_websockets()}},5000)}}}catch(b){this.$disable_websockets()}};NitrogenClass.prototype.$handle_websocket_close=function(a){if(a.target.instance_id==this.$current_websocket_instance_id){this.$console_log("The current websocket (instance_id = "+a.target.instance_id+") has closed with type ("+a.type+"). Doing some clean-up.");this.$ws_close()}else{this.$console_log("The stale websocket (instance_id = "+a.target.instance_id+") has closed with type ("+a.type+"). Nothing to clean up.")}};NitrogenClass.prototype.$ws_url=function(a){return a.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 a=this.$params.pageContext;var b=Bert.encode_to_bytearray(Bert.tuple(Bert.atom("page_context"),Bert.binary(a)));this.$ws_send(b)};NitrogenClass.prototype.$ws_close=function(){this.$console_log("The websocket has closed");if(this.$system_event_is_running){this.$requeue_last_system_event()}if(this.$event_is_running){this.$requeue_last_event()}this.$disable_websockets()};NitrogenClass.prototype.$ws_message=function(data){this.$last_websocket_received=this.$get_time();if(typeof data=="string"){if(data=="pong"){this.$pong_received()}else{var matches=null;if(matches=data.match(/^nitrogen_system_event:([\s\S]*)/)){this.$system_event_success(matches[1])}else{if(matches=data.match(/^nitrogen_event:([\s\S]*)/)){var response_data=null;if(this.$event_data_type=="json"){response_data=eval(matches[1])}else{response_data=matches[1]}this.$event_data_type=null;this.$event_success(response_data)}else{this.$run_registered_ws_handlers(data)}}}}else{this.$run_registered_ws_handlers(data)}};NitrogenClass.prototype.$register_ws_handler=function(c,b){for(var a=0;a<this.$websocket_handlers.length;a++){if(this.$websocket_handlers[a].id==c){this.$websocket_handlers[a].fun=b;return}}this.$websocket_handlers.push({id:c,fun:b})};NitrogenClass.prototype.$unregister_ws_handler=function(b){for(var a=0;a<this.$websocket_handlers.length;a++){if(this.$websocket_handlers[a].id==b){this.$websocket_handlers.splice(a,1);return}}};NitrogenClass.prototype.$run_registered_ws_handlers=function(a){this.$websocket_handlers.forEach(function(b){if(b.fun(a)){return true}});this.$console_log({error:"Received a websocket message that was not handled.",message:a});return false};NitrogenClass.prototype.$listen_for_online=function(){var a=this;window.addEventListener("offline",function(){a.$console_log("'offline' event has posted to the browser.");a.$kill_reconnect_loop();a.$set_disconnected(true)});window.addEventListener("online",function(){a.$console_log("Browser is back online. Running the reconnect loop");a.$attempt_websockets();a.$init_reconnect_loop()})};NitrogenClass.prototype.$attempt_websockets=function(){var a=this;$(document).ready(function(){if(typeof Bert=="object"){a.$ws_init()}else{a.$console_log("Bert not linked from template. Attempting to load dynamically.");this.$set_disconnected_no_notice(false);a.$dependency_register_function("/nitrogen/bert.js",function(){a.$console_log("Bert successfully loaded");a.$ws_init()})}})};NitrogenClass.prototype.$init_reconnect_loop=function(){var a=this;if(!this.$reconnect_timeout){this.$reconnect_timeout=setTimeout(function(){a.$reconnect_timeout=undefined;if(navigator.onLine){a.$reconnect_loop();a.$init_reconnect_loop()}},a.$sleep_check_interval)}};NitrogenClass.prototype.$kill_reconnect_loop=function(){if(!!this.$reconnect_timeout){this.$console_log("Killing the reconnect loop while browser is offline");clearTimeout(this.$reconnect_timeout);this.$reconnect_timeout=undefined}};NitrogenClass.prototype.$reconnect_loop=function(){if(this.$websocket_status==1){var a=this.$get_time();if(this.$older_than(this.$last_sleep_time,this.$sleep_check_interval*2)){this.$console_log("Potential Sleep Detected. Checking websocket status with a ping");this.$ping_test()}else{if(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=a}};NitrogenClass.prototype.$older_than=function(b,a){if(b==null){return true}var c=this.$get_time();return c>(b+a)};NitrogenClass.prototype.$ping_test=function(){if(this.$ping_test_running){this.$console_log("Ping test is still running. Skipping")}else{this.$ping_sent=this.$get_time();var a=this.$ws_send("ping");if(a=="ok"){this.$ping_test_running=true;var b=this;this.$console_log("Ping test sent");this.$ping_timer=setTimeout(function(){b.$pong_not_received()},this.$ping_timeout)}}};NitrogenClass.prototype.$pong_received=function(){var b=this.$get_time();var a=b-this.$ping_sent;this.$ping_test_running=false;clearTimeout(this.$ping_timer);this.$ping_timer=null;this.$console_log("Websocket still connected. Ping: "+a+"ms")};NitrogenClass.prototype.$pong_not_received=function(){this.$console_log("Websocket does not appear to be connected. Triggering reconnect...");this.$ping_test_running=false;this.$close_websocket()};NitrogenClass.prototype.$close_websocket=function(){var b=this;try{b.$websocket_closing_timer=setTimeout(function(){if(b.$websocket_closing_timer!=null){b.$console_log("Websockets still trying to disconnect. Short-circuiting...")}b.$disable_websockets()},b.$websocket_closing_timeout);b.$websocket.close()}catch(a){b.$console_log(["Closing the websocket failed with this error message",a]);b.$disable_websockets()}};NitrogenClass.prototype.$get_time=function(){return(new Date()).getTime()};var page=document;var Nitrogen=new NitrogenClass();$(window).on("beforeunload",function(){if(!Nitrogen.$allow_redirect){return Nitrogen.$redirect_prompt}Nitrogen.$maybe_going_away=true;setTimeout(function(){Nitrogen.$maybe_going_away=false},1000);return});document.addEventListener("readystatechange",function(){if("complete"!==document.readyState||nitrogen_jqm_loaded){return}Nitrogen.$attempt_websockets();Nitrogen.$init_reconnect_loop();Nitrogen.$event_loop();Nitrogen.$listen_for_online()});