Вы находитесь на странице: 1из 8

window.

$ = function(selector) {
var selectorType = 'querySelectorAll';

if (selector.indexOf('#') === 0) {
selectorType = 'getElementById';
selector = selector.substr(1, selector.length);
}

return document[selectorType](selector);
};

function slideup(find){
element = document.querySelector(find);
element.className = "animate slideup";

}
function moveDown(element) {
if(element.nextElementSibling)
element.parentNode.insertBefore(element.nextElementSibling, element);
}
var jek ="";
var isnew = 2;
var mozx = "";
var con = document.getElementById('content');
var hidenewz = document.getElementById('hidenewz');
var gz = document.getElementById('gz');
function load_home(e){
// e.preventDefault();
document.getElementById("navrbar").innerHTML = "";
document.querySelector('#selectone').style.display='none';
document.querySelector('.left').classList.add('showed');
document.querySelector('#loader').style.display='block';
document.querySelector('.right').classList.add('showed');
document.querySelector('#hero').classList.add('fixed');
document.querySelector('#tobet').classList.add('fillup');
closeAllLists();
con.innerHTML = "";
hidenewz.innerHTML = "";
document.querySelector('#spcl').classList.add('box-closed');

document.querySelector('.trends').classList.add('box-closed');
con.innerHTML = "<div class=\"loadingna\" id=\"gz\"><span class=\"loadingnaimg
abg\"></span><span class=\"loadingnat1 abg\"></span><span class=\"loadingnat2
abg\"></span><span class=\"loadingna3 abg\"></span></div>";
jek = document.getElementById('se').value;
isnew = 1;
window.location.hash='searchvalue='+encodeURIComponent(jek);

document.querySelector('#se').className ='hide';

var xhr = new XMLHttpRequest();


xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4 && xhr.status == 200) {
document.getElementById('se').blur();
con.innerHTML += xhr.responseText;
if(xhr.responseText != "") {
moveDown(document.getElementById('gz'));
moveDown(document.getElementById('gz'));
}
load_more();

}
}

xhr.open("GET","all/sig.php?req=1&q="+encodeURIComponent(jek), true);
xhr.setRequestHeader('Content-type', 'text/html');
xhr.send();
document.getElementById('se').blur();

return false;
}

window.onhashchange = function () {
var hash = location.hash;
if(hash.indexOf("searchvalue") !== -1) {

hash = hash.replace(/#searchvalue=/g, '');


if(document.getElementById('se').value != decodeURIComponent(hash)) {

document.getElementById('se').value = decodeURIComponent(hash);
load_home(event);
}

else {

if(isnew !== 1) {

closedt("byhash");

}
}

} else {}

};

window.onload = function () {
var hash = location.hash;
if(hash.indexOf("searchvalue") !== -1) {

hash = hash.replace(/#searchvalue=/g, '');


if(document.getElementById('se').value != decodeURIComponent(hash)) {
document.getElementById('se').value = decodeURIComponent(hash);
load_home(event);
}

else {
console.log("elsefired");

if(isnew !== 1) {

closedt("byhash");

}
}

} else {}

};

function load_more(){

var xhr = new XMLHttpRequest();


xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4 && xhr.status == 200) {
// document.getElementById('se').blur();

// document.querySelector('#gz').classList.add('box-closed');
document.querySelector('#loader').style.display='none';
document.querySelector('#selectone').style.display='block';
hidenewz.innerHTML += xhr.responseText;
document.querySelector('#gz').classList.add('box-closed');
sortOut();
displaylabels();
// mozx += xhr.responseText;
}
}

xhr.open("GET","all/sig.php?req=2&q="+encodeURIComponent(jek), true);
xhr.setRequestHeader('Content-type', 'text/html');
xhr.send();
// document.getElementById('se').blur();
return false;
}

function zort(a, b) {
vaxz = +a.getAttribute("data-val") - +b.getAttribute("data-val");
if (vaxz >= 0){
return true;
} else {
return false;
}
}

