Advertisement
heavenlydoctor

highlight codes (explained)

Aug 23rd, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <!---SEARCH + HIGHLIGHT CODE BY EURHIPIDES (ELISIONTHEMES)---->
  2. <script>
  3. $.expr[":"].contains = $.expr.createPseudo(function(arg) {
  4. return function( elem ) {
  5. return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
  6. };
  7. }); // this whole piece of code makes the :contain selector case insensitive, so that the search box returns results regardless of upper/lowercase
  8. $(document).ready(function(){
  9. $('#searchfor').keyup(function() { //when someone types anything in the searchbox
  10. var key = event.keyCode || event.charCode;
  11. var searchedText = $('#searchfor').val(); // variable for the text entered into the searchbox
  12. if( key == 13) { // if they clicked the enter key
  13. if ($(".content:contains('"+ searchedText +"')").length > 0 ) { //if they clicked the enter key AND the text is found
  14. $('.noresult').fadeOut(); // then fade OUT the div that says 'no results found'
  15. }
  16. else {
  17. $('.noresult').fadeIn(); // or else fade IN the div that says 'no results found'
  18. }
  19. }
  20. });
  21. });
  22. </script>
  23.  
  24. <script style="text/javascript" src="http://static.tumblr.com/9y86jzv/bovnsdesg/highlight.css"></script>
  25.  
  26. <script>
  27. $(document).ready(function(){
  28. $('#searchfor').keypress(function (e) { // when someone types something in the searchbox
  29. var key = e.which;
  30. var searchedText = $('#searchfor').val(); // variable for the text entered into the searchbox
  31. if(key == 13) { // if they click the enter key
  32. $('.content').highlight( searchedText ); // then highlight the found text
  33. }
  34. });
  35. });
  36. </script>
  37.  
  38. <script>
  39. $(document).ready(function(){
  40. $('#searchfor').keyup(function() { // when someone types something in the searchbox
  41. var key = event.keyCode || event.charCode;
  42. if (key == 8 || key == 46) { // if they click the backspace button
  43. $('.content').removeHighlight(); // then remove the highlight
  44. $('.noresult').fadeOut(); // or if the text wasnt found, fade out the 'no results' text
  45. }
  46. });
  47. });
  48. </script>
  49. <!----END SEARCH + HIGHLIGHT CODES---->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement