Fixed bug #7307: Move 'Open Documents' to Header in the BE
authorIngo Renner <ingo.renner@typo3.org>
Tue, 18 Mar 2008 13:37:34 +0000 (13:37 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Tue, 18 Mar 2008 13:37:34 +0000 (13:37 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3457 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/opendocs/class.tx_opendocs.php
typo3/sysext/opendocs/ext_tables.php
typo3/sysext/opendocs/locallang_opendocs.xml
typo3/sysext/opendocs/opendocs.css
typo3/sysext/opendocs/opendocs.js
typo3/sysext/opendocs/opendocs.png
typo3/sysext/opendocs/toolbar_item_active_bg.png [new file with mode: 0644]

index 74995cc..8c5616a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-03-18  Ingo Renner  <ingo@typo3.org>
+
+       * Fixed bug #7307: Move 'Open Documents' to Header in the BE
+
 2008-03-17  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Fixed bug #7886: JS error raised in htmlArea RTE in IE5.5 when setting inline markup or text style
index 7f009af..6b610ed 100644 (file)
@@ -34,7 +34,8 @@ require_once(PATH_typo3.'interfaces/interface.backend_toolbaritem.php');
 /**
  * Adding a list of all open documents of a user to the backend.php
  *
- * @author     Benjamin Mack <mack@xnos.org>
+ * @author     Benjamin Mack <benni@typo3.org>
+ * @author     Ingo Renner <ingo@typo3.org>
  * @package    TYPO3
  * @subpackage opendocs
  */
@@ -46,6 +47,7 @@ class tx_opendocs implements backend_toolbarItem {
         * @var TYPO3backend
         */
        private $backendReference;
+
        private $openDocs;
        private $recentDocs;
        private $EXTKEY = 'opendocs';
@@ -61,7 +63,6 @@ class tx_opendocs implements backend_toolbarItem {
                $this->loadDocsFromUserSession();
        }
 
-
        /**
         * checks whether the user has access to this toolbar item
         *
@@ -72,82 +73,130 @@ class tx_opendocs implements backend_toolbarItem {
                return ($conf['value'] == 1 ? false : true);
        }
 
-
        /**
-        * loads the opened and recently opened documents from the user 
+        * loads the opened and recently opened documents from the user
         *
         * @return  void
         */
        public function loadDocsFromUserSession() {
-               list($this->openDocs,)  = $GLOBALS['BE_USER']->getModuleData('alt_doc.php','ses');
+               list($this->openDocs,)  = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
                $this->recentDocs       = $GLOBALS['BE_USER']->getModuleData('opendocs::recent');
        }
 
-
        /**
-        * renders the toolbar item and the empty menu
+        * renders the toolbar item and the initial menu
         *
-        * @return      void
+        * @return      string          the toolbar item including the initial menu content as HTML
         */
        public function render() {
                $this->addJavascriptToBackend();
                $this->addCssToBackend();
-               $numDocs = count($this->openDocs);
+               $numDocs      = count($this->openDocs);
+               $opendocsMenu = array();
+
+                       // toolbar item icon
+               $opendocsMenu[] = '<a href="#" class="toolbar-item">';
+               $opendocsMenu[] = '<input type="text" id="tx-opendocs-counter" disabled="disabled" value="'.$numDocs.'" />';
+               $opendocsMenu[] = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.png', 'width="23" height="16"').'  alt="Open Documents" title="Open Documents" /></a>';
 
-                       // return the toolbar item and an empty UL
-               $output  = '<a href="#" class="toolbar-item">';
-               $output .= '<span id="tx-opendocs-num">'.($numDocs > 0 ? $numDocs : '').'</span>';
-               $output .= '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.png', 'width="23" height="14"').' title="'.$GLOBALS['LANG']->getLL('toolbaritem',1).'" alt="" />';
-               $output .= '</a>';
-               $output .= '<div class="toolbar-item-menu" style="display: none;"></div>';
+                       // toolbar item menu and initial content
+               $opendocsMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
+               $opendocsMenu[] = $this->renderMenu();
+               $opendocsMenu[] = '</div>';
 
-               return $output;
+               return implode("\n", $opendocsMenu);
        }
 
+       /**
+        * renders the pure contents of the menu
+        *
+        * @return      string          the menu's content
+        */
+       public function renderMenu() {
+               $openDocuments   = $this->openDocs;
+               $recentDocuments = $this->recentDocs;
+               $entries         = array();
+               $content         = '';
+
+               if(count($openDocuments)) {
+                       $entries[] = '<tr><th colspan="3">'.$GLOBALS['LANG']->getLL('open_docs', 1).'</th></tr>';
+
+                       $i = 0;
+                       foreach ($openDocuments as $md5sum => $openDocument) {
+                               $i++;
+                               $entries[] = $this->renderMenuEntry($openDocument, $md5sum, false, ($i == 1));
+                       }
+               }
+
+                       // if there are "recent documents" in the list, add them
+               if(count($recentDocuments)) {
+                       $entries[] = '<tr><th colspan="3">'.$GLOBALS['LANG']->getLL('recent_docs', 1).'</th></tr>';
+
+                       $i = 0;
+                       foreach ($recentDocuments as $md5sum => $recentDocument) {
+                               $i++;
+                               $entries[] = $this->renderMenuEntry($recentDocument, $md5sum, true, ($i == 1));
+                       }
+               }
+
+               if(count($entries)) {
+                       $content = '<table class="list" cellspacing="0" cellpadding="0" border="0">'.implode('', $entries).'</table>';
+               } else {
+                       $content = '<div class="no-docs">'.$GLOBALS['LANG']->getLL('no_docs', 1).'</div>';
+               }
+
+               return $content;
+       }
 
        /**
         * returns the recent documents list as an array
         *
         * @return      array   all recent documents as list-items
         */
-       public function renderMenuEntry($itm, $md5sum, $isRecentDoc = false) {
-               $table = $itm[3]['table'];
-               $uid   = $itm[3]['uid'];
-               $rec   = t3lib_BEfunc::getRecordWSOL($table, $uid);
-               $label = htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($itm[0])));
-               $icon  = '<img src="'.t3lib_iconWorks::getIcon($table, $rec).'" alt="'.$label.'" />';
-               $link  = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$itm[2];
-
-               if ($isRecentDoc) {
+       public function renderMenuEntry($document, $md5sum, $isRecentDoc = false, $isFirstDoc = false) {
+               $table  = $document[3]['table'];
+               $uid    = $document[3]['uid'];
+               $record = t3lib_BEfunc::getRecordWSOL($table, $uid);
+               $label  = htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($document[0])));
+               $icon   = t3lib_iconWorks::getIconImage($table, $record, $GLOBALS['BACK_PATH']);
+               $link   = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$document[2];
+
+               $firstRow = '';
+               if($isFirstDoc) {
+                       $firstRow = ' first-row';
+               }
+
+               if (!$isRecentDoc) {
+                               // open document
+                       $closeIcon = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/closedok.gif', 'width="16" height="16"').' title="'.$GLOBALS['LANG']->getLL('rm.closeDoc', 1).'" alt="" />';
+
                        $entry = '
-                               <tr id="opendocs-'.$table.'-'.$uid.'" class="recentdoc">
-                                       <td class="opendocs-icon">'.$icon.'</td>
-                                       <td class="opendocs-label" colspan="2" id="opendocs-label-'.$table.'-'.$uid.'"><a href="'.$link.'" target="content" onclick="TYPO3BackendOpenDocs.hideMenu();">'.$label.'</a></td>
+                               <tr id="opendocs-'.$table.'-'.$uid.'" class="opendoc'.$firstRow.'">
+                                       <td class="icon">'.$icon.'</td>
+                                       <td class="label"><a href="'.$link.'" target="content" onclick="TYPO3BackendOpenDocs.toggleMenu();">'.$label.'</a></td>
+                                       <td class="close" onclick="return TYPO3BackendOpenDocs.closeDocument(\''.$md5sum.'\');">'.$closeIcon.'</td>
                                </tr>';
                } else {
-                       $closeIcon = '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/closedok.gif', 'width="16" height="16"').' title="Close Document" alt="" />';
+                               // recently used document
                        $entry = '
-                               <tr id="opendocs-'.$table.'-'.$uid.'" class="opendoc">
-                                       <td class="opendocs-icon">'.$icon.'</td>
-                                       <td class="opendocs-label" id="opendocs-label-'.$table.'-'.$uid.'"><a href="'.$link.'" target="content" onclick="TYPO3BackendOpenDocs.hideMenu();">'.$label.'</a></td>
-                                       <td class="opendocs-close" onclick="return TYPO3BackendOpenDocs.closeDocument(\''.$md5sum.'\');">'.$closeIcon.'</td>
+                               <tr id="opendocs-'.$table.'-'.$uid.'" class="recentdoc'.$firstRow.'">
+                                       <td class="icon">'.$icon.'</td>
+                                       <td class="label" colspan="2"><a href="'.$link.'" target="content" onclick="TYPO3BackendOpenDocs.toggleMenu();">'.$label.'</a></td>
                                </tr>';
                }
