home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / twitter / res / app.js < prev    next >
Encoding:
JavaScript  |  2010-11-24  |  4.3 KB  |  167 lines

  1.  
  2. timelineWindows = [];
  3.  
  4. var defaultSettings = {
  5.     show_real_names: false,
  6.     frame_focus_unread: true,
  7.     autoscroll_when_at_bottom: true,
  8.     user_feeds: false,
  9. };
  10.  
  11. var settings = $.extend(true, {}, defaultSettings);
  12.  
  13. verbose = false;
  14.  
  15. function openWindow(feedName) {
  16.     window.feedToOpen = feedName;
  17.     var windowOptions = 'status=0,toolbar=0,width=400,height=800';
  18.     var win = window.open((window.resdir ? window.resdir : '')+ '/feed.html', 'mywindow', windowOptions);
  19.  
  20.     if (win) {
  21.         console.log('feed window opened successfully: ' + win);
  22.         timelineWindows.push(win);
  23.     } else
  24.         console.error('could not open window');
  25. }
  26.  
  27. function update() {
  28.     window.account.forceUpdate();
  29. }
  30.  
  31. function getPrefs(opts) {
  32.     opts.success({user: settings, defaults: defaultSettings});
  33. }
  34.  
  35. var addFeed = function(opts) { window.account.addFeed(opts.feed || opts.group); }
  36. var addGroup = addFeed;
  37.  
  38. var favorite = function(opts) {
  39.     window.account.favorite(opts.tweet,
  40.                             function(tweet){opts.success('win_favorite');},
  41.                             function(error_obj){opts.error('fail_favorite');}
  42.     );
  43. }
  44.  
  45. var deleteTweet = function(opts) {
  46.     window.account.deleteTweet({id: opts.tweet.id,
  47.                                 success: function(tweet){opts.success('win_delete');},
  48.                                 error: function(error_obj){opts.error('fail_delete');}
  49.     });
  50. }
  51.  
  52. function editFeed(opts) {
  53.     window.account.editFeed(opts.feed);
  54. }
  55.  
  56. function setFeeds(opts) {
  57.     window.account.setFeeds(opts.feeds);
  58. }
  59.  
  60. function markAsRead(opts) {
  61.     var tweet = window.account.tweets[opts.tweet_id];
  62.     if (tweet) window.account.markAsRead(tweet);
  63. }
  64.  
  65. function inviteFollowers() {
  66.     window.account.inviteFollowers();
  67. }
  68.  
  69. function markFeedAsRead(opts) {
  70.     window.account.markFeedAsRead(opts.feedName);
  71. }
  72.  
  73. function toggleAddsToCount(opts) {
  74.     window.account.toggleAddsToCount(opts.feedName);
  75. }
  76.  
  77. // globals that get forwarded to the global account
  78. $.each(['markAllAsRead', 'deleteFeed', 'getUsers', 'setAccountOptions', 'follow'], function (i, name) {
  79.     window[name] = function(opts) {
  80.         return window.account[name](opts);
  81.     };
  82. });
  83.  
  84. function tweet(opts) {
  85.     var success = opts.success,
  86.         error = opts.error,
  87.         status = opts.status,
  88.         replyTo = opts.replyTo;
  89.  
  90.     window.account.tweet(status, replyTo, success, error);
  91. }
  92.  
  93. function showReply(opts) {
  94.     window.account.popupInReplyTo(opts.tweetId);
  95. }
  96.  
  97. function onTweet(tweetjson) {
  98.     window.account.onRealTimeTweet(tweetjson);
  99. }
  100.  
  101. function signalCorruptedDatabase() {
  102.     console.log('calling on_corrupted_database...');
  103.     guard(function() {
  104.         D.notify('corrupted_database');
  105.     });
  106.     console.log('called on_corrupted_database...');
  107. }
  108.  
  109. function initializeDatabase(opts) {
  110.     // open the global database connection used by all child windows
  111.     
  112.     if (window.db)
  113.         return;
  114.  
  115.     try {
  116.         window.db = window.openDatabase('digsbysocial_2_' + opts.username, "1.0", "Digsby Social Feed", 1024 * 5);
  117.     } catch (err) {
  118.         try { printException(err); } catch (_e) {}
  119.         return signalCorruptedDatabase();
  120.     }
  121.  
  122.     if (!window.db) {
  123.         console.error('failed to open database.')
  124.         return signalCorruptedDatabase();
  125.     }
  126.  
  127.     return true;
  128. }
  129.  
  130. function initialize(opts) {
  131.     if (!initializeDatabase(opts))
  132.         return;
  133.  
  134.     console.log('creating twitter account ' + opts.username);
  135.     var acct = window.account = new TwitterAccount(opts.username, opts.password, opts);
  136.     acct.ownerWindow = window;
  137.  
  138.     acct.addClient(new TwitterHTTPClient(acct));
  139.  
  140.     guard(function() {
  141.         acct.initialize(opts.feeds, opts.accountopts);
  142.     });
  143.  
  144.     // preload skin images
  145.     SmoothOperator.prototype.preload();
  146. }
  147.  
  148. function onLoad() {
  149.     var creds = queryParse(window.location.search);
  150.     if (creds.username && creds.password) {
  151.         window.login.username.value = creds.username;
  152.         window.login.password.value = creds.password;
  153.         initialize(creds.username, creds.password);
  154.     }
  155. }
  156.  
  157. function onChildWindowLoaded(childWindow) {
  158.     twitterPageLoaded(childWindow);
  159. }
  160.  
  161. function onChildWindowUnloaded(childWindow) {
  162.     timelineWindows.remove(childWindow);
  163. }
  164.  
  165. $(onLoad);
  166.  
  167.