-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
793 lines (703 loc) · 28.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Search Workbench</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link href="custom.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-433406-10"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'UA-433406-10');
</script>
</head>
<!--
Designed and built by Ed Sperr (esperr@uga.edu or ed_sperr@hotmail.com)
-->
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="venn.js"></script>
<script src="vennframework.js"></script>
<script src="yearframework.js"></script>
<!--<script src="uniques.js"></script>-->
<script src="hedges.js"></script>
<div class="container">
<div id="topbanner" class="jumbotron">
<h1>Search Workbench</h1>
<a id="about" class="label label-default" href="about.html">About Search Workbench</a>
</div>
<div class="row">
<!--<form id="search">
<input id="pmsearch" type="text" />
<input id="runsearch" type="button" value="Search by category" />
</form>
-->
<div id="left" class="col-sm-12 col-md-6 col-lg-8">
<div id="search" class="input-group input-group-lg">
<input type="text" id="pmsearch" class="form-control">
<span class="input-group-btn">
<button id="runsearch" class="btn btn-primary" type="button">Search</button>
</span>
</div>
<div id="translation">
<div id="splash">
<p>Search Workbench lets you easily examine, edit and visualize your <a href="https://www.ncbi.nlm.nih.gov/pubmed/">PubMed</a> Searches. See
how the parts of your search overlap and observe how it performs over time.</p>
<p>Then <em>compare</em> your searches to another in order to zero-in on exactly the terms you want to use.
<em><a href="about.html">(more)</a></em></p>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-4">
<div id="load-session" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Load previous session</h3>
</div>
<div class="panel-body">
<button id="loadText" class="btn btn-default" title="Load a session from a saved file on this machine" data-toggle="modal" data-target="#load-text" type="button">Load from textfile</button>
</div>
</div>
<div id="past" class="panel panel-default hideme">
<div class="panel-heading">
<h3 class="panel-title">Searches</h3>
</div>
<div id="searches" class="panel-body">
</div>
</div>
</div>
</div>
<div class="row">
<div id="charts">
<div class="col-md-6">
<div id="vennpanel" class="panel panel-default hideme">
<div class="panel-heading">
<a href="questionsandanswers.html#vennplanation" target="_qanda"><span class="question-prompt glyphicon glyphicon-question-sign"></span></a>
<h3 class="panel-title">Venn diagram</h3>
</div>
<div class="panel-body">
<div id="vennresults"></div>
</div>
<div class="panel-footer"></div>
</div>
</div>
<div class="col-md-6">
<div id="yearpanel" class="panel panel-default hideme">
<div class="panel-heading">
<a href="questionsandanswers.html#yearplanation" target="_qanda"><span class="question-prompt glyphicon glyphicon-question-sign"></span></a>
<h3 class="panel-title">Proportion by year</h3>
</div>
<div class="panel-body">
<div id="yearresults"></div>
</div>
<div class="panel-footer"></div>
</div>
</div>
</div>
</div>
<div id="hedges-list" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="hedges-list">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Hedges</h4>
</div>
<div class="modal-body">
<form id="hedges"></form>
</div>
<div class="modal-footer">
<span style="float: left;">Sources: <a href="https://www.ncbi.nlm.nih.gov/books/NBK3827/#pubmedhelp.Clinical_Queries_Filters" target="_blank">NLM</a>, <a href="https://hiru.mcmaster.ca/hiru/HIRU_Hedges_MEDLINE_Strategies.aspx" target="_blank">HiRU</a></span>
<button type="button" id="hedge" class="btn btn-primary">Add Hedge</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="unique-records" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="unique-records">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Unique Records</h4>
</div>
<div id="uniques" class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="save-session" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="save-session">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Save this session</h4>
</div>
<div class="modal-body">
<p>You can save this session to return and work with it later.</p> <p>Choose to save it locally (only on this computer/browser) or to download it
as a text file.</p>
<a id="savemeText" href="" download="searchworkbench_session.txt" class="btn btn-success">Download session</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="save-local" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="save-local">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Save this session</h4>
</div>
<div class="modal-body">
<input type='text' name='sessionname' value="enter a name"><br />
<em>This session will only be saved on this browser and machine – choose "download session" to export it to another machine.</em>
</div>
<div class="modal-footer">
<button id="savelocally" type="button" class="btn btn-success">Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="load-local" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="load-local">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Load a saved session</h4>
</div>
<div class="modal-body">
<p>Choose a saved session from the following list:</p>
<div id="loadme"></div>
<br />
<button id="loadLocal" type="button" class="btn btn-success">Load this session</button>
<button id="deleteLocal" type="button" class="btn btn-danger">Delete</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="load-text" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="load-text">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Load session from text file</h4>
</div>
<div class="modal-body">
<input type="file" id="input" accept="text/plain">
</div>
<div class="modal-footer">
<button id="loadtextfile" type="button" class="btn btn-success">Load this session</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<p style='clear: both; margin-bottom: 60px;'></p>
<br />
<footer class="footer">
<div class="container">
<span class="text-muted">Design and contruction by <a href="https://esperr.github.io/about/">Ed Sperr, M.L.I.S.</a> |
Data from <a href="http://www.ncbi.nlm.nih.gov/">NCBI</a> | Visualization tools from <a href="https://developers.google.com/chart/interactive/docs/gallery/linechart" target="_blank">Google</a> and
<a href="https://github.com/benfred/venn.js/" target="_blank">Ben Frederickson</a>
| See the code at <a href="https://github.com/esperr/search-workbench">GitHub</a></span>
</div>
</footer>
<script>
var searches = {};
var pausetime;
var searchkey = 0;
var pubmedURLstem = "https://www.ncbi.nlm.nih.gov/pubmed/?term=";
//var chartwidth = $("#charts").innerWidth() * .9;
var yearwidth = $("#yearresults").innerWidth() * .9;
var vennwidth = $("#vennresults").innerWidth() * .9;
var myyearwidth = 500;
var myyearheight = 250;
if (yearwidth > myyearwidth) {
myyearwidth = yearwidth;
myyearheight = yearwidth*.50;
}
$( "#yearresults" ).attr( "style", "min-width: " + yearwidth + "px;" );
$( "#vennresults" ).attr( "style", "min-width: " + vennwidth + "px;" );
//google.charts.load('current', {'packages':['line']});
//trying standard
google.charts.load("current", {packages: ["corechart"]});
function shareLinks(terms, type) {
var vennlinkbase = "https://pubvenn.appspot.com/?";
var yearlinkbase = "https://esperr.github.io/pubmed-by-year/?";
var vennqstr = "";
var yearqstr = "";
if (terms.length == 1) {
vennqstr = terms[0];
yearqstr = "q1=" + terms[0];
} else {
for (i=0; i<terms.length; i++) {
yearqstr += "q" + Number(i+1).toString() + "=" + terms[i];
vennqstr += "(" + terms[i] + ")";
if (i > -1 && i < terms.length-1) {
vennqstr += " AND ";
yearqstr += "&";
}
}
}
var yearshare = yearlinkbase + encodeURI(yearqstr);
var vennshare = vennlinkbase + encodeURI(vennqstr);
if (type == "venn") {
$( "#vennpanel .panel-footer" ).append('<p id="vennshare" class="sharelink"><a href="' + vennshare + '" target="_blank">See more on PubVenn</a>')
} else if (type == "year") {
$( "#yearpanel .panel-footer" ).append('<p id="yearshare" class="sharelink"><a href="' + yearshare + '" target="_blank">See more on Pubmed by Year</a>')
}
}
(function() {
//$('[data-toggle="tooltip"]').tooltip();
//do hedges programatically
for (i=0; i < hedges.length; i++){
var myvalue = hedges[i].term;
var myname = hedges[i].name;
$("#hedges").append('<input type="radio" name="hedge" value="' + myvalue + '"> ' + myname + '<br>')
}
//localSession stuff...
if (storageAvailable('localStorage')) {
$( "#savemeText" ).before('<button id="savemeLocal" type="button" class="btn btn-success">Save locally</button> ');
}
getLocalsessions();
function handlesearch() {
var term = $("#pmsearch").val();
if (!term) {
return;
}
dosearch(term);
}
//Page actions and behaviors
function showWait() {
$( "#pmsearch" ).prop( "disabled", true );
$( "#pmsearch").val("");
$( "#runsearch" ).prop( "disabled", true );
$( "form" ).addClass( "hideme" );
$( "#yearresults").empty();
$( "#yearresults" ).append("<div id='loading'><p class='text-center'>Grabbing your results — please wait</p></div>")
$( "#yearresults p" ).append( '<br /><img src="loading-bars.svg">' );
}
function showDone() {
$( "#pmsearch" ).prop( "disabled", false );
$( "#runsearch" ).prop( "disabled", false );
$( "form" ).removeClass( "hideme" );
$( "#runsearch" ).removeClass( "hideme" );
//$("#loading").remove();
$("#fetchresults").remove();
}
$( "#past" ).on( "click", ".pastsearch", function() {
//while (sets.length) { sets.pop(); }
var searchIndex = $(this).data("searchIndex");
showCurrentSearch(searchIndex);
//console.log(JSON.stringify(searches[searchIndex].vennsets));
drawYearChart([searchIndex]);
//console.log(searches[searchIndex]);
if (searches[searchIndex].vennsets.length < 1) {
$("#vennresults").empty();
$("#vennresults").append('<p class="vennMsg">Only one valid term entered.</p>');
} else {
sets = searches[searchIndex].vennsets.slice(0);
drawVennDiagram();
}
});
//Modifying a search and running it again
$( "#translation" ).on( "click", "#searchedits", function() {
$( "#search" ).toggle();
var newterm = $("#translationtext").text();
newterm = newterm.replace(/(\r\n|\n|\r)/gm,"");
dosearch(newterm);
});
$( "#translation" ).on( "click", "#canceledits", function() {
$( "#search" ).toggle();
var searchIndex = $("[name=nickname]").data("searchIndex");
showCurrentSearch(searchIndex);
});
$( "#translation" ).on( "click", "#showedit", function() {
$( "#search" ).toggle();
$( "#showedit" ).toggle();
$( "#yourterm" ).toggle();
$( "#count" ).toggle();
$( "#deleteme" ).toggle();
$('#translationtext').attr('contenteditable','true');
$('#translationtext').addClass( "editing" );
$("#translationtext").after('<br /><button id="searchedits" type="button" class="btn btn-primary">Run this search</button>');
$("#searchedits").after(' <button id="hedgeslink" type="button" class="btn btn-info" data-toggle="modal" data-target="#hedges-list">Add a Hedge</button>');
$("#hedgeslink").after(' <button id="canceledits" type="button" class="btn btn-default">Cancel</button>');
});
$( "#translation" ).on( "click", "#nicknameit", function() {
var searchIndex = $("[name=nickname]").data("searchIndex");
if ( $("input[name='nickname']")) {
nickname = $("input[name='nickname']");
searches[searchIndex].nickname = $("input[name='nickname']").val();
showSearches();
showCurrentSearch(searchIndex);
}
});
$( "#translation" ).on( "click", "#deleteme", function() {
var searchIndex = $("[name=nickname]").data("searchIndex");
delete searches[searchIndex];
alert("Search deleted");
showSearches();
$( "#translation" ).hide();
$( "#search" ).show();
});
//$( "#translation" ).on( "click", "#hedgeslink", function() {
// $('#hedges-list').modal();
// });
$( "#hedge" ).click(function() {
var selHedge = $('input[name=hedge]:checked').val();
var prehedge = $("#translationtext").text();
var hedgesearch = prehedge + " AND (" + selHedge + ")";
$('#hedges-list').modal('hide');
dosearch(hedgesearch);
$( "#search" ).show();
});
$( "#past" ).on( "click", "#showcompare", function() {
$("#past input[name='term']").toggle();
$("#showcompare").toggle();
$("#savebutton").toggle();
$("#past dl").after('<input id="compare" type="button" class="btn btn-primary" value="Compare" /><button id="closecompare" type="button" class="btn btn-default showsearches">Close</button>')
});
$( "#past" ).on( "click", "#compare", function() {
var comparisons = [];
//var compareterms = [];
$( "input[name='term']" ).each(function( index ) {
if (this.checked) {
comparisons.push( $( this ).val() );
}
});
showComparisons(comparisons);
compVenn(comparisons);
drawYearChart(comparisons);
});
$( "#past" ).on( "click", ".showsearches", function() {
showSearches();
});
$( ".row" ).on( "click", "#reset", function() {
location.replace(location.pathname);
});
//Searching...
function showSearches() {
$('#load-session').hide();
var maxheight = $(".row").first().height() * .8;
var searchname;
$( "#searches" ).empty();
$( "#past" ).removeClass( "hideme" );
$( "#searches" ).attr( 'style', 'max-height:' + maxheight + 'px' );
//$( "#past" ).append("<div class='panel-heading'>");
//$( "#past div" ).append("<h3 class='panel-title'>Searches</h3>");
$( "#searches" ).append("<dl>");
for (var key in searches) {
if (searches.hasOwnProperty(key)) {
if (searches[key].nickname) {
searchname = '"' + searches[key].nickname + '"';
} else {
searchname = searches[key].term;
}
$("#searches dl").append('<dt class="pastsearch"><input type="checkbox" name="term" id="' + key + '" value="' + key + '"> <a href="#!">' + searchname + "</a></dt>");
$("#searches dt").last().append(": " + searches[key].count );
$("#searches dt").last().data("searchIndex", key);
}
}
$("#past input[name='term']").toggle();
if ($("#searches dt").last().data("searchIndex") > 0) {
$("#searches dl").after('<input id="showcompare" type="button" class="btn btn-default" value="Compare searches" />');
$("#showcompare").after('<button id="savebutton" class="btn btn-default" data-toggle="modal" data-target="#save-session">Save session</button>');
}
}
//...and displaying results
function showCurrentSearch(searchkey) {
currentSearch = searches[searchkey];
$( "#translation" ).show();
$( "#translation" ).empty();
$( "#translation" ).append('<a href="questionsandanswers.html#translations" target="_qanda"><span class="question-prompt glyphicon glyphicon-question-sign"></span></a>');
$('[data-toggle="popover"]').popover();
$( "#translation" ).append('<p id="yourterm">Your search:</p>');
$( "#yourterm" ).append("'" + currentSearch.term + "'");
if (currentSearch.nickname) {
$( "#yourterm" ).append(' (alias "' + currentSearch.nickname + '")');
}
var pmurl = pubmedURLstem + encodeURI(currentSearch.term);
$( "#yourterm" ).append('<span id="count"> found <a href="' + pmurl + '" target="_pmresults">' + currentSearch.count + '</a> results</span>');
$( "#yourterm" ).append(' <a href="' + pmurl +'" " target="_blank"><span class="glyphicon glyphicon-link"></span></a>');
$( "#translation" ).append('<p>Was translated to:</p>');
$( "#translation" ).append("<div id='translationtext'>");
var newtranslation = fieldstyle(currentSearch.translation);
$( "#translationtext" ).append(newtranslation);
$("#translation").append("<span id='nickname'>Add a nickname for this search:<br /><input type='text' name='nickname'> <button id='nicknameit' type='button' class='btn btn-default'>Add</button></span>");
$( "#translation" ).append('<br /><button id="showedit" type="button" class="btn btn-info">Edit this search</button>');
$("[name=nickname]").data("searchIndex", searchkey);
$("#showedit").after(' <button id="deleteme" type="button" class="btn btn-danger">Delete this search</button>');
//shareLinks([currentSearch.term], "year");
}
function showComparisons(comparisons) {
$( "#translation" ).empty();
$( "#translation" ).append('<p id="yourterm">Now comparing:</p><ul />');
var shareterms = [];
var pmurl;
for (i=0; i<comparisons.length; i++) {
if (searches[comparisons[i]].nickname) {
$( "#translation ul" ).append('<li>"' + searches[comparisons[i]].nickname + '"</li>');
} else {
$( "#translation ul" ).append("<li>" + searches[comparisons[i]].term + "</li>");
}
pmurl = pubmedURLstem + encodeURI(searches[comparisons[i]].term);
$( "li" ).last().append('<span id="count"> — <a href="' + pmurl + '" target="_pmresults"">' + searches[comparisons[i]].count + '</a>');
$( "li" ).last().append(' <a href="' + pmurl +'" " target="_blank"><span class="glyphicon glyphicon-link"></span></a>');
shareterms.push(searches[comparisons[i]].term);
}
$( ".sharelink" ).remove();
shareLinks(shareterms, "year");
shareLinks(shareterms, "venn");
//findUniques(comparisons);
}
function fieldstyle(transtext) {
var leftbracket = transtext.replace(/\[/g, '<span class="field">[');
var rightbracket = leftbracket.replace(/\]/g, ']</span>');
return rightbracket;
}
function shareLinks(terms, type) {
var vennlinkbase = "https://pubvenn.appspot.com/?";
var yearlinkbase = "https://esperr.github.io/pubmed-by-year/?";
var vennqstr = "";
var yearqstr = "";
if (terms.length == 1) {
vennqstr = terms[0];
yearqstr = "q1=" + terms[0];
} else {
for (i=0; i<terms.length; i++) {
yearqstr += "q" + Number(i+1).toString() + "=" + terms[i];
vennqstr += "(" + terms[i] + ")";
if (i > -1 && i < terms.length-1) {
vennqstr += " AND ";
yearqstr += "&";
}
}
}
var yearshare = yearlinkbase + encodeURI(yearqstr);
var vennshare = vennlinkbase + encodeURI(vennqstr);
if (type == "venn") {
$( "#vennpanel .panel-footer" ).append('<p id="vennshare" class="sharelink"><a href="' + vennshare + '" target="_blank">See more on PubVenn</a>')
} else if (type == "year") {
$( "#yearpanel .panel-footer" ).append('<p id="yearshare" class="sharelink"><a href="' + yearshare + '" target="_blank">See more on Pubmed by Year</a>')
}
}
//If something goes wrong, we start over
function startOver() {
//$("#loading").remove();
alert("Something bad happened when we called the API...");
searches.pop();
showDone();
//handlesearch();
}
function dosearch(term) {
showWait();
pausetime = performance.now();
$.ajax({
url: 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi',
error: function () {
startOver();
return;
},
data: {
db: 'pubmed',
usehistory: 'y',
term: term ,
retmode: 'json',
retmax: 0,
email: 'ed_sperr@hotmail.com',
tool: 'pmsearchbench'
},
success: function( data ) {
// e.g. filter the response
if (!data.esearchresult.count) {
//if there's no count we have to start over
startOver();
return;
}
if (data.esearchresult.count == "0") {
$("#translation").prepend('<div class="alert alert-danger" role="alert">Nothing found for this search. Please try again</div>');
showDone();
return;
} else {
var nickname = "";
if ( $("input[name='nickname']")) { nickname = $("input[name='nickname']").val(); }
search = {
'term': term,
'count': data.esearchresult.count,
'translation': data.esearchresult.querytranslation,
'nickname': nickname
};
searches[searchkey] = search;
showDone();
showSearches();
$( ".sharelink" ).remove();
if (data.esearchresult.count < 500) {
$("#yearresults").empty();
$("#yearresults").append('<p class="vennMsg">Your search only retrieved <strong>' + data.esearchresult.count + '</strong> results. PubMed by Year can only graph searches that have at least 500 results in total.</p>');
searches[searchkey].yearcounts = "none";
} else {
yearsearch(searchkey, term);
shareLinks([term], "year");
}
startVenn(searchkey, term);
showCurrentSearch(searchkey);
searchkey++;
if (searchkey == 1) {
$( "#vennpanel" ).removeClass( "hideme" )
$( "#yearpanel" ).removeClass( "hideme" )
$("#charts").after('<button id="reset" type="button" style="float: right;" class="btn btn-danger">Reset All Searches</button>');
$('[data-toggle="popover"]').popover();
}
//showTranslation(data.esearchresult.querytranslation);
}
}
});
}
$("#runsearch").click(function(){
handlesearch();
});
$(document).keypress(function(e) {
if(e.which == 13) {
//Because both IE and FF now "helpfully" ignore the spec and treat 'button' the same as 'submit'
e.preventDefault();
handlesearch();
}
});
$( "#savemeLocal" ).click(function() {
//localStorage.setItem('session', JSON.stringify(searches));
$('#save-session').modal('hide');
$('#save-local').modal('show');
});
$( "#savelocally" ).click(function() {
var savekey = $("input[name='sessionname']").val();
localStorage.setItem(savekey, JSON.stringify(searches));
$('#save-local').modal('hide');
});
$( "#loadLocal" ).click(function() {
var selsession = $('input[name=savedsession]:checked').val();
searches = JSON.parse(localStorage.getItem(selsession));
$('#load-local').modal('hide');
var newIndex = 0;
for (index in searches) {
newIndex = index;
}
showSearches();
searchkey = newIndex + 1;
$( "#vennpanel" ).removeClass( "hideme" );
$( "#yearpanel" ).removeClass( "hideme" );
});
$( "#deleteLocal" ).click(function() {
var selsession = $('input[name=savedsession]:checked').val();
localStorage.removeItem(selsession);
$('#load-local').modal('hide');
$('#llocalbutton').remove();
getLocalsessions();
});
$( "#loadtextfile" ).click(function() {
var selectedFile = document.getElementById('input').files[0];
checkdate(selectedFile);
var r = new FileReader();
r.onload = function(event) {
// Why yes, this is a nested mess!
try {
(function () {
searches = JSON.parse(event.target.result);
var newIndex = 0;
for (index in searches) {
newIndex = index;
}
showSearches();
searchkey = newIndex + 1;
})();
} catch (e) {
alert("Unable to load search! Please try again...")
}
};
r.readAsText(selectedFile);
$( "#vennpanel" ).removeClass( "hideme" );
$( "#yearpanel" ).removeClass( "hideme" );
$('#load-text').modal('hide');
});
$( "#save-session" ).on('shown.bs.modal', function (e){
//alert("I want this to appear after the modal has opened!");
var dataurl ='data:text/plain;charset=utf-8,'
+ encodeURIComponent(JSON.stringify(searches));
$("#savemeText").attr("href", dataurl);
});
function storageAvailable(type) {
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
}
catch(e) {
return e instanceof DOMException && (
// everything except Firefox
e.code === 22 ||
// Firefox
e.code === 1014 ||
// test name field too, because code might not be present
// everything except Firefox
e.name === 'QuotaExceededError' ||
// Firefox
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
// acknowledge QuotaExceededError only if there's something already stored
storage.length !== 0;
}
}
function getLocalsessions() {
$("#loadme").empty();
localSessions = [];
$.each(localStorage, function(key, value){
if (typeof localStorage[key] == "string") {
localSessions.push(key);
}
});
if (localSessions.length > 0) {
$( "#loadText" ).before('<button id="llocalbutton" class="btn btn-default" title="Tooltip on top" data-toggle="modal" data-target="#load-local">Load local</button> ');
//$('[data-toggle="tooltip"]').tooltip();
for (i=0; i < localSessions.length; i++){
var myvalue = localSessions[i];
var myname = localSessions[i];
$("#loadme").append('<input type="radio" name="savedsession" value="' + myvalue + '"> ' + myname + '<br>');
}
$("input[name=savedsession]").prop("checked", true);
}
}
function checkdate(selectedFile) {
var now = new Date();
if ( selectedFile.lastModified ) {
var filedate = new Date(selectedFile.lastModified);
} else {
var filedate = new Date(selectedFile.lastModifiedDate);
}
var daysDiff = (Math.floor(now - filedate) / 86400000);
if (daysDiff > 30) {
alert("This saved session is more than 30 days old. Result counts may have changed.");
}
}
})
();
</script>
</body>
</html>