Team:Warsaw/JSTest

From 2008.igem.org

(Difference between revisions)
 
(44 intermediate revisions not shown)
Line 6: Line 6:
-
<script src=http://adamv.com/dev/javascript/files/querystring.js"></script>
+
 
<script type="text/javascript">
<script type="text/javascript">
 +
/* <![CDATA[ */  
/* <![CDATA[ */  
 +
 +
/* Client-side access to querystring name=value pairs
 +
Version 1.3
 +
28 May 2008
 +
 +
License (Simplified BSD):
 +
http://adamv.com/dev/javascript/qslicense.txt
 +
*/
 +
function Querystring(qs) { // optionally pass a querystring to parse
 +
this.params = {};
 +
 +
if (qs == null) qs = location.search.substring(1, location.search.length);
 +
if (qs.length == 0) return;
 +
 +
// Turn <plus> back to <space>
 +
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
 +
qs = qs.replace(/\+/g, ' ');
 +
var args = qs.split(String.fromCharCode(38)); // parse out name/value pairs separated via &
 +
 +
// split out each name=value pair
 +
for (var i = 0; i < args.length; i++) {
 +
var pair = args[i].split('=');
 +
var name = decodeURIComponent(pair[0]);
 +
 +
var value = (pair.length==2)
 +
? decodeURIComponent(pair[1])
 +
: name;
 +
 +
this.params[name] = value;
 +
}
 +
}
 +
 +
Querystring.prototype.get = function(key, default_) {
 +
var value = this.params[key];
 +
return (value != null) ? value : default_;
 +
}
 +
 +
Querystring.prototype.contains = function(key) {
 +
var value = this.params[key];
 +
return (value != null);
 +
}
 +
 +
Array.prototype.indexOf = function( v, b, s ) {
Array.prototype.indexOf = function( v, b, s ) {
Line 24: Line 68:
}
}
-
function removeHTMLTags(strInputCode ){
+
function removeHTMLTags(strInputCode2 ){
-
+
                var strInputCode=new String();
-
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
+
                strInputCode=strInputCode2;
 +
                //if (strInputCode==undefined) return;
 +
/*
 +
                strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
return (p1 == "lt")? "<" : ">";
});
});
 +
                */
 +
                strInputCode = strInputCode.replace(/&(lt);/g,"<");
 +
                strInputCode = strInputCode.replace(/&(gt);/g,">");
var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
return strTagStrippedText;
return strTagStrippedText;
Line 47: Line 97:
var div=document.createElement("div");
var div=document.createElement("div");
var h=document.createElement("h3");
var h=document.createElement("h3");
-
h.innerHTML='<a href="'+adresbase+days[i]+'">'+days[i]+"</a>";
+
h.innerHTML='<a href="'+adresbase+days[i]+'">'+days[i]+'</a>&nbsp;<div align="right"><a href="https://2008.igem.org/wiki/index.php?title=Team:Warsaw/Calendar-Main/'+days[i]+String.fromCharCode(38)+'action=edit">'+"[Edit]"+'</a></div>';
div.setAttribute("id",days[i]);
div.setAttribute("id",days[i]);
document.getElementById("merg").appendChild(h);
document.getElementById("merg").appendChild(h);
Line 70: Line 120:
                 ans=req.responseText;
                 ans=req.responseText;
                 ans=ans.substr(ans.search("<start>"),ans.search("<end>")-ans.search("<start>"));
                 ans=ans.substr(ans.search("<start>"),ans.search("<end>")-ans.search("<start>"));
-
                 document.getElementById(day).innerHTML=trimContents(ans,title);
+
                 document.getElementById(day).innerHTML=trimStr(trimContents(ans,title));
             }
             }
}  
}  
Line 78: Line 128:
req.open('GET', adresbase+day, true);
req.open('GET', adresbase+day, true);
req.send(null);
req.send(null);
-
}
 
-
 
-
function oldtrimContents(ans, title)
 
-
{
 
-
ans=ans.replace("<h3></h3>","");
 
-
var titlepos=ans.search(title);
 
-
if (titlepos<0) return "'"+title+"' not found";
 
-
var endpos=ans.indexOf("<h3>",titlepos);
 
-
if (endpos<0) return ans.substr(titlepos+title.length,ans.length-titlepos);
 
-
 
-
return ans.substr(titlepos+title.length,endpos-titlepos);
 
}
}
function trimStr(str)
function trimStr(str)
{
{
-
//if (str==undefined) return "";
 
return str.replace(/^\s+|\s+$/g, '');
return str.replace(/^\s+|\s+$/g, '');
}
}
Line 99: Line 137:
function trimContents(ans, title)
function trimContents(ans, title)
{
{
-
h3=new RegExp(/<h3.*>(.*)<\/h3>/i);
+
ans=ans.replace(/<h3><\/h3>/ig,"");
 +
h3=new RegExp(/<h3.*>(.*)<\/h3>/ig);
 +
title=removeHTMLTags(trimStr(title));
-
var topics=ans.split(h3);
+
var titles=ans.match(h3);
-
alert(ans.find(h3));
+
for (var i=0;i<titles.length;i++)
-
for (var i=0;i<topics.length;i++)
+
{
{
-
if (removeHTMLTags(trimStr(topics[i]))==removeHTMLTags(trimStr(title))) return topics[i+1];
+
if (titles[i].search("h3")>0)
 +
{
 +
//alert(titles[i].split(/(<h3>)|(<\/h3>)/i));
 +
var notags=titles[i].split(/(<h3>)|(<\/h3>)/i);
 +
if (notags[3]==undefined) var currtitle=removeHTMLTags(notags[0]);  //dirty IE hack
 +
else var currtitle=removeHTMLTags(notags[3]);
 +
currtitle=trimStr(currtitle.replace(/\+/g,' '));
 +
//alert ("C: "+currtitle+"\nT: "+title);
 +
if (currtitle==title)  
 +
{
 +
if (i+1<titles.length) return ans.substring(ans.indexOf(titles[i])+titles[i].length,ans.indexOf(titles[i+1]));
 +
else return ans.substring(ans.indexOf(titles[i])+titles[i].length);
 +
}
 +
}
}
}
 +
return "Search Error";
return "Search Error";
Line 113: Line 166:
var qs=new Querystring();
var qs=new Querystring();
-
var num=parseInt(qs.get("num", "0"));
+
 
var title=qs.get("name");
var title=qs.get("name");
 +
var num=parseInt(qs.get("num", "0"));
var tgt=new Array(num);
var tgt=new Array(num);
for (var i=0;i<num;i++)
for (var i=0;i<num;i++)
Line 120: Line 174:
tgt[i]=qs.get("arg"+i);
tgt[i]=qs.get("arg"+i);
}
}
 +
 +
if (tgt.length>0) merge(tgt);
if (tgt.length>0) merge(tgt);

Latest revision as of 18:40, 28 October 2008

Gallery Bricks Notebook Team Project Home