/**
* @author t3knomanser
*/
/* IDENTICA SECTION */
function buildIdentica() {
const LACONICA_STATUS_MAXLEN = 140;
const LACONICA_API_ROOT = "http://identi.ca/api/statuses/";
const LACONICA_ROOT = "http://identi.ca/";
//##STYLESHEET DEFINITION
//Here's where the stlyesheet is born.
const STYLESHEET = "<style> .char_count { text-align: right; opacity: .5; font-size: 30pt; }\n" +
".container {font-family: Geneva, Verdana, Arial, sans-serif; font-size:10pt;}\n" +
".dentpost {z-index: 2; background-color: #222255; opacity: .75; border-top: 1px solid black; border-bottom: 1px solid black;}\n" +
"a {color: #AAAAFF} \n" +
".icon {position: relative; left: 10px;}\n" +
".dentread {position: relative; left: 42px; top: -24px; width: 90%; height: 34px;}\n"+ //this is the bit that's causing problems.
"</style>\n";

var linkify = function(text) {
var urlRegex = /\b(((https?|ftp|irc|telnet|nntp|gopher|file):\/\/|(mailto|news|data):)[^\s\"<>\{\}\'\(\)]*)/g;
var res = text.replace(urlRegex, "<a href=\"$1\">$1</a>");
return res;
};

var atify = function(text) {
var atRegex = /@([^\s\"<>\{\}\'\(\)]*)/g;
var res = text.replace(atRegex, "@<a href=\"" + LACONICA_ROOT + "$1\">$1</a>");
return res;
};

var hashify = function(text) {
var hashRegex = /\s#([^\s\"<>\{\}\'\(\)]*)/g;
var res = text.replace(hashRegex, " #<a href=\"" + LACONICA_ROOT + "tag/$1\">$1</a>");
return res;
};

CmdUtils.CreateCommand({
name: "get-dents",
takes: {n: noun_arb_text},
homepage: "http://a.a.a/",
author: {name: "Remy Porter", homepage: "http://identi.ca/t3knomanser"},
license: "MPL",

preview: function(previewBlock, numPosts) {
previewBlock.innerHTML = "....."; //See, I build all these bits...
var link_start = "<a href=\"http://identi.ca/${user}\">"; var link_end = "</a>";
var image_template = "<div class=\"icon\">" + link_start + "<img src=\" ${imageUrl}\" height=\"25px\" width=\"25px\" />" + link_end +"</div>";
var user_cell = "<div class=\"user\">" +
link_start + "${user}" + link_end + ":</div>";
var stat_cell = "<div class=\"dentread\">${dent}</div>" //And put them into a DIV container.
var dent_template = "<div class=\"container\" style=\"background-color:${color}\">" + user_cell + image_template + stat_cell + "</div>";

var num = 5;
if ((numPosts) && isNumeric(numPosts.text) && numPosts.text.length > 0) { num = numPosts.text; } else { num = 5; }
var updateURL;
updateURL = LACONICA_API_ROOT + "friends_timeline.xml?count=" + num;
jQuery.ajax({
type: "GET",
url: updateURL,
success: function(xml) {
var body = ""; var count = 0;
jQuery("status", xml).each(function() {
body += CmdUtils.renderTemplate(dent_template,
{user:jQuery("screen_name", this).text(),
dent:atify(hashify(linkify(jQuery("text", this).text()))),
imageUrl:jQuery("profile_image_url", this).text(),
color:(count%2==0)?"#222277":"#222244"}
);
count+=1;
});
previewBlock.innerHTML = STYLESHEET + body; //And output it. But the DIV is the size BEFORE the relative positioning takes effect, not after. That's my problem.
//The container DIV is bigger than it needs to be.
},
error: function() {displayMessage("Failed getting dents."); }
});
},
execute: function() {}
});
};
buildIdentica();