We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7527
    • 437 Posts
    Ok I got the links working. Don’t know how? Tried 2 things, one worked lol. The only error is that the ’C’ which should insert above the ’Q’ section only appears in the expandable area.

    For example instead of C

    Chrysalis
    etc

    I get nothing, but when you expand the answer it appears below the answer text
      www.PawsForWildlife.co.uk
      www.Borntobrick.co.uk
      • 3749
      • 24,544 Posts
      It might be because the Extra: there is wrapped in <p>Extra:</p>.

      I think it may have to be the first thing on the line.

      If you’re using TinyMCE, turn it off to fix it.
        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
        • 7527
        • 437 Posts
        Okay. Here is an example of my code

        <p>Extra:</p>
        <p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_A" style="width: 161px; height: 11px;" name="#jump_to_A"></a><strong>A</strong></p>
        <p class="az-anchor" style="background-color: #61ee89; background-repeat: repeat; background-position: 350px 50%;"><strong> A</strong></p>
        <p>Q:<strong>Abdomen</strong></p>
        <p>A:The lower part of the body</p>
        <p>Q:<strong>Abdominal segment</strong></p>
        <p>A:A section of the abdomen</p>
        <p>Q:<strong>Antenna(e)</strong></p>
        <p>A:Two 'feelers' on the head of insects and some invertebrates</p>
        <p>Q:<strong>Apiarist</strong></p>
        <p>A:The correct term for a beekeeper</p>
        <p>Extra:</p>
        <p class="az-anchor"><strong>C</strong></p>
        <p class="az" style="background-color: #61ee89; background-repeat: repeat; background-position: 350px 50%;"><strong> C</strong></p>
        <p>Q:<strong>Cephalothorax</strong></p>
        <p>A:Combined head and thorax as seen in tarantulas and spiders</p>
        <p>Q:<strong>Chrysalis</strong></p>
        <p>A:A type of pupa</p>
        <p class="az-anchor"><a id="jump_to_D" name="#jump_to_D"></a><strong>D</strong></p>
        <div class="code">
        

        Im sure it’s something obvious undecided
          www.PawsForWildlife.co.uk
          www.Borntobrick.co.uk
          • 3749
          • 24,544 Posts
          I don’t see anything obvious, although the non Q& A stuff following Extra: should all be on the same line with no tags around the Extra:. There are a lot of errors in the HTML of the page (202) that might be causing trouble. Many are trivial, but some are serious, like overlapping tags.

          <p></span></p> (a closing <span> tag can't be in its own paragraph)
          <h3><b><u>General Wildlife Search</b></u></h3>  (</b> and </u> tags are backwards)
          <h5><a href="index.php?q=acknowledgements.html">Acknowledgements</h5></a></li>  (the <a> tag has to close inside the heading)
          

          There are also many unclosed <p> tags and one <ul> tag that should be </ul> so the rest of the document is technically a nested list.

          You should be able to see all of the errors here:.
          http://validator.w3.org/check?uri=http%3A%2F%2Fwww.pawsforwildlife.co.uk%2Findex.php%3Fq%3Dglossary.html&charset=%28detect+automatically%29&doctype=Inline&group=0
          Remove the <p></p> tags from around Extra:. They’re not displayed elements. In fact, you shouldn’t need any <p></p> tags for any of the questions or answers. use

          if you need to separate paragraphs in a question or answer.

          You should also consider moving the style information into a CSS file. That will make your HTML code much cleaner and more reliable.

          You might want to invest in a good HTML code editor (or at least get a good free one). wink

          NetBeans, for example, is free and would have pointed out many of these errors as you typed them.

          Again, and I can’t stress this enough, if you have the Rich Text editor turned on (TinyMCE), I’d recommend turning it off and getting used to working in raw HTML.
            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
            • 7527
            • 437 Posts
            Thanks Bob Ray, wow what a lot of errors!. I have now amended them.

            My code so far...

            Unpublished page content

            Extra:<p class="az-anchor"><a name="jump_to_A"  id="jump_to_A"></a><strong>A</strong></p>
            
            Q:<strong>Abdomen</strong>
            A:The lower part of the body
            
            Q:<strong>Abdominal segment</strong>
            A:A section of the abdomen
            
            Q:<strong>Antenna(e)</strong>
            A:Two 'feelers' on the head of insects and some invertebrates
            
            Q:<strong>Apiarist</strong>
            A:The correct term for a beekeeper
            
            Extra:<p class="az-anchor"><a name="jump_to_C"  id="jump_to_C"></a><strong>C</strong></p>
            
            Q:<strong>Cephalothorax</strong>
            A:Combined head and thorax as seen in tarantulas and spiders
            
            Q:<strong>Chrysalis</strong>
            A:A type of pupa
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_D" style="width: 161px; height: 11px;" name="jump_to_D"></a><strong>D</strong></p>
            
            Q:<strong>Dam</strong>
            A:Female parent of a horse or pony
            
            Q:<strong>Dorsal Stripe</strong>
            A:Coloured line along the ridge of an animals back
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_E" style="width: 161px; height: 11px;" name="jump_to_E"></a><strong>E</strong></p>
            
            Q:<strong>Entemology</strong>
            A:The study of insects
            
            Q:<strong>Entemologist</strong>
            A:Someone who studies insects
            
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_F" style="width: 161px; height: 11px;" name="jump_to_F"></a><strong>F</strong></p>
            
            Q:<strong>Femur / Femora</strong>
            A:The first segment of the leg, equal to the thigh
            
            Q:<strong>Flight Feather</strong>
            A:The large outer row of feathers on a wing that aid flight
            
            Q:<strong>Forewing</strong>
            A:The first pair of wings on an animal with more than one set, such as a butterfly
            
            Q:<strong>Frenulum</strong>
            A:The small 'hook' that most moths have to hold their wings in position
            
            Q:<strong>Fringe</strong>
            A:Refers to the edge of the body, wing, etc
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_G" style="width: 161px; height: 11px;" name="jump_to_G"></a><strong>G</strong></p>
            
            Q:<strong>Greater Coverts</strong>
            A:The middle row of feathers on a birds wing
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_H" style="width: 161px; height: 11px;" name="jump_to_H"></a><strong>H</strong></p>
            
            Q:<strong>Hindwings</strong>
            A:The second pair of wings on an animal with more than one pair (these are sometime hidden when at rest)
            
            Q:<strong>Hybrid</strong>
            A:The offspring of two animals from different species
            
            Q:<strong>Hybridise</strong>
            A:The act of two different species mating
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_I" style="width: 161px; height: 11px;" name="jump_to_I"></a><strong>I</strong></p>
            
            Q:<strong>Imago</strong>
            A:The adult phase of an insect
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_L" style="width: 161px; height: 11px;" name="jump_to_L"></a><strong>L</strong></p>
            
            Q:<strong>Larva(e)</strong>
            A:The young form of some insects
            
            Q:<strong>Lesser Coverts</strong>
            A:The first row of feathers on a birds wing (nearest the body)
            
            Q:<strong>Longitudinal Stripe</strong>
            A:A stripe that runs the length of the body, from head to tail
            
            Q:<strong>Lower Mandible</strong>
            A:The lower jaw, or lower half of a beak
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_M" style="width: 161px; height: 11px;" name="jump_to_M"></a><strong>M</strong></p>
            
            Q:<strong>Mealy</strong>
            A:Refers to a cream colouration
            
            Q:<strong>Median Stripe</strong>
            A:A stripe through the middle of an area (such as a wing)
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_N" style="width: 161px; height: 11px;" name="jump_to_N"></a><strong>N</strong></p>
            
            Q:<strong>Nape</strong>
            A:The back of the neck
            
            Q:<strong>Neoteny</strong>
            A:When an adult has grown slower than normal and still displays juvenile traits, such as feathered gills in newts for example
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_P" style="width: 161px; height: 11px;" name="jump_to_P"></a><strong>P</strong></p>
            
            Q:<strong>Plumage</strong>
            A:The feathers that cover a bird
            
            Q:<strong>Pupa(e)</strong>
            A:The solid casing that embodies insect larvae during the process of metamorphasis
            
            Q:<strong>Pupation</strong>
            A:The process of becoming a pupa
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_R" style="width: 161px; height: 11px;" name="jump_to_R"></a><strong>R</strong></p>
            
            Q:<strong>Rump</strong>
            A:The base of the spine, bottom of the back (rear area)
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_S" style="width: 161px; height: 11px;" name="jump_to_S"></a><strong>S</strong></p>
            
            Q:<strong>Sexual Dimorphism</strong>
            A:Where the male and female show a difference in colour, size and/or ornamental decoration (i.e, the Mandarin Duck)
            
            Q:<strong>Sire</strong>
            A:The male parent of a horse or pony
            
            Q:<strong>Supraocular Scales</strong>
            A:Enlarged scales found on certain snakes, located just above the eye
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_T" style="width: 161px; height: 11px;" name="jump_to_T"></a><strong>T</strong></p>
            
            Q:<strong>Thorax</strong>
            A:The second part of an insect / invertebrates body (between the head and the abdomen). Roughly translated as the chest area
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_U" style="width: 161px; height: 11px;" name="jump_to_U"></a><strong>U</strong></p>
            
            Q:<strong>Upper Mandible</strong>
            A:The upper jaw, or upper half of the beak
            
            Extra:<p class="az-anchor" style="background-repeat: repeat; background-position: 350px 50%;"><a id="jump_to_Z" style="width: 161px; height: 11px;" name="jump_to_Z"></a><strong>Z</strong></p>
            
            Q:<strong>Zebroid</strong>
            A:Any Equine (horse, donkey, etc) hybrid that has a zebra as one of it's parents
            <p> </p>


            Published page content

            <p style="text-align: center;"><span style="color: #ff6600; text-decoration: underline;"><strong><span style="font-size: 260%;">Glossary</span></strong></span></p>
            
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_A">A</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_C">C</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_D">D</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_E">E</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_F">F</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_G">G</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_H">H</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_I">I</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_L">L</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_M">M</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_N">N</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_P">P</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_R">R</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_S">S</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_T">T</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_U">U</a> |  
            <a class="az-headeritem" href="[~[*id*]~]#jump_to_Z">Z</a> |  
            
            [[EZfaq? &docID=`623` &showHideAllOption`false` &statusOpenHTML=`` &statusClosedHTML=`` &openColor=`#049604`]] 
            <p> </p>


            I have set both pages to not have Rich Text on. The lionks are still not working. Any ideas?
              www.PawsForWildlife.co.uk
              www.Borntobrick.co.uk
              • 3749
              • 24,544 Posts
              I can see what’s happening, but I can’t see why.

              The Extra: sections are being parsed into the answer div so the anchors are invisible until the JS opens them. For some reason, it’s not recognizing Extra: (although it did recognize some of them before huh ).

              If you open the Rump answer and scroll back to the top, the S link will work.

              The only thing I can think of is that EZfaq is confused by some of the line ending characters used in your content resource file. Are you pasting them in from another editor, by any chance?
                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
                • 7527
                • 437 Posts
                Sorry I don’t quite understand the question? If you are referring to my content, then I have typed it all in Modx, not copied
                  www.PawsForWildlife.co.uk
                  www.Borntobrick.co.uk
                  • 3749
                  • 24,544 Posts
                  Never mind that. I looked at the code and the line endings shouldn’t matter at all.

                  Try clearing the site cache and your browser cache and checking it again.

                  If that doesn’t work, paste the code from your EZfaq snippet into a reply.

                  Looking at the version I have, I can’t see any reason why it wouldn’t work the way you have it.
                    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
                    • 7527
                    • 437 Posts
                    Still no success. Thanks ever so much for helping, its greatly appreciated. Here is my snippet code

                    <?php
                    /*
                    
                    Snippet: EZfaq
                    $Revision: 26 $
                    $Date: 2008-03-14 21:27:09 -0400 (Fri, 14 Mar 2008) $
                    Author:  Bob Ray (based on an idea from SorenG JavaScript code from DynamicDrive.com)
                    Version: 1.0.4
                    Compatibility: MODX 0.9.6, 0.9.7
                    Thanks to: jaredc for suggestions on .css usage and cssPath parameter
                     */
                    
                    /************************************************************
                    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:false;
                    
                    // 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 = "";
                    
                    
                    $output .= '<div class="faqExpand">';
                    $output .= '<p>'.$faq_lang['ezfaq-show-hide-msg'].'</p>';
                    if ($showHideAllOption) {
                    $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>';
                    
                    
                    $docString = $doc['content'];
                    $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) {
                      $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>';
                         $output .= '<div id="faq'.$itemCount.'" class="switchgroup1">';
                            //$output .= '<p class="faqAnswer">';
                         $output .= $items[1];
                            //$output .= '</p>';
                         $output .= '</div>';
                    
                      }
                      $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;
                    ?>
                      www.PawsForWildlife.co.uk
                      www.Borntobrick.co.uk
                      • 3749
                      • 24,544 Posts
                      That certainly explains it. Your code doesn’t have the "Extra:" option.

                      Do you remember where and when you got the snippet?

                      If you like, you can try pasting the following code in to replace the current snippet code:

                      <?php
                      /*
                      
                      Snippet: EZfaq
                      $Revision: 31 $
                      $Date: 2008-09-27 21:01:37 -0700 (Sat, 27 Sep 2008) $
                      Author:  Bob Ray (based on an idea from SorenG JavaScript code from DynamicDrive.com)
                      Version: 1.0.6
                      Compatibility: MODX 0.9.6
                      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 class="handcursor">';
                           $output .= '<a href="[~[*id*]~]#faq-'.$itemCount.'">';
                           $output .= '<span class="faqQuestion" id=faq'.$itemCount.'-title>';
                           $output .= $items[0];
                           $output .= '</span></a>';
                           $output .= '</p>';
                           $aArray = explode("Extra:",$items[1]);
                           $output .= '<div id="faq'.$itemCount.'" class="switchgroup1">';
                           $output .= $aArray[0];
                           $output .= '</div>';
                      
                           if ($aArray[1] != "") {  // add "extra" material if there is any
                             $output .= '<div class = "faqExtra">';
                             $output .= $aArray[1];
                             $output .= '</div>';
                           }
                      
                        }
                        $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