comparison NCBI Blast reference example_files/results.js @ 31:344cd76f6fd2

rename NCBI reference example
author Jan Kanis <jan.code@jankanis.nl>
date Thu, 15 May 2014 16:59:18 +0200
parents Blast output page example_files/results.js@bad241dc701f
children
comparison
equal deleted inserted replaced
30:2143f62809d0 31:344cd76f6fd2
1 // JScript source code
2
3 //Display Reformat page button only after the whole page is loaded
4
5 function ReformatPageEvent()
6 {
7 var refPageLink = document.getElementById("refPage");
8
9 //alert(refPageLink);
10 //alert(refPageLink.getAttribute("submitForm"));
11 var submitForm = refPageLink.getAttribute("submitForm");
12 alert(submitForm);
13 if(refPageLink && submitForm) {
14 utils.addEvent(refPageLink,
15 "click",
16 function() {
17 document.getElementById(submitForm).submit();
18 },
19 false);
20 }
21 }
22
23
24 function SubmitEvent(linkID)
25 {
26
27 var link = document.getElementById(linkID);
28 //alert(link.getAttribute("submitForm"));
29 var submitForm = link.getAttribute("submitForm");
30 if(link && submitForm) {
31 utils.addEvent(link,
32 "click",
33 function() {
34 document.getElementById(submitForm).submit();
35 },
36 false);
37 }
38 }
39
40
41 function SubmitEventSave(linkID)
42 {
43
44 var link = document.getElementById(linkID);
45 //alert(link.getAttribute("submitForm"));
46 var submitForm = link.getAttribute("submitForm");
47 if(link && submitForm) {
48 utils.addEvent(link,
49 "click",
50 function() {
51 //$(submitForm).CMD.value = "GetSaved";
52 document.getElementById(submitForm).submit();
53 },
54 false);
55 }
56 }
57
58
59
60
61 //This function creates submit form event on click
62 //form submitted is defined in submitForm attribute
63 //It also copies params from forms[0] (search paramateres) created by formatter
64 function SubmitEventNew(linkID)
65 {
66
67 var link = document.getElementById(linkID);
68 //alert(link.getAttribute("submitForm"));
69 if(!link) return;
70 var submitForm = link.getAttribute("submitForm");
71 if(link && submitForm) {
72 utils.addEvent(link,
73 "click",
74 function() {
75 document.forms[0].CMD.value = "";
76 if(document.forms[0].PAGE_TYPE) {
77 document.forms[0].PAGE_TYPE.value = "";
78 }
79 var s = document.forms[0].innerHTML;
80 var form = $(submitForm);
81 form.innerHTML = s + form.innerHTML;
82 form.submit();
83 },
84 false);
85 }
86 }
87
88 function GetResults()
89 {
90 form = $("results");
91 form.QUERY_INDEX.value = $("queryList")[$("queryList").selectedIndex].value;
92 form.submit();
93 }
94
95 function isIdIn(id, idArray){
96 var idSeen=false;
97
98 for(i=0; i<idArray.length; i++){
99 if(id==idArray[i]){
100 idSeen=true;
101 break;
102 }
103 }
104 return idSeen;
105 }
106
107 function GetSelectedSeqString(formName)
108 {
109 var selSeqs = "";
110 var idArray=new Array();
111 forms = document.getElementsByName(formName);
112 for(var j=0; j < forms.length; j++){
113 for(var i=0; i < forms[j].elements.length; i++){
114 var theElem=forms[j].elements[i];
115 if(theElem.type=="checkbox"&&theElem.name=="getSeqGi"&&theElem.checked){
116 if(!isIdIn(theElem.value, idArray)){
117 idArray[idArray.length]=theElem.value;
118 }
119 }
120 }
121 }
122 selSeqs = idArray.join();
123 return selSeqs;
124 }
125
126 function ViewSelectedSeqs(e)
127 {
128 var submitForm = $("submitterTop");
129 var targetForm = submitForm.getAttribute("seqsForm");
130 $("selSeqs").value = GetSelectedSeqString(targetForm);
131 submitForm.submit();
132 utils.preventDefault(e);
133 }
134
135
136 function ViewSelectedSeqTree()
137 {
138 var submitForm = $("treesubmitterTop");
139 var targetForm = submitForm.getAttribute("seqsForm");
140 $("seqSet").value = GetSelectedSeqString(targetForm);
141 $("scrWidth").value = screen.width;
142 $("scrHeight").value = screen.height;
143 submitForm.submit();
144 }
145
146 function ViewTree(linkID) {
147 link = document.getElementById(linkID);
148 var target = link.target;
149 winRef = window.open(link.href + "&screenWidth=" + screen.width + "&screenHeight=" + screen.height, target);
150 }
151
152 function ViewSelectedSeqMultiAlign()
153 {
154 var submitForm = $("multisubmitterTop");
155 var targetForm = submitForm.getAttribute("seqsForm");
156 $("seqSetM").value = GetSelectedSeqString(targetForm);
157 submitForm.submit();
158 }
159
160
161
162 function selectAllSeqs()
163 {
164 var formName = this.getAttribute("seqsForm");
165 forms = document.getElementsByName(formName);
166 for(var j=0; j < forms.length; j++){
167 for(var i=0; i < forms[j].elements.length; i++){
168 //for(var i=0; i < document.forms[formName].elements.length; i++){
169 var theElem=forms[j].elements[i];
170 if(theElem.type=="checkbox"&&theElem.name=="getSeqGi"){
171 theElem.checked=this.checked;
172 }
173 }
174 }
175 links = document.getElementsByName("selectAll");
176 for(var i=0; i < links.length;i++) {
177 if(links[i] != this) links[i].checked = this.checked;
178 }
179 }
180
181
182 function InitSeqAlignLinks()
183 {
184 var links = document.getElementsByName("getSeqs");
185 for(var i=0; i < links.length;i++) {
186 utils.addEvent(links[i],"click",ViewSelectedSeqs,false);
187 }
188 links = document.getElementsByName("treeView");
189 for(var i=0; i < links.length;i++) {
190 utils.addEvent(links[i],"click",ViewSelectedSeqTree,false);
191 }
192 links = document.getElementsByName("mltiAln");
193 for(var i=0; i < links.length;i++) {
194 utils.addEvent(links[i],"click",ViewSelectedSeqMultiAlign,false);
195 }
196 links = document.getElementsByName("selectAll");
197 for(var i=0; i < links.length;i++) {
198 utils.addEvent(links[i],"click",selectAllSeqs,false);
199 }
200
201 if($("showAlign"))
202 utils.addEvent($("showAlign"),"click",showHideLinks,false);
203 }
204
205 function InitDownLoad()
206 {
207 var deltaBlast = ($("diThresh") && $("diThresh").value != "") ? true : false;
208 if (!deltaBlast && ($("stepNumber").value == "" || $("stepNumber").value < 2)) {
209 utils.addClass($("dnPSSMPar"),"hidden");
210 }
211 }
212 function Reformat()
213 {
214 if(utils.hasClass($("FormatForm").FORMAT_ORGANISM,"orgHint")) $("FormatForm").FORMAT_ORGANISM.value = "";
215
216 $("FormatForm").submit();
217 }
218 function InitCustomButton(bn)
219 {
220 utils.addEvent(bn, "mouseover", function() {this.src = this.getAttribute("mouseovImg");}, false);
221 utils.addEvent(bn, "mouseout", function() {this.src = this.getAttribute("mouseoutImg");}, false);
222 utils.addEvent(bn, "mousedown", function() {this.src = this.getAttribute("mousedownImg");}, false);
223 utils.addEvent(bn, "mouseup", function() {this.src = this.getAttribute("mouseupImg");}, false);
224 }
225
226 function InitAllCustomButtons()
227 {
228 if($("go")) InitCustomButton($("go"));
229 if($("dn")) InitCustomButton($("dn"));
230 if($("onPageReformat")) InitCustomButton($("onPageReformat"));
231 }
232 function showHideLinks()
233 {
234 var links = document.getElementsByName("selectAll");
235 for(var i=0; i < links.length;i++) {
236 //This is done since IE does not recognize getElementsByName for span elem
237 var allLinks = utils.getParent(links[i]);
238 var removeClass,addClass;
239 if(utils.hasClass(allLinks,"shownInl")) {
240 removeClass="shownInl";
241 addClass="hidden";
242 }
243 else {
244 removeClass="hidden";
245 addClass="shownInl";
246 }
247 utils.removeClass(allLinks,removeClass);
248 utils.addClass(allLinks,addClass);
249 }
250 }
251 /*remove this function */
252 function InitHelpLinks()
253 {
254 for(var i=1; i <= 11;i++) {
255 InitToggleEvent($("hlp" + i));
256 }
257 }
258 //This function is used for collapsible deflines onmouseover="showInfo(this)"
259 //Initialized in showdefline.cpp
260 function showInfo(elem)
261 {
262 var targetElem = $("info_" + elem.id);
263 if(!targetElem) return;
264 if(elem.getAttribute("init") == "on") return;
265
266 Toggle.addTarget(elem, targetElem);
267 elem.setAttribute("init","on");
268 }
269
270 function InitPsiBlast()
271 {
272 //utils.addEvent($("ttt"),"keyup",SetHitlistSize,false);
273 var hts = document.getElementsByName("HITLIST_SIZE");
274 for(var i=0; i < hts.length;i++) {
275 utils.addEvent(hts[i],"keyup",SetHitlistSize,false);
276 }
277 if($("psiInp")) {
278 var numSubsets = $("psiInp").getAttribute("numSubsets");
279 for(var i=1; i <= numSubsets;i++) {
280 if ($("alnPos" + i)) InitToggleEvent($("alnPos" + i));
281 if ($("deflnG" + i)) InitToggleEvent($("deflnG" + i));
282 if ($("deflnB" + i)) InitToggleEvent($("deflnB" + i));
283 }
284 }
285 }
286
287 function SetHitlistSize()
288 {
289 var hts = document.getElementsByName("HITLIST_SIZE");
290 for(var i=0; i < hts.length;i++) {
291 if(this != hts[i]) {
292 hts[i].value = this.value;
293 }
294 }
295 }
296 function InitToggleEvent(toggleNode)
297 {
298 if(toggleNode) {
299 var srcid = toggleNode.getAttribute("toggle");
300 if(srcid) Toggle.addTarget(srcid, toggleNode);
301 }
302 }
303
304 function InitIFrameLinks()
305 {
306 CheckIframe($("RSIFrameNoRes"),"prlink");
307 CheckIframe($("RSIFrameDesc"),"prlink");
308 CheckIframe($("RSIFrameAln"),"prlink");
309 }
310
311 function CheckIframe(iframe,contentElemID)
312 {
313 if(!iframe) return;
314
315 var iframeDoc;
316
317 if(iframe.contentDocument) {//Firefox
318 iframeDoc = iframe.contentDocument;
319 }
320 else if (iframe.contentWindow) {//IE
321 iframeDoc = iframe.contentWindow.document;
322 }
323 else if(iframe.document) {
324 iframeDoc = iframe.document;
325 }
326 if(iframeDoc){
327 if(iframeDoc.getElementById(contentElemID)) {
328 utils.addClass(iframe,"shown");
329 utils.removeClass(iframe,"hidden");
330 }
331 }
332 }
333
334
335 function InitHitMatrix()
336 {
337 if($("bl2seImg")) {
338
339 utils.addEvent($("hitmtImg"),"load",
340 function() {
341 utils.addClass($("bl2seImg"),"shown");
342 utils.removeClass($("bl2seImg"),"hidden");
343
344 },
345 false);
346 utils.addEvent($("showHitMatrix"),"click",
347 function() {
348 $("hitmtImg").src= $("hitmtImg").getAttribute("imgsrc");
349 if(utils.hasClass($("htmb"),"shown")) {
350 utils.addClass($("htmb"),"hidden");
351 utils.removeClass($("htmb"),"shown");
352 }
353 else {
354 utils.addClass($("htmb"),"shown");
355 utils.removeClass($("htmb"),"hidden");
356 }
357 },
358 false);
359
360 if($("blastSpec") && $("blastSpec").value=="GlobalAln") {
361 $("hitmtImg").src= $("hitmtImg").getAttribute("imgsrc");
362 }
363 }
364 }
365
366
367
368
369
370 function SetFormSubmitEvent()
371 {
372 var el = $("refPage");
373 if(el) {
374 SubmitEventNew("refPage");
375 }
376 SubmitEventNew("frmPage");
377 el = $("searchOptions");
378 if(el) {
379 SubmitEventNew("searchOptions");
380 }
381 el = $("saveSearchOptions");
382 if(el) {
383 SubmitEventNew("saveSearchOptions");
384 }
385 //SubmitEventNew("breadCrSearchOptions");
386 list = $("queryList");
387 if(list) {
388 utils.addEvent(list,"change",GetResults,false);
389 }
390
391 list = $("go");
392 if(list) {
393 utils.addEvent(list,"click",GetResults,false);
394 }
395
396
397 list= $("onPageReformat");
398 if(list) {
399 utils.addEvent(list,"click",Reformat,false);
400 }
401
402 if ($("cddResults") && $("statInfo")) {
403 jQuery($("cddResults")).ncbitoggler('toggle');
404 }
405 //New design still uses toggle
406 if ($("showCDD")) {
407 InitToggleEvent($("cddInfo"));
408 }
409 InitToggleEvent($("refInfo"));
410 InitToggleEvent($("resStat"));
411 InitToggleEvent($("dbDetails"));
412 InitToggleEvent($("graphicInfo"));
413 InitToggleEvent($("descrInfo"));
414 InitToggleEvent($("alignInfo"));
415 InitToggleEvent($("ovrInfo"));
416 InitToggleEvent($("queryInfo"));
417 InitToggleEvent($("hitMatrixInfo"));
418 InitToggleEvent($("bl2ovrInfo"));
419 //Init only for PSI blastfse
420 if($("prevRID")) InitPsiBlast();
421 InitSeqAlignLinks();
422 InitAllCustomButtons();
423 if($("dnPSSMPar")) InitDownLoad();
424 InitHitMatrix();
425 if($("noRes")) {
426 if($("hitCvs")) utils.addClass($("hitCvs"),"hidden");
427 if($("hitText")) utils.addClass($("hitText"),"hidden");
428 }
429 InitIFrameLinks();
430 showDbDetails(); //fill behind the scene
431 if ($("showDetails") && utils.hasClass($("showDetails"), "shown")) {
432 utils.addEvent($("showDetails"), "click", showDbDetails, false);
433 }
434 initContentWidth();
435 }
436
437 function initContentWidth() {
438 var lineLengthElem = $("FormatForm").LINE_LENGTH;
439 if (lineLengthElem) {
440 var lineLength = parseInt(lineLengthElem[lineLengthElem.selectedIndex].value);
441 if (parseInt(lineLengthElem.getAttribute("defval")) == lineLength) return;
442
443 var charWidth = (navigator.userAgent.match(/ie/i)) ? 8 : 7;
444 var minWidth = (lineLength + parseInt(17)) * charWidth;
445
446
447 var alignView = $("FormatForm").ALIGNMENT_VIEW;
448 var formatType = $("FormatForm").FORMAT_TYPE;
449 var queryAnch = formatType[formatType.selectedIndex].value == "HTML" && (alignView[alignView.selectedIndex].value != "Pairwise" && alignView[alignView.selectedIndex].value != "PairwiseWithIdentities");
450
451 var addWidth = ($("FormatForm").OLD_VIEW.checked || queryAnch) ? 250 : 350;
452
453 minWidth = minWidth + parseInt(addWidth) + "px";
454 jQuery($("content")).css("min-width", minWidth);
455 }
456
457 }
458
459
460
461
462
463 function ShowHideAlnDeflines(alnID, checkbx) {
464 var dflTableID = "dln_" + alnID;
465 if ($(dflTableID)) {
466 var rmClass, addClass;
467 if (checkbx.checked) {
468 rmClass = "hidden";
469 addClass = "shown";
470 }
471 else {
472 rmClass = "shown";
473 addClass = "hidden";
474 }
475 var elems = $C(rmClass, "class", $(dflTableID), "tr");
476 if (elems) {
477 //alert(elems.length);
478 for (var i = 0; i < elems.length; i++) {
479 utils.removeClass(elems[i], rmClass);
480 utils.addClass(elems[i], addClass);
481 }
482 }
483 }
484 }
485
486 function SortAln(e, sortLink, sortItem) {
487 var p = utils.getParent(sortLink);
488 var p = utils.getParent(p);
489 p_TD = utils.getParent(p);
490 p_TR = utils.getParent(p_TD);
491 if (utils.hasClass(p_TR, "dflnAln")) {
492 p_TD.innerHTML = "Reading seqaligns...";
493 var gi = p_TD.id.substr(2);
494 var rid = p_TD.getAttribute("rid");
495 getAlignSort(rid, gi, p_TD, sortItem);
496 e = e || window.event;
497 utils.preventDefault(e);
498 return;
499 }
500 var links = document.getElementsByName("alnSort");
501 if (links.length >= sortItem) {
502 var href = links[sortItem].href.replace(new RegExp("selectAllTop.*(&|$)"), "");
503 var hrefLn = sortLink.href.replace(new RegExp(".*#"), "");
504 sortLink.href = href + hrefLn;
505 }
506 }
507
508
509
510 var fullArr;
511 var numDbs;
512 function showDbDetails(e,dbSetIndex)
513 {
514 if (!($("dbPlusSpecies"))) return; //No org display
515 if ($("dbPlusSpecies").getAttribute("init") == "on" && dbSetIndex == null) return;
516 $("dbPlusSpecies").setAttribute("init", "on");
517
518 dbInfoUrl = "getDBInfo.cgi";
519 var rp = new RemoteDataProvider(dbInfoUrl);
520 rp.minArr = 10;
521
522 if (!fullArr) {
523 var arr = $("results").DATABASE.value.split(" ");
524 numDbs = arr.length;
525 if (arr.length > rp.minArr) {
526 fullArr = new Array();
527 while (arr.length > 1) {
528 var arrNew = arr.splice(0, rp.minArr); //does not include stopindex
529 fullArr.push(arrNew);
530 }
531 if (!dbSetIndex) dbSetIndex = 0;
532 }
533 }
534
535 rp.onSuccess = function(obj) {
536 var navDB = document.createElement("div");
537 if (fullArr) {
538 var prevLink, nextLink, firstLink, lastLink;
539 if (this.currDbSetIndex >= 1) {
540 var firstStart = 1;
541 var firstEnd = firstStart + fullArr[0].length - 1;
542 firstLink = document.createElement("a");
543 jQuery(firstLink).attr("href", "#");
544 jQuery(firstLink).attr("id", "firstDbSet");
545 jQuery(firstLink).attr("onclick", "showDbDetails(event,0);");
546 jQuery(firstLink).attr("title", "Databases " + firstStart + "-" + firstEnd);
547 jQuery(firstLink).html("First " + this.minArr + " dbs");
548
549 }
550 if (this.currDbSetIndex >= 1) {
551 var prevStart = (this.currDbSetIndex - 1) * this.minArr + 1;
552 var prevEnd = prevStart + fullArr[this.currDbSetIndex - 1].length - 1;
553 prevLink = document.createElement("a");
554 jQuery(prevLink).attr("href", "#");
555 jQuery(prevLink).attr("id", "prevDbSet");
556 jQuery(prevLink).attr("onclick", "showDbDetails(event," + (this.currDbSetIndex - 1) + ");");
557 jQuery(prevLink).attr("title", "Databases " + prevStart + "-" + prevEnd);
558 jQuery(prevLink).html("Prev " + this.minArr + " dbs");
559 }
560
561 if (this.currDbSetIndex < fullArr.length - 1) {
562 var nextStart = (this.currDbSetIndex + 1) * this.minArr + 1;
563 var nextEnd = nextStart + fullArr[this.currDbSetIndex + 1].length - 1;
564 nextLink = document.createElement("a");
565 jQuery(nextLink).attr("href", "#");
566 jQuery(nextLink).attr("id", "nextDbSet");
567 jQuery(nextLink).attr("onclick", "showDbDetails(event," + (this.currDbSetIndex + 1) + ");");
568 jQuery(nextLink).attr("title", "Databases " + nextStart + "-" + nextEnd);
569 jQuery(nextLink).html("Next " + this.minArr + " dbs");
570 }
571 if (this.currDbSetIndex < fullArr.length - 1) {
572 var lastInd = fullArr.length - 1;
573 var lastStart = numDbs - fullArr[lastInd].length;
574 var lastEnd = numDbs;
575 lastLink = document.createElement("a");
576 jQuery(lastLink).attr("href", "#");
577 jQuery(lastLink).attr("id", "lastDbSet");
578 jQuery(lastLink).attr("onclick", "showDbDetails(event," + lastInd + ");");
579 jQuery(lastLink).attr("title", "Databases " + lastStart + "-" + lastEnd);
580 jQuery(lastLink).html("Last " + this.minArr + " dbs");
581 }
582
583
584 jQuery(navDB).attr("id", "addDbSet");
585 if (firstLink) jQuery(navDB).append(firstLink);
586 if (prevLink) jQuery(navDB).append(prevLink);
587 if (lastLink) jQuery(navDB).append(lastLink);
588 if (nextLink) jQuery(navDB).append(nextLink);
589 }
590
591 jQuery($("dbPlusSpecies")).html(navDB);
592 jQuery(navDB).after(obj.responseText);
593 if (fullArr) {
594 var cap = jQuery($("dbSpecies")).find("caption");
595 if (cap) {
596 var currStart = (this.currDbSetIndex) * this.minArr + 1;
597 var currEnd = currStart + fullArr[this.currDbSetIndex].length - 1;
598 var capText = cap.html() + "<div class=\"cpAdd\"> Databases " + currStart + "-" + currEnd;
599 cap.html(capText);
600 }
601 }
602 };
603 rp.onError = function(obj) {
604 $("dbPlusSpecies").innerHTML += "error, requests:" + this.iActiveRequests + " status:" + obj.status;
605 }
606 var dbs;
607 if (fullArr) {
608 rp.currDbSetIndex = dbSetIndex;
609 var currArr = fullArr[dbSetIndex];
610 dbs = currArr.join(",");
611 }
612 else {
613 dbs = $("results").DATABASE.value.replace(/ /g, ",");
614 }
615
616 rp.Request("CMD=getDBOrg&DATABASE=" + dbs, "POST");
617 if(e) utils.preventDefault(e);
618 }
619
620 function synchronizeCheck(id, formName, inputName, isChecked) {
621
622 for (var i = 0; i < document.forms[formName].elements.length; i++) {
623 var theElem = document.forms[formName].elements[i];
624 if (theElem.type == "checkbox" && theElem.name == inputName && id == theElem.value) {
625 theElem.checked = isChecked;
626
627 }
628 }
629
630 }
631
632 utils.addEvent(window,
633 "load", SetFormSubmitEvent,
634 false);
635
636
637 /* If user agent has "safari" in it, include safari-specific stylesheet. */
638 if (navigator.userAgent.match(/safari/i) || navigator.userAgent.match(/opera/i)) {
639 document.write("<link rel='stylesheet' type='text/css' href='css/safari-descriptions.css' media='screen'/>");
640 }
641 if (navigator.userAgent.match(/opera/i)) {
642 document.write("<link rel='stylesheet' type='text/css' href='css/opera-descriptions.css' media='screen'/>");
643 }
644 if (navigator.userAgent.match(/firefox/i) || navigator.userAgent.match(/safari/i)) {
645 document.write("<link rel='stylesheet' type='text/css' href='css/firefox-descriptions.css' media='screen'/>");
646 }
647
648
649