Tuesday, September 16, 2008

Pastebin Compitible with Ubiquity

After reading James Boston's blog regarding fusion Ubiquity and Patebin, I got so much interest in the project. I red the code and I found it more interesting as it contains some JQuery, an upcoming technology, which is new to me.

James' code is lot easier to understand. His code will returns the ID of the code if we select something and "Ubiquity" it by command "pastebin". But his code is not able highlight the code as per the language, which is a useful feature of Pastebin.com. I will use his code and try to go somewhat further in that and make it highlight.

His Code:

CmdUtils.CreateCommand({

name: "pastebin1",

takes: {"your code": noun_arb_text},

preview: function( pblock, theCode ) { pblock.innerHTML = "Will paste: " + theCode.text; },

execute: function( theCode ) {
var baseUrl = "http://pastebin.mozilla.org";

// var params = Utils.paramsToString({code2: theCode.text, parent_pid: ""});
var params = { format: "java", poster: "ubiquity", expiry: "m", code2: theCode.text, paste: "Send" };
// displayMessage(params);
jQuery.post( baseUrl, params, function(html) {

//displayMessage(html);
var re = /dl=(.+?)"/;

var pid = re.exec(html);
if (pid) {
displayMessage(pid[1]);
Utils.openUrlInBrowser("http://pastebin.mozilla.org/"+pid[1]);
} else {
displayMessage("Failure!");
}
} );
}
})

I think I just have to replace the value of "format" parameter from "params" variable by the user entry. If somebody have better idea, just let me know.

No comments:

Followers