PageSourceSearch

https://www.pathwaycommons.org/js/pc.js

js pathwaycommons.org collected 2026-10-03 21:21:41 UTC 4,484 bytes, 153 lines download raw bytes

1$(function(){ // document ready
2
3  var env = 'production';
4
5  // URL for PC resource links
6  var pcBaseUrl = "https://www.pathwaycommons.org/";
7  var pcBaseUrlBeta = "https://beta.pathwaycommons.org/";
8  var pcAppsBaseUrl = "https://apps.pathwaycommons.org/";
9  var pcAppsBaseUrlBeta = "https://appsbeta.pathwaycommons.org/";
10
11  $(".pc-url").each(function(i, a) {
12    var e = $(a);
13    var baseUrl = pcBaseUrl;
14    if( e.hasClass( 'has-beta' ) && env != 'production' ) {
15        baseUrl = pcBaseUrlBeta;
16    }
17    e.attr('href', baseUrl+e.attr('href'));
18  });
19
20  $(".apps-url").each(function(i, a) {
21    var e = $(a);
22    var baseUrl = pcAppsBaseUrl;
23    if( e.hasClass( 'has-beta' ) && env != 'production' ) {
24        baseUrl = pcAppsBaseUrlBeta;
25    }
26    e.attr('href', baseUrl+e.attr('href'));
27  });
28
29  $(".on-beta").each(function(i, a) {
30    if( env == 'production' ) $(a).css("display", "none");
31  });
32
33  function getPCDatasources(){
34    var baseUrl = env != 'production' ? pcBaseUrlBeta: pcBaseUrl;
35    var datasourcesUrl = `${baseUrl}pc2/metadata/datasources`;
36    return fetch(datasourcesUrl)
37        .then( response => response.json() )
38        .then( sources => sources.filter( s => s.type != 'WAREHOUSE' && s.type != 'MAPPING' ) );
39  }
40
41  (function(){
42    var sum = ( prev, curr ) => prev + curr;
43    getPCDatasources().then( sources => {
44        var numSources = sources.length;
45        var numPathways = sources.map( s => s.numPathways ).reduce( sum, 0 );
46        var numInteractions = sources.map( s => s.numInteractions ).reduce( sum, 0 );
47        $("#pc-stats").text(`${numPathways} Pathways -- ${numInteractions} Interactions -- ${numSources} Databases`);
48      });
49  }());
50
51  $("#pcviz-form").submit(function() {
52      var geneTxt = $("#pcviz-gene-text").val();
53      if(geneTxt.search(",") > 0) {
54          // comma separators, clean-up the spaces
55          geneTxt = geneTxt.replace(/ /g, " ");
56      } else if (geneTxt.search(" ") > 0) {
57          // space separators, replace them with commas
58          geneTxt = geneTxt.replace(/ /g, ",");
59      } else { /* nothing */ }
60
61      window.open(pcBaseUrl + "pcviz/#neighborhood/" + geneTxt, "_blank");
62      return false;
63  });
64
65  $("#pathway-search-form").submit(function() {
66      var geneTxt = $("#pathway-search-query-text").val();
67      var baseUrl = env != 'production' ? pcAppsBaseUrlBeta : pcAppsBaseUrl;
68      window.open(`${baseUrl}search?type=Pathway&q=` + encodeURIComponent(geneTxt), "_blank");
69      return false;
70  });
71
72  // Google Analytics
73  // Event handler for all .ga classed elements
74  $(".ga").on('click',function(e){
75    var
76      self,
77      category = "",
78      action = "click",
79      label = "",
80      self = $(this),
81      send = true
82      ;
83
84    if(self.hasClass("ga-publications"))
85    {
86      category = "Publications";
87      label = self.text();
88    }
89    else if(self.hasClass("ga-search"))
90    {
91      category = "Search";
92      label = self.val();
93    }
94    else if(self.hasClass("ga-apps"))
95    {
96      category = "Apps";
97      label = self.text();
98    }
99    else if(self.hasClass("ga-training"))
100    {
101      category = "Training";
102      label = self.find(".pc-list-group-item-text .pc-list-group-item-title").text();
103    }
104    else if(self.hasClass("ga-data"))
105    {
106      category = "Data";
107      label = self.find(".pc-list-group-item-text .pc-list-group-item-title").text();
108    }
109    else if(self.hasClass("ga-tools"))
110    {
111      category = "Tools";
112      label = self.find(".pc-list-group-item-text .pc-list-group-item-title").text();
113    }
114    else if(self.hasClass("ga-faq"))
115    {
116      category = "FAQ";
117      label = self.find(".faq-question").text();
118    }
119    else if(self.hasClass("ga-contact"))
120    {
121      category = "Contact";
122
123      if(self.hasClass("ga-social")){
124        self.children("i").attr("class", function(i, val){
125          if(val) label = val.split(" ")[0];
126        });
127      } else {
128        label = self.text();
129      }
130    }
131    else
132    {
133      send = false;
134    }
135
136    if(send){
137      ga('send', 'event', category, action, label);
138      console.info("Event - Category: %s; Action: %s; Label: %s", category, action, label);
139    }
140
141  });
142
143  // Google Analytics depth tracking plugin (scrolldepth.parsnip.io/)
144  jQuery.scrollDepth({
145    minHeight: 0,
146    elements: ["#search", "#pcviz", "#training", "#data", "#tools", "#faq", "#contact"],
147    percentage: false,
148    userTiming: false,
149    pixelDepth: false,
150    nonInteraction: false
151  });
152
153});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.