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:
" + "${status}

" + "Characters remaining: ${chars}"; var truncateTemplate = "
The last ${truncate} " + "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"); } }); } });