function sortOut() {
var clzxp= document.getElementsByClassName('newz');
for (var i = 0; i < clzxp.length; ++i) {

var classname = document.getElementsByClassName('product-list');


for (var j = 0; j < classname.length; ++j) {
czx = classname[j];
zxa = clzxp[i];
if(zort(zxa,czx)) {
czx.parentNode.insertBefore(zxa, czx);
break;
} else {

}
}
}

}
function isInArray(value, array) {
return array.indexOf(value) > -1;
}
function displaylabels() {
var arrayof = [];
var dataElems = document.querySelectorAll("[data-store]")
for (var i=0;i<dataElems.length;i++) {
var storev = dataElems[i].getAttribute("data-store");
if(isInArray(storev,arrayof)) {} else {
arrayof.push(storev);
}
}

var navbar = '<div id="nav"><span data-valuee="all" class="thelok


active">All</span>';
for (i = 0; i < arrayof.length; i++) {
navbar += '<span data-valuee="' + arrayof[i] + '" class="thelok">' + arrayof[i]
+ '</span>';
}
navbar += '</div>';
document.getElementById("navrbar").innerHTML = navbar;
addlistnr();
addlistnr2();
}
function addlistnr() {
var inputsx = document.querySelectorAll(".thelok");
for (i = 0; i < inputsx.length; i++) {
inputsx[i].addEventListener('click', function() {
var value = this.getAttribute("data-valuee");
var inputsxz = document.querySelectorAll(".thelok");
for (i = 0; i < inputsxz.length; i++) {
inputsxz[i].classList.remove('active')
}
this.classList.add('active');
var dataElems = document.querySelectorAll("[data-store]");

for (var i=0;i<dataElems.length;i++) {


if(value == "all"){
dataElems[i].style.display="block";
}
else if( dataElems[i].getAttribute("data-store") != value) {
dataElems[i].style.display="none";
}
else {
dataElems[i].style.display="block";
}
}
});
}}
function closed(event) {console.log("eventd"); console.log(event);}
function closedt(byy) {
console.log("closedran " + byy);

if(byy !== "byhash") {


history.go(-1);
}

var target = document.getElementById("banner");


target.style.marginRight = '-10px';
setTimeout(function(){ target.style.marginRight= '-20px'; }, 40);
setTimeout(function(){ target.style.marginRight = '-50px';

}, 100);
setTimeout(function(){

target.style.display = 'none';
document.getElementById("banner2").innerHTML = "";
}, 190);

};

function addlistnr2() {
var inputsx = document.querySelectorAll("[data-store]");
for (i = 0; i < inputsx.length; i++) {
inputsx[i].addEventListener('click', function(e) {

if(e.target.classList.contains("buyit")) {
console.log(e.target.classList);
e.stopPropagation();
return true;
}
isnew = 2;
window.location.hash='back='+encodeURIComponent("justcheck");
var namenz = this.getAttribute("data-name");
var pricenz = this.getAttribute("data-price");
var storenz = this.getAttribute("data-store");
var imagenz = this.getAttribute("data-image");
var linknz = this.getAttribute("data-link");
var extranz = this.getAttribute("data-extra");

var newup = '<div class="image"><img tabindex="0" src="'+ imagenz +'"


onerror="this.onerror=null;this.src=\'placeholder.jpg\';"/></div><div
class="textan"><b>'+ namenz+'</b><span class="price">Rs. '+ pricenz +'</span><div
class="extrazz"><span title="store" class="sttr">'+ storenz +'</span><div
class="addfv" onclick="addlike(\''+ namenz+'\',\''+ pricenz+'\',\''+
storenz+'\',\''+ linknz+'\',\''+ imagenz+'\',event);">Save</div><br><small>'+
extranz +'</small><a href="'+linknz+ '">Buy Now</a>';

document.getElementById("closeit").addEventListener("click", closedt);

document.getElementById("banner2").innerHTML = newup;
var target = document.getElementById("banner");
target.style.display = 'block';
target.style.marginRight = '-80px';
setTimeout(function(){ target.style.marginRight= '-40px'; }, 40);
setTimeout(function(){ target.style.marginRight = '0px'; }, 80);
e.stopPropagation();
});

}}
function sortthis(AttrToSort,orderof,thetxt) {

Array.prototype.slice.call(document.querySelectorAll('.product-
list')).sort(function(a, b) {
if (orderof === 'H') {
return +b.getAttribute(AttrToSort) -
+a.getAttribute(AttrToSort);
}
if (orderof === 'L') {
return +a.getAttribute(AttrToSort) -
+b.getAttribute(AttrToSort);
}

}).forEach(function(a) {
a.parentNode.appendChild(a);
});
document.getElementById("wut").innerHTML = thetxt;
document.getElementById("buttonsid").style.display="none";
}

