Joao's test

by tonytlwu

HTML

<script src="https://www.google.com/jsapi"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<h1>RSS Feeds </h1>

<form id="searchform" name="myform" class="form-inline" method="post" role="form">
    <div class="form-group">
        <input type="text" class="form-control" name="searchrss" id="rssurl" placeholder="Enter RSS URL" />
    </div>
    <button type="submit" id="searchbutton" class="btn btn-default">Search</button>
</form>
<div id="feeds"></div>

CSS

h1 {
    text-align: center;
}
#searchform {
    text-align: center;
}
#feeds {
    text-align: center;
}
.imgplaceholder {
    float:left;
}

JavaScript

function readfeed() {
     var rssurl = document.getElementById('rssurl').value;
     validateURL(rssurl);
     initialize(rssurl);
 }


 function validateURL(rssurl) {
     //regular expression to validate a URL
     var urlregex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i;
     if (!urlregex.test(rssurl)) {
         alert("URL not valid");
     }
 }

 function initialize(rssurl) {
     var feed = new google.feeds.Feed(rssurl);
     feed.load(function (result) {
         if (!result.error) {
             for (var i = 0; i < result.feed.entries.length; i++) {
                 var entry = result.feed.entries[i];


                 var div1 = document.getElementById("feeds");
                 //creating table for the RSS feed
                 var x = document.createElement("TABLE");
                 x.setAttribute("id", "myTable");
                 div1.appendChild(x);

                 var y = document.createElement("TR");
                 y.setAttribute("id", "myTr".concat(i));
                 document.getElementById("myTable").appendChild(y);

                 //Generate new Title with link to a new tab
                 var z = document.createElement("TD");
                 var d = document.createElement("h3");
                 d.className = "titletext";
                 d.setAttribute('href', entry.link);
                 d.setAttribute('target', "_blank");
                 var title = document.createTextNode(entry.title);
                 d.appendChild(title);
                 z.appendChild(d);
                ...