igorette (owner)

Revisions

gist: 19397 Download_button fork
public
Public Clone URL: git://gist.github.com/19397.git
Embed All Files: show embed
x #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Mozilla Ubiquity Bartle Command
   Written by David Futcher (bobbo) <bobbo@ubuntu.com>
   Heavily based on an earlier command to do the same thing (thanks!)
   Do whatever the hell you want with this */
 
// max of 140 chars is recommended, but it really allows 160
const BARTLE_STATUS_MAXLEN = 160;
 
 
CmdUtils.CreateCommand({
name: "bartle.doomicile.de",
icon: "",
takes: {status: noun_arb_text},
modifiers: {},
preview: function(previewBlock, statusText) {
     var charsLeft = BARTLE_STATUS_MAXLEN - statusText.text.length;
     var truncCharsLeft = charsLeft;
     if (charsLeft < 0) charsLeft = 0
 
  var previewTemplate = "Updates your Bartle 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.text,
   chars: charsLeft
  };
 
  var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
 
  if(previewData.chars <= 0) {
   var truncateData = {
    truncate: 0 - truncCharsLeft
   };
 
   previewHTML += CmdUtils.renderTemplate(truncateTemplate, truncateData);
  }
 
  previewBlock.innerHTML = previewHTML;
},
execute: function(statusText) {
  if(statusText.text.length < 1) {
   displayMessage("Bartle requires a status to be entered");
   return;
  }
 
  var updateUrl = "http://bartle.doomicile.de/api/statuses/update.json";
  var updateParams = {
   source: "ubiquity",
   status: statusText.text
   };
 
  jQuery.ajax({
   type: "POST",
   url: updateUrl,
   data: updateParams,
   dataType: "json",
   error: function() {
    displayMessage("Bartle error - status not updated");
   },
   success: function() {
    displayMessage("Bartle status updated");
   }
  });
}
});