jQuery Ext: $.matchUrl

by SpYk3

HTML

<script src="https://cdn.rawgit.com/JDMcKinstry/8d3ccae2868e7d6dd265bb45663828f8/raw/1c555830050ef3ff74b0b9001f35e0987d3ae58b/string.matchUrl.js"></script>
<h2>
Now found at <a href="https://gist.github.com/JDMcKinstry/8d3ccae2868e7d6dd265bb45663828f8s">gist.github.com</a>
</h2>
<div>
<label for="bobbicus" class="ui-widget ui-widget-header">Type an URL in the Input Box Below, Then Press Enter or Click Submit Button</label>
<input id="bobbicus" name="bobbicus" type="text" value="http://www.google.com/index.php/controller/function?key1=value1&key2=value2#!state" />
<br />
<button>SUBMIT</button>
</div>
<table>
    <tbody>
    </tbody>
</table>

CSS

div, label, table { margin: 0 auto; width: 90%; }
label, input { text-align: center; }
input { background-color: #CCFFCC; border-left: none; border-right: none; }
input, button { line-height: 1.25em; width: 100%; }
button { font-size: 1.1em; }
table { border-collapse: collapse; }
td { border: 1px groove #c8c8c8; padding: .25em .5em; }
td:first-child { font-weight: bold; text-align: right; width: 80px; }
td:nth-child(2) { background-color: #000; color: #f8f8ff; }

JavaScript

/* BEGIN PLUG-ING */
/*
now hosted at 
https://gist.github.com/JDMcKinstry/8d3ccae2868e7d6dd265bb45663828f8
*/
/* END PLUG-ING */

$(function() {           
  var noVal = "NO VALUE FOUND";
  $("button").button().click(function(e) {
      var itry = $("#bobbicus").val();
      console.log("Url = ", itry);
      itry = $.matchUrl(itry);
      console.log('$.matchUrl() = ', itry);
      console.log('isValidURL = ', itry.valid);
      if (typeof itry === "object") {
          $("tbody").empty();
          for (x in itry) {
            var label = x,
                value = itry[x] ? itry[x] != "" ? itry[x] : noVal : x === "valid" && itry[x] == false ? "false" : noVal,
                tdCss = value == noVal ? { "font-style": "italic", color: "#FFA" } : {};
            $("tbody").append(
                  $("<tr />").append(
                      $("<td />").text(label),
                          $("<td />").text(value).css(tdCss)
                  )
              );          
          }
      };
  }).click();

    $("#bobbicus").keyup(function(e) {
        if (parseInt(e.which) === 13) $("button").click();
    });
});