Difference between revisions of "Vesper:scratchspace"

From CDOT Wiki
Jump to: navigation, search
(Welcome to Vesper's Scratchspace~)
m
Line 23: Line 23:
 
  ================================================================================================
 
  ================================================================================================
 
   
 
   
var noun_type_url = {
+
var noun_type_url = {
 
   _name: "Valid URL",
 
   _name: "Valid URL",
 
+
 
   suggest: function( text, html ) {
 
   suggest: function( text, html ) {
 
     if (!text)
 
     if (!text)
 
       return [ CmdUtils.makeSugg("http://") ];
 
       return [ CmdUtils.makeSugg("http://") ];
 
+
 
+
 
     if(/^[A-Za-z0-9]+:\/\/([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-]+))+(\/([A-Za-z0-9_-~]+))+[/]?$/.test(text)){
 
     if(/^[A-Za-z0-9]+:\/\/([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-]+))+(\/([A-Za-z0-9_-~]+))+[/]?$/.test(text)){
 
       return [ CmdUtils.makeSugg(text) ];
 
       return [ CmdUtils.makeSugg(text) ];
 
     }
 
     }
 
+
 
     return [ CmdUtils.makeSugg("http://" + text) ];
 
     return [ CmdUtils.makeSugg("http://" + text) ];
 
   }
 
   }

Revision as of 21:47, 11 September 2008

Welcome to Vesper's Scratchspace~

Today's menu: Ubiquity URL noun type (and a basic function that uses it)

The regex in the code more or less says this:

(some protocol name) :// (a string) [. (a string)] [/ (a string)] (maybe / if you want)

Items in square brackets can be repeated. So,

pasta://a.taste.from.little.italy

is a valid url, according to this model. And, so is this:

universe://milky.way/earth/north-america/canada/ontario/

This is not valid.

a://b.c/d.e

All of these choices were arbitrarily chosen by me. I'll be pursuing the community for a better description of what a URL should and should not be.

================================================================================================

var noun_type_url = {
 _name: "Valid URL",

 suggest: function( text, html ) {
   if (!text)
     return [ CmdUtils.makeSugg("http://") ];


   if(/^[A-Za-z0-9]+:\/\/([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-]+))+(\/([A-Za-z0-9_-~]+))+[/]?$/.test(text)){
     return [ CmdUtils.makeSugg(text) ];
   }

   return [ CmdUtils.makeSugg("http://" + text) ];
 }

};


CmdUtils.CreateCommand({
  name: "url",
  takes: {"your shout": noun_type_url},
  preview: function( pblock, theShout ) {
    pblock.innerHTML = "Will verify: " + theShout.text;
  },
  execute: function( theShout ) {
    var msg = theShout.text;
    displayMessage( msg );
  }
})