+
                return $entry;
        }
 
-
-
        /**
         * returns additional attributes for the list item in the toolbar
         *
         * @return      string          list item HTML attibutes
         */
        public function getAdditionalAttributes() {
-               return ' id="open-documents-menu"';
+               return ' id="tx-opendocs-menu"';
        }
 
-
        /**
         * adds the neccessary javascript to the backend
         *
@@ -157,7 +206,6 @@ class tx_opendocs implements backend_toolbarItem {
                $this->backendReference->addJavascriptFile(t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.js');
        }
 
-
        /**
         * adds the neccessary CSS to the backend
         *
@@ -176,86 +224,67 @@ class tx_opendocs implements backend_toolbarItem {
         * called as a hook in t3lib_BEfunc::setUpdateSignal, calls a JS function to change
         * the number of opened documents
         *
+        * @param       array           $params
+        * @param       unknown_type            $ref
         * @return      string          list item HTML attibutes
         */
        public function updateNumberOfOpenDocsHook(&$params, &$ref) {
                $params['JScode'] = '
                        if (top && top.TYPO3BackendOpenDocs) {
-                               top.TYPO3BackendOpenDocs.updateNumberOfDocs('.count($this->openDocs).', false);
+                               top.TYPO3BackendOpenDocs.updateNumberOfDocs('.count($this->openDocs).', true);
                        }
                ';
        }
 
 
