From: Michael J. Rubinsky Date: Sat, 3 Jul 2010 00:12:39 +0000 (-0400) Subject: Implement ajax refreshing of the twitter stream. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dc2c41f40942fa286d6eec13fa10adf58d3f92ff;p=horde.git Implement ajax refreshing of the twitter stream. --- diff --git a/horde/js/twitterclient.js b/horde/js/twitterclient.js index 05dece0f2..ce0846aa1 100644 --- a/horde/js/twitterclient.js +++ b/horde/js/twitterclient.js @@ -9,7 +9,6 @@ */ var Horde_Twitter = Class.create({ inReplyTo: '', - page: 1, oldestId: null, newestId: null, @@ -21,12 +20,16 @@ var Horde_Twitter = Class.create({ * opts.content The main content area, where the tweets are placed. * opts.endpoint The url endpoint for horde/servcies/twitter.php * opts.inreplyto + * opts.refreshrate How often to refresh the stream * opts.strings.inreplyto * opts.strings.defaultText * opts.strings.justnow */ initialize: function(opts) { - this.opts = opts; + this.opts = Object.extend({ + refreshrate: 300 + }, opts); + $(this.opts.input).observe('focus', function() {this.clearInput()}.bind(this)); $(this.opts.input).observe('blur', function() { if (!$(this.opts.input).value.length) { @@ -100,7 +103,7 @@ var Horde_Twitter = Class.create({ new Ajax.Request(this.opts.endpoint, { method: 'post', parameters: params, - onComplete: this._getOlderEntriesCallback.bind(this), + onSuccess: this._getOlderEntriesCallback.bind(this), onFailure: function() { $(this.opts.spinner).toggle(); } @@ -121,7 +124,7 @@ var Horde_Twitter = Class.create({ new Ajax.Request(this.opts.endpoint, { method: 'post', parameters: params, - onComplete: this._getNewEntriesCallback.bind(this), + onSuccess: this._getNewEntriesCallback.bind(this), onFailure: function() { $(this.opts.spinner).toggle(); } @@ -162,6 +165,8 @@ var Horde_Twitter = Class.create({ if (!this.oldestId) { this.oldestId = response.responseJSON.o; } + + new PeriodicalExecuter(function(pe) { this.getNewEntries(); pe.stop(); }.bind(this), this.opts.refreshrate ); }, /** diff --git a/horde/lib/Block/twitter_timeline.php b/horde/lib/Block/twitter_timeline.php index 7fbf51348..62de98116 100644 --- a/horde/lib/Block/twitter_timeline.php +++ b/horde/lib/Block/twitter_timeline.php @@ -26,12 +26,11 @@ if (!empty($GLOBALS['conf']['twitter']['enabled'])) { class Horde_Block_Horde_twitter_timeline extends Horde_Block { /** - * Whether this block has changing content. We dissallow autoupdating for - * sites not using OAuth since the per-hour limits are then based on IP - * address. + * Whether this block has changing content. Set this to false since we + * handle the updates via AJAX on our own. * */ - var $updateable = true; + var $updateable = false; /** * @@ -89,7 +88,11 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block 'height' => array( 'name' => _("Height of map (width automatically adjusts to block)"), 'type' => 'int', - 'default' => 250) + 'default' => 250), + 'refresh_rate' => array( + 'name' => _("Number of seconds to wait to refresh"), + 'type' => 'int', + 'default' => 300) ); } @@ -135,6 +138,7 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block $inReplyToText = _("In reply to:"); $contentNode = 'twitter_body' . $instance; $justNowText = _("Just now..."); + $refresh = empty($this->_params['refresh_rate']) ? 300 : $this->_params['refresh_rate']; /* Add the client javascript / initialize it */ Horde::addScriptFile('twitterclient.js'); @@ -146,6 +150,7 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block content: 'twitter_body{$instance}', endpoint: '{$endpoint}', inreplyto: '{$inReplyToNode}', + refreshrate: {$refresh}, strings: { inreplyto: '{$inReplyToText}', defaultText: '{$defaultText}', justnow: '{$justNowText}' } }); EOT;