Team:Warsaw/JSTest2
From 2008.igem.org
(Difference between revisions)
(21 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
{{WarHead}} | {{WarHead}} | ||
<html> | <html> | ||
+ | <style> | ||
+ | .hidden { display:none; } | ||
+ | .visible {display:block; } | ||
- | <a id="anch">Jump</a> | + | </style> |
- | <div id=" | + | |
+ | <h3>Browse by topics</h3> | ||
+ | <form name="params" action="JavaScript:analyze()"> | ||
+ | <table class="month" width="100%"> | ||
+ | |||
+ | <tr><td width="50%">Start date</td><td>End date</td></tr> | ||
+ | <tr><td width="50%"> | ||
+ | <input type="text" value="4" size=1 name="start_day"> | ||
+ | <select name="start_month"> | ||
+ | <option value="January">January</option> | ||
+ | <option value="February">February</option> | ||
+ | <option value="March">March</option> | ||
+ | <option value="April">April</option> | ||
+ | <option value="May" selected="selected">May</option> | ||
+ | <option value="June">June</option> | ||
+ | <option value="July">July</option> | ||
+ | <option value="August">August</option> | ||
+ | <option value="September">September</option> | ||
+ | <option value="October">October</option> | ||
+ | <option value="November">November</option> | ||
+ | <option value="December">December</option> | ||
+ | </select> | ||
+ | <input type="text" value="2008" size=3 name="start_year" disabled="disabled"> | ||
+ | </td> | ||
+ | <td> | ||
+ | <input type="text" value="16" size=1 name="end_day"> | ||
+ | <select name="end_month"> | ||
+ | <option value="January">January</option> | ||
+ | <option value="February">February</option> | ||
+ | <option value="March">March</option> | ||
+ | <option value="April">April</option> | ||
+ | <option value="May" selected="selected">May</option> | ||
+ | <option value="June">June</option> | ||
+ | <option value="July">July</option> | ||
+ | <option value="August">August</option> | ||
+ | <option value="September">September</option> | ||
+ | <option value="October">October</option> | ||
+ | <option value="November">November</option> | ||
+ | <option value="December">December</option> | ||
+ | </select> | ||
+ | <input type="text" value="2008" size=3 name="end_year" disabled="disabled"> | ||
+ | </td></tr></table> | ||
+ | <input type="submit" value="Go!"> | ||
+ | </form> | ||
+ | |||
+ | <a id="anch" style="display:none;">Jump</a> | ||
+ | <div id="progress"></div> | ||
+ | <div id="result"> </div> | ||
+ | <br> | ||
+ | <div align="right"><a href="javascript:toggle_dump()">Toggle source</a></div> | ||
+ | <textarea id="dump" readonly="true" class="hidden" style="width:100%;height:400px">core dump</textarea> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
/* <![CDATA[ */ | /* <![CDATA[ */ | ||
- | |||
- | |||
function removeHTMLTags(strInputCode ){ | function removeHTMLTags(strInputCode ){ | ||
Line 21: | Line 72: | ||
} | } | ||
+ | var codebase="https://2008.igem.org/wiki/index.php?title=Team:Warsaw/JSTest"+String.fromCharCode(38); | ||
- | var | + | var months=['January','February','March','April','May','June','July','August','September','October','November','December']; |
- | + | ||
- | var | + | var adresbase='https://2008.igem.org/Team:Warsaw/Calendar-Main/'; |
- | for (var i=0;i< | + | Array.prototype.indexOf = function( v, b, s ) { |
+ | for( var i = +b || 0, l = this.length; i < l; i++ ) { | ||
+ | if( this[i]===v || s ) if ( this[i]==v ) { return i; } | ||
+ | } | ||
+ | return -1; | ||
+ | }; | ||
- | + | function longmonth(mon) | |
+ | { | ||
+ | var long=['May','July','August','October']; | ||
+ | if (long.indexOf(mon,0,false)>=0) return true; | ||
+ | return false; | ||
+ | } | ||
- | document.getElementById(" | + | function nextday(date) |
- | document.getElementById(" | + | { |
+ | date=date.replace(' ','_'); | ||
+ | date=date.replace(' ','_'); | ||
+ | var date_array=date.split('_'); | ||
+ | var d=parseInt(date_array[0]); | ||
+ | var m=date_array[1]; | ||
+ | //var y="2008"; | ||
+ | var y=parseInt(date_array[2]); | ||
+ | var next_day; | ||
+ | |||
+ | if (d+1<31) { next_day=(d+1)+'_'+m+'_'+y; } | ||
+ | else | ||
+ | { | ||
+ | var next_month=months[(parseInt(months.indexOf(m,0,false))+1)]; | ||
+ | next_day='1'+'_'+next_month+'_'+y; | ||
+ | } | ||
+ | if (longmonth(m)) if((d+1)==31) { next_day=(d+1)+'_'+m+'_'+y; } | ||
+ | |||
+ | return next_day; | ||
+ | } | ||
+ | |||
+ | var eday="empty"; | ||
+ | eday=eday.replace("y","yday"); | ||
+ | |||
+ | |||
+ | var topics=new Array(); | ||
+ | function find_topics(day,end_day) | ||
+ | { | ||
+ | |||
+ | var nday=nextday(day); | ||
+ | |||
+ | document.getElementById("progress").innerHTML="Processing: "+day; | ||
+ | |||
+ | if (window.XMLHttpRequest) { // Mozilla, Safari, Opera ... | ||
+ | var req = new XMLHttpRequest(); | ||
+ | } else if (window.ActiveXObject) { // IE | ||
+ | var req = new ActiveXObject("Microsoft.XMLHTTP"); | ||
+ | } | ||
+ | var ans; | ||
+ | |||
+ | if (window.overrideMimeType) req.overrideMimeType('text/xml'); | ||
+ | req.onreadystatechange = function() { //początek wewnętrznej funkcji | ||
+ | if (req.readyState == 4) { | ||
+ | if (req.status == 200) { | ||
+ | ans=req.responseText; | ||
+ | if(ans.search(eday)<0) | ||
+ | { | ||
+ | var a_t=get_topics(ans); | ||
+ | for (var i=0;i<a_t.length;i++) | ||
+ | { | ||
+ | if (topics[a_t[i]]==undefined)topics[a_t[i]]=nday+';'; | ||
+ | else topics[a_t[i]]+=nday+';'; | ||
+ | |||
+ | } | ||
+ | } | ||
+ | if (day==end_day) { | ||
+ | document.getElementById("progress").innerHTML="Done"; | ||
+ | create_links(topics); | ||
+ | document.getElementById("dump").value=document.getElementById("result").innerHTML; | ||
+ | return true; | ||
+ | } | ||
+ | else { find_topics(nday,end_day); } | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | }; //koniec wewnętrznej funkcji | ||
+ | |||
+ | req.open('GET', adresbase+nday, true); | ||
+ | req.send(null); | ||
+ | } | ||
+ | |||
+ | function analyze() | ||
+ | { | ||
+ | var start_day=parseInt(document.params.start_day.value); | ||
+ | var start_month=document.params.start_month.value; | ||
+ | var start_year=parseInt(document.params.start_year.value); | ||
+ | var end_day=parseInt(document.params.end_day.value); | ||
+ | var end_month=document.params.end_month.value; | ||
+ | var end_year=parseInt(document.params.end_year.value); | ||
+ | |||
+ | if (start_day>0) if (start_day<32) var start_date=start_day+'_'+start_month+'_'+start_year; | ||
+ | else | ||
+ | { | ||
+ | document.getElementById("progress").innerHTML="Start day error" | ||
+ | return; | ||
+ | } | ||
+ | if (end_day>0) if (end_day<32) var end_date=end_day+'_'+end_month+'_'+end_year; | ||
+ | else | ||
+ | { | ||
+ | document.getElementById("progress").innerHTML="End day error" | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | if (start_month==end_month) if(end_day<start_day) | ||
+ | { | ||
+ | document.getElementById("progress").innerHTML="Wrong date range" | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | find_topics(start_date,end_date); | ||
+ | } | ||
+ | |||
+ | function trimStr(str) | ||
+ | { | ||
+ | return str.replace(/^\s+|\s+$/g, ''); | ||
+ | } | ||
+ | |||
+ | |||
+ | function get_topics(ans) | ||
+ | { | ||
+ | ans=ans.replace(/<h3><\/h3>/gi,""); | ||
+ | var ans_topics=new Array(); | ||
+ | h3=new RegExp(/<h3.*>(.*)<\/h3>/ig); | ||
+ | var titles=ans.match(h3); | ||
+ | for (var i=0;i<titles.length;i++) | ||
+ | { | ||
+ | if (titles[i].search("h3")>0) | ||
+ | { | ||
+ | var notags=titles[i].split(/(<h3>)|(<\/h3>)/i); | ||
+ | if (notags[3]==undefined) var currtitle=removeHTMLTags(notags[0]); | ||
+ | else var currtitle=removeHTMLTags(notags[3]); | ||
+ | currtitle=trimStr(currtitle.replace(/\+/g,' ')); | ||
+ | if(currtitle!="") ans_topics.push(currtitle); | ||
+ | } | ||
+ | } | ||
+ | return ans_topics; | ||
+ | } | ||
+ | |||
+ | function create_links(topics) | ||
+ | { | ||
+ | for (i in topics) | ||
+ | { | ||
+ | |||
+ | var d=topics[i]; // another dirty IE hack | ||
+ | //alert (typeof(d)); | ||
+ | if (typeof(d)=="string") | ||
+ | { | ||
+ | //if (d.match(/from\ 2008.igem.org/i)==null) continue; | ||
+ | var days=d.split(';'); | ||
+ | var ans=""; | ||
+ | var num=0; | ||
+ | for (var j=0;j<days.length;j++) | ||
+ | { | ||
+ | if(days[j]!="") ans+="arg"+j+"="+days[j]+String.fromCharCode(38); | ||
+ | else num=j; | ||
+ | } | ||
+ | ans=codebase+"num="+num+String.fromCharCode(38)+ans+"name="+escape(removeHTMLTags(i)); | ||
+ | document.getElementById("result").innerHTML+='<a href="'+ans+'">'+i+"</a><br>\n"; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function and(cond1,cond2) | ||
+ | { | ||
+ | if (cond1==true) if (cond2==true) return true; | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | var dump_visible=false; | ||
+ | function toggle_dump() | ||
+ | { | ||
+ | if (dump_visible) | ||
+ | { | ||
+ | document.getElementById("dump").className="hidden"; | ||
+ | dump_visible=false; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | document.getElementById("dump").className="visible"; | ||
+ | dump_visible=true; | ||
+ | } | ||
+ | } | ||
Latest revision as of 15:57, 27 October 2008
Browse by topics |