Learn how to use jQuery at the Blog

Web20dir « visit

  • Added 8 months ago
  • 175 Lines of Code shown
  • 1 Links of Interest
http://web20dir.com
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Web20dir - http://web20dir.com

var Web20 = window.Web20 || 
{
    timerID: new Object(),
    loadingTimeout: 2000,   
    //baseURL: "http://localhost/dev001/projects/web20/index.php/",
    //bURL: "http://localhost/dev001/projects/web20/",
    baseURL: "http://web20dir.com/index.php/",
    bURL: "http://web20dir.com/",    
    init: function() 
    {        
        this.Util.init();
    },
    
    /**
     * Prepend Web20.Options.baseURL to $url
     * @param $url: URL to which baseURL needs to be prepended.
     * Example: convertURL('/test') will return http:/websct/text,
     * where http://websct is the baseURL
     */
    convertURL: function($url)
    {
        return Web20.baseURL + $url;    
    }
    
};

Web20.Util =
{ 
	init: function() 
    {   
    },    
    isScrollBottom : function() {
      var documentHeight = dir_listing_inner.scrollHeight;      	 
	  var scrollPosition = $('#dir_listing_inner').height() + $('#dir_listing_inner').scrollTop();
	  var diff =Math.abs( scrollPosition - documentHeight );
	  if(documentHeight==scrollPosition || diff <25){
	  	return true;
	  }else{
	  	return false;
	  }	  
	},
	sort : function(type){		
		$('#txtType').val(type);
		$('#start').val('40')
		var searchTags = $('#txtTags').val();
		var search = $('#txtSearch').val();
		if(search == 'Search'){
		   	search = 0;
		}	
		this.showLoading();
		this.setScrollTopZero();
		$.ajax({
			  url: Web20.convertURL('front/index/0/'+type+'/'+search+'/'+searchTags),
			  success:(function(results){			 	
			  $("#results").html(results);  
			  })			  
		});				
	},
	searchAuto : function (){		
		var $input = $('#txtSearch').attr("autocomplete", "off");
		var timeout;
		$input.keydown(function(e) {
			// track last key pressed
			lastKeyPressCode = e.keyCode;
			switch(e.keyCode) {
				case 38: // up
					e.preventDefault();				
					break;
				case 40: // down
					e.preventDefault();					
					break;
				case 9:  // tab
				case 13: // return
					break;
				default:
					if (timeout) clearTimeout(timeout);
					timeout = setTimeout(function(){Web20.Util.searchCheck()}, 500);
					break;
			}
		});
	},
	searchCheck : function(){
		if(lastKeyPressCode != 46 || (lastKeyPressCode < 8 && lastKeyPressCode > 32)){
			this.search();
		}
	},
	search :function(){		
		this.hideTagCloud();				
		var search = $('#txtSearch').val();		
		var type  = $('#txtType').val();
		$('#start').val('40');	
		$('#txtTags').val('0');			
		if(search == 'Search' || search == ''){
		   	search = 'Search';
		}
		if(search!=0){
			this.showLoading();	
		}
		this.setScrollTopZero();
		$.ajax({
			  url: Web20.convertURL('front/index/0/'+type+'/'+search+'/0'),
			  success:(function(results){			  	
			  $("#results").html(results);  
			  })			  
		});
	},
	searchByTags :function(val){
		this.hideTagCloud();
		$('#start').val('40');
		$('#txtSearch').val('Search');
		$('#txtTags').val(val);
		$.ajax({
			  url: Web20.convertURL('front/index/0/0/0/'+val),
			  success:(function(results){			  	
			  $("#results").html(results);  
			  })			  
		});	
		
	},	
	setScrollTopZero : function(){
		$('#dir_listing_inner').scrollTop('0');
	},
	showLoading :function(){
		$("#results").html("<div align='center' style='padding-top:180px;'><img src='images/load.gif'></div>");
	},
	setDefault : function(){		
		this.hideTagCloud();		
		$('#start').val('40');
		$('#txtTags').val('0');
		this.setScrollTopZero();		
	},
	loadPage : function(){
		this.showLoading();
		$.ajax({
			  url: Web20.convertURL('front/index/0/0/0'),
			  success:(function(results){			  	
			  $("#results").html(results);  
			  })			  
		});
	},
	hideTagCloud : function(){
		$('#browstag').hide('slow');
	},
	showTagCloud :function(){
		$('#browstag').show('slow');
	}
	
}	

$(document).ready(function(){		
	$('#dir_listing_inner').scroll(function(){		
	    if(Web20.Util.isScrollBottom()){
		    var start = parseInt($('#start').val());
		    var count = parseInt($('#count').val());
		    var type  = $('#txtType').val();
		    var search = $('#txtSearch').val();
		    var txtTags = $('#txtTags').val();
		    if(search == 'Search'){
		    	search = 0;
		    }
		    start = start + 30;		     
		    $('#start').val(start);
		    if(start <= count){
			    $.ajax({
				  url: Web20.convertURL('front/next/'+start+'/'+type+'/'+search+'/'+txtTags),
				  success:(function(results){	
				  $("#results").append(results);  
				  })
				});
		    }
		}
	});	
	Web20.Util.setDefault();
	Web20.Util.searchAuto();
});