Skip to content

Instantly share code, notes, and snippets.

@danielharan
Created August 27, 2008 15:17
Show Gist options
  • Save danielharan/7500 to your computer and use it in GitHub Desktop.
Save danielharan/7500 to your computer and use it in GitHub Desktop.
const MICROBLOG_STATUS_MAXLEN = 140;
CmdUtils.CreateCommand({
name: "dent",
takes: {status: noun_arb_text},
author: {name: "Daniel Haran, barely modifying work by Blair McBride as seen in the Ubiquity tutorial", homepage: "http://danielharan.com/"},
license: "MPL",
preview: function(previewBlock, statusText) {
var previewTemplate = "Updates your Identi.ca status to: <br/>" +
"<b>${status}</b><br /><br />" +
"Characters remaining: <b>${chars}</b>";
var truncateTemplate = "<br />The last <b>${truncate}</b> " +
"characters will be truncated!";
var previewData = {
status: statusText.text,
chars: MICROBLOG_STATUS_MAXLEN - statusText.text.length
};
var previewHTML = CmdUtils.renderTemplate(previewTemplate,
previewData);
if(previewData.chars < 0) {
var truncateData = {
truncate: 0 - previewData.chars
};
previewHTML += CmdUtils.renderTemplate(truncateTemplate,
truncateData);
}
previewBlock.innerHTML = previewHTML;
},
execute: function(statusText) {
if(statusText.text.length < 1) {
displayMessage("Identi.ca requires a status to be entered");
return;
}
var updateUrl = "http://identi.ca/api/statuses/update.json";
var updateParams = {
source: "ubiquity",
status: statusText.text
};
jQuery.ajax({
type: "POST",
url: updateUrl,
data: updateParams,
dataType: "json",
error: function() {
displayMessage("Identi.ca error - status not updated");
},
success: function() {
displayMessage("Identi.ca status updated");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment