Subversion Repositories SmartDukaan

Rev

Rev 15026 | Rev 15058 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15026 Rev 15042
Line 435... Line 435...
435
});
435
});
436
function setCookie(cname, cvalue, days) {
436
function setCookie(cname, cvalue, days) {
437
    var d = new Date();
437
    var d = new Date();
438
    d.setTime(d.getTime() + (days*24*60*60*1000));
438
    d.setTime(d.getTime() + (days*24*60*60*1000));
439
    var expires = "expires="+d.toUTCString();
439
    var expires = "expires="+d.toUTCString();
440
    document.cookie = cname + "=" + cvalue + "; " + expires;
440
    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
441
}
441
}
442
 
442
 
443
function getCookie(cname) {
443
function getCookie(cname) {
444
    var name = cname + "=";
444
    var name = cname + "=";
445
    var ca = document.cookie.split(';');
445
    var ca = document.cookie.split(';');
Line 530... Line 530...
530
$(document).on('click','.applyfilter',function(){	
530
$(document).on('click','.applyfilter',function(){	
531
	var brands = [];
531
	var brands = [];
532
	var brandnames = [];
532
	var brandnames = [];
533
	$('.filterbrand').each(function(){
533
	$('.filterbrand').each(function(){
534
		if($(this).prop('checked')){
534
		if($(this).prop('checked')){
535
			console.log($(this).parent().siblings('.brandname').html());
535
			// console.log($(this).parent().siblings('.brandname').html());
536
			brands.push($(this).val());
536
			brands.push($(this).val());
537
			brandnames.push($(this).parent().siblings('.brandname').html());
537
			brandnames.push($(this).parent().siblings('.brandname').html());
538
		}		
538
		}		
539
	});
539
	});
540
	if(brands.length==0){
540
	if(brands.length==0){
541
		$('#message').html('Please choose a few brands first').removeClass('hidden');
541
		$('#message').html('Please choose a few brands first').removeClass('hidden');
542
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
542
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
543
		return false;
543
		return false;
544
	}else{
544
	}else{
-
 
545
		setCookie('brandschosen', brands, 2);
545
		var url = $('#brandselecter').prop('action');
546
		var url = $('#brandselecter').prop('action');
546
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
547
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
547
		document.location = url+'&brands='+brands.join('^');
548
		document.location = url+'&brands='+brands.join('^');
548
	}	
549
	}	
549
});
550
});
Line 556... Line 557...
556
	$('#showallbrands').hide();
557
	$('#showallbrands').hide();
557
	var that = $(this);
558
	var that = $(this);
558
	$('li.brand').filter(function() { 
559
	$('li.brand').filter(function() { 
559
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
560
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
560
	}).removeClass('hidden','slow');
561
	}).removeClass('hidden','slow');
561
});
-
 
562
562
});
-
 
563
$(document).on('click','.brand',function(){
-
 
564
	var clicked = $(this);
-
 
565
	clicked.find('.filterbrand',0).prop('checked',true);
-
 
566
	// all the LIs above the clicked one
-
 
567
	var previousAll = clicked.prevAll();
-
 
568
 
-
 
569
	// only proceed if it's not already on top (no previous siblings)
-
 
570
	if(previousAll.length > 0) {
-
 
571
	// top LI
-
 
572
	var top = $(previousAll[previousAll.length - 1]);
-
 
573
 
-
 
574
	// immediately previous LI
-
 
575
	var previous = $(previousAll[0]);
-
 
576
 
-
 
577
	// how far up do we need to move the clicked LI?
-
 
578
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
-
 
579
 
-
 
580
	// how far down do we need to move the previous siblings?
-
 
581
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
-
 
582
 
-
 
583
	// let's move stuff
-
 
584
	clicked.css('position', 'relative');
-
 
585
	previousAll.css('position', 'relative');
-
 
586
	clicked.animate({'top': -moveUp});
-
 
587
	previousAll.animate({'top': moveDown}, {complete: function() {
-
 
588
	  // rearrange the DOM and restore positioning when we're done moving
-
 
589
	  clicked.parent().prepend(clicked);
-
 
590
	  clicked.css({'position': 'static', 'top': 0});
-
 
591
	  previousAll.css({'position': 'static', 'top': 0}); 
-
 
592
	}});
-
 
593
	}
-
 
594
})
-
 
595
$(document).on('click','.clearfilters',function(){
-
 
596
	setCookie('brandschosen', '', -1);
-
 
597
	document.location.reload();
-
 
598
});
-
 
599
function selectChosenBrands(){
-
 
600
	var brandschosen = getCookie('brandschosen');
-
 
601
	if(brandschosen && brandschosen.length>0){
-
 
602
		var brands = brandschosen.split(',');
-
 
603
		for(var i in brands){
-
 
604
			$('.brand').filter(function() { 
-
 
605
			  	return $(this).data("brandid") == brands[i];
-
 
606
			}).trigger( "click" );
-
 
607
		}
-
 
608
	}
-
 
609
}
-
 
610
563
611