Difference between revisions of "Vesper:scratchspace"
(→Welcome to Vesper's Scratchspace~) |
m (→Welcome to Vesper's Scratchspace~) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Welcome to Vesper's Scratchspace~== | ==Welcome to Vesper's Scratchspace~== | ||
− | Today's menu: [https://wiki.mozilla.org/Labs/Ubiquity Ubiquity] URL noun type (and a basic function that uses it) | + | '''Today's menu:''' [https://wiki.mozilla.org/Labs/Ubiquity Ubiquity] URL noun type (and a basic function that uses it) |
The regex in the code more or less says this: | The regex in the code more or less says this: | ||
Line 15: | Line 15: | ||
universe://milky.way/earth/north-america/canada/ontario/ | universe://milky.way/earth/north-america/canada/ontario/ | ||
− | + | 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. | |
− | |||
− | + | '''The code itself:''' | |
− | + | ||
− | = | + | 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_-~#=]*))*(\/[A-Za-z0-9_]*\.[A-Za-z0-9_]+)?$/.test(text)){ | ||
+ | return [ CmdUtils.makeSugg(text) ]; | ||
+ | } | ||
− | + | return [ CmdUtils.makeSugg("http://" + text) ]; | |
− | + | } | |
− | + | }; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | }; | ||
Line 51: | Line 48: | ||
} | } | ||
}) | }) | ||
+ | |||
+ | My apologies to those with screens that aren't 1280 pixels wide, but the regex doesn't like to be split into multiple lines. | ||
+ | |||
+ | |||
+ | '''Known issues:''' | ||
+ | |||
+ | It can't handle the "?" in PHP querries. I assume there can only be one, and it must be after the filename (with the extension). Hashes (#) should probably be handled the same way, instead of the way I'm handling them now (as letters, allowed anywhere except in the domain). | ||
+ | |||
+ | http://foo.com/index.php?user=blarg | ||
+ | |||
+ | |||
+ | '''Credits:''' | ||
+ | |||
+ | Syntax for the sample command was edited from the sample "echo" command in the [https://wiki.mozilla.org/Labs/Ubiquity/Ubiquity_0.1_Author_Tutorial tutorial]. |
Latest revision as of 21:32, 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/
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.
The code itself:
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_-~#=]*))*(\/[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 ); } })
My apologies to those with screens that aren't 1280 pixels wide, but the regex doesn't like to be split into multiple lines.
Known issues:
It can't handle the "?" in PHP querries. I assume there can only be one, and it must be after the filename (with the extension). Hashes (#) should probably be handled the same way, instead of the way I'm handling them now (as letters, allowed anywhere except in the domain).
http://foo.com/index.php?user=blarg
Credits:
Syntax for the sample command was edited from the sample "echo" command in the tutorial.