Finished pagination code (was incomplete in previous revision) and added a few hacks for an upcoming theme
authorDan
Fri, 10 Aug 2007 15:57:22 -0400
changeset 86 c162ca39db8f
parent 85 7c68a18a27be
child 87 570f68c3fe36
Finished pagination code (was incomplete in previous revision) and added a few hacks for an upcoming theme
includes/clientside/static/comments.js
includes/clientside/static/enano-lib-basic.js
includes/clientside/static/paginate.js
includes/clientside/static/toolbar.js
includes/comment.php
includes/functions.php
includes/template.php
index.php
themes/admin/js/menu.js
--- a/includes/clientside/static/comments.js	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/clientside/static/comments.js	Fri Aug 10 15:57:22 2007 -0400
@@ -34,7 +34,7 @@
       switch(response.mode)
       {
         case 'fetch':
-          document.getElementById('ajaxEditContainer').innerHTML = 'Rendering response...';
+          document.getElementById('ajaxEditContainer').innerHTML = '<div class="wait-box">Rendering '+response.count_total+' comments...</div>';
           if(response.template)
             comment_template = response.template;
           setAjaxLoading();
@@ -53,7 +53,7 @@
           materializeComment(response);
           break;
         case 'error':
-          alert(response.error);
+          new messagebox(MB_OK|MB_ICONSTOP, ( response.title ? response.title : 'Error fetching comment data' ), response.error);
           break;
         default:
           alert(ajax.responseText);
@@ -183,12 +183,12 @@
   if ( this_comment.user_level >= data.user_level.member ) tplvars.USER_LEVEL = 'Member';
   if ( this_comment.user_level >= data.user_level.mod ) tplvars.USER_LEVEL = 'Moderator';
   if ( this_comment.user_level >= data.user_level.admin ) tplvars.USER_LEVEL = 'Administrator';
-  
+                              
   // Send PM link
-  tplvars.SEND_PM_LINK=(this_comment.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( this_comment.name.replace(/ /g, '_') )) +'">Send private message</a><br />':'';
+  tplvars.SEND_PM_LINK=(this_comment.user_id>1 && data.logged_in)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( this_comment.name.replace(/ /g, '_') )) +'">Send private message</a><br />':'';
   
   // Add buddy link
-  tplvars.ADD_BUDDY_LINK=(this_comment.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( this_comment.name.replace(/ /g, '_') )) +'">Add to buddy list</a><br />':'';
+  tplvars.ADD_BUDDY_LINK=(this_comment.user_id>1 && data.logged_in)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( this_comment.name.replace(/ /g, '_') )) +'">Add to buddy list</a><br />':'';
   
   // Edit link
   tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">edit</a>';
--- a/includes/clientside/static/enano-lib-basic.js	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/clientside/static/enano-lib-basic.js	Fri Aug 10 15:57:22 2007 -0400
@@ -9,7 +9,7 @@
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
  *
- * For more information about Enano, please visit http://www.enanocms.org/.
+ * For more information about Enano, please visit http://enanocms.org/.
  * All of the code in these script files may be used freely so long as the above license block is displayed and your
  * modified code is distributed under the GPL. See the page Special:About_Enano on this website for more information.
  */
--- a/includes/clientside/static/paginate.js	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/clientside/static/paginate.js	Fri Aug 10 15:57:22 2007 -0400
@@ -60,19 +60,25 @@
   pagin_objects[this.random_id] = this;
 }
 
