var GenePageController=PageController.extend({setupPage:function(n){this._super($.extend(!0,{symbol:null,keywords:null,prefilter:null},n));this._loadedImageMaps={}},startPage:function(){this._bindPageEvents();this._bindSocialEvents();this._prefilterElements();this._highlightKeywords();this._augmentRedirectLinksWithSectionInfo();this._bindExpressionImg(".gene-expression-img");this._bindExpressionImg(".protein-expression-img")},_bindPageEvents:function(){var i=this,n=$("nav.gc-section-nav"),r=n.find("a[data-category-class]"),u=$(".related-products a[data-category-class]"),t=n.outerHeight(!0)+30;this.navbarHeight=t;$("#followGeneButton").favoriteGene({isAuthUser:LM.getIsAuthUser()},$("#cardPage").data("gene-symbol"));$(".js-gc-nav-container").on("activate.bs.scrollspy",function(n){i._onSectionChanged(n)});$("body").scrollspy({target:".js-gc-nav-container",offset:t});n.on("affix.bs.affix",function(){$("body").find("#FixedProductCategories").hide()});n.on("affix-top.bs.affix",function(){$("body").find("#FixedProductCategories").show()});n.affix({offset:{top:n.offset().top}});$(".js-gc-categories").find("a").add(r).add(u).click(function(i){var f=$(this),e=f.data("category-class"),r=$("."+e).first(),o={mode:n.hasClass("affix")?"floating":"fixed",product_type:f.text()},u;LM.trackGAEvent("Card","Product Navigation",JSON.stringify(o));i.preventDefault();r.length&&(u=r.offset().top-t,$(".gc-product-nav").hasClass("gc-products-visible")&&(u=u-$(".gc-product-dropdown").outerHeight()),$("body,html").animate({scrollTop:u},0),r.parent().addClass("notify-highlight").focus(),setTimeout(function(){r.parent().removeClass("notify-highlight")},3e3))});$('[data-toggle="gifts-title"]').popover();$('[data-role="right-improved-products-nav"]').each(function(){var n=$(this),u=".gc-product-type."+n.data("selector"),i=$(u).first().parent().children(".gc-company").clone(),r=LM.collectCardPageEventData($(this)),t;i.attr("data-gene-symbol",r.symbol);i.attr("data-section",r.section);i.attr("data-subsection",r.subsection);i.attr("data-product-menu",!0);t=$("<div><\/div>").append(i);t.find(".gc-action-link").remove();t.find(".ng-isolate-scope").removeClass("ng-isolate-scope");t.find(".ng-scope").removeClass("ng-scope");t.find("[ng-class]").removeAttr("ng-class");n.popover({trigger:"manual",html:!0,content:t.html(),title:$(u).first().text(),placement:"bottom",container:"#cardPage"}).click(function(t){t.preventDefault();t.stopPropagation();var i={ProductType:n.text().trim(),Section:n.closest("[data-ga-label]").data("ga-label")};LM.trackGAEvent("Card","Section Product Menu",JSON.stringify(i));$('[data-role="right-improved-products-nav"]').not(n).popover("hide");n.popover("show")}).on("show.bs.popover",function(){$(this).data("bs.popover").tip().css("max-width","100%")}).on("shown.bs.popover",function(){var n=$(".popover.in");angular.element(document).injector().invoke(["$compile",function(t){var i=angular.element(n).scope();i=i.$new(!0);t(n)(i)}])})});$("html").on("click",function(n){typeof $(n.target).data("original-title")!="undefined"||$(n.target).parents().is(".popover.in")||$('[data-role="right-improved-products-nav"]').popover("hide")});$(".jump-to-section-in-section-header select").on("change",function(n){n=n.target;var t=n.options[n.selectedIndex].value;location.hash=t})},_bindSocialEvents:function(){var n=$(".social-share span[class*='bg-']");n.each(function(){var n=$(this);n.click(function(){var t=n.attr("class").substring(3),i=LM.collectCardPageEventData(n);LM.trackGAEvent("Social","Share",JSON.stringify({type:t,symbol:i.symbol.toLowerCase()}))})})},_prefilterElements:function(){var n=this._options,t;$.is_empty(n.keywords)||$.is_empty(n.prefilter)||n.keywords.toLowerCase()!=n.symbol.toLowerCase()&&(t=setInterval(function(){var i=$("#"+n.prefilter).find("[data-role='show-all']");i.click();window.clearInterval(t)},2e3))},_highlightKeywords:function(){var n=this._options,t;$.is_empty(n.keywords)||n.keywords.toLowerCase()!=n.symbol.toLowerCase()&&(t=this._options.keywords.split(",").map(n=>n.replace(/\*$/,"")),t.forEach(function(n){var t=n.startsWith('"')&&n.endsWith('"');t&&(n=n.substring(1,n.length-1));$(".gc-subsection").mark(n,{exclude:[".gc-section-header","h1","h2","h3","h4","h5"],className:"hilite",wildcards:n.contains("*"),element:"span",separateWordSearch:!t,accuracy:{value:"exactly",limiters:["-",",",".",";","=",")","(","::","_"]}})}))},_augmentRedirectLinksWithSectionInfo:function(){$("section a[href^='/ProductRedirect'], [data-ga-category='Banners'] .gc-company a[href^='/ProductRedirect']").each(function(){try{var t,r="",i=$(this).closest("section"),n=$(this).closest("div.gc-subsection");i.length===1?(t=i[0].id,n.length===1&&(r=n[0].id)):(i=$(this).closest("[data-ga-category='Banners']"),n=$(this).closest("[data-ga-label]"),i.length===1&&(t="Banner",n.length===1&&(r=$(n[0]).data("ga-label"))));t&&($(this)[0].href+="&section="+t+"&subsection="+r)}catch(u){}})},_bindImageMaps:function(n){this._loadedImageMaps[n]||(this._loadedImageMaps[n]=!0,$(n).find("img[usemap]").each(function(){var n=$(this),t=n.attr("src"),i=t.replace(/.jpg|.png|.gif/g,".htm");$.get(i,function(t){n.after(t);n.rwdImageMaps()})}))},_onSectionChanged:function(n){var t=$(n.target).find("a").attr("href"),i=$(n.target).find("a").text();switch(t){case"#expression":this._bindImageMaps(t);break;case"#genomic_location":this._bindImageMaps(t)}},_bindExpressionImg:function(n){var t=$(n).find(".expression-images-togglers"),u=$(n).find(".more-wrapper img"),i=function(n,t){switch(n.data("target")){case"BioGPS":return"Microarray expression";case"GTEx":return"RNAseq expression";case"GCs":return"cell lines";default:return t?"more":""}},r=function(){u.hide();t.find("li > a").each(function(){var n=$(this);n.text("Show "+i(n,!0))})};r();t.find("li > a").each(function(){var n=$(this),t=$("."+n.data("target"));n.click(function(){var u=t.is(":visible"),e=u?"hide":"show",f;r();t[e]();u=t.is(":visible");f=(u?"Hide":"Show")+" "+i(n,!u);n.text(f)})})}});(function(n){var t={serviceURI:"/MyGenes/api/",markedClass:"marked",isAuthUser:!1,popOverMarkup:'<div id="myGenesPopover"><div><Label>Comments: <textarea id="mygene-txt-comment"><\/textarea><label><\/div><div><a href="/MyGenes" target="_blank">Manage<\/a><\/div> <div><button id="mygene-btn-save" type="button" class="btn btn-primary">Save<\/button> <button id="mygene-btn-remove" type="button" class="btn btn-primary">Remove<\/button> <span>or<\/span><button type="button" class="btn btn-link">Cancel<\/button><\/div>'},r={init:function(r,u){r=n.extend({},t,r);i.isFavoriteGene(u,r,function(t){n("#cardPage").data("myGenes",t);var f=n("#followGeneButton");f&&(f.attr("title",t!=null?__DIC._favoriteGene.tip_marked:__DIC._favoriteGene.tip_unmarked),t!=null&&n("#followGeneOn").addClass(r.markedClass),t!=null&&t.SendDigest===!0&&n("#followGeneEmail").addClass(r.markedClass),r.isAuthUser?i.initPopover(f,u,r,t):i.initRegistrationPopover(f))})}},i={createFavIcon:function(t){var i=n("<span><\/span>").addClass("favorite-gene-marker");return t.prepend(i),i},showModal:function(t,i,r,u){n(t).on("show.bs.modal",function(){n("#followGeneNotesSymbol").text(i);n("#followGeneToggle").bootstrapToggle("on");n("#followGeneNotes").val(r?r.Comments:"");n("#followGeneEmailToggle").bootstrapToggle(r==null?"on":r.SendDigest===!0?"on":"off");n("#followGeneToggle").change(function(){n("#followGeneToggle").prop("checked")||n("#followGeneEmailToggle").bootstrapToggle("off")})}).modal("show");n("#followGeneDlgSaveButton").off("click").on("click",u)},initPopover:function(t,r,u){t.on("click",function(f){f.preventDefault();var e=n("#cardPage").data("myGenes");i.showModal(n(this).data("target"),r,e,function(){var o=e,s=n("#followGeneToggle").prop("checked"),h=n("#followGeneNotes").val(),f;s?(f=n("#followGeneEmailToggle").prop("checked"),i.addToMyGenes(t,r,u,h,f)):o!=null&&i.removeFromMyGenes(t,r,u);n("#myGenesModal").modal("hide")})})},initRegistrationPopover:function(n){n.popover(LM.getRegistrationPopoverConfiguration())},addToMyGenes:function(i,r,f,e,o){var s={SendDigest:o,Symbol:r,Comments:e};n("#cardPage").data("myGenes",s);n.post(t.serviceURI+"add",{GeneSymbol:r,SendDigest:o,Comments:e},function(t){u.handleAddFavoriteGene(t,r,i,f);i.data("comments",e);n("#followGeneOn").hasClass(f.markedClass)||n("#followGeneOn").addClass(f.markedClass);o&&!n("#followGeneEmail").hasClass(f.markedClass)?n("#followGeneEmail").addClass(f.markedClass):n("#followGeneEmail").removeClass(f.markedClass)})},removeFromMyGenes:function(i,r,f){n.post(t.serviceURI+"remove",{GeneSymbol:r},function(t){n("#cardPage").data("myGenes",null);i.data("comments",null);u.handleRemoveFavoriteGene(t,r,i,f);n("#followGeneOn").removeClass(f.markedClass);n("#followGeneEmail").removeClass(f.markedClass)})},cancel:function(n){n.popover("hide")},isFavoriteGene:function(i,r,f){if(!r.isAuthUser){f(!1,null);return}n.getJSON(t.serviceURI+"list",function(n){var t=u.handleIsFavoriteGene(n,i,r);f(t);return})}},u={handleIsFavoriteGene:function(n,t){var r=null,i;if(n.Status==="Success")for(i in n.Genes.Genes)if(Object.prototype.hasOwnProperty.call(n.Genes.Genes,i)&&t==n.Genes.Genes[i].Symbol){r=n.Genes.Genes[i];break}return r},handleAddFavoriteGene:function(n,t,i){switch(n.Status){case"Success":i.attr("data-original-title",__DIC._favoriteGene.tip_marked);break;default:console.log(n)}},handleRemoveFavoriteGene:function(n,t,i,r){switch(n.Status){case"Success":i.removeClass(r.markedClass);i.addClass(r.unMarkedClass);i.attr("data-original-title",__DIC._favoriteGene.tip_unmarked);break;default:console.log(n)}}};n.fn.favoriteGene=function(t){return r[t]?r[t].apply(this,Array.prototype.slice.call(arguments,1)):typeof t!="object"&&t?(n.error("Method "+t+" does not exist on jQuery.tooltip"),!1):r.init.apply(this,arguments)};n.fn.editGene=function(r,u){i.showModal("#myGenesModal",u,r,function(){var f=r,e=n("#followGeneToggle").prop("checked"),o=n("#followGeneNotes").val(),i;e?(i=n("#followGeneEmailToggle").prop("checked"),n.post(t.serviceURI+"add",{GeneSymbol:u,SendDigest:i,Comments:o},function(){location.href="/MyGenes"})):f!=null&&(LM.trackGAEvent("My Genes","Delete",u),n.post(t.serviceURI+"remove",{GeneSymbol:u},function(){location.href="/MyGenes"}));n("#myGenesModal").modal("hide")})};n.fn.showUnsubscribePopover=function(){n("#myGenesUnsubscribeModal").on("show.bs.modal").modal("show");n("#unsubscribeButton").off("click").on("click",function(){n("#myGenesUnsubscribeModal").modal("hide");n.post(t.serviceURI+"unsubscribeAll",{},function(){location.href="/MyGenes"})})}})(jQuery)