Library: Difference between revisions
No edit summary |
No edit summary |
||
| Line 11: | Line 11: | ||
var t = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text; | var t = window.getSelection ? window.getSelection().toString() : document.selection.createRange().text; | ||
// create a Regular Expression to test the validity of our input | // create a Regular Expression to test the validity of our input | ||
var re = / | var re = /[\s\-xX0-9]{10,17}/; | ||
var OK = re.exec(t); | var OK = re.exec(t); | ||
if (!OK) { | if (!OK) { | ||
// Notify the user if their selection doesn't look right | // Notify the user if their selection doesn't look right | ||
alert(t + | alert(t + ' is not a valid ISBN\n Please just select a 10 or 13 digit ISBN\ndashes and spaces are OK'); | ||
} else { | } else { | ||
// clean up by removing dashes and spaces | |||
t = t.replace(/[\-\s]/,''); | |||
// hand off to MLVC search | // hand off to MLVC search | ||
window.location = 'http://newburyport.mvlc.org/eg/opac/results?contains=contains;_special=1;qtype=identifier%7Cisbn;locg=1;pane=numeric;query=' + t; | window.location = 'http://newburyport.mvlc.org/eg/opac/results?contains=contains;_special=1;qtype=identifier%7Cisbn;locg=1;pane=numeric;query=' + t; | ||
| Line 25: | Line 27: | ||
{{Messagebox|type=success|text=Note: for the bookmarklet to work, it all has to be on one line. The code above is presented on several lines for readability.}} | {{Messagebox|type=success|text=Note: for the bookmarklet to work, it all has to be on one line. The code above is presented on several lines for readability.}} | ||
Want this bookmarklet? Drag this link to your browser bookmark bar: <html><a href="javascript: (function(){var t=window.getSelection?window.getSelection().toString():document.selection.createRange().text;window.location='http://newburyport.mvlc.org/eg/opac/results?contains=contains;_special=1;qtype=identifier%7Cisbn;locg=1;pane=numeric;query='+t})();">Search MLVC</a></html> | Want this bookmarklet? Drag this link to your browser bookmark bar: <html><a href="javascript: (function(){var t=window.getSelection?window.getSelection().toString():document.selection.createRange().text;var re = /[\s\-xX0-9]{10,17}/;var OK = re.exec(t);if (!OK) {alert(t + ' is not a valid ISBN\n Please just select a 10 or 13 digit ISBN\ndashes and spaces are OK');} else {t = t.replace(/[\-\s]/,'');window.location='http://newburyport.mvlc.org/eg/opac/results?contains=contains;_special=1;qtype=identifier%7Cisbn;locg=1;pane=numeric;query='+t}})();">Search MLVC</a></html> | ||
== Try it == | == Try it == | ||
{{Messagebox|type=failure|text=This | {{Messagebox|type=failure|text=This bookmarklet works only when you have selected a valid numeric ISBN (dashes and spaces are OK)}} | ||
Select ONLY the numeric portion of an ISBN | Select ONLY the numeric portion of an ISBN. Do not include the letters "ISBN" | ||
* Little Rabbit Foo Foo is ISBN 0671709682 | * Little Rabbit Foo Foo is ISBN 0671709682 | ||
* Free Culture is ISBN 1594200068 | * Free Culture is ISBN 1594200068 | ||