document.getElementById("sortbyy").onclick = function() {
(function(style) {
style.display = style.display === 'none' ? 'block' : 'none';
})(document.getElementById("buttonsid").style);

};

function addlike(name,price,store,url,image,el) {
if(el.target.classList.contains("activeit")) {
return true;
}
el.target.classList.add('activeit');
var objarry = [];
var fvrtslcl = localStorage.getItem("fvrtslcl");
if(fvrtslcl){
objarry= JSON.parse(fvrtslcl);
}
objarry.push({"ts": Date.now(),
"name":name,"price":price,"store":store,"url":url,"image":image});
localStorage.setItem("fvrtslcl",JSON.stringify(objarry));
fvrtslcl = JSON.parse(localStorage.getItem("fvrtslcl"));

}
function showrt(event) {
document.getElementById("rtmenu").style.display = 'block';
document.getElementById("overlayit").style.display = 'block';
}
function hidert() {
document.getElementById("rtmenu").style.display = 'none';
document.getElementById("overlayit").style.display = 'none';
closeAllLists();
}

function autocomplete(inp) {

var currentFocus;
inp.addEventListener("input", function(e) {
closeAllLists();
val = this.value;
if (!val || val.length < 3) { return false;}

var foo = document.createElement('div');


var txap = document.getElementById("txap");
foo.setAttribute('id', 'searchvals');
foo.setAttribute('class', 'aitems');
txap.appendChild(foo);
document.getElementById("overlayit").style.display = 'block';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4 && xhr.status == 200) {
var mtring = xhr.responseText;
var regexz = /-text-(.*?)-text-/mgi;

var matchesz = mtring.match(regexz);


for (i = 0; i < matchesz.length; i++) {
var a = document.getElementById("searchvals");
var matchnn = matchesz[i].split("-text-").join("");
var b = document.createElement("DIV");

b.innerHTML = "<strong>" + matchnn.substr(0, val.length) + "</strong>";


b.innerHTML += matchnn.substr(val.length);
b.innerHTML += "<input type='hidden' value='" + matchnn + "'>";

b.addEventListener("click", function(e) {
inp.value = this.getElementsByTagName("input")[0].value;
hidert();
load_home(e);

});
a.appendChild(b);

console.log(matchesz[i].split("-text-").join(""));
}

}
}
xhr.open("GET","suggest.php?q="+encodeURIComponent(val), true);
xhr.setRequestHeader('Content-type', 'text/html');
xhr.send();

});}
window.onload = function () {
var trendsx = document.querySelectorAll(".trnd");
for (i = 0; i < trendsx.length; i++) {
trendsx[i].addEventListener('click', function() {
var trendvalue = this.innerHTML;
document.getElementById('se').value = trendvalue;
load_home(event);
});
}
};

function closeAllLists(elmnt) {
/*close all autocomplete lists in the document,
except the one passed as an argument:*/
var aitems = document.getElementsByClassName("aitems");
var inp = document.getElementById("se");
for (var i = 0; i < aitems.length; i++) {
if (elmnt != aitems[i] && elmnt != inp) {
aitems[i].parentNode.removeChild(aitems[i]);
}
}
}
autocomplete(document.getElementById("se"));