!function(a,b,c,d,e){var f=d.Model.extend({defaults:{bookId:null,chapterId:null,verseId:null,lastVerseId:99,notes:null,lastVerseIdOpened:null},initialize:function(){var a=this;a.set("notes",new NoteCollection),a.on("change:verseId",a.logRead)},focusPreviousVerse:function(){var a=this,b=a.get("verseId");b>1&&a.set("verseId",b-1)},focusNextVerse:function(){var a=this,b=a.get("lastVerseId"),c=a.get("verseId");c<%= title %><%= body %>');var h=c.$(".verse-sentence:last").attr("data-key"),i=h.split("-");2==i.length&&(g=parseInt(i[1],10));var j=b.location.hash;if(j){var i=j.split("#");2==i.length&&(e=parseInt(i[1],10))}c.model=new f({logReadUrl:SCRIPTURE_JAVARS.logReadUrl,bookId:SCRIPTURE_JAVARS.bookId,chapterId:SCRIPTURE_JAVARS.chapterId,verseId:e,lastVerseId:g}),e>1&&c.scrollToFocusVerse(),c.renderFocusVerse(),c.model.logRead(),c.model.on("change:verseId",c.renderFocusVerse,c),c.on("scrollToFocusVerse",c.scrollToFocusVerse,c),c.initVerseIndicator(),a("body").on("mouseenter",".comment-popover .ref",function(a){c.openRefPopover(a)});var k=c.model.get("notes");c.noteViews={},k.on("add",c.renderExistingNoteWriterView,c),k.on("change",c.renderNotePopover,c),k.on("destroy",c.removeNoteIndicator,c),c.model.fetchNotes(),a("body").on("click",".write-comment-modal .close-modal",function(){c.closeWriteCommentModal()}),c.initStickFooter(),c.initStickHeader(),a(b).scroll(),_.defer(function(){c.initTooltip()}),a("body").on("keyup",function(a){c.handleKeyup(a)}),_.bindAll(c,"openRefPopover","openCmtPopover","openMixedPopover"),a("body").on("mouseenter",".ref",c.openRefPopover),a("body").on("mouseenter",".sfw",c.openCmtPopover),a("body").on("mouseenter",".verse-indicator",c.openCmtPopover),a("body").on("mouseenter",".mixed-tip",c.openMixedPopover)},events:{"click .switcher .btn":"handleClickSwitchContentNav","click .verse-sentence":"handleClickVerseSentence","click .verse-intro":"handleClickVerseIntro","click .verse-intro .to-close":"handleClickCloseVerseIntro","click .write-note .write":"renderNewNoteWriterView","click .note-indicator":"handleClickNoteIndicator"},initStickHeader:function(){var c=this,d=a(b),e=c.$(".control-panel"),f=e.offset(),g=f.top,h=e.width(),i=e.height();e.find(".wrapper").css({height:i,width:h}),e.css({height:i,width:h}),d.scroll(function(){var a=d.scrollTop();e.toggleClass("stick",a>g)})},initStickFooter:function(){var c=this,d=a(b),e=c.$(".category-icons"),f=e.offset(),g=f.top,h=g+e.height(),i=e.width(),j=e.height(),k={height:j,width:i};e.find(".wrapper").css(k),e.parent().css(k),d.scroll(function(){var a=d.scrollTop()+d.height();e.toggleClass("stick",a'+f[1]+"",fadeSpeed:0,autoReposition:!1,preventDefault:!1}).popover("show"),a.ajax({url:"../Recoder/Log",type:"POST",data:{"Recoders[Type]":4,"Recoders[key]":e,"Recoders[bookId]":c.model.get("bookId"),"Recoders[chapterId]":c.model.get("chapterId"),"Recoders[verseId]":c.model.get("lastVerseIdOpened")}}))}},openCmtPopover:function(b){var f,c=this,d=a(b.target),g=/-(\d*)/;f=g.exec(d.attr("data-to"));var h=d.attr("data-to"),i=c.commentCandidates[h];if(_.isUndefined(d.data("popover"))&&(d.attr("data-to")!=e&&c.model.set("lastVerseIdOpened",f[1]),i)){var j="";_.isArray(i[0])?_.each(i,function(a,b){j+=c.multiCmtTmpl({title:a[0],body:a[1]})}):j=c.multiCmtTmpl({title:i[0],body:i[1]}),d.cascadePopover({title:null,content:'
'+j+"
"}).popover("show")}timer=setTimeout(function(){a.ajax({url:"../Recoder/Log",type:"POST",data:{"Recoders[Type]":1,"Recoders[key]":h,"Recoders[bookId]":c.model.get("bookId"),"Recoders[chapterId]":c.model.get("chapterId"),"Recoders[verseId]":f[1]}}),console.log("Log:"+h)},3e3)},openMixedPopover:function(b){var c=this,d=a(b.target);if(_.isUndefined(d.data("popover"))){var e=d.attr("data-to"),f=c.mixedTipCandidates[e];if(f){d.cascadePopover({title:null,content:f}).popover("show")}}},initVerseIndicator:function(){var b=this;b.$(".paratext-panel .verse-indicator").each(function(c,d){var e=a(d),f=e.attr("data-to"),g=b.commentCandidates[f];g&&e.addClass("has-popover")})},handleClickSwitchContentNav:function(b){var c=this,d=c.$(".main-panel"),e=a(b.target),f=e.attr("data-to"),g=!e.hasClass("active");e.toggleClass("active",g).siblings().removeClass("active"),d.find(".left-panel").toggleClass("span12",!g).toggleClass("span6",g).end().end().find(".right-panel").toggleClass("hide",!g).end().find("."+f+"-panel").removeClass("hide").siblings().addClass("hide"),clearTimeout(c.scrollFocustimer),g?(c.trigger("scrollToFocusVerse"),a.cookie("scriptureIndexOpenedPanel",f)):(c.scrollFocustimer=setTimeout(function(){c.trigger("scrollToFocusVerse")},201),a.cookie("scriptureIndexOpenedPanel",0))},handleClickVerseSentence:function(b){if(a(b.target).attr("data-key")!==e){var c=this,d=a(b.target),f=d.attr("data-key"),g=f.split("-");2===g.length&&c.model.set({chapterId:parseInt(g[0],10),verseId:parseInt(g[1],10)})}},handleClickVerseIntro:function(b){var c=this,d=a(b.currentTarget),e="opened";d.hasClass(e)||(c.$(".verse-intro").removeClass(e),d.addClass(e))},handleClickCloseVerseIntro:function(b){var d=a(b.target).parents(".verse-intro"),e="opened";d.removeClass(e),b.stopPropagation()},handleClickNoteIndicator:function(b){var c=this,d=a(b.target),e=d.attr("data-id");c.noteViews[e]||(c.noteViews[e]=new NoteWriterView({model:c.model.get("notes").get(e)})),c.noteViews[e].trigger("open")},handleKeyup:function(a){var b=this,c=a.keyCode;37==c&&(b.model.focusPreviousVerse(),b.trigger("scrollToFocusVerse")),39==c&&(b.model.focusNextVerse(),b.trigger("scrollToFocusVerse"))},renderFocusVerse:function(){var a=this,b=a.model.get("chapterId"),c=a.model.get("verseId"),d=a.getTargetVerse(b,c);a.$(".verse-sentence").removeClass("active"),d.addClass("active")},renderNewNoteWriterView:function(){var a=this,b=a.model.get("bookId"),c=a.model.get("chapterId"),d=a.model.get("verseId"),e=a.getTargetVerse(c,d),f=new Note,g=new NoteWriterView({model:f});e=e.filter(":first").clone().find("span").remove().end(),f.set({bookId:b,chapterId:c,verseId:d,title:e.text()}),g.trigger("open"),f.on("sync",function(){a.model.fetchNotes({patch:!0})})},renderExistingNoteWriterView:function(a){var b=this,c=a.get("chapterId"),d=a.get("verseId");b.$('.verse-sentence[data-key="'+c+"-"+d+'"]').before(NoteIndicatorTmpl({id:a.id})),b.renderNotePopover(a)},renderNotePopover:function(b){var e,d=a('.note-indicator[data-id="'+b.id+'"]');e=_.template('
<%=title%>

<%=content%>
',{title:_.escape(b.get("title")),content:_.escape(b.get("content"))}),d.popover("destroy").popover({trigger:"hover",content:e,verticalOffset:5,horizontalOffset:5})},removeNoteIndicator:function(b){a('.note-indicator[data-id="'+b.id+'"]').remove()},scrollToFocusVerse:function(){var c=this,d=c.model.get("chapterId"),e=c.model.get("verseId"),f=c.getTargetVerse(d,e),g=f.filter(":first");if(g.length){var h=a(b),i=h.height(),j=h.scrollTop(),k=i/3,l=j+i,m=g.offset();i>200&&(m.top-kl)&&a("html, body").stop(!0,!0).animate({scrollTop:m.top-k})}},getTargetVerse:function(a,b){var c=this,d=a+"-"+b;return c.$('.verse-sentence[data-key="'+d+'"]')}});a(b).on("load",function(){new g({el:a(".scripture")})})}(jQuery,window,document,Backbone); var SCRIPTURE_JAVARS={"logReadUrl":"\/yii2\/cusb\/scripture\/ajaxLogRead","commentCandidates":[],"refCandidates":[],"mixedTipCandidates":null,"bookId":43,"chapterId":10};