if("undefined"==typeofjQuery)thrownewError("Baby Buddy requires jQuery.");varBabyBuddy={};functionpreventDoubleSubmit(){return!1}BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.RememberAdvancedToggle=function(e){localStorage.setItem("advancedForm",event.newState)},window.addEventListener("load",function(){"open"===localStorage.getItem("advancedForm")&&document.querySelectorAll(".advanced-fields").forEach(function(e){e.open=!0})}),BabyBuddy.Timer=function(e){varn=null,t=null,i=null,d=newDate,o=null,r={run:function(d,u){returnt=d,0===(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0===i.find(".timer-seconds").length||0===i.find(".timer-minutes").length||0===i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void0!==document.hidden?o="hidden":void0!==document.msHidden?o="msHidden":void0!==document.webkitHidden&&(o="webkitHidden"),voidwindow.addEventListener("focus",r.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[o]&&newDate-d>1&&r.update()},tick:function(){vare=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);vart=i.find(".timer-minutes"),d=Number(t.text());if(d<59)t.text(d+1);else{t.text(0);varo=i.find(".timer-hours"),r=Number(o.text());o.text(r+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"ine){clearInterval(n);vart=e.duration.split(/[\s:.]/);5===t.length&&(t[0]=24*parseInt(t[0])+parseInt(t[1]),t[1]=t[2],t[2]=t[3]),i.find(".timer-hours").text(parseInt(t[0])),i.find(".timer-minutes").text(parseInt(t[1])),i.find(".timer-seconds").text(parseInt(t[2])),d=newDate,n=setInterval(r.tick,1e3)}})}};returnr}(jQuery),BabyBuddy.Dashboard=function(e){varn=null,t={watch:function(i,d){if(0==e("#"+i).length)returnconsole.error("Baby Buddy: Dashboard element not found."),!1;void0!==document.hidden?n="hidden":void0!==document.msHidden?n="msHidden":void0!==document.webkitHidden&&(n="webkitHidden"),void0===window.addEventListener||void0===document.hidden?d&&setInterval(this.update,d):(window.addEventListener("focus",t.handleVisibilityChange,!1),d&&setInterval(t.handleVisibilityChange,d))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};returnt}(jQuery);