-
        /******************
         *** AJAX CALLS ***
         ******************/
 
        /**
-        * returns the opened documents list for the AJAX call formatted as HTML list
+        * closes a document in the session and
         *
-        * @param       array           array full of additional params, not used yet
-        * @param       TYPO3AJAX       Ajax request object
+        * @param       array           array of parameters from the AJAX interface, currently unused
+        * @param       TYPO3AJAX       object of type TYPO3AJAX
         * @return      string          list item HTML attibutes
         */
-       public function renderBackendMenuContents($params, &$ajaxObj) {
-               $itms = $this->openDocs;
-               $itmsRecent = $this->recentDocs;
-               $entries = array();
-
-               if (count($itms)) {
-                       $entries[] = '<tr class="menu-item-div"><td colspan="3">'.$GLOBALS['LANG']->getLL('open_docs',1).'</td></tr>';
-                       foreach ($itms as $md5sum => $itm) {
-                               $entries[] = $this->renderMenuEntry($itm, $md5sum);
-                       }
-               }
-
-
-
-                       // if there are "recent documents" in the list, add them
-               if (count($itmsRecent)) {
-                       $entries[] = '<tr class="menu-item-div"><td colspan="3">'.$GLOBALS['LANG']->getLL('recent_docs',1).'</td></tr>';
-                       foreach ($itmsRecent as $md5sum => $itm) {
-                               $entries[] = $this->renderMenuEntry($itm, $md5sum, true);
-                       }
-               }
-
-               if (count($entries)) {
-                       $content = '<table class="opendocs-list">'.implode('', $entries).'</table>';
-                       $ajaxObj->addContent('opendocs', $content);
-               } else {
-                       $ajaxObj->addContent('opendocs', '<div id="opendocs-nodocs">'.$GLOBALS['LANG']->getLL('no_docs',1).'</div>');
-               }
-       }
-
-
-
-       /**
-        * closes a document in the session and 
-        * @param       array           array full of additional params, not used yet
-        * @param       TYPO3AJAX       Ajax request object
-        * @return      string          list item HTML attibutes
-        */
-       public function closeDocument($params, &$ajaxObj) {
+       public function closeDocument($params = array(), TYPO3AJAX &$ajaxObj = null) {
                $md5sum = t3lib_div::_GP('md5sum');
+
                if ($md5sum && isset($this->openDocs[$md5sum])) {
 
-                               // add the closing document to the recent documents
-                       $this->recentDocs = array_merge(array($md5sum => $this->openDocs[$md5sum]), $this->recentDocs);
+                               // add the document to be closed to the recent documents
+                       $this->recentDocs = array_merge(
+                               array($md5sum => $this->openDocs[$md5sum]),
+                               $this->recentDocs
+                       );
+
+                               // allow a maximum of 8 recent documents
                        if (count($this->recentDocs) > 8) {
                                $this->recentDocs = array_slice($this->recentDocs, 0, 8);
                        }
 
-                               // remove it from the list of the open documents
+                               // remove it from the list of the open documents, and store the status
                        unset($this->openDocs[$md5sum]);
-
-                               // store it again
-                       list(,$docDat) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php','ses');
+                       list(, $docDat) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
                        $GLOBALS['BE_USER']->pushModuleData('alt_doc.php', array($this->openDocs, $docDat));
                        $GLOBALS['BE_USER']->pushModuleData('opendocs::recent', $this->recentDocs);
                }
-               $this->renderBackendMenuContents($params, $ajaxObj);
+
+               $this->renderAjax($params, $ajaxObj);
+       }
+
+       /**
+        * renders the menu so that it can be returned as response to an AJAX call
+        *
+        * @param       array           array of parameters from the AJAX interface, currently unused
+        * @param       TYPO3AJAX       object of type TYPO3AJAX
+        * @return      void
+        */
+       public function renderAjax($params = array(), TYPO3AJAX &$ajaxObj = null) {
+               $menuContent = $this->renderMenu();
+
+               $ajaxObj->addContent('opendocsMenu', $menuContent);
        }
 
 }