+/**
+ * Yet another demonstration of the fact that with the right tools, any amount of Javascript can be ported from PHP.
+ * @access private
+ */
+
 function _build_paginator(this_page)
 {
-  var begin = '<div class="tblholder" style="display: table; margin: 10px 0 0 auto;"><table border="0" cellspacing="1" cellpadding="4"><tr><th>Page:</th>';
-  var block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+  var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 0 auto;';
+  var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>Page:</th>';
+  var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
   var end = '</tr></table></div>';
   var blk = new templateParser(block);
   var inner = '';
   var cls = 'row2';
   
-  if ( this.offset > 0 )
+  if ( this_page > 0 )
   {
-    var url = '#';
-    var link = "<a href=\""+url+"\" style='text-decoration: none;'>&laquo; Prev</a>";
+    var url = '#page_'+(this_page);
+    var link = "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this_page-1)+"); return false;\" style='text-decoration: none;'>&laquo; Prev</a>";
     cls = ( cls == 'row1' ) ? 'row2' : 'row1';
     blk.assign_vars({
         CLASS: cls,
@@ -85,8 +91,8 @@
     for ( var i = 0; i < this.num_pages; i++ )
     {
       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
-      var url = '#';
       var j = i + 1;
+      var url = '#page_'+j;
       var link = ( i == this_page ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+i+"); return false;\" style='text-decoration: none;'>"+j+"</a>";
       blk.assign_vars({
           CLASS: cls,
@@ -100,10 +106,10 @@
     if ( this_page + 5 > this.num_pages )
     {
       var list = new Array();
-      var tp = this_page;
-      if ( this_page + 0 == this.num_pages ) tp = tp - 3;
-      if ( this_page + 1 == this.num_pages ) tp = tp - 2;
-      if ( this_page + 2 == this.num_pages ) tp = tp - 1;
+      var tp = this_page;                    // The vectors below used to be 3, 2, and 1
+      if ( this_page + 0 == this.num_pages ) tp = tp - 2;
+      if ( this_page + 1 == this.num_pages ) tp = tp - 1;
+      if ( this_page + 2 == this.num_pages ) tp = tp - 0;
       for ( var i = tp - 1; i <= tp + 1; i++ )
       {
         list.push(i);
@@ -119,8 +125,8 @@
         list.push(lower + i);
       }
     }
-    var url = '#';
-    var link = ( 0 == this.offset ) ? "<b>First</b>" : "<a href=\""+url+"\" style='text-decoration: none;'>&laquo; First</a>";
+    var url = '#page_1';
+    var link = ( 0 == this_page ) ? "<b>First</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', 0); return false;\" style='text-decoration: none;'>&laquo; First</a>";
     blk.assign_vars({
         CLASS: cls,
         LINK: link
@@ -140,10 +146,9 @@
       if ( i == this.num_pages )
         break;
       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
-      var offset = i * this_page;
-      var url = '#';
       var j = i + 1;
-      var link = ( offset == this.offset ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" style='text-decoration: none;'>"+j+"</a>";
+      var url = '#page_'+j;
+      var link = ( i == this_page ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+i+"); return false;\" style='text-decoration: none;'>"+j+"</a>";
       blk.assign_vars({
           CLASS: cls,
           LINK: link
@@ -151,8 +156,6 @@
       inner += blk.run();
     }
 
-    var total = num_pages * perpage - perpage;
-
     if ( this_page < this.num_pages )
     {
       // $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
@@ -160,9 +163,8 @@
       // $inner .= $blk->run();
 
       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
-      var url = '#';
-      var j = i + 1;
-      var link = ( total == this.offset ) ? "<b>Last</b>" : "<a href=\""+url+"\" style='text-decoration: none;'>Last &raquo;</a>";
+      var url = '#page_' + String( this.num_pages-1 );
+      var link = ( ( this.num_pages - 1 ) == this_page ) ? "<b>Last</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this.num_pages-1)+"); return false;\" style='text-decoration: none;'>Last &raquo;</a>";
       blk.assign_vars({
           CLASS: cls,
           LINK: link
@@ -172,10 +174,10 @@
 
   }
 
-  if ( this.offset < total )
+  if ( this_page < ( this.num_pages - 1 ) )
   {
-    var url = '#page_' + abs(this.offset + this.perpage);
-    var link = "<a href=\""+url+"\" style='text-decoration: none;'>Next &raquo;</a>";
+    var url = '#page_' + String(this_page + 2);
+    var link = "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this_page+1)+"); return false;\" style='text-decoration: none;'>Next &raquo;</a>";
     cls = ( cls == 'row1' ) ? 'row2' : 'row1';
     blk.assign_vars({
           CLASS: cls,
@@ -194,13 +196,63 @@
 function jspaginator_goto(pagin_id, jump_to)
 {
   var theobj = pagin_objects[pagin_id];
+  var current_div = false;
+  var new_div = false;
   for ( var i = 0; i < theobj.num_pages; i++ )
   {
-    var display = ( i == jump_to ) ? 'block' : 'none';
     var thediv = document.getElementById(pagin_id + '_' + i);
-    if ( thediv )
-      thediv.style.display = display;
+    if ( !thediv )
+    {
+      // if ( window.console )
+        // window.console.error('jspaginator_goto(): got a bad DOM object in loop');
+      return false;
+    }
+    // window.console.debug("Div "+i+' of '+(theobj.num_pages-1)+': ', thediv);
+    if ( thediv.style.display != 'none' )
+      current_div = thediv;
+    else if ( i == jump_to )
+      new_div = thediv;
+  }
+  
+  if ( !new_div )
+  {
+    // if ( window.console )
+      // window.console.error('jspaginator_goto(): didn\'t get new div');
+    return false;
+  }
+  if ( !current_div )
+  {
+    // if ( window.console )
+      // window.console.error('jspaginator_goto(): didn\'t get current div');
+    return false;
   }
+  
+  // window.console.debug(current_div);
+  // window.console.debug(new_div);
+  
+  // White-out the old div and fade in the new one
+  
+  if ( IE || is_Safari )
+  {
+    current_div.style.display = 'none';
+    new_div.style.display = 'block';
+  }
+  else
+  {
+    var fade_time = 375;
+    var code = 'var old = \'' + current_div.id + '\';';
+    code    += 'var newer = \'' + new_div.id + '\';';
+    code    += 'document.getElementById(old).style.display = "none";';
+    code    += 'changeOpac(0, newer);';
+    code    += 'document.getElementById(newer).style.display = "block";';
+    code    += 'opacity(newer, 0, 100, '+fade_time+');';
+    // if ( window.console )
+      // window.console.debug('metacode for fader: ', code);
+    opacity(current_div.id, 100, 0, fade_time);
+    setTimeout(code, (fade_time + 50));
+  }
+  
+  
   var pg_control = theobj._build_control(jump_to);
   var divs = getElementsByClassName(document, 'div', pagin_id + '_control');
   for ( var i = 0; i < divs.length; i++ )
--- a/includes/clientside/static/toolbar.js	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/clientside/static/toolbar.js	Fri Aug 10 15:57:22 2007 -0400
@@ -40,7 +40,10 @@
 {
   if ( !document.getElementById('pagebar_main') )
     return false;
-  if(typeof(document.getElementById('mdgToolbar_'+which)) == 'object')
+  var dom = document.getElementById('mdgToolbar_'+which);
+  if ( !dom )
+    return false;
+  if(typeof(dom) == 'object')
   {
     unselectAllButtonsMajor();
     document.getElementById('mdgToolbar_'+which).className = 'selected';
--- a/includes/comment.php	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/comment.php	Fri Aug 10 15:57:22 2007 -0400
@@ -85,7 +85,15 @@
     $data = decode_unicode_array($data);
     if ( !isset($data['mode']) )
     {
-      return $parser->encode(Array('mode'=>'error','error'=>'No mode defined!'));
+      $ret = Array('mode'=>'error','error'=>'No mode defined!');
+      echo $parser->encode($ret);
+      return $ret;
+    }
+    if ( getConfig('enable_comments') == '0' )
+    {
+      $ret = Array('mode'=>'error','error'=>'Comments are not enabled on this site.');
+      echo $parser->encode($ret);
+      return $ret;
     }
     $ret = Array();
     $ret['mode'] = $data['mode'];
--- a/includes/functions.php	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/functions.php	Fri Aug 10 15:57:22 2007 -0400
@@ -731,7 +731,7 @@
   
   if ( $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   {
-    echo '<div class="mdg-comment" style="margin: 10px 0 0 0;">';
+    echo '<div class="mdg-comment" style="margin: 10px 0 0 0;" id="category_box_wrapper">';
     echo '<div style="float: right;">';
     echo '(<a href="#" onclick="ajaxCatToTag(); return false;">show page tags</a>)';
     echo '</div>';
--- a/includes/template.php	Thu Aug 09 12:26:16 2007 -0400
+++ b/includes/template.php	Fri Aug 10 15:57:22 2007 -0400
@@ -165,8 +165,8 @@
         <script language="JavaScript">
         function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
         {
-           var arVersion = navigator.appVersion.split("MSIE")
-           var version = parseFloat(arVersion[1])
+           var arVersion = navigator.appVersion.split("MSIE");
+           var version = parseFloat(arVersion[1]);
            if (version >= 5.5 && typeof(document.body.filters) == "object")
            {
               for(var i=0; i<document.images.length; i++)
@@ -748,7 +748,7 @@
       'STYLE_ID'=>$this->style,
       'JS_DYNAMIC_VARS'=>$js_dynamic,
       'UNREAD_PMS'=>$session->unread_pms,
-      'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', true)
+      'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true)
       );
     
     foreach ( $paths->nslist as $ns_id => $ns_prefix )
--- a/index.php	Thu Aug 09 12:26:16 2007 -0400
+++ b/index.php	Fri Aug 10 15:57:22 2007 -0400
@@ -15,7 +15,7 @@
 
   // Set up gzip encoding before any output is sent
   
-  $aggressive_optimize_html = true;
+  $aggressive_optimize_html = false;
   
   global $do_gzip;
   $do_gzip = true;
--- a/themes/admin/js/menu.js	Thu Aug 09 12:26:16 2007 -0400
+++ b/themes/admin/js/menu.js	Fri Aug 10 15:57:22 2007 -0400
@@ -1,4 +1,9 @@
+/*
+ * IE doesn't like display: table.
+ */
+
 var TBL_SHOW = ( IE ) ? 'block' : 'table';
+
 function admin_expand()
 {
   var expander = document.getElementById('sidebar-hide');