var Loop=window.Loop||{};Loop.viewModels=Loop.viewModels||{};Loop.viewModels.ProfileNavigation=function(){function v(){var t=Loop.Configuration.profile.ProfileUserId,i=Loop.Core.EndpointRepository.getEndpoint("PublicationCounts",{userID:t});$.ajax({type:e,url:i.url(),contentType:o,dataType:s,processdata:h,success:function(t){!t||t.Confirmed===undefined?n(""):n(t.Confirmed)},error:function(){n("")}})}function k(){var t=Loop.Core.EndpointRepository.getEndpoint("PublicationCounts",{userID:u});$.ajax({type:e,url:t.url(),contentType:o,dataType:s,processdata:h,success:function(t){!t||!t.Confirmed?n(0):n(t.Confirmed)},error:function(){n("")}})}function y(){var n=Loop.Core.Breakpoints.isCurrentBreakpoint("xs"),t=n?"136px":"85px";n?$("#header, #header2").css({position:"fixed"}):$("#header, #header2").css({position:"absolute"});r&&(r.options.offset=t,r.context.refresh())}function d(){var t=Loop.Core.Breakpoints.isCurrentBreakpoint("xs"),n=document.getElementById("main-container"),i=t?"136px":"85px";n&&(r=new Waypoint({element:n,handler:function(n){$(".container-profile-navigation").toggleClass("stuck",n==="down")},offset:i}))}function g(n,t){a(t.firstName+" "+t.lastName)}function nt(){c(Loop.Configuration.totals.GetTotalEditorialContributions())}var t=this,e="GET",o="application/json; charset=utf-8",s="json",h=!0,n=ko.observable(""),p=ko.observable(Loop.Configuration.totals.TopicsCount),w=ko.observable(Loop.Configuration.totals.NetworkCount),c=ko.observable(),u=Loop.Configuration.profile.ProfileUserId,b=Loop.Configuration.LoggedUserId,l=ko.observable(!1),i=ko.observable(),f=null,r=null,a=ko.observable(Loop.Configuration.profile.FirstName+" "+Loop.Configuration.profile.LastName);return t.profilePicture=ko.observable(Loop.Configuration.urls.ProfilePicture),u&&u===b&&l(!0),t.updateProfilePicture=function(n,i){i&&t.profilePicture(i+"?"+n.timeStamp)},i.subscribe(function(n){n&&(f=n)},this,"beforeChange"),i.subscribe(function(n){var r=new RegExp("impact","g"),t=!0;r.test(n)&&!Loop.Core.Configuration.isUserLogged()&&(t=!1);t?($.sammy.apps&&$.sammy.apps.body.setLocation(n),Loop.Ibar&&Loop.Ibar.Events&&Loop.Ibar.Events.updateMobileMenu()):(Loop.Common.showImpactLoginRegisterModal("/people/"+Loop.Configuration.profile.ProfileUserId+"/impact","click-impact-page"),f&&i(f))},this),$(document).ready(function(){d();Loop.Core.Breakpoints.smartResize(y);y();l()?(v(),Loop.Core.subscribe(Loop.constants.Events.PUBLICATIONS_COUNT_CHANGED,v),Loop.Core.subscribe(Loop.Ibar.Configuration.events.NAME_UPDATED,g)):Loop.Configuration.profile.showAsPublic&&k();Loop.Core.subscribe(Loop.constants.Events.PROFILE_PICTURE_UPDATED,t.updateProfilePicture)}),nt(),{numberOfConnections:w,numberOfPublications:n,numberOfTopics:p,numberOfEditorialContributions:c,currentTab:i,profilePicture:t.profilePicture,fullName:a}};Loop=window.Loop||{};Loop.viewModels=Loop.viewModels||{};Loop.viewModels.Header=function(){function i(){t.blockUser(function(){n.networkButtonMenu.replaceOptionAt(0,"header-nwm-op1","Unblock",r,"unblock-user")})}function r(){t.unblockUser(function(){n.networkButtonMenu.replaceOptionAt(0,"header-nwm-op1","Block",i,"block-user")})}var n=this,t=null;n.initMenu=function(){n.networkButtonMenu=new Loop.controls.Menu("header-network-button-menu")};n.showProfilePicture=function(){n.headerEditor.showEditor()};n.headerEditor=null};ko.components.register("create-organization",{viewModel:Loop.viewModels.partials.CreateOrganization,template:{element:"create-organization-template"}});Loop=window.Loop||{};Loop.viewModels=Loop.viewModels||{};Loop.viewModels.Main=function(){var n=new Loop.viewModels.Header,t=new Loop.viewModels.ProfileNavigation,i;return{headerViewModel:n,profileNavigationViewModel:t,bodyViewModel:i}}();jQuery(function(){function i(n){var r=window.location.search.substring(1).split("&"),t,i="";return!window.location.search||$(r).each(function(r,u){t=u.split("=");t[0].toUpperCase()===n.toUpperCase()&&(i=t[1])}),i}function n(n){var f=window.location.search.substring(1).split("&"),t,i="",r=!1,u="";!window.location.search||$(f).each(function(u,f){t=f.split("=");t[0].toUpperCase()!==n.toUpperCase()?i=i.length===0?i+"?"+t[0]+"="+t[1]:i+"&"+t[0]+"="+t[1]:r=!0});r&&(u=document.location.origin+document.location.pathname+i,window.history.replaceState({},document.title,u))}function t(n,t){var r=i(n);return r&&r.toUpperCase()===t.toUpperCase()?!0:!1}function r(){if(!!window.location.search){var n=window.location.search.substring(1).split("="),t=new Loop.viewModels.partials.TryAnotherSearch(!0);t.init();n&&n.length>1&&typeof n[0]=="string"&&n[0].toUpperCase()==="TRYANOTHERSEARCH"&&typeof n[1]=="string"&&n[1].toUpperCase()==="TRUE"&&t.showTryAnotherSearch()}}function u(){var n=document.location.pathname,t=n.substring(n.lastIndexOf("/")+1),i=$("#mobile-navigation-"+t).val();$("#profile-navigation-select").show();$("#profile-navigation-mobile").val(i)}ko.applyBindingsWithValidation(Loop.viewModels.Main,$("#spaContainer")[0],{insertMessages:!0,messageTemplate:"customMessageTemplate"});Loop.Core.publish(Loop.constants.Events.SPA_KO_BINDING_DONE);new Sammy(function(){function g(){$(".popover button[id*=-cancel]").each(function(){$(this).click()})}function nt(){Loop.Core.unsubscribe(Loop.constants.Events.FOLLOWING_FOLLOWER_VISIBILITY_CHANGED);Loop.Core.unsubscribe(Loop.constants.Events.MODAL_DIALOG_DESTROY);Loop.Core.unsubscribe(Loop.constants.Events.ACTIVATE_ALL);Loop.Core.unsubscribe(Loop.constants.Events.DEACTIVATE_ALL)}function c(t){Loop.Common.IsEditMode&&(Loop.Common.IsEditMode=!1,Loop.Common.ActivateAllIcons(),g(),$(document).focus());nt();h&&h!==t&&f[h].hide();h=t;Loop.Ibar&&Loop.Ibar.Events&&Loop.Ibar.Events.updateMobileMenu();u();n("referrer");p&&Loop.Configuration.features.PrivateMessagesEnabled===!0&&Loop.Messaging.ViewModels.ConversationDispatcher.openConversation(p.id);w&&(w=undefined,Loop.viewModels.Main.headerViewModel.showProfilePicture())}function a(n){var t="(/people){0,1}/"+o+"/"+n;return new RegExp(t,"g")}function e(n){var t=["overviewTab","bioTab","networkTab","publicationsTab","editorialTab","impactTab"];$("#"+n).addClass("active");t.splice(t.indexOf(n),1);$.each(t,function(n,t){$("#"+t).removeClass("active")});$("#mainColumn .brick").removeClass("brick-sidebar");$("#sideBar .brick").addClass("brick-sidebar")}function tt(){Loop.Core.Configuration.isUserLogged()&&(c(Loop.constants.TabNames.IMPACT),f[Loop.constants.TabNames.IMPACT].init(),e("impactTab"))}function it(n,t){t.app.router.call(t,n,t)}var o=Loop.Configuration.profile.ProfileUserId,d=Loop.Configuration.profile.showAsPublic,v,s,y,w,l,p,h,k,f,b;this.router=function(n){n===Loop.constants.RouteAliases.Impact&&tt()};d?(f=[],f[Loop.constants.TabNames.OVERVIEW]=new Loop.viewModels.profile.Overview,f[Loop.constants.TabNames.BIO]=new Loop.viewModels.profile.Bio,f[Loop.constants.TabNames.NETWORK]=new Loop.viewModels.profile.Network,f[Loop.constants.TabNames.EDITORIAL]=new Loop.viewModels.profile.Editorial,f[Loop.constants.TabNames.PUBLICATIONS]=new Loop.viewModels.profile.Publications,Loop.Configuration.features.ImpactTabEnabled&&(f[Loop.constants.TabNames.IMPACT]=new Loop.viewModels.profile.Impact),this.get(a("overview"),function(){var r=i("conversationId"),u=t("editProfilePicture","true");r!==""&&typeof parseInt(r,10)=="number"?(p={id:parseInt(r,10)},n("conversationId"),Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"/people/"+o+"/overview")):u?(w=u,n("editProfilePicture"),Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"overview")):(c(Loop.constants.TabNames.OVERVIEW),f[Loop.constants.TabNames.OVERVIEW].init(),e("overviewTab"),p=undefined)}),this.get(a("bio"),function(){h!==Loop.constants.TabNames.BIO&&c(Loop.constants.TabNames.BIO);var i=t("editBio","true"),r=t("editExpertise","true"),u=t("editSpecialty","true"),o=t("editAffiliation","true"),l=t("focusAffiliations","true");i||r||u||o||l?(i?(s=Loop.constants.BioEditMode.BIO,n("editBio")):r?(s=Loop.constants.BioEditMode.EXPERTISE,n("editExpertise")):u&&(s=Loop.constants.BioEditMode.SPECIALTY,n("editSpecialty")),o&&(s=Loop.constants.BioEditMode.AFFILIATIONS,n("editAffiliation")),l&&(y=Loop.constants.BioFocusMode.AFFILIATIONS,n("focusAffiliations")),window.history.replaceState?Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"bio"):(f[Loop.constants.TabNames.BIO].init(s,y),e("bioTab"),s=undefined,y=undefined)):(f[Loop.constants.TabNames.BIO].init(s,y),e("bioTab"),s=undefined,y=undefined)}),this.get(a("network"),function(){h!==Loop.constants.TabNames.NETWORK&&c(Loop.constants.TabNames.NETWORK);this.params&&this.params.networkTab?(v=this.params.networkTab,window.history.replaceState?(n("networkTab"),Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"network")):(f[Loop.constants.TabNames.NETWORK].init(v),v=undefined,e("networkTab"))):(f[Loop.constants.TabNames.NETWORK].init(v),v=undefined,e("networkTab"))}),this.get("/"+o+"/publications/orcid",function(){var n=i("status");n&&(l={orcidOAuthStatus:n});Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"/people/"+o+"/publications")}),this.get(a("publications"),function(){if(h!==Loop.constants.TabNames.PUBLICATIONS){c(Loop.constants.TabNames.PUBLICATIONS);var u=t("confirm","true"),n;u&&(n={confirm:!0,suffixDoi:i("suffixDoi"),prefixDoi:i("prefixDoi"),initialTab:Loop.constants.publicationType.CONFIRMED},Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"publications"));f[Loop.constants.TabNames.PUBLICATIONS].init(n,l);e("publicationsTab");r();l=undefined}else l&&(f[Loop.constants.TabNames.PUBLICATIONS].init(undefined,l),e("publicationsTab"),l=undefined)}),this.get("/"+o+"/publications/new",function(){c(Loop.constants.TabNames.PUBLICATIONS);f[Loop.constants.TabNames.PUBLICATIONS].init({initialTab:Loop.constants.publicationType.SUGGESTED});e("publicationsTab");r()}),this.get(a("editorial"),function(n){if(!Loop.Configuration.features.EditorialBoardTabEnabled||Loop.Configuration.disabledEditorialContributions())Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"/people/"+o+"/overview");else{var t=n.path.split("/");t.length>4?(b=t[4].trim().toLowerCase(),Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"/people/"+o+"/editorial")):(c(Loop.constants.TabNames.EDITORIAL),f[Loop.constants.TabNames.EDITORIAL].init(b),b=null,e("editorialTab"))}}),this.get(a("impact"),function(n){Loop.Configuration.features.ImpactTabEnabled?it(Loop.constants.RouteAliases.Impact,n):Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,"/people/"+o+"/overview")}),this.get(/\/([0-9]{1,7})\/(.*)#(.*)/,function(n){var t="/people"+n.path.match(/\/([0-9]{1,7})\/[a-zA-Z]*/)[0];Loop.Common.ReplaceStateWithQueryString({},Loop.constants.UIMessages.titlePage,t)}),this.get(/http(s)?:\/\/(.*)/,function(n){var t=n.path.substr(1);document.location.replace(t)})):(k=new RegExp("/"+o+"/.*"),this.get(k))}).run()})