@@ -263,4 +292,5 @@ class tx_opendocs implements backend_toolbarItem {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['EXT:opendocs/class.tx_opendocs.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['EXT:opendocs/class.tx_opendocs.php']);
 }
-?>
+
+?>
\ No newline at end of file
index 18d12f2..f302260 100644 (file)
@@ -1,26 +1,29 @@
 <?php
+
 if (!defined('TYPO3_MODE'))    die('Access denied.');
 
 
-if (TYPO3_MODE == 'BE') {
+if(TYPO3_MODE == 'BE') {
+
+       $opendocsPath = t3lib_extMgm::extPath('opendocs');
 
-               // register top module
-       $GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'][] = t3lib_extMgm::extPath('opendocs').'registerToolbarItem.php';
+               // register toolbar item
+       $GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'][] = $opendocsPath.'registerToolbarItem.php';
 
 
                // register AJAX calls
-       $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['tx_opendocs::backendMenu']   = t3lib_extMgm::extPath('opendocs').'class.tx_opendocs.php:tx_opendocs->renderBackendMenuContents';
-       $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['tx_opendocs::closeDocument'] = t3lib_extMgm::extPath('opendocs').'class.tx_opendocs.php:tx_opendocs->closeDocument';
+       $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['tx_opendocs::renderMenu']   = $opendocsPath.'class.tx_opendocs.php:tx_opendocs->renderAjax';
+       $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['tx_opendocs::closeDocument'] = $opendocsPath.'class.tx_opendocs.php:tx_opendocs->closeDocument';
 
                // register update signal to update the number of open documents
-       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['updateSignalHook']['tx_opendocs::updateNumber'] = t3lib_extMgm::extPath('opendocs').'class.tx_opendocs.php:tx_opendocs->updateNumberOfOpenDocsHook';
+       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['updateSignalHook']['tx_opendocs::updateNumber'] = $opendocsPath.'class.tx_opendocs.php:tx_opendocs->updateNumberOfOpenDocsHook';
 
 
                // register menu module if option is wanted
        $_EXTCONF = unserialize($_EXTCONF);
-       if ($_EXTCONF['enableModule']) {
-               t3lib_extMgm::addModule('user', 'doc', 'after:ws', t3lib_extMgm::extPath($_EXTKEY).'mod/');
+       if($_EXTCONF['enableModule']) {
+               t3lib_extMgm::addModule('user', 'doc', 'after:ws', $opendocsPath.'mod/');
        }
 }
 
-?>
+?>
\ No newline at end of file
index 4874ffa..fad102d 100755 (executable)
@@ -9,9 +9,9 @@
        </meta>
        <data type="array">
                <languageKey index="default" type="array">
-                       <label index="toolbaritem">Open and Recently Edited Documents</label>
-                       <label index="open_docs">Opened Documents</label>
-                       <label index="recent_docs">Recently Edited Documents</label>
+                       <label index="toolbaritem">Open and Recently Used Documents</label>
+                       <label index="open_docs">Open Documents</label>
+                       <label index="recent_docs">Recently Used Documents</label>
                        <label index="no_docs">There are no open documents at this time.</label>
                </languageKey>
        </data>
index 0797803..e87046a 100644 (file)
@@ -1,53 +1,85 @@
-#open-documents-menu {
-       width: 40px;
+/* - - - - - - - - - - - - - - - - - - - - -
+
+Title  : Open Documents toolbar item menu styles
+Author : Banejamin Mack <benni@typo3.org>
+URL    : http://typo3.org
+
+Description : styles the Open Documents toolbar item
+
+       $Id$
+
+- - - - - - - - - - - - - - - - - - - - - */
+
+#tx-opendocs-menu .toolbar-item {
+       padding-left: 8px;
+       padding-right: 7px;
 }
 
-span#tx-opendocs-num {
-       padding: 0 2px;
-       line-height: 14px;
+#tx-opendocs-menu .toolbar-item-active {
+       background-image: url('toolbar_item_active_bg.png');
 }
 
-#open-documents-menu div {
+#tx-opendocs-counter {
+       width: 14px;
+       text-align: right;
+       border: 1px dashed #999;
+       padding: 1px 2px;
+       position: relative;
+       top: -4px;
+}
+
+#tx-opendocs-menu .toolbar-item-menu {
        position: absolute;
        list-style: none;
-       margin: 0;
-       padding: 2px 0 0;
+       padding: 2px 0px 0px;
+       margin: 0px;
        background-color: #f9f9f9;
        border: 1px solid #abb2bc;
        border-top: none;
+       width: 200px;
 }
 
-#open-documents-menu table,
-#open-documents-menu tr {
+#tx-opendocs-menu .toolbar-item-menu .list {
        width: 100%;
-       border-collapse: collapse;
-       padding: 0;
-       border: 0;
-       margin: 0;
 }
 
-#open-documents-menu td {
+#tx-opendocs-menu .toolbar-item-menu .list th {
+       border-top: 1px solid #a5a5a5;
+       border-bottom: 1px solid #a5a5a5;
+       background-color: #dbdbdb;
+
        text-align: left;
-       vertical-align: top;
-       line-height: 14px;
-       font-size: 11px;
-       margin: 0;
-       padding: 1px 1px 1px 0;
+       font-weight: normal;
+       line-height: 16px;
+       padding-left: 7px;
 }
 
-#open-documents-menu td.opendocs-close {
-       text-align: right;
+#tx-opendocs-menu .toolbar-item-menu .list  td {
+       padding: 2px 1px;
+       line-height: 16px;
+}
+
+#tx-opendocs-menu .toolbar-item-menu .list tr.opendoc.first-row td,
+#tx-opendocs-menu .toolbar-item-menu .list tr.recentdoc.first-row td {
+       background-image: url('../../gfx/shortcutgroups-bg.png');
+       background-repeat: repeat-x;
+       padding-top: 4px;
 }
 
-#open-documents-menu tr.menu-item-div td {
-       border-top: 1px solid #abb2bc;
-       font-weight: bold;
-       padding: 2px 3px;
+#tx-opendocs-menu .toolbar-item-menu .list .opendoc .icon,
+#tx-opendocs-menu .toolbar-item-menu .list .recentdoc .icon {
+       padding-left: 7px;
+       vertical-align: top;
+       width: 16px;
+}
+
+#tx-opendocs-menu .toolbar-item-menu .list .opendoc .close {
+       width: 20px;
+       text-align: center;
+       vertical-align: top;
 }
 
-#open-documents-menu td a {
-       text-decoration: none;
-       padding: 1px;
-       font-size: 11px;
+#tx-opendocs-menu .toolbar-item-menu .list .opendoc .close img {
+       cursor: pointer;
 }
 
