Skip to content

Instantly share code, notes, and snippets.

@pao
Created October 16, 2009 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pao/211553 to your computer and use it in GitHub Desktop.
Save pao/211553 to your computer and use it in GitHub Desktop.
var noun_type_url_or_arb = {
label: "url or text",
default: noun_type_url.default,
suggest: function nt_url_arb_sugg(text, html, callback, selectionIndices) {
var textLC = text.toLowerCase();
if (textLC.substring(0,4) == "url ") {
return noun_type_url.suggest(text.substring(4), text.substring(4), callback, selectionIndices);
} else {
return noun_arb_text.suggest(text, html, callback, selectionIndices);
}
}
};
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["qr"],
icon: "http://2dcode.ning.com/favicon.ico",
description: "Generate a QR code.",
help: "Input text to encode it in a QR barcode. The default is the URL of the current page. Press enter to insert the QR code.",
author: {name: "Patrick O'Leary", email: "patrick.oleary@gmail.com"},
license: "GPL",
homepage: "http://patrick.greentaperacing.us/",
arguments: [{role: 'object', nountype: noun_type_url_or_arb}, {role: 'format', nountype: noun_type_percentage, label: 'size'}],
preview: function preview(pblock, args) {
var chssize = Math.ceil(150*args.format.data);
var chsstr = chssize + 'x' + chssize;
pblock.innerHTML = "<img src='http://chart.apis.google.com/chart?cht=qr&chs=" + chsstr + "&chl=" + escape(args.object.text) + "' />";
},
execute: function execute(args) {
var chssize = Math.ceil(350*args.format.data);
var chsstr = chssize + 'x' + chssize;
CmdUtils.setSelection("<img src='http://chart.apis.google.com/chart?cht=qr&chs=" + chsstr + "&chl=" + escape(args.object.text) + "' />");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment