php - Jquery Sorting by Letter -


I'm using jquery to sort through the group of paragraph tags (Aaron Haroon's fate). This URL pulls the string "letter" (a letter) from the string and displays the paragraphs starting with that paragraph. It hides all others and consolidates the list so that no duplicate is displayed.

See the code:

  var letter = '& lt ;? Php echo (strlen $ _GET ['letter']) == 1)? $ _GET ['Letter']: ''; ? & Gt; 'Function Finish () {var found_first = []; JQuery ('P'). Each (function () {if (jQuery (this) .text (). Substr (0,1) .toUpperCase () == letter) {if (found_first [jQuery (this) .text)]! = True {jQuery} (This) .addClass ('current-series'); Found_first [jQuery (this) .text ()] = true;} and {jQuery (it) .hide ();}} else {JQuery (this) .hide ();}}}}  

Working with this whole day and I have 2 questions on this:

  1. Is this the first time to ignore the word 'this'? For example, if a paragraph starts with 'Amazing', then I would like to show it on the 'A' page, not on the 'T' page, as it is currently.

  2. Is there a page for (all) numbers? For example, the URL on the page will be similar to domain.com/index.php?letter=0 and it will only show the paragraph tag, which starts with a number, any number. I can currently do this with a number but, I need 1 page for all the numbers.

"post-text" itemprop = "text">

Hi! I've finished typing the script again, but have done one thing for you :)

  / * Return a unique array / / Array.prototype.getUnique = function () {var u = {}, A = [], i, l; For (i = 0, l = this.length; i & lt; l; ++ i) {If (u in this [i] is continuing; A.push (this [i]); U [this [i]] = 1; } Return; } / * Show paragraphs in the first letter (or if number zero) * / function Finnish (letter) {var t, txt, found = []; If (letter.match (/ \ d /)) {letter = "0"; } // If there is a number $ ('P'), then set the letter for zero. Each (function () {// grab contains the first 20 characters so that we divide the entire paragraph txt = $ (this) .text Do not need to () .substr (0,20) .split (''); if (txt [0] .toLowerCase () == 'the') {txt.shift ();} // remove the first element If this is the "the" T = txt [0] .mail (/ \ d /)? "0": txt [0] .substr (0,1) .toLowerCase (); // zero for the digits set or before Letter found. Add letter / number in the Push (t); // array if ((t == "0" and; == "0") || T == letter.substr (0, 1) .toLowerCase ()) {/ $ (this) .addClass ('Current-Series') show. Show ();} and {$ (this) .hide ();}}) found. }  

Update: OK, I understand what you think by integrating! Wow! You mean you want to show only unique entries! I have done and I have a small script that has kept the letter variable from the URL, so you do not have to use php for it:

Note In Demo, I had to remove the selection list, but you can modify the selected line (for demo only) by modifying this line:

  var letter = getletter () || '0';  

For any letters you want to display, replace '0' (for demos only). In the live version, it will automatically receive the letter from the URL. Get the letter / get the URL from

  / * url () {var p = (new regx ("[\\ \\? & Amp; sheet = (= [^ & amp; #] *) ")) Executive (window.location.href). Return (P === blank)? "": P [1]; } / * Show paragraphs in the first letter (or if number zero) * / function finish () {var t, txt, found = []; Get the letter from // url or set to zero if this var letter = getletter () || '0'; // If there is a number, then set the letter to zero (letter.match (/ \ d /)) {letter = "0"; } $ ('P') Each (function () {// is 20 characters before grab, so we need to split the whole article txt = $ (this) .text (). Substr (0,20) is not needed .split (''); // If the element is already extracted then "if" (txt [0] .toLowerCase () == 'the') {txt.shift ();} t = txt [0] .mail ( / \ D /)? "0": txt [0] .substr (0,1) .toLowerCase (); // Set zero for digits or get the first letter / if the paragraph is unique to show and mail (Found [$ (this) .text ()]! = True) & amp; ((T == "0" & ​​Letter == "0") || T == letter.substr (0,1) .toLowerCase () ($) () ($) () ($) () ($) ();)}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -