var loadrunning = 0; var _temp_loader = "
"; var authorsdirectory = (function(){ return{ ajaxGet : function(url){ return $.ajax({ type: "GET", url: url }); }, isElementInViewport : function(el) { if(el == undefined){ return ; } if (typeof jQuery === "function" && el instanceof jQuery) { el = el[0]; } var rect = el.getBoundingClientRect(); return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ ); }, getAuthorbyAlphabet:function(searchtxt,curpg){ if(searchtxt!='' && searchtxt!=null){ var getauthor = "/authorsdirectorylist.cms?query="; if(curpg!=null && curpg > 1){ $('#authordirlisting').append(_temp_loader); $('#temploader').removeClass('temploader'); var getauthor = getauthor+searchtxt+"&curpg="+curpg; }else if(curpg!=null && (curpg==0 || curpg==1) ){ $('#authordirlisting').append(_temp_loader); $('#temploader').addClass('temploader'); var getauthor = getauthor+searchtxt; } if(typeof tempname != "undefined" && tempname =="designersdirectory"){ getauthor = getauthor + '&celeb=designer'; } var ajaxresult = authorsdirectory.ajaxGet(getauthor); ajaxresult.done(function(data){ if(data!=''){ console.log("curpg",curpg); $('#temploader').remove(); if(curpg >1 ){ $("#authordirlisting").append(data); }else{ $("#authordirlisting").html(data); } }else{ $('#temploader').remove(); } loadrunning = 0; }); } }, getAllAuthor:function(searchtxt,curpg){ if(searchtxt!='' && searchtxt!=null){ var getauthor = "/authorsdirectorylist_all.cms?"; if(curpg!=null && curpg > 1){ $('#authordirlisting').append(_temp_loader); $('#temploader').removeClass('temploader'); var getauthor = getauthor+"curpg="+curpg; if(typeof tempname != "undefined" && tempname =="designersdirectory"){ getauthor = getauthor + '&celeb=designer'; } }else if(curpg!=null && (curpg==0 || curpg==1) ){ $('#authordirlisting').append(_temp_loader); $('#temploader').addClass('temploader'); var getauthor = getauthor; if(typeof tempname != "undefined" && tempname =="designersdirectory"){ getauthor = getauthor + 'celeb=designer'; } } var ajaxresult = authorsdirectory.ajaxGet(getauthor); ajaxresult.done(function(data){ if(data!=''){ console.log("curpg",curpg); $('#temploader').remove(); if(curpg >1 ){ $("#authordirlisting").append(data); }else{ $("#authordirlisting").html(data); } }else{ $('#temploader').remove(); } loadrunning = 0; }); } }, getAuthorbySearch:function(){ }, checkq:function(q){ if(q!=''){ var q = q.toLowerCase(); return q.replace("*", ""); } }, closesearchbar(){ $('[name="searchauthor"]').val(''); $("#crossgryicon").trigger('click'); }, m_activetab:function(a){ var _li = $(".alphabetsearch li"); _li.find("a.active").removeClass('active'); if(_li.find('a:contains('+a.toUpperCase()+')')) _li.find('a:contains('+a.toUpperCase()+')').addClass('active'); } } }()); $(document).ready(function(){ $( ".alphabetsearch li" ).on( "click", function(){ var _this = $(this); $(".alphabetsearch li").find("a.active").removeClass('active'); _this.find('a').addClass('active'); var seachby = _this.text(); var searchtxt = seachby.toLowerCase(); if(searchtxt!='' && searchtxt == 'all'){ authorsdirectory.getAllAuthor(searchtxt,1); if(typeof tempname != "undefined" && tempname =="designersdirectory"){ window.history.replaceState({}, 'Designer Search', '/life-style/fashion/designer-directory'); }else{ window.history.replaceState({}, 'Author Search', '/life-style/books/authors'); } }else{ authorsdirectory.getAuthorbyAlphabet(searchtxt,1); if(typeof tempname != "undefined" && tempname =="designersdirectory"){ window.history.replaceState({}, 'Designer Search by alphabet', '/life-style/fashion/designer-directory?query='+searchtxt); }else{ window.history.replaceState({}, 'Author Search by alphabet', '/life-style/books/authors?query='+searchtxt); } $(".hintopt").find('ul').html('').hide(); } }); $('body').on('click', '#searchgryicon', function(){ $('.authorsearchopen').addClass('open'); $(this).hide(); $('.authorsearchopen .searchauthor').val(''); $('#crossgryicon').show(); // $('[name="searchauthor"]').focus(); }).on('click', '#crossgryicon', function(){ $('.authorsearchopen').removeClass('open'); $(this).hide(); $('#searchgryicon').show(); $(".hintopt").find('ul').html('').hide(); }).on('click', '[data-plugin="hintauthor"]', function(){ var searchval = $('[name="searchauthor"]').val(); //alert(searchval); if(searchval.trim() != "" && searchval.trim() != "Search Author Name" && searchval.trim() != "Search Designer Name"){ //location.href = location.protocol+"//"+location.host+"/etimes/etsearch.cms?query="+searchval.trim(); var sq = searchval.trim(); if(typeof tempname !="undefined" && (tempname=='authorsdirectory' || tempname=='designersdirectory')){ authorsdirectory.getAuthorbyAlphabet(searchval.trim(),1); authorsdirectory.closesearchbar(); //fake history push var _temp_q =''; _temp_q = (searchval.trim()).split('')[0]; authorsdirectory.m_activetab(_temp_q); if(typeof tempname !="undefined" && tempname=='designersdirectory'){ window.history.replaceState({}, 'Designer Search by alphabet', '/life-style/fashion/designer-directory?query='+sq); }else{ window.history.replaceState({}, 'Author Search by alphabet', '/life-style/books/authors?query='+sq); } }else{ var isDesigner = ''; if($('[name="searchauthor"]')&& $('[name="searchauthor"]')[0] && $('[name="searchauthor"]')[0].getAttribute('isDesigner')){ isDesigner = $('[name="searchauthor"]')[0].getAttribute('isDesigner'); } if(typeof tempname !="undefined" && (tempname=='designersdirectory' || isDesigner == 'yes')){ location.href = location.protocol+"//"+location.host+"/life-style/fashion/designer-directory?query="+sq; }else{ location.href = location.protocol+"//"+location.host+"/life-style/books/authors?query="+sq; } } } else{ var isDesigner = ''; isDesigner = $('[name="searchauthor"]')[0].getAttribute('isDesigner'); if(typeof tempname !="undefined" && (tempname=='designersdirectory' || isDesigner == 'yes')){ alert("Please fill Designer name."); }else{ alert("Please fill Author name."); } } }).on('keyup','[data-plugin="searchauthor"]',function(e){ var searchval = $('[name="searchauthor"]').val(); searchval = searchval.replace(/<([^>]+?)([^>]*?)>(.*?)<\/\1>/ig, ""); if(searchval.trim() != "" && searchval.trim() != "Search Author Name" && searchval.trim().length > 2){ var isDesigner = $('[name="searchauthor"]')[0].getAttribute('isDesigner'); if(event.keyCode==13) { //location.href = location.protocol+"//"+location.host+"/etimes/etsearch.cms?query="+searchval.trim(); var sq = searchval.trim(); if(tempname=='authorsdirectory' || tempname=='designersdirectory'){ authorsdirectory.getAuthorbyAlphabet(searchval.trim(),1); authorsdirectory.closesearchbar(); //fake history push var _temp_q =''; _temp_q = (searchval.trim()).split('')[0]; authorsdirectory.m_activetab(_temp_q) if(typeof tempname !="undefined" && tempname=='designersdirectory'){ window.history.replaceState({}, 'Designer Search by alphabet', '/life-style/fashion/designer-directory?query='+sq); }else{ window.history.replaceState({}, 'Author Search by alphabet', '/life-style/books/authors?query='+sq); } }else{ if(typeof tempname !="undefined" && (tempname=='designersdirectory' || (isDesigner && isDesigner == 'yes'))){ location.href = location.protocol+"//"+location.host+"/life-style/fashion/designer-directory?query="+sq; }else{ location.href = location.protocol+"//"+location.host+"/life-style/books/authors?query="+sq; } } } else{ var searchUrl = "/authorsdirectorylist_search.cms?query="+searchval.trim(); if(typeof tempname != "undefined" && (tempname =="designersdirectory" || (isDesigner && isDesigner == 'yes'))){ searchUrl = searchUrl + '&celeb=designer'; } $.ajax({ type: "GET", url: searchUrl, success: function(data){ $(".hintopt").html(data).show(); } }); } } else{ $(".hintopt").find('ul').hide(); } }); //if($(".authorsearchopen").is(":visible")) }); $(window).scroll(function(){ var lstele,ele,lengthreview= ''; lengthreview = $('#authordirlisting .reviewlisting').length; ele = $('#authordirlisting .reviewlisting').eq(lengthreview-2)[0]; lstele = $('#authordirlisting .reviewlisting:last-child'); if(authorsdirectory.isElementInViewport(lstele) && lstele.attr('data-isloading')== "true" && loadrunning == 0){ loadrunning = 1; var cpg = parseInt(lstele.attr('data-curpg')) + 1; var dataq = authorsdirectory.checkq(lstele.attr('data-q')); if(dataq=='all'){ authorsdirectory.getAllAuthor('all',cpg); }else{ authorsdirectory.getAuthorbyAlphabet(dataq,cpg); } } });