Added modal dialog support for page editor; added customizability for breadcrumbs (thanks to Manoj for idea)
authorDan
Sun, 02 Mar 2008 22:52:23 -0500
changeset 473 518bc2b214f1
parent 472 bc4b58034f4d
child 474 3d751a6f2b05
Added modal dialog support for page editor; added customizability for breadcrumbs (thanks to Manoj for idea)
includes/clientside/static/editor.js
includes/clientside/static/enano-lib-basic.js
includes/clientside/static/faders.js
includes/functions.php
includes/pageprocess.php
language/english/admin.json
language/english/core.json
plugins/SpecialAdmin.php
--- a/includes/clientside/static/editor.js	Sun Mar 02 19:32:19 2008 -0500
+++ b/includes/clientside/static/editor.js	Sun Mar 02 22:52:23 2008 -0500
@@ -122,10 +122,35 @@
   }
   
   // Destroy existing contents of page container
-  var edcon = document.getElementById('ajaxEditContainer');
-  for ( var i = edcon.childNodes.length - 1; i >= 0; i-- )
+  if ( editor_use_modal_window )
   {
-    edcon.removeChild(edcon.childNodes[i]);
+    darken(true);
+    // Build a div with 80% width, centered, and 10px from the top of the window
+    var edcon = document.createElement('div');
+    edcon.style.position = 'absolute';
+    edcon.style.backgroundColor = '#FFFFFF';
+    edcon.style.padding = '10px';
+    edcon.style.width = '80%';
+    edcon.id = 'ajaxEditContainerModal';
+    
+    // Positioning
+    var top = getScrollOffset() + 10;
+    var left = ( getWidth() / 10 ) - 10; // 10% of window width on either side - 10px for padding = perfect centering effect
+    edcon.style.top = String(top) + 'px';
+    edcon.style.left = String(left) + 'px';
+    var body = document.getElementsByTagName('body')[0];
+    
+    // Set opacity to 0
+    domObjChangeOpac(0, edcon);
+    body.appendChild(edcon);
+  }
+  else
+  {
+    var edcon = document.getElementById('ajaxEditContainer');
+    for ( var i = edcon.childNodes.length - 1; i >= 0; i-- )
+    {
+      edcon.removeChild(edcon.childNodes[i]);
+    }
   }
   
   var content = response.src;
@@ -519,10 +544,30 @@
     }
   }
   
+  // if we're using the modal window, fade it in
+  if ( editor_use_modal_window )
+  {
+    domOpacity(edcon, 0, 100, 500);
+  }
+  
   // Autosave every 5 minutes           (m  *  s  *  ms)
   setInterval('ajaxPerformAutosave();', ( 5 * 60 * 1000 ));
 }
 
+function ajaxEditorDestroyModalWindow()
+{
+  if ( editor_use_modal_window )
+  {
+    var edcon = document.getElementById('ajaxEditContainerModal');
+    var body = document.getElementsByTagName('body')[0];
+    if ( edcon )
+    {
+      body.removeChild(edcon);
+      enlighten(true);
+    }
+  }
+}
+
 function ajaxEditorSave(is_draft)
 {
   if ( !is_draft )
@@ -661,6 +706,7 @@
                   selectButtonMajor('article');
                   unselectAllButtonsMinor();
                   
+                  ajaxEditorDestroyModalWindow();
                   document.getElementById('ajaxEditContainer').innerHTML = '<div class="usermessage">' + $lang.get('editor_msg_saved') + '</div>' + ajax.responseText;
                   opacity('ajaxEditContainer', 0, 100, 1000);
                 }
@@ -766,6 +812,7 @@
   mb.onclick['Yes'] = function()
   {
     setAjaxLoading();
+    ajaxEditorDestroyModalWindow();
     editor_open = false;
     enableUnload();
     setTimeout('ajaxReset();', 750);
--- a/includes/clientside/static/enano-lib-basic.js	Sun Mar 02 19:32:19 2008 -0500
+++ b/includes/clientside/static/enano-lib-basic.js	Sun Mar 02 22:52:23 2008 -0500
@@ -119,6 +119,7 @@
 var startheight = false;
 var do_width    = false;
 var ajax_load_icon = scriptPath + '/images/loading.gif';
+var editor_use_modal_window = false;
 
 // You have an NSIS coder in your midst...
 var MB_OK = 1;
--- a/includes/clientside/static/faders.js	Sun Mar 02 19:32:19 2008 -0500
+++ b/includes/clientside/static/faders.js	Sun Mar 02 22:52:23 2008 -0500
@@ -6,14 +6,14 @@
     nofade = true;
   if(document.getElementById('specialLayer_darkener'))
   {
-    document.getElementById('specialLayer_darkener').style.display = 'block';
     if(nofade)
     {
-      document.getElementById('specialLayer_darkener').style.opacity = '0.7';
-      document.getElementById('specialLayer_darkener').style.filter = 'alpha(opacity=70)';
+      changeOpac(70, 'specialLayer_darkener');
+      document.getElementById('specialLayer_darkener').style.display = 'block';
     }
     else
     {
+      document.getElementById('specialLayer_darkener').style.display = 'block';
       opacity('specialLayer_darkener', 0, 70, 1000);
     }
   } else {
@@ -97,12 +97,21 @@
  */
 
 var mb_current_obj;
+var mb_previously_had_darkener = false;
 
 function messagebox(type, title, message)
 {
   var y = getScrollOffset();
-  if(document.getElementById('messageBox')) return;
-  darken(true);
+  
+  // Prevent multiple instances
+  if ( document.getElementById('messageBox') )
+    return;
+  
+  if ( document.getElementById('specialLayer_darkener') )
+    if ( document.getElementById('specialLayer_darkener').style.display == 'block' )
+      mb_previously_had_darkener = true;
+  if ( !mb_previously_had_darkener )
+    darken(true);
   if ( aclDisableTransitionFX )
   {
     document.getElementById('specialLayer_darkener').style.zIndex = '5';
@@ -291,7 +300,8 @@
       var mbdiv = document.getElementById('messageBox');
       mbdiv.parentNode.removeChild(mbdiv.nextSibling);
       mbdiv.parentNode.removeChild(mbdiv);
-      enlighten(true);
+      if ( !mb_previously_had_darkener )
+        enlighten(true);
     };
   
   //domObjChangeOpac(0, mydiv);
@@ -339,12 +349,13 @@
     var mbdiv = document.getElementById('messageBox');
     mbdiv.parentNode.removeChild(mbdiv.nextSibling);
     mbdiv.parentNode.removeChild(mbdiv);
-    enlighten(true);
+    if ( !mb_previously_had_darkener )
+      enlighten(true);
   }
   else
   {
     var to = fly_out_top(maindiv, true, false);
-    setTimeout("var mbdiv = document.getElementById('messageBox'); mbdiv.parentNode.removeChild(mbdiv.nextSibling); mbdiv.parentNode.removeChild(mbdiv); enlighten(true);", to);
+    setTimeout("var mbdiv = document.getElementById('messageBox'); mbdiv.parentNode.removeChild(mbdiv.nextSibling); mbdiv.parentNode.removeChild(mbdiv); if ( !mb_previously_had_darkener ) enlighten(true);", to);
   }
   if(typeof mb.onclick[val] == 'function')
   {
--- a/includes/functions.php	Sun Mar 02 19:32:19 2008 -0500
+++ b/includes/functions.php	Sun Mar 02 22:52:23 2008 -0500
@@ -293,7 +293,7 @@
   $idata = RenderMan::strToPageID($page_id);
   $page_id_key = $paths->nslist[ $idata[1] ] . $idata[0];
   $page_id_key = sanitize_page_id($page_id_key);
-  $page_data = $paths->pages[$page_id_key];
+  $page_data = @$paths->pages[$page_id_key];
   $title = ( isset($page_data['name']) ) ?
     ( ( $page_data['namespace'] == 'Article' || !$show_ns ) ?
       '' :
--- a/includes/pageprocess.php	Sun Mar 02 19:32:19 2008 -0500
+++ b/includes/pageprocess.php	Sun Mar 02 22:52:23 2008 -0500
@@ -1694,20 +1694,51 @@
   function do_breadcrumbs()
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $lang;
+    
     if ( strpos($this->text_cache, '__NOBREADCRUMBS__') !== false )
       return false;
+    
+    $mode = getConfig('breadcrumb_mode');
+    
+    if ( $mode == 'never' )
+      // Breadcrumbs are disabled
+      return true;
+      
+    // Minimum depth for breadcrumb display
+    $threshold = ( $mode == 'always' ) ? 0 : 1;
+    
     $breadcrumb_data = explode('/', $this->page_id);
-    if ( count($breadcrumb_data) > 1 )
+    if ( count($breadcrumb_data) > $threshold )
     {
+      // If we're not on a subpage of the main page, add "Home" to the list
+      $show_home = false;
+      if ( $mode == 'always' )
+      {
+        $show_home = true;
+      }
       echo '<!-- Start breadcrumbs -->
             <div class="breadcrumbs">
               ';
+      if ( $show_home )
+      {
+        if ( count($breadcrumb_data) > 1 )
+        {
+          echo '<a href="' . makeUrl(getConfig('main_page'), false, true) . '">' . $lang->get('onpage_btn_breadcrumbs_home') . '</a> &raquo;';
+        }
+        else
+        {
+          echo $lang->get('onpage_btn_breadcrumbs_home');
+        }
+      }
       foreach ( $breadcrumb_data as $i => $higherpage )
       {
         $higherpage = $paths->nslist[$this->namespace] . sanitize_page_id(implode('/', array_slice($breadcrumb_data, 0, ($i+1))));
+        if ( $higherpage === getConfig('main_page') )
+          continue;
         if ( ($i + 1) == count($breadcrumb_data) )
         {
-          $title = get_page_title($higherpage, false);
+          $title = ( $higherpage === getConfig('main_page') ) ? $lang->get('onpage_btn_breadcrumbs_home') : get_page_title($higherpage, false);
           if ( !$this->page_exists )
           {
             $title = explode('/', $title);
--- a/language/english/admin.json	Sun Mar 02 19:32:19 2008 -0500
+++ b/language/english/admin.json	Sun Mar 02 22:52:23 2008 -0500
@@ -215,6 +215,12 @@
       heading_default_theme: 'Visual defaults',
       field_defualt_theme: 'Default theme for guests and new users:',
       
+      // Section: breadcrumbs
+      field_breadcrumb_mode: 'Enable breadcrumbs:',
+      field_breadcrumb_mode_subpages: 'Only with a slash in the URL (default)',
+      field_breadcrumb_mode_always: 'Always',
+      field_breadcrumb_mode_never: 'Never',
+      
       // Main section: users and communication
       heading_users: 'Users and communication',
       
--- a/language/english/core.json	Sun Mar 02 19:32:19 2008 -0500
+++ b/language/english/core.json	Sun Mar 02 22:52:23 2008 -0500
@@ -236,6 +236,7 @@
       btn_viewsource: 'view source',
       btn_history: 'history',
       btn_moreoptions: 'more options',
+      btn_breadcrumbs_home: 'Home',
       
       btn_rename: 'rename',
       btn_printable: 'view printable version',
--- a/plugins/SpecialAdmin.php	Sun Mar 02 19:32:19 2008 -0500
+++ b/plugins/SpecialAdmin.php	Sun Mar 02 22:52:23 2008 -0500
@@ -279,6 +279,12 @@
     $default_theme = ( isset($template->named_theme_list[@$_POST['default_theme']]) ) ? $_POST['default_theme'] : $template->theme_list[0]['theme_id'];
     setConfig('theme_default', $default_theme);
     
+    // Breadcrumb mode
+    if ( in_array($_POST['breadcrumb_mode'], array('subpages', 'always', 'never')) )
+    {
+      setConfig('breadcrumb_mode', $_POST['breadcrumb_mode']);
+    }
+    
     setConfig('register_tou', RenderMan::preprocess_text($_POST['register_tou'], true, false));
     
     // Account lockout policy
@@ -521,6 +527,26 @@
         </td>
       </tr>
       
+    <!-- Breadcrumbs -->
+    
+      <tr>
+        <td class="row1">
+          <?php echo $lang->get('acpgc_field_breadcrumb_mode'); ?>
+        </td>
+        <td class="row1">
+          <select name="breadcrumb_mode">
+          <?php
+            foreach ( array('subpages', 'always', 'never') as $mode )
+            {
+              $str = $lang->get("acpgc_field_breadcrumb_mode_$mode");
+              $sel = ( getConfig('breadcrumb_mode') == $mode ) ? ' selected="selected"' : '';
+              echo "  <option value=\"$mode\"$sel>$str</option>\n          ";
+            }
+          ?>
+          </select>
+        </td>
+      </tr>
+      
     </table>
     </div>