We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Here’s how I spent my Saturday morning (most of it wrestling with IE...piece of shit)

    Self-contained, intended for presenting a list of docments as a list of options, such as games or languages. Pure CSS, except for a bit of javascript clicky stuff for sucky browsers. I suppose I should separate out the javascript and load it in with the modx loader, but it’s only a few lines, it would suck up more resources getting it off the file system and parsing it in than just putting it here to begin with. Ditto the CSS, just a few lines to control the display.
    // CSSDropMenu
    // simple drop=down menu for ModX
    // usage: [[DropDown?id=x&tt=y]]
    // where x is the parent of the documents to be listed
    // and y is the text you want for the top of the menu
    
    $id = isset($id)?$id:0;
    $children = $modx->getActiveChildren($id);
    if($children == false) return;
    $toptext = isset($tt)?$tt:"Menu";
    $dm = "";
    
      // a bit of javascript for those whose browsers aren't 
      // CSS2 compliant (and we all know who they are)
    $dm .= "<script type='text/javascript'>
    function showList(thistag) {
       styleObj = document.getElementById(thistag).style;
       if (styleObj.display=='none') {styleObj.display = 'block';}
       else {styleObj.display = 'none';}
    }
    </script>";
    
      // set up the style for the list
    $dm .= "<style type='text/css'>
      #CSSMenu {
          position:relative;
          width:100px;
          z-index:10;
          background:yellow;
      }
      #CSSMenu ul, #CSSMenu li {list-style:none;}
      #cmTopItem {display:block;cursor:pointer;}
      #cmTopItem ul {display: none;} 
      #cmTopItem:hover ul {display: block;}
    </style>";
    
      // generate the list
    $dm .= "<div id='CSSMenu'>";
    $dm .= "<ul class='cmList' id='cmTopList'>";
    $dm .= "<li id='cmTopItem' class='cmItem' onClick='showList(\"cmList\");'>$toptext";
    $dm .= "<ul class='cmList' id='cmList'";
      // individual items
    foreach($children as $child) {
        $dm .= "<li class='cmItem'>";
        $dm .= "<a href='";
        $dm .= "[~".$child['id']."~]";
        $dm .= "'>";
        $dm .= $child['pagetitle']; 
        $dm .= "</a>";
        $dm .= "</li>";
    }
    $dm .= "</ul></li></ul></div>";
    
    return $dm;
    
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 33337
      • 3,975 Posts
      Thanks for nice contribution Susan !! smiley

      Thunmbs up for you wink

      Regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 19562
        • 18 Posts
        Susan, thanks !! Great work. Just what i needed !

        Keep up the good work ! smiley
          "Just smile and wave boys..smile and wave"
        • Great, Susan! Thanks for sharing. smiley

          A saturday morning well-spent grin

          Cheers, Garry
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com