pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

ubiquity private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Fernando Takai on Thu 28 Aug 00:23
report abuse | download | new post

  1. const JAIKU_MAXLEN = 140;
  2.  
  3. Jaiku = {
  4.         addKey:function(key){
  5.                 if (!Application.prefs.has("jaiku_user_api_key")) {
  6.                     Application.prefs.setValue("jaiku_user_api_key", key);
  7.                 } else {
  8.                     var new_key = Application.prefs.get("jaiku_user_api_key");
  9.                     new_key.value = key;
  10.                     return new_key.value;
  11.                 }
  12.  
  13.         },
  14.        
  15.         addUsername:function(username){
  16.                 Application.prefs.setValue("jaiku_user_username", username);
  17.         },
  18.        
  19.         getUsername:function(){
  20.                 return Application.prefs.get("jaiku_user_username").value;
  21.         },
  22.        
  23.         getKey:function(){
  24.                 return Application.prefs.get("jaiku_user_api_key").value;
  25.         },
  26.        
  27.         everythingIsOK:function(){
  28.                 return Application.prefs.has("jaiku_user_username") && Application.prefs.has("jaiku_user_api_key");
  29.         }
  30. };
  31.  
  32. CmdUtils.CreateCommand({
  33.   name: "jaiku",
  34.   takes: {status: noun_arb_text},
  35.   modifiers : {"at":noun_arb_text},
  36.  
  37.   author: {name: "Fernando Takai", homepage: "http://fernandotakai.wordpress.com"},
  38.   license: "MPL",
  39.   description: "Post to Jaiku using Ubiquity",
  40.   help: "Type jaiku your message to post.",
  41.  
  42.   preview: function(previewBlock, statusText) {
  43.     var previewTemplate = "Updates your Jaiku presence : <br/>" +      
  44.                           "<b>${status}</b> <br /><br />" +
  45.                           "Characters remaining: <b>${chars}</b>";
  46.     var truncateTemplate = "<br />The last <b>${truncate}</b> " +
  47.                            "characters will be truncated!";
  48.     var previewData = {
  49.       status: statusText.text,
  50.       chars: JAIKU_MAXLEN - statusText.text.length,
  51.       username: Jaiku.getUsername()
  52.     };
  53.      
  54.     var previewHTML = CmdUtils.renderTemplate(previewTemplate,
  55.                                                     previewData);
  56.    
  57.     if(previewData.chars < 0) {
  58.       var truncateData = {
  59.         truncate: 0 - previewData.chars
  60.       };
  61.      
  62.       previewHTML += CmdUtils.renderTemplate(truncateTemplate,
  63.                                                    truncateData);
  64.     }
  65.    
  66.     previewBlock.innerHTML = previewHTML;
  67.   },
  68.  
  69.   execute: function(statusText, mods) {
  70.  
  71.     if(statusText.text.length < 1) {
  72.       displayMessage("Jaiku requires a status to be entered");
  73.       return;
  74.     }
  75.    
  76.     if (Jaiku.everythingIsOK()) {
  77.         var loc = "";
  78.         if(mods.at.text){
  79.           loc = mods.at.text;
  80.         } else {
  81.           var place = CmdUtils.getGeoLocation();  
  82.           loc = place.city + "," + place.country;
  83.         }
  84.  
  85.         var updateUrl = "http://api.jaiku.com/jason";
  86.         var status = statusText.text;
  87.         var updateParams = {
  88.           personal_key: Jaiku.getKey(),
  89.           user: Jaiku.getUsername(),
  90.           message: status,
  91.           method: "presence.send",
  92.           location: loc
  93.         };
  94.        
  95.  
  96.         jQuery.ajax({
  97.           type: "POST",
  98.           url: updateUrl,
  99.           data: updateParams,
  100.           dataType: "json",
  101.           error: function(msg) {
  102.             displayMessage("Jaiku error - status not updated");
  103.           },
  104.           success: function(msg) {
  105.             if(msg.status != "error"){
  106.                displayMessage("Status updated!");
  107.             } else {
  108.                displayMessage(msg.message);
  109.             }
  110.           }
  111.         });
  112.     } else {
  113.         displayMessage("Please set your user api key with jaiku-setuserandkey");
  114.     }
  115.   }
  116. });
  117.  
  118. CmdUtils.CreateCommand({
  119.   name: "jaiku-setuserandkey",
  120.   takes: {username: noun_arb_text},
  121.   modifiers: {"api": noun_arb_text},
  122.  
  123.   license: "MPL",
  124.   description: "Set your jaiku username and key. Check your key at http://api.jaiku.com",
  125.   help: "Type jaiku-setuserandkey <username> <apikey>. Check your key at http://api.jaiku.com",
  126.    
  127.   execute: function(username, mods) {
  128.     if(username.text.length < 1) {
  129.       displayMessage("Please, enter your username");
  130.       return;
  131.     }
  132.  
  133.     var api = mods.api.text || ""
  134.  
  135.     if(api.length < 1) {
  136.       displayMessage("Please, enter your api key");
  137.       return;
  138.     }
  139.    
  140.     Jaiku.addKey(mods.api.text);
  141.     Jaiku.addUsername(username.text);
  142.     displayMessage("Your username and api key has been set.");    
  143.   }
  144. });

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post