Created
November 27, 2009 23:23
-
-
Save gialloporpora/244283 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// max of 140 chars is recommended, but it really allows 160 | |
const IDENTICA_STATUS_MAXLEN = 160; | |
CmdUtils.CreateCommand({ | |
name: "mozillaca", | |
icon: "", | |
takes: {status: noun_arb_text}, | |
modifiers: {}, | |
preview: function(previewBlock, statusText) { | |
var previewTemplate = "Updates your mozilla.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, | |
chars: IDENTICA_STATUS_MAXLEN - statusText.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.length < 1) { | |
displayMessage("mozilla.ca requires a status to be entered"); | |
return; | |
} | |
var updateUrl = "http://mozilla.ca/api/statuses/update.json"; | |
var updateParams = { | |
source: "ubiquity", | |
status: statusText | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
displayMessage("mozilla.ca error - status not updated"); | |
}, | |
success: function() { | |
displayMessage("mozilla.ca status updated"); | |
} | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment