We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: cbaone at Jul 25, 2008, 03:56 PM

    Hey Bob,
    I was wondering if you had a chance to look at the files I attached in my earlier post. Thanks for all your help so far.

    Sorry, I missed your post.

    I just took a look at it and it looks like to get your effect to work, you needed to remove all the JS that makes the snippet work in the first place. I don’t think I can put that in a general release. wink (Or did I miss something?)

    Bob
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 4749
      • 623 Posts
      It’s working with all of the JS, but just not working as intended. Sorry, maybe I’m not understanding what you’re saying. If you’re saying you can’t help any further that’s fine. If you’re saying that the JS is what’s causing the problem then maybe I can modify it. Thanks.
        The MODx has you...
        Utah Web Design
        • 3749
        • 24,544 Posts
        Sorry, the misunderstanding was mine. I forgot that I asked you for those files and thought you were posting an improved version. I’ll try to take a look at them soon.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 4749
          • 623 Posts
          Oh, great. Thanks Bob, that’s good news.
            The MODx has you...
            Utah Web Design
            • 3749
            • 24,544 Posts
            Quote from: cbaone at Jul 29, 2008, 02:00 PM

            Oh, great. Thanks Bob, that’s good news.

            cbaone, I’ve gotten your example content to work (almost - the "A" anchor doesn’t render, but all the rest do) with the corrected code I gave you.

            http://bobsguides.com/index.php?id=47

            Before I go any further, is there a reason you prefer the Mootols/Accordian version? It brings along a lot of extra baggage and I’m not sure it allows the same easy control of the open and close symbols.

            If the example in the link would work for you, I’ll try to add the capability of inserting EXTRA: stuff at the beginning. If there’s a compelling reason to use the Mootools version, I might switch to that.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 4749
              • 623 Posts
              Beggars can’t be choosers, right? That’s really great that you’ve gotten it to work. If you could get the A to show up that would be really nice, but I understand that you’re doing this as a service to the community and not my personal helper.

              Also, about the mootools stuff... There isn’t really one specific reason why I use it. It’s more of an issue of consistency and familiarity than anything else. I try to only use one js library on a  site so I can rule out cross-compatibility issues between different libraries. Plus, I’m just comfortable with mootools. ModX uses mootools and almost all of the "cool" features on my sites are exclusively mootools. It’s been great to me and, well, that sliding accordion effect is pretty slick.  grin OH, I don’t use the open close symbols anyway. I’m just using the link text to open the definitions.

              Anyway, thanks for all of your help you’ve been great. Will you post back the changes you made to the code?
                The MODx has you...
                Utah Web Design
                • 3749
                • 24,544 Posts
                Here it is. I’ll be putting it in the Repository when I get a chance.

                Now, anything above the first Q: is rendered as is. Be sure to uncheck the rtf box when you save the content. Also, don’t put "EXTRA:" for the stuff at the top. You shouldn’t need the <div> around the content.

                PS: some of your anchors are misnamed.


                <?php
                /*
                
                Snippet: EZfaq
                $Revision: 28 $
                $Date: 2008-07-29 12:51:35 -0700 (Tue, 29 Jul 2008) $
                Author:  Bob Ray (based on an idea from SorenG JavaScript code from DynamicDrive.com)
                Version: 1.0.5
                Compatibility: MODX 0.9.6, 0.9.7
                Thanks to: jaredc for suggestions on .css usage and cssPath parameter
                                  cbaone for suggestions about inserting anchors
                 */
                
                /************************************************************
                Usage (see readme.txt for installation information and usage)
                -----
                
                Minimal EZfaq call:
                -------------------
                
                [[EZfaq? &docID=`12`]]
                
                (Use the document ID of your unpublished FAQ content document
                -- NOT THE DOCUMENT THAT SHOWS THE FAQ --.)
                
                &docID is required.
                
                Optional parameters:
                --------------------
                
                &lang   [Language for error messages and prompts - defaults to "en"]
                
                &showHideAllOption [display the show/hide all buttons - default "true"]
                
                &statusOpenHTML  [symbol to put next to open topics (can be an image URL) - defaults to "[-]"]
                
                &statusClosedHTML [symbol to put next to closed topics (can be an image URL) - defaults to "[+]"]
                
                &openColor  [color for open questions (name or hex value #ffffff) - default "red"]
                
                &closedColor [color for closed questions (name or hex value #ffffff) - default "black"]
                
                &setPersist  [does open state persist across visits/reloads - default "true";]
                
                &collapsePrevious [if set, only one answer can be open at a time - default "true"]
                
                &defaultExpanded  [expand answers n1 through n2 ("0,1" expands items 1 through 2)when page is opened (default, no)]
                
                &cssPath [Optional Path to .css file -- set to `` for no .css file]
                
                
                ***************************************************/
                
                $faqPath = "assets/snippets/ezfaq/"; // set path to resources (language file, .css, .js)
                
                
                $error_message = ""; // initialize error message variable
                
                /* ********************************************
                Make sure we have what we need before proceding
                ***********************************************/
                
                $lang = isset($lang)?$lang:'en'; // set default language
                require_once $modx->config['base_path'].$faqPath."lang/".$lang.".inc.php"; // get the language file
                
                if (!isset($docID)) {  // user didn't send docID parameter
                    return $faq_lang['ezfaq-docID-required'];
                }
                
                $doc = $modx->getDocument((string)$docID, '*', 1); // Search published first.
                if (empty($doc)) {
                    $doc = $modx->getDocument((string)$docID, '*', 0); // Un-published next?
                }
                if (empty($doc)) { // user requested a non-existing document
                   return $faq_lang['ezfaq-doc-not-found'];
                }
                
                /****************************************************************************************
                Now that we have the language file and the document with the FAQ
                content, we'll plug in the .css and .js and  initialize the optional parameters.
                *****************************************************************************************/
                
                /*  Inject .css file into document header - maybe.
                    Use $cssPath=`` if you want to put the .css in your site's .css file
                    rather than using a separate .css file for the FAQ
                */
                if (isset($cssPath) ) {    // user has set this parameter
                    if ($cssPath == "") {
                        // do nothing, user doesn't want a separate .css file
                    } else { // user has specified the .css file to use
                        $src = $cssPath;
                        $modx->regClientCSS($src);
                    }
                } else { // not set, use the default .css file
                
                    $src = $faqPath."ezfaq.css";
                    $modx->regClientCSS($src);
                }
                
                // inject the .js into the document header.
                $src = $faqPath."switchcontent.js";
                $modx->regClientStartupScript($src);
                
                
                //Show the buttons that show and hide all answers.
                $showHideAllOption = isset($showHideAllOption)?$showHideAllOption:true;
                
                // Set prefix markers for open and closed answers (can be string or an
                // image URL). Defaults to plus and minus signs.
                $statusOpenHTML = isset($statusOpenHTML)?$statusOpenHTML:"[-]";
                $statusClosedHTML = isset($statusClosedHTML)?$statusClosedHTML:"[+]";
                
                // Set colors for open and closed (applies to question; answer is styled in .css).
                // can be color name or hex color value (#ffffff);
                $openColor = isset($openColor)?$openColor:"red";
                $closedColor = isset($closedColor)?$closedColor:"black";
                
                // set whether state persists on return visits
                $setPersist = isset($setPersist)?$setPersist:"true";
                
                //when set to true, only one answer can be expanded at a time (default)
                $collapsePrevious = isset($collapsePrevious)?$collapsePrevious:"true";
                
                //expand answers n1 through n2 when page is opened (default, no)
                // to set, use "0,2" to expand first three answers, "0" to expand just the first
                $defaultExpanded = isset($defaultExpanded)?$defaultExpanded:"";
                
                // Work starts here
                
                //replace "EQUALS" in URLs with "="
                $statusOpenHTML = str_replace("EQUALS","=",$statusOpenHTML);
                $statusClosedHTML = str_replace("EQUALS","=",$statusClosedHTML);
                
                
                $output = "";
                
                $docString = $doc['content'];
                
                
                
                if ($showHideAllOption) {
                
                $output .= '<div class="faqExpand">';
                $output .= '<p>'.$faq_lang['ezfaq-show-hide-msg'].'</p>';
                
                $output .= '<a href="javascript:faq.sweepToggle('."'expand')".'"> '.$faq_lang['ezfaq-expand-button-msg'].' </a>';
                $output .='    ';
                $output .= '<a href="javascript:faq.sweepToggle('."'contract')".'"> '.$faq_lang['ezfaq-contract-button-msg'].' </a>';
                
                $output .= '</div>';
                
                }
                
                
                
                $docArray = explode("Q:",$docString);
                
                //$i = count($docArray);
                // echo "count: ".$i.'<br>';
                
                $itemCount=0; // used to make every id different
                
                
                $output .= '<div class="faqContainer">'."\n";
                foreach($docArray as $value) {
                
                
                    if ($itemCount==0) {  // very first item (or pre first item)
                        if (!strstr($value,"A:")) {   // no answer, assume it's before the beginning
                           $output .= $value;  // send it out without processing
                           continue;  // got to the next (first real item)
                        }
                    } else {
                        //normal item, continue
                    }
                  $items = explode("A:",$value);
                      if (stristr($items[0],"FAQ-END")) {
                         break;
                      }
                
                  if ( ($items[0] != "") && ($items[1] != "") ) {
                
                     $output .= '<p id="faq'.$itemCount.'-title" class="handcursor">';
                     $output .= '<span class="faqQuestion">';
                     $output .= $items[0];
                     $output .= '</span>';
                     $output .= '</p>';
                     $aArray = explode("Extra:",$items[1]);
                     $output .= '<div id="faq'.$itemCount.'" class="switchgroup1">';
                        //$output .= '<p class="faqAnswer">';
                     $output .= $aArray[0];
                        //$output .= '</p>';
                     $output .= '</div>';
                     if ($aArray[1] != "") {
                       $output .= $aArray[1];
                     }
                
                  }
                  $itemCount++;
                }
                $output .= '</div>'."\n"; // end of faqContainer div
                
                //   MAIN FUNCTION: new switchcontent("class name", "[optional_element_type_to_scan_for]") REQUIRED
                //1) Instance.setStatus(openHTML, closedHTML)- Sets optional HTML to prefix the headers to indicate open/closed states
                //2) Instance.setColor(openheaderColor, closedheaderColor)- Sets optional color of header when it's open/closed
                //3) Instance.setPersist(true/false)- Enables or disabled session only persistence (recall contents' expand/contract states)
                //4) Instance.collapsePrevious(true/false)- Sets whether previous content should be contracted when current one is expanded
                //5) Instance.defaultExpanded(indices)- Sets contents that should be expanded by default (ie: 0, 1). Persistence feature overrides this setting!
                //6) Instance.init() REQUIRED
                
                $output .= '<script type="text/javascript">;'."\n";
                $output .= 'var faq=new switchcontent("switchgroup1", "div");'."\n";  //Limit scanning of switch contents to just "div" elements
                
                
                $output .= "faq.setStatus('".$statusOpenHTML." ','".$statusClosedHTML." ');"."\n"; // set open/closed indicators
                $output .= 'faq.setColor("'.$openColor.'", "'.$closedColor.'");'."\n"; // set open/closed text colors
                $output .= 'faq.setPersist('.$setPersist.');'."\n";
                $output .= 'faq.collapsePrevious('.$collapsePrevious.');'."\n"; //Only one content open at any given time
                $output .= 'faq.defaultExpanded("'.$defaultExpanded.'");'."\n"; // expand some on open?
                $output .= 'faq.init();'."\n";
                $output .= '</script>'."\n";
                
                //$output .='<hr>'.$doc['content'];
                
                return $output;
                
                ?>
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 4749
                  • 623 Posts
                  Awesome! I’ll be trying it shortly. Thanks so much for your work! smiley
                    The MODx has you...
                    Utah Web Design
                    • 3749
                    • 24,544 Posts
                    Quote from: cbaone at Jul 29, 2008, 07:34 PM

                    Awesome! I’ll be trying it shortly. Thanks so much for your work! smiley

                    You’re welcome. Let me know how it works.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 4749
                      • 623 Posts
                      Works as advertised! Thanks a million! I really appreciate your work on this. grin
                        The MODx has you...
                        Utah Web Design