Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!---SEARCH + HIGHLIGHT CODE BY EURHIPIDES (ELISIONTHEMES)---->
- <script>
- $.expr[":"].contains = $.expr.createPseudo(function(arg) {
- return function( elem ) {
- return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
- };
- }); // this whole piece of code makes the :contain selector case insensitive, so that the search box returns results regardless of upper/lowercase
- $(document).ready(function(){
- $('#searchfor').keyup(function() { //when someone types anything in the searchbox
- var key = event.keyCode || event.charCode;
- var searchedText = $('#searchfor').val(); // variable for the text entered into the searchbox
- if( key == 13) { // if they clicked the enter key
- if ($(".content:contains('"+ searchedText +"')").length > 0 ) { //if they clicked the enter key AND the text is found
- $('.noresult').fadeOut(); // then fade OUT the div that says 'no results found'
- }
- else {
- $('.noresult').fadeIn(); // or else fade IN the div that says 'no results found'
- }
- }
- });
- });
- </script>
- <script style="text/javascript" src="http://static.tumblr.com/9y86jzv/bovnsdesg/highlight.css"></script>
- <script>
- $(document).ready(function(){
- $('#searchfor').keypress(function (e) { // when someone types something in the searchbox
- var key = e.which;
- var searchedText = $('#searchfor').val(); // variable for the text entered into the searchbox
- if(key == 13) { // if they click the enter key
- $('.content').highlight( searchedText ); // then highlight the found text
- }
- });
- });
- </script>
- <script>
- $(document).ready(function(){
- $('#searchfor').keyup(function() { // when someone types something in the searchbox
- var key = event.keyCode || event.charCode;
- if (key == 8 || key == 46) { // if they click the backspace button
- $('.content').removeHighlight(); // then remove the highlight
- $('.noresult').fadeOut(); // or if the text wasnt found, fade out the 'no results' text
- }
- });
- });
- </script>
- <!----END SEARCH + HIGHLIGHT CODES---->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement