Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hiya! I ended up rewriting the script, but made a working <a href="http://jsfiddle.net/P3YKp/3/" rel="nofollow noreferrer">demo</a> for you :)</p> <pre><code>/* Return a unique array */ Array.prototype.getUnique = function(){ var u = {}, a = [], i, l; for(i = 0, l = this.length; i &lt; l; ++i){ if(this[i] in u) continue; a.push(this[i]); u[this[i]] = 1; } return a; } /* Show paragraph containing first letter (or number if zero) */ function finish(letter){ var t, txt, found = []; if (letter.match(/\d/)) { letter = "0"; } // set letter to zero if it is any number $('p').each(function(){ // grab first 20 characters so we don't need to split the entire paragraph txt = $(this).text().substr(0,20).split(' '); if (txt[0].toLowerCase() == 'the') { txt.shift(); } // remove first element if it's "the" t = txt[0].match(/\d/) ? "0" : txt[0].substr(0,1).toLowerCase(); // set zero for digits or get first letter found.push(t); // Add letter/number to array if ((t == "0" &amp;&amp; letter == "0") || t == letter.substr(0,1).toLowerCase()){ // show paragraph $(this).addClass('current-series').show(); } else { $(this).hide(); } }) return found.getUnique().sort(); } </code></pre> <hr> <p>Update: Ok I finally understand what you mean by consolidated! YAY! You mean you only want the unique entries to show! I've <a href="http://jsfiddle.net/P3YKp/6/" rel="nofollow noreferrer">updated the demo</a> and I've also added a small script that grabs the letter variable from the URL, so you really don't need to use php for this:</p> <p><em>Note</em> in the demo, I had to remove the select list, but you can change the selected letter (for the demo only) by modifying this line:</p> <pre><code> var letter = getletter() || '0'; </code></pre> <p>Change the <code>'0'</code> to whatever letter you want to display (for the demo only). In the live version, it'll grab the letter from the URL automatically.</p> <pre><code>/* get letter from URL */ function getletter(){ var p = (new RegExp("[\\?&amp;]letter=([^&amp;#]*)")).exec(window.location.href); return (p===null) ? "" : p[1]; } /* Show paragraph containing first letter (or number if zero) */ function finish(){ var t, txt, found = []; // get letter from url or set to zero if it doesn't exist var letter = getletter() || '0'; // set letter to zero if it is any number if (letter.match(/\d/)) { letter = "0"; } $('p').each(function(){ // grab first 20 characters so we don't need to split the entire paragraph txt = $(this).text().substr(0,20).split(' '); // remove first element if it's "the" if (txt[0].toLowerCase() == 'the') { txt.shift(); } t = txt[0].match(/\d/) ? "0" : txt[0].substr(0,1).toLowerCase(); // set zero for digits or get first letter // show paragraph if unique and matches letter if ((found[$(this).text()] != true) &amp;&amp; ((t == "0" &amp;&amp; letter == "0") || t == letter.substr(0,1).toLowerCase())){ $(this).addClass('current-series').show(); found[$(this).text()] = true; } else { $(this).hide(); } }) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload