less obtrusive observing, allow more then one twitter block on a page
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 14 Aug 2010 19:09:43 +0000 (15:09 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 14 Aug 2010 19:09:43 +0000 (15:09 -0400)
horde/js/twitterclient.js
horde/lib/Block/twitter_timeline.php

index 2829c84..2640ed2 100644 (file)
@@ -25,6 +25,7 @@ var Horde_Twitter = Class.create({
     * opts.strings.inreplyto
     * opts.strings.defaultText
     * opts.strings.justnow
+    * opts.getmore
     */
     initialize: function(opts) {
         this.opts = Object.extend({
@@ -42,6 +43,11 @@ var Horde_Twitter = Class.create({
             $(this.opts.counter).update(140 - $F(this.opts.input).length);
         }.bind(this));
 
+        $(this.opts.getmore).observe('click', function(e) {
+            this.getOlderEntries();
+            e.stop();
+        }.bind(this));
+
         /* Get the first page */
         this.getNewEntries();
    },
index 90e23b2..52251c4 100644 (file)
@@ -142,7 +142,8 @@ class Horde_Block_Horde_twitter_timeline extends Horde_Block
         Horde::addScriptFile('twitterclient.js');
         $script = <<<EOT
             var Horde = window.Horde || {};
-            Horde.twitter = new Horde_Twitter({
+            Horde.twitter{$instance} = new Horde_Twitter({
+               getmore: 'getmore{$instance}',
                input: '{$instance}_newStatus',
                spinner: '{$instance}_loading',
                content: 'twitter_body{$instance}',
@@ -161,13 +162,13 @@ EOT;
         /* Build the UI */
         $html = '<div style="padding: 0 8px 8px">'
            . '<div class="fbgreybox"><textarea rows="2" style="width:98%;margin-top:4px;margin-bottom:4px;" type="text" id="' . $instance . '_newStatus" name="' . $instance . '_newStatus">' . $defaultText . '</textarea>'
-           . '<a class="button" onclick="Horde.twitter.updateStatus($F(\'' . $instance . '_newStatus\'));" href="#">' . _("Tweet") . '</a><span id="' . $instance . '_counter" style="color: rgb(204, 204, 204);margin-left:6px;">140</span>  <span id="' . $instance . '_inReplyTo"></span>'
+           . '<a class="button" onclick="Horde.twitter' . $instance . '.updateStatus($F(\'' . $instance . '_newStatus\'));" href="#">' . _("Tweet") . '</a><span id="' . $instance . '_counter" style="color: rgb(204, 204, 204);margin-left:6px;">140</span>  <span id="' . $instance . '_inReplyTo"></span>'
            . Horde::img('loading.gif', '', array('id' => $instance . '_loading', 'style' => 'display:none;'));
         $html .= '<div id="currentStatus" class="" style="margin: 10px;"><strong>' . _("Latest") . '</strong> ' . $latestStatus . ' - <span class="fbstreaminfo">' . Horde_Date_Utils::relativeDateTime(strtotime($this->_profile->status->created_at), $GLOBALS['prefs']->getValue('date_format'), ($GLOBALS['prefs']->getValue('twentyFour') ? "%H:%M" : "%I:%M %P")) . '</span></div></div>';
         $html .= '<div style="height:' . (empty($this->_params['height']) ? 350 : $this->_params['height']) . 'px;overflow-y:auto;" id="twitter_body' . $instance . '">';
         $filter = $GLOBALS['injector']->getInstance('Horde_Text_Filter')->getFilter('Text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
         $html .= '</div>';
-        $html .= '<div class="fbgetmore"><input type="button" class="button" onclick="Horde.twitter.getOlderEntries();return false;" value="' . _("Get More") . '"></div>';
+        $html .= '<div class="fbgetmore"><input type="button" class="button" id="getmore' . $instance . '"  value="' . _("Get More") . '"></div>';
         $html .= '</div>';
 
         return $html;