index 50687a6..dab4f58 100644 (file)
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
+
 /**
  * class to handle the open documents menu, loads the open documents dynamically
+ *
  */
 var OpenDocs = Class.create({
        ajaxScript: 'ajax.php',
-       ajaxIDloadMenu: 'tx_opendocs::backendMenu',
-       ajaxIDcloseDoc: 'tx_opendocs::closeDocument',
-       menuItem: 'open-documents-menu',
-       menu: null,             // the <div> tag
-       toolbarItem: null,      // the <a> tag
-
+       menu: null,
+       toolbarItemIcon: null,
 
        /**
         * registers for resize event listener and executes on DOM ready
         */
        initialize: function() {
-               Event.observe(window, 'load', function() {
-                       this.ajaxScript = top.TS.PATH_typo3 + this.ajaxScript; // can't be initialized earlier
-                       this.getMenu();
-                       Event.observe(window,          'resize', this.positionMenu.bindAsEventListener(this));
-                       Event.observe(this.toolbarItem, 'click',   this.toggleMenu.bindAsEventListener(this));
-               }.bindAsEventListener(this));
-       },
+               Event.observe(window, 'resize', this.positionMenu);
 
+               Event.observe(window, 'load', function(){
+                       this.positionMenu();
+                       this.toolbarItemIcon = $$('#tx-opendocs-menu .toolbar-item img')[0].src;
+                       this.ajaxScript      = top.TS.PATH_typo3 + this.ajaxScript; // can't be initialized earlier
 
-       getMenu: function() {
-               this.toolbarItem = $(this.menuItem).firstChild;
-               this.menu = this.toolbarItem.nextSibling;
+                       Event.observe($$('#tx-opendocs-menu .toolbar-item')[0], 'click', this.toggleMenu);
+                       this.menu = $$('#tx-opendocs-menu .toolbar-item-menu')[0];
+                       this.toolbarItemIcon = $$('#shortcut-menu .toolbar-item img')[0].src;
+               }.bindAsEventListener(this));
        },
 
-
        /**
-        * positions the menu below the toolbar icon
+        * positions the menu below the toolbar icon, let's do some math!
         */
        positionMenu: function() {
                var calculatedOffset = 0;
-               var ownWidth         = $(this.menu).getWidth();
-               var parentWidth      = $(this.menuItem).getWidth();
-               var parentSiblings   = $(this.menuItem).previousSiblings();
+               var parentWidth      = $('tx-opendocs-menu').getWidth();
+               var ownWidth         = $$('#tx-opendocs-menu .toolbar-item-menu')[0].getWidth();
+               var parentSiblings   = $('tx-opendocs-menu').previousSiblings();
 
                parentSiblings.each(function(toolbarItem) {
-                       calculatedOffset += toolbarItem.getWidth()-1;
+                       calculatedOffset += toolbarItem.getWidth() - 1;
+                       // -1 to compensate for the margin-right -1px of the list items,
+                       // which itself is necessary for overlaying the separator with the active state background
+
+                       if(toolbarItem.down().hasClassName('no-separator')) {
+                               calculatedOffset -= 1;
+                       }
                });
                calculatedOffset = calculatedOffset - ownWidth + parentWidth;
-               this.menu.setStyle({ left: calculatedOffset-2 + 'px' });
-       },
 
 
+               $$('#tx-opendocs-menu .toolbar-item-menu')[0].setStyle({
+                       left: calculatedOffset + 'px'
+               });
+       },
+
        /**
         * toggles the visibility of the menu and places it under the toolbar icon
         */
        toggleMenu: function(event) {
-               Event.stop(event);
-               this.toolbarItem.blur();
-               if(!this.toolbarItem.hasClassName('toolbar-item-active')) {
-                       this.showMenu();
+               var toolbarItem = $$('#tx-opendocs-menu > a')[0];
+               var menu        = $$('#tx-opendocs-menu .toolbar-item-menu')[0];
+               toolbarItem.blur();
+
+               if(!toolbarItem.hasClassName('toolbar-item-active')) {
+                       toolbarItem.addClassName('toolbar-item-active');
+                       Effect.Appear(menu, {duration: 0.2});
+                       TYPO3BackendToolbarManager.hideOthers(toolbarItem);
                } else {
-                       this.hideMenu();
+                       toolbarItem.removeClassName('toolbar-item-active');
+                       Effect.Fade(menu, {duration: 0.1});
                }
-       },
-
-
 
-       /**
-        * displays the menu and does the AJAX call to the TYPO3 backend
-        */
-       showMenu: function() {
-               new Ajax.Updater(this.menu, this.ajaxScript, {
-                       parameters: { ajaxID: this.ajaxIDloadMenu },
-                       onSuccess: function(xhr) {
-                               if (!this.menu.visible()) {
-                                       Effect.Appear(this.menu, {
-                                               duration: 0.2,
-                                               afterFinish: function() { this.positionMenu(); }.bind(this)
-                                       });
-                               }
-                       }.bind(this)
-               });
-               if (!this.toolbarItem.hasClassName('toolbar-item-active')) {
-                       this.toolbarItem.addClassName('toolbar-item-active');
-                       TYPO3BackendToolbarManager.hideOthers(this.toolbarItem);
+               if(event) {
+                       Event.stop(event);
                }
        },
 
-
        /**
-        * hides the menu
+        * displays the menu and does the AJAX call to the TYPO3 backend
         */
-       hideMenu: function() {
-               Effect.Fade(this.menu, {duration: 0.1} );
-               this.toolbarItem.removeClassName('toolbar-item-active');
+       updateMenu: function() {
+               var origToolbarItemIcon = this.toolbarItemIcon.src;
+               this.toolbarItemIcon.src = 'gfx/spinner.gif';
+
+               new Ajax.Updater(
+                       this.menu,
+                       this.ajaxScript, {
+                               parameters: {
+                                       ajaxID: 'tx_opendocs::renderMenu'
+                               },
+                               onComplete: function(xhr) {
+                                       this.toolbarItemIcon.src = origToolbarItemIcon;
+                               }.bind(this)
+                       }
+               );
        },
 
-
        /**
-        * updates the number of open documents in the toolbar
+        * updates the number of open documents in the toolbar according to the
+        * first parameter. If "num" is smaller than "0", the number of opendocs
+        * is counted from the open menu
+        *
+        * @param       integer         number of open documents
+        * @param       boolean         flag to explicitly update the menu
         */
-       updateNumberOfDocs: function(num, doNotUpdateMenu) {
-               if (num < 0) {
-                       num = $$('tr.opendoc').length;
-               }
-               if (num == 0) {
-                       num = '';
+       updateNumberOfDocs: function(num, explicitlyUpdateMenu) {
+               if (explicitlyUpdateMenu) {
+                               // re-render the menu e.g. if a document was closed inside the menu
+                       this.updateMenu();
                }
-               $('tx-opendocs-num').innerHTML = num;
-               if (this.menu.visible() && !doNotUpdateMenu) {
-                       this.showMenu();
+
+               if (num < 0) {
+                       num = $$('#tx-opendocs-menu tr.opendoc').length;
                }
+
+               $('tx-opendocs-counter').writeAttribute('value', num);
        },
 
        /**
-        * this function calls the backend to close an open documentshould let the 
+        * closes an open document
         */
        closeDocument: function(md5sum) {
-               new Ajax.Updater(this.menu, this.ajaxScript, {
-                       parameters: { ajaxID: this.ajaxIDcloseDoc, md5sum: md5sum },
-                       onSuccess: function() { this.updateNumberOfDocs(-1, true); }.bind(this)
-               });
-               return false;
+               new Ajax.Updater(
+                       this.menu,
+                       this.ajaxScript, {
+                               parameters: {
+                                       ajaxID: 'tx_opendocs::closeDocument',
+                                       md5sum: md5sum
+                               },
+                               onComplete: function() {
+                                       this.updateNumberOfDocs(-1, false);
+                               }.bind(this)
+                       }
+               );
+
+               this.updateNumberOfDocs(-1, true);
        }
 
 });
index f22c29f..4370f99 100644 (file)
Binary files a/typo3/sysext/opendocs/opendocs.png and b/typo3/sysext/opendocs/opendocs.png differ
diff --git a/typo3/sysext/opendocs/toolbar_item_active_bg.png b/typo3/sysext/opendocs/toolbar_item_active_bg.png
new file mode 100644 (file)
index 0000000..8458345
Binary files /dev/null and b/typo3/sysext/opendocs/toolbar_item_active_bg.png differ