home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / twitter / res / twittermock.js < prev    next >
Encoding:
Text File  |  2009-10-15  |  15.1 KB  |  218 lines

  1.  
  2. function FakeTwitterSource(account, numTweets) {
  3.     this.account = account;
  4.     this.numTweets = numTweets;
  5.     this.usedIds = {};
  6. }
  7.  
  8. FakeTwitterSource.prototype = {
  9.     fakeTweetId: function () {
  10.         var items = this.account.feeds.timeline.items;
  11.         var highestId = items[items.length-1].id;
  12.  
  13.         var newId = highestId + 1000;
  14.         while (newId in this.account.tweets || newId in this.usedIds)
  15.             newId += 1000;
  16.         
  17.         this.usedIds[newId] = true;
  18.         return newId;
  19.     },
  20.     
  21.     fakeUser: function () {
  22.         var account = this.account;
  23.         var userId;
  24.         while (!userId || userId in account.users)
  25.             userId = Math.floor(Math.random() * 10000000);
  26.         return {
  27.             "id": userId, 
  28.             "verified": false, 
  29.             "profile_sidebar_fill_color": "e0ff92", 
  30.             "profile_text_color": "000000", 
  31.             "followers_count": Math.floor(Math.random() * 500), 
  32.             "protected": false, 
  33.             "location": "San Diego, CA", 
  34.             "profile_background_color": "9ae4e8", 
  35.             "utc_offset": -28800, 
  36.             "statuses_count": 8, 
  37.             "description": "Classical Vocalist, Life Coach, Business Coach, Lover of Life", 
  38.             "friends_count": 44, 
  39.             "profile_link_color": "0000ff", 
  40.             "profile_image_url": "http://a1.twimg.com/profile_images/467719152/Heidi-IMG_8247F-twitter_normal.jpg", 
  41.             "notifications": null, 
  42.             "geo_enabled": false, 
  43.             "profile_background_image_url": "http://s.twimg.com/a/1255384803/images/themes/theme1/bg.png", 
  44.             "screen_name": "1classicaldiva", 
  45.             "profile_background_tile": false, 
  46.             "favourites_count": 0, 
  47.             "name": "Heidi Lee", 
  48.             "url": "http://google.com", 
  49.             "created_at": "Mon Oct 12 16:11:39 +0000 2009", 
  50.             "time_zone": "Pacific Time (US & Canada)", 
  51.             "profile_sidebar_border_color": "87bc44", 
  52.             "following": null
  53.          };
  54.     },
  55.  
  56.     update: function(updateNotification) {
  57.         var tweets = [];
  58.  
  59.         for (var i = 0; i < this.numTweets; ++i) {
  60.             var date = new Date().toString().slice(0, 33);
  61.             tweets.push({
  62.                 "favorited": false, 
  63.                 "truncated": false, 
  64.                 "text": loremIpsumParagraph(24),
  65.                 "created_at": date,
  66.                 "source": "web", 
  67.                 "in_reply_to_status_id": null, 
  68.                 "in_reply_to_screen_name": null, 
  69.                 "in_reply_to_user_id": null, 
  70.                 "geo": null, 
  71.                 "id": this.fakeTweetId(), 
  72.                 user: this.fakeUser(),
  73.             });
  74.         }
  75.  
  76.         console.log('created ' + tweets.length + ' fake tweets');
  77.  
  78.         var self = this, account = this.account;
  79.         tweets = $.map(tweets, function (t) { return account.makeTweetFromNetwork(t); });
  80.         account.newTweets(tweets, self);
  81.         if (updateNotification)
  82.             updateNotification.success(self, tweets);
  83.     }
  84. };
  85.  
  86. function fakeTweets(numTweets) {
  87.     var src = new FakeTwitterSource(account, numTweets);
  88.     account.maybeUpdate(false, [src]);
  89.     account.discardOldTweets();
  90. }
  91.  
  92.  
  93. /* Lorem Ipsum Generator
  94.  * (CC-BY) Fredrik Bridell <fredrik@bridell.com> 2009
  95.  * Version 0.21 - multilingual
  96.  * Released under a Creative Commons Attribution License
  97.  *
  98.  * You are welcome to use, share, modify, print, frame, or do whatever you like with this 
  99.  * software, including commercial use. My only request is that you tell the world where you found it.
  100.  * 
  101.  * One way is to include the phrase: 
  102.  * "Using the The Lorem Ipsum Generator by Fredrik Bridell (http://bridell.com/loremipsum/)"
  103.  *
  104.  * To use this on your web page: download the .js file and place it on your web server (please
  105.  * do not include it from my server). In your html file, include the markup
  106.  * <script type="text/javascript" src="loremipsum.js" />
  107.  * (In the head or in the body).
  108.  *
  109.  * Where you want the Lorem Ipsum, include this markup:
  110.  * <script type="text/javascript">loremIpsumParagraph(100)</script>
  111.  * The number is the number of words in the paragraph. 
  112.  */ 
  113.  
  114. /* Latin words, These are all the words in the first 100 lines of Ovid's Metamorphoses, Liber I. */
  115. var latin =["ab", "aberant", "abscidit", "acervo", "ad", "addidit", "adhuc", "adsiduis", "adspirate", "aequalis", "aer", "aera", "aere", "aeris", "aestu", "aetas", "aethera", "aethere", "agitabilis", "aliis", "aliud", "alta", "altae", "alto", "ambitae", "amphitrite", "animal", "animalia", "animalibus", "animus", "ante", "aquae", "arce", "ardentior", "astra", "aurea", "auroram", "austro", "bene", "boreas", "bracchia", "caeca", "caecoque", "caeleste", "caeli", "caelo", "caelum", "caelumque", "caesa", "calidis", "caligine", "campoque", "campos", "capacius", "carentem", "carmen", "cepit", "certis", "cesserunt", "cetera", "chaos:", "cingebant", "cinxit", "circumdare", "circumfluus", "circumfuso", "coegit", "coeperunt", "coeptis", "coercuit", "cognati", "colebat", "concordi", "congeriem", "congestaque", "consistere", "contraria", "conversa", "convexi", "cornua", "corpora", "corpore", "crescendo", "cum", "cuncta", "cura", "declivia", "dedit", "deducite", "deerat", "dei", "densior", "deorum", "derecti", "descenderat", "deus", "dextra", "di", "dicere", "diffundi", "diremit", "discordia", "dispositam", "dissaepserat", "dissociata", "distinxit", "diu", "diversa", "diverso", "divino", "dixere", "dominari", "duae", "duas", "duris", "effervescere", "effigiem", "egens", "elementaque", "emicuit", "ensis", "eodem", "erant", "erat", "erat:", "erectos", "est", "et", "eurus", "evolvit", "exemit", "extendi", "fabricator", "facientes", "faecis", "fecit", "feras", "fert", "fidem", "figuras", "finxit", "fixo", "flamina", "flamma", "flexi", "fluminaque", "fontes", "foret", "forma", "formaeque", "formas", "fossae", "fratrum", "freta", "frigida", "frigore", "fronde", "fuerant", "fuerat", "fuit", "fulgura", "fulminibus", "galeae", "gentes", "glomeravit", "grandia", "gravitate", "habendum", "habentem", "habentia", "habitabilis", "habitandae", "haec", "hanc", "his", "homini", "hominum", "homo", "horrifer", "humanas", "hunc", "iapeto", "ignea", "igni", "ignotas", "illas", "ille", "illi", "illic", "illis", "imagine", "in", "inclusum", "indigestaque", "induit", "iners", "inmensa", "inminet", "innabilis", "inposuit", "instabilis", "inter", "invasit", "ipsa", "ita", "iudicis", "iuga", "iunctarum", "iussit", "lacusque", "lanient", "lapidosos", "lege", "legebantur", "levitate", "levius", "liberioris", "librata", "ligavit:", "limitibus", "liquidas", "liquidum", "litem", "litora", "locavit", "locis", "locoque", "locum", "longo", "lucis", "lumina", "madescit", "magni", "manebat", "mare", "margine", "matutinis", "mea", "media", "meis", "melior", "melioris", "membra", "mentes", "mentisque", "metusque", "militis", "minantia", "mixta", "mixtam", "moderantum", "modo", "moles", "mollia", "montes", "montibus", "mortales", "motura", "mundi", "mundo", "mundum", "mutastis", "mutatas", "nabataeaque", "nam", "natura", "naturae", "natus", "ne", "nebulas", "nec", "neu", "nisi", "nitidis", "nix", "non", "nondum", "norant", "nova", "nubes", "nubibus", "nullaque", "nulli", "nullo", "nullus", "numero", "nunc", "nuper", "obliquis", "obsistitur", "obstabatque", "occiduo", "omni", "omnia", "onerosior", "onus", "opifex", "oppida", "ora", "orba", "orbe", "orbem", "orbis", "origine", "origo", "os", "otia", "pace", "parte", "partim", "passim", "pendebat", "peragebant", "peregrinum", "permisit", "perpetuum", "persidaque", "perveniunt", "phoebe", "pinus", "piscibus", "plagae", "pluvialibus", "pluviaque", "poena", "pondere", "ponderibus", "pondus", "pontus", "porrexerat", "possedit", "posset:", "postquam", "praebebat", "praecipites", "praeter", "premuntur", "pressa", "prima", "primaque", "principio", "pro", "pronaque", "proxima", "proximus", "pugnabant", "pulsant", "quae", "quam", "quanto", "quarum", "quem", "qui", "quia", "quicquam", "quin", "quinta", "quisque", "quisquis", "quod", "quoque", "radiis", "rapidisque", "recens", "recepta", "recessit", "rectumque", "regat", "regio", "regna", "reparabat", "rerum", "retinebat", "ripis", "rudis", "sanctius", "sata", "satus", "scythiam", "secant", "secrevit", "sectamque", "secuit", "securae", "sed", "seductaque", "semina", "semine", "septemque", "sibi", "sic", "siccis", "sidera", "silvas", "sine", "sinistra", "sive", "sole", "solidumque", "solum", "sorbentur", "speciem", "spectent", "spisso", "sponte", "stagna", "sua", "subdita", "sublime", "subsidere", "sui", "suis", "summaque", "sunt", "super", "supplex", "surgere", "tanta", "tanto", "tegi", "tegit", "tellure", "tellus", "temperiemque", "tempora", "tenent", "tepescunt", "terra", "terrae", "terram", "terrarum", "terras", "terrenae", "terris", "timebat", "titan", "tollere", "tonitrua", "totidem", "totidemque", "toto", "tractu", "traxit", "triones", "tuba", "tum", "tumescere", "turba", "tuti", "ubi", "ulla", "ultima", "umentia", "umor", "unda", "undae", "undas", "undis", "uno", "unus", "usu", "ut", "utque", "utramque", "valles", "ventis", "ventos", "verba", "vesper", "videre", "vindice", "vis", "viseret", "vix", "volucres", "vos", "vultus", "zephyro", "zonae"];
  116.  
  117. /* Swedish words. These are all the words in the two first paragraphs of August Strindberg's R÷da Rummet. */
  118. var swedish = ["afton", "allmänheten", "allting", "arbetat", "att", "av", "bakom", "barΦge-lappar", "berberisbär", "Bergsund", "bersåer", "beströdd", "bjödo", "blev", "blivit", "blom", "blommor", "bofinkarne", "bon", "bort", "bosättningsbekymmer", "branta", "bygga", "bänkfot", "både", "började", "början", "börjat", "Danviken", "de", "del", "deltogo", "den", "det", "detsamma", "djur", "draga", "drog", "drogos", "där", "därför", "därifrån", "därinne", "då", "efter", "ej", "eklärerade", "emot", "en", "ett", "fjolårets", "fjor", "fjärran", "for", "fortsatte", "fram", "friska", "från", "färd", "fästningen", "få", "fönstervadden", "fönstren", "för", "förbi", "fördes", "förfärligt", "förut", "genom", "gick", "gingo", "gjorde", "granris", "gren", "gripa", "gråsparvarne", "gå", "gångarne", "gått", "gömde", "hade", "halmen", "havet", "hela", "hittade", "hon", "hundar", "hus", "Hästholmen", "hårtappar", "höllo", "höstfyrverkeriet", "i", "icke", "igen", "ilade", "illuminerade", "in", "ingen", "innanfönstren", "Josefinadagen", "just", "kastade", "kiv", "klistringen", "klättrade", "knoppar", "kol", "kom", "korset", "korta", "kunde", "kvastar", "kände", "kärleksfilter", "köksan", "lavklädda", "lekte", "levdes", "Lidingöskogarne", "ligger", "Liljeholmen", "lilla", "lindarne", "liv", "luften", "lukten", "lämna", "långt", "lövsamlingar", "maj", "med", "medan", "mellan", "men", "moln", "Mosebacke", "mot", "mänskofot", "navigationsskolans", "nu", "näsan", "obesvärat", "obrustna", "och", "ofruktsamt", "om", "os", "paljetter", "passade", "piga", "plats", "plockade", "päronträd", "på", "rabatterna", "rakethylsor", "Riddarfjärden", "Riddarholmskyrkan", "ringdans", "rivit", "Rosendal", "rosenfärgat", "rusade", "rökarne", "saffransblommorna", "samla", "samma", "sandgångarne", "sedan", "sig", "Siklaön", "sin", "sina", "sista", "Sjötullen", "Sjötulln", "Skeppsbrobåtarne", "skolan", "skrämd", "skräp", "skydd", "sköt", "slagits", "slog", "sluppit", "sluta", "snart", "snö", "snödropparne", "solen", "som", "sommarnöjena", "spillror", "Stadsgården", "stam", "stekflott", "stickorna", "stod", "stor", "stora", "stranden", "strålar", "störtade", "sydlig", "syrenerna", "sågo", "sågspån", "sålunda", "södra", "tagit", "tak", "takpannorna", "till", "tillbaka", "tittade", "tjära", "tonade", "trampat", "tran", "träd", "trädgården", "Tyskans", "törnade", "törnrosblad", "undanröjda", "under", "unga", "upp", "uppför", "uppgrävda", "ur", "ut", "utefter", "utmed", "var", "Vaxholm", "verksamhet", "vilka", "vilken", "vimplarne", "vind", "vinden", "vinterns", "voro", "vägg", "väggen", "väntade", "ännu", "året", "åt", "ölskvättar", "ömtåligare", "öppnad", "öppnades", "öster", "över"];
  119.  
  120. // just switch language like this! You can also do this in a script block on the page. 
  121. var loremLang = latin;
  122.  
  123. /* Characters to end a sentence with. Repeat for frequencies (i.e. most sentences end in a period) */
  124. var endings = "................................??!";
  125.  
  126. /* randomly returns true with a certain chance (a percentage) */
  127. function chance(percentage) {
  128.     return (Math.floor(Math.random() * 100) < percentage);
  129. }
  130.  
  131. /* capitalizes a word */
  132. function capitalize(aString) {
  133.     return aString.substring(0,1).toUpperCase() + aString.substring(1, aString.length);
  134. }
  135.  
  136. /* returns a random lorem word */
  137. function getLoremWord() {
  138.     return loremLang[Math.floor(Math.random()*loremLang.length)];
  139. }
  140.  
  141. function getLoremEnding() {
  142.     var i = Math.floor(Math.random()*endings.length);
  143.     return endings.substring(i, i+1);
  144. }
  145.  
  146. /* inserts a number of lorem words. Does not append a space at the end. */
  147. function loremIpsum(s, numWords) {
  148.     for(var i=0; i<numWords-1; ++i)
  149.         s.push(getLoremWord() + ' ');
  150.     s.push(getLoremWord());
  151. }
  152.  
  153. /* inserts a sentence of random words. Appends a space at the end. */
  154. function loremIpsumSentence(s, numWords) {
  155.     s.push(capitalize(getLoremWord()) + " ");
  156.     loremIpsum(s, numWords-1);
  157.     s.push(getLoremEnding());
  158.     s.push(' ');
  159. }
  160.  
  161. /* inserts a sentence of random words, sometimes with extra punctuation. Appends a space at the end. */
  162. function loremIpsumSentence2(s, numWords) {
  163.     s.push(capitalize(getLoremWord()) + " ");
  164.     var part1 = 0;
  165.     if(chance(50)) {
  166.         // insert a comma or other punctuation within the sentence
  167.         part1 = Math.floor(Math.random() * numWords-2);
  168.         loremIpsum(s, part1);
  169.         s.push(', ');
  170.     } else
  171.         s.push(' ');
  172.  
  173.     loremIpsum(s, numWords - part1 - 1);
  174.  
  175.     s.push(getLoremEnding());
  176.     s.push(' ');
  177. }
  178.  
  179. /* inserts a paragraph of sentences of random words. */
  180. function loremIpsumParagraph(numWords) {
  181.     var words = numWords;
  182.     var s = [];
  183.     while(words > 0){
  184.         if(words > 10){
  185.             w = Math.floor(Math.random() * 8) + 2;
  186.             loremIpsumSentence2(s, w);
  187.             words = words - w;
  188.         } else {
  189.             loremIpsumSentence2(s, words);
  190.             words = 0;
  191.         }
  192.     }
  193.     return s.join('');
  194. }
  195.  
  196.  
  197. function debugCounts() {
  198.     var info = [
  199.         'objectKeys(account.tweets).length',
  200.         'objectKeys(account.users).length',
  201.         'account.timeline.toInsert.length',
  202.         'account.timeline.toDelete.length',
  203.         'timelineWindows[0].document.all.length',
  204.         'account.timeline.container.childNodes.length',
  205.         'objectLength(Digsby.callbacks)',
  206.     ];
  207.  
  208.     var infos = [];
  209.     $.each(info, function (i, s) {
  210.         var val = '';
  211.         try { val = eval(s); } catch(err) {}
  212.         infos.push(s + ': ' + val);
  213.     });
  214.  
  215.     return infos.join('\n');
  216. }
  217.  
  218.