source: branches/bibliolocean/src/tablerefsabsbibsort.begin.layout @ 190

Last change on this file since 190 was 189, checked in by pinsard, 12 years ago

improve sorting issue (no more tablerefsabsbibsort in recent jabref filters)

File size: 13.1 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html lang="en">
3<head>
4<title>JabRef References output</title>
5<meta http-equiv="Content-Type" content="text/html; charset=\encoding">
6<meta name="robots" content="noindex,nofollow,noarchive">
7
8<script type="text/javascript">
9<!--
10
11SEE ALSO
12========
13
14:ref:`locean_tablerefsabsbibsort.layout`
15
16:ref:`sorttable.js`
17
18TODO
19====
20
21remove abstract and bibtex
22
23EVOLUTIONS
24==========
25
26$Id$
27
28$URL$
29
30- fplod 20120419T121226Z cratos (Linux)
31
32   * replace sort stuf (not anymore available in jabref filters
33
34- fplod 20100616T072219Z aedon.locean-ipsl.upmc.fr (Darwin)
35
36  * add meta robots
37
38// QuickSearch script for JabRef HTML export
39// Version: 2.0
40//
41// Copyright (c) 2006-2008, Mark Schenk
42//
43// This software is distributed under a Creative Commons Attribution 3.0 License
44// http://creativecommons.org/licenses/by/3.0/
45
46// Some features:
47// + optionally searches Abstracts and Reviews
48// + allows RegExp searches
49//   e.g. to search for entries between 1980 and 1989, type:  198[0-9]
50//   e.g. for any entry ending with 'symmetry', type:  symmetry$
51//   e.g. for all reftypes that are books: ^book$, or ^article$
52//   e.g. for entries by either John or Doe, type john|doe
53// + easy toggling of Abstract/Review/BibTeX
54
55// Search settings
56var searchAbstract = true;
57var searchReview = true;
58
59// Speed optimisation introduced some esoteric problems with certain RegExp searches
60// e.g. if the previous search is 200[-7] and the next search is 200[4-7] then the search doesn't work properly until the next 'keyup'
61// hence the searchOpt can be turned off for RegExp adepts
62var searchOpt = true;
63
64if (window.addEventListener) {
65        window.addEventListener("load",initSearch,false); }
66else if (window.attachEvent) {
67        window.attachEvent("onload", initSearch); }
68
69function initSearch() {
70        // basic object detection
71        if(!document.getElementById || !document.getElementsByTagName) { return; }
72        if (!document.getElementById('qstable')||!document.getElementById('qs')) { return; }
73
74        // find QS table and appropriate rows
75        searchTable = document.getElementById('qstable');
76        var allRows = searchTable.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
77
78        // split all rows into entryRows and infoRows (e.g. abstract, review, bibtex)
79        entryRows = new Array();
80        infoRows = new Array(); absRows = new Array(); revRows = new Array();
81
82        for (var i=0, k=0, j=0; i<allRows.length;i++) {
83                if (allRows[i].className.match(/entry/)) {
84                        entryRows[j++] = allRows[i];
85                } else {
86                        infoRows[k++] = allRows[i];
87                        // check for abstract/review
88                        if (allRows[i].className.match(/abstract/)) {
89                                absRows.push(allRows[i]);
90                        } else if (allRows[i].className.match(/review/)) {
91                                revRows.push(allRows[i]);
92                        }
93                }
94        }
95
96        //number of entries and rows
97        numRows = allRows.length;
98        numEntries = entryRows.length;
99        numInfo = infoRows.length;
100        numAbs = absRows.length;
101        numRev = revRows.length;
102
103        //find the query field
104        qsfield = document.getElementById('qsfield');
105
106        // previous search term; used for speed optimisation
107        prevSearch = '';
108
109        //find statistics location
110        stats = document.getElementById('stat');
111        setStatistics(-1);
112
113        // creates the appropriate search settings
114        createQSettingsDialog();
115
116        // shows the searchfield
117        document.getElementById('qs').style.display = 'block';
118        document.getElementById('qsfield').onkeyup = testEvent;
119}
120
121function quickSearch(tInput){
122
123         if (tInput.value.length == 0) {
124                showAll();
125                setStatistics(-1);
126                qsfield.className = '';
127                return;
128        } else {
129                // only search for valid RegExp
130                try {
131                        var searchText = new RegExp(tInput.value,"i")
132                        closeAllInfo();
133                        qsfield.className = '';
134                }
135                catch(err) {
136                        prevSearch = tInput.value;
137                        qsfield.className = 'invalidsearch';
138                        return;
139                }
140        }
141       
142        // count number of hits
143        var hits = 0;
144
145        // start looping through all entry rows
146        for (var i = 0; cRow = entryRows[i]; i++){
147
148                // only show search the cells if it isn't already hidden OR if the search term is getting shorter, then search all
149                // some further optimisation is possible: if the search string is getting shorter, and the row is already visible, skip it. Then be careful with hits!
150                if(!searchOpt || cRow.className.indexOf('noshow')==-1 || tInput.value.length <= prevSearch.length){
151                        var found = false;
152
153                        var inCells = cRow.getElementsByTagName('td');
154                        var numCols = inCells.length;
155                               
156                        for (var j=0; j<numCols; j++) {
157                                cCell = inCells[j];
158                                var t = cCell.innerText?cCell.innerText:getTextContent(cCell);
159                                if (t.search(searchText) != -1){
160                                        found=true;
161                                        break;
162                                }
163                        }
164
165                        // look for further hits in Abstract and Review
166                        if(!found) {
167                                var articleid = cRow.id;
168                                if(searchAbstract && (abs = document.getElementById('abs_'+articleid))) {
169                                        if (getTextContent(abs).search(searchText) != -1){ found=true; }
170                                }
171                                if(searchReview && (rev = document.getElementById('rev_'+articleid))) {
172                                        if (getTextContent(rev).search(searchText) != -1){ found=true; }
173                                }
174                        }
175                       
176                        if(found) {
177                                cRow.className = 'entry show';
178                                hits++;
179                        } else {
180                                cRow.className = 'entry noshow';
181                        }
182                }
183        }
184
185        // update statistics
186        setStatistics(hits)
187       
188        // set previous search value
189        prevSearch = tInput.value;
190}
191
192function toggleInfo(articleid,info) {
193
194        var entry = document.getElementById(articleid);
195        var abs = document.getElementById('abs_'+articleid);
196        var rev = document.getElementById('rev_'+articleid);
197        var bib = document.getElementById('bib_'+articleid);
198
199        // Get the abstracts/reviews/bibtext in the right location
200        // in unsorted tables this is always the case, but in sorted tables it is necessary.
201        // Start moving in reverse order, so we get: entry, abstract,review,bibtex
202        if (searchTable.className.indexOf('sortable') != -1) {
203                if(bib) { entry.parentNode.insertBefore(bib,entry.nextSibling); }
204                if(rev) { entry.parentNode.insertBefore(rev,entry.nextSibling); }
205                if(abs) { entry.parentNode.insertBefore(abs,entry.nextSibling); }
206        }
207
208        if (abs && info == 'abstract') {
209                if(abs.className.indexOf('abstract') != -1) {
210                abs.className.indexOf('noshow') == -1?abs.className = 'abstract noshow':abs.className = 'abstract';
211                }
212        } else if (rev && info == 'review') {
213                if(rev.className.indexOf('review') != -1) {
214                rev.className.indexOf('noshow') == -1?rev.className = 'review noshow':rev.className = 'review';
215                }
216        } else if (bib && info == 'bibtex') {
217                if(bib.className.indexOf('bibtex') != -1) {
218                bib.className.indexOf('noshow') == -1?bib.className = 'bibtex noshow':bib.className = 'bibtex';
219                }               
220        } else {
221                return;
222        }
223       
224        // check if one or the other is available
225        var revshow = false;
226        var absshow = false;
227        var bibshow = false;
228        (abs && abs.className.indexOf('noshow') == -1)? absshow = true: absshow = false;
229        (rev && rev.className.indexOf('noshow') == -1)? revshow = true: revshow = false;       
230        (bib && bib.className == 'bibtex')? bibshow = true: bibshow = false;
231       
232        // highlight original entry
233        if(entry) {
234                if (revshow || absshow || bibshow) {
235                entry.className = 'entry highlight show';
236                } else {
237                entry.className = 'entry show';
238                }               
239        }
240       
241        // When there's a combination of abstract/review/bibtex showing, need to add class for correct styling
242        if(absshow) {
243                (revshow||bibshow)?abs.className = 'abstract nextshow':abs.className = 'abstract';
244        }
245        if (revshow) {
246                bibshow?rev.className = 'review nextshow': rev.className = 'review';
247        }
248       
249}
250
251function setStatistics (hits) {
252        if(hits < 0) { hits=numEntries; }
253        if(stats) { stats.firstChild.data = hits + '/' + numEntries}
254}
255
256function getTextContent(node) {
257        // Function written by Arve Bersvendsen
258        // http://www.virtuelvis.com
259       
260        if (node.nodeType == 3) {
261        return node.nodeValue;
262        } // text node
263        if (node.nodeType == 1) { // element node
264        var text = [];
265        for (var chld = node.firstChild;chld;chld=chld.nextSibling) {
266                text.push(getTextContent(chld));
267        }
268        return text.join("");
269        } return ""; // some other node, won't contain text nodes.
270}
271
272function showAll(){
273        // first close all abstracts, reviews, etc.
274        closeAllInfo();
275
276        for (var i = 0; i < numEntries; i++){
277                entryRows[i].className = 'entry show';
278        }
279}
280
281function closeAllInfo(){
282        for (var i=0; i < numInfo; i++){
283                if (infoRows[i].className.indexOf('noshow') ==-1) {
284                        infoRows[i].className = infoRows[i].className + ' noshow';
285                }
286        }
287}
288
289function testEvent(e){
290        if (!e) var e = window.event;
291        quickSearch(this);
292}
293
294function clearQS() {
295        qsfield.value = '';
296        quickSearch(qsfield);
297}
298
299function redoQS(){
300        showAll();
301        quickSearch(qsfield);
302}
303
304// Create Search Settings
305
306function toggleQSettingsDialog() {
307
308        var qssettings = document.getElementById('qssettings');
309       
310        if(qssettings.className.indexOf('active')==-1) {
311                qssettings.className = 'active';
312
313                if(absCheckBox && searchAbstract == true) { absCheckBox.checked = 'checked'; }
314                if(revCheckBox && searchReview == true) { revCheckBox.checked = 'checked'; }
315
316        } else {
317                qssettings.className= '';
318        }
319}
320
321function createQSettingsDialog(){
322        var qssettingslist = document.getElementById('qssettings').getElementsByTagName('ul')[0];
323       
324        if(numAbs!=0) {
325                var x = document.createElement('input');
326                x.id = "searchAbs";
327                x.type = "checkbox";
328                x.onclick = toggleQSetting;
329                var y = qssettingslist.appendChild(document.createElement('li')).appendChild(document.createElement('label'));
330                y.appendChild(x);
331                y.appendChild(document.createTextNode('search abstracts'));             
332        }
333        if(numRev!=0) {
334                var x = document.createElement('input');
335                x.id = "searchRev";
336                x.type = "checkbox";           
337                x.onclick = toggleQSetting;
338                var y = qssettingslist.appendChild(document.createElement('li')).appendChild(document.createElement('label'));         
339                y.appendChild(x);               
340                y.appendChild(document.createTextNode('search reviews'));
341        }
342               
343        // global variables
344        absCheckBox = document.getElementById('searchAbs');
345        revCheckBox = document.getElementById('searchRev');
346       
347        // show search settings
348        if(absCheckBox||revCheckBox) {
349                document.getElementById('qssettings').style.display = 'block';
350        }
351}
352
353function toggleQSetting() {
354        if(this.id=='searchAbs') { searchAbstract = !searchAbstract; }
355        if(this.id=='searchRev') { searchReview = !searchReview; }
356        redoQS()
357}
358-->
359</script>
360<script type="text/javascript" src="sorttable.js"></script>
361<style type="text/css">
362body { background-color: white; font-family: "Trebuchet MS", Arial, sans-serif; font-size: 12px; line-height: 1.2; padding: 1em; color: #2E2E2E; }
363
364#qs { width: auto; border-style: solid; border-color: gray; border-width: 1px 1px 0px 1px; padding: 0.5em 0.5em; display:none; position:relative; }
365#qs form { padding: 0px; margin: 0px; }
366#qs form p { padding: 0px; margin: 0px; }
367
368.invalidsearch { background-color: red; }
369
370table { border: 1px gray solid; width: 100%; empty-cells: show; }
371th, td { border: 1px gray solid; padding: 0.5em; vertical-align: top;  }
372td { text-align: left; vertical-align: top; }
373th { background-color: #EFEFEF; }
374
375td a { color: navy; text-decoration: none; }
376td a:hover  { text-decoration: underline; }
377
378tr.noshow { display: none;}
379
380tr.highlight td { background-color: #F1F1F1; border-top: 2px black solid; font-weight: bold; }
381tr.abstract td, tr.review td, tr.bibtex td { background-color: #F1F1F1; border-bottom: 2px black solid; }
382tr.nextshow td { border-bottom: 1px gray solid; }
383
384tr.bibtex pre { width: 100%; overflow: auto;}
385
386p.infolinks { margin: 0.5em 0em 0em 0em; padding: 0px; }
387
388#qssettings { padding: 0.5em; position: absolute; top: 0.2em; right: 0.2em; border: 1px gray solid; background-color: white; display: none; }
389#qssettings p { font-weight: bold; cursor: pointer; }
390#qssettings ul { display: none; list-style-type: none; padding-left: 0; margin: 0; }
391#qssettings.active ul { display: block; }
392
393@media print {
394        p.infolinks, #qssettings, #qs { display: none !important; }
395        table { border-width: 0px; }
396        tr { page-break-inside: avoid; }
397        tr > * + * + * + * + * {display: none; }
398        thead tr::before { content: "Reference"; border: 1px gray solid; padding: 0.5em; vertical-align: top; font-weight: bold; text-align: center; display: table-cell; background-color: #EFEFEF; }
399        tr[id]::before { content: attr(id); display: table-cell; border: 1px gray solid; padding: 0.5em; vertical-align: top; font-style: italic; }
400}
401
402th.sort_asc, th.sort_des { border: 2px black solid; }
403</style>
404</head>
405<body>
406
407<div id="qs">
408        <form action="">
409        <p>QuickSearch: <input type="text" name="qsfield" id="qsfield" autocomplete="off" title="Allows plain text as well as RegExp searches" /><input type="button" onclick="clearQS()" value="clear" />&nbsp; Number of matching entries: <span id="stat">0</span>.</p>
410        <div id="qssettings">
411                <p onclick="toggleQSettingsDialog()">Search Settings</p>
412                <ul></ul>
413        </div>
414        </form>
415</div>
416<table id="qstable" class="sortable" border="1">
417<thead><tr><th width="20%">Author</th><th width="30%">Title</th><th width="5%">Year</th><th width="30%">Journal/Proceedings</th><th width="10%">Reftype</th><th width="5%">DOI/URL</th></tr></thead>
418<tbody>
Note: See TracBrowser for help on using the repository browser.