var loadedMore = false; $(function() { if(typeof(is_items_page) !== 'undefined' && is_items_page) { var filter = parseURI('filter').replace("#", ""); if (filter != "") { var tmp = []; filter.split(";").forEach(function (item) { var name = item.substr(0, item.indexOf("~")); var vals = item.substr(item.indexOf("~")+1); vals.split(",").forEach(function (val) { if (val != "") { $('#' + name + "_" + val).prop('checked', true); $('#M' + name + "_" + val).prop('checked', true); $('#button_' + name + "_" + val).show(); } }); }); filter_disable.split(",").forEach(function (item) { if($("#" + item).prop('checked')) { //do nothing } else { $("#" + item).attr("disabled", true).closest( "li" ).addClass("text-muted"); $("#M" + item).attr("disabled", true).closest( "li" ).addClass("text-muted"); } }); /* $(":checkbox").each(function() { if($(this).prop('checked')){ $("[id^=" + this.name.substring(0, this.name.indexOf("_")+1) + "]").attr("disabled", false); $("[id^=M" + this.name.substring(0, this.name.indexOf("_")+1) + "]").attr("disabled", false); } }); */ } $("[id^=button_]").click(function(){ $("#" + this.id.replace("button_", "")).removeAttr('checked'); go_to_search_results("refine25"); }); $('.dropdown-menu').on('click', function(e){ if($(this).hasClass('filter-dropdown')){ e.stopPropagation(); } }); var timer; $("#refine2 input[type=checkbox]").change( function() { try{ clearTimeout(timer); } catch(ex){} //submit_search_changes(); timer = setTimeout(function() {go_to_search_results("refine25");}, 3000); }); /* $("#refine input[type=checkbox]").change( function() { try{ clearTimeout(timer); } catch(ex){} //submit_search_changes(); timer = setTimeout(function() {go_to_search_results("refine35");}, 3000); }); */ $("#refine [id^=apply_]").click( function() { go_to_search_results("refine25"); }); $("#filter-apply").click( function() { go_to_search_results("refine35"); }); $("#refine [id^=reset_]").click(function(event){ event.preventDefault(); $("#refine [id^=" + this.id.substring(6) + "]").each(function(){ $(this).prop('checked', false); }); go_to_search_results("refine25"); }); $("#filter-clear").click(function(event){ $("#refine-mobile input[type=checkbox]").each( function() { $(this).prop('checked', false); }); go_to_search_results("refine35"); }); $("#refine-mobile input[type=checkbox]").change( function() { $("#filter-apply").show(); displayClear(); }); $("#show").change(function () { $("#per-page-txt").text($("#show").find(":selected").text()); $("#frmMain").submit(); }); $("#sortby-text").text($("#sortby").find(":selected").text()); $("#sortby").change(function () { $("#sortby-text").text($("#sortby").find(":selected").text()); $("#frmMain").submit(); }); $('.dropdown-menu input, .dropdown-menu label').click(function(e) { e.stopPropagation(); }); displayClear(); } function parseURI(val) { var result = "", tmp = []; location.href.split("&").forEach(function (item) { tmp = item.split("="); if (tmp[0] === val) result = decodeURIComponent(tmp[1]); }); if(result != "") return result; else { try { tmp = location.href.split("?")[1]; tmp = tmp.split("="); if (tmp[0] === val){ if(tmp[1].indexOf('&') !== -1) result = decodeURIComponent(tmp[1].split("&")[0]); else result = decodeURIComponent(tmp[1]); } return result; } catch (ex) { return result; } } } function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } function displayClear() { $("#refine-mobile input[type=checkbox]").each( function() { if($(this).prop('checked')) { $("#filter-clear").show(); return false; } else { $("#filter-clear").hide(); } }); } function go_to_search_results(formId) { $.ajax({ type: "POST", url: "/preowned/servers/search", data: $("#" + formId).serialize(), success: function (msg) { var href = window.location.href.replace("#", ""); if(href.indexOf("&filter") > -1) href = href.substr(0, href.indexOf("&filter")); if(href.indexOf("?filter") > -1) href = href.substr(0, href.indexOf("?filter")); if(href.indexOf("?") === -1) msg = msg.replace("&", "?"); window.location = href + msg; } }); } var lastCount = 0; $("#see-more").click(function () { $("#see-more").text("Loading More Watches..."); $("#see-more").prop('disabled', true); var page = 1; if(!isNaN(parseInt(getQueryVariable("page"))) && parseInt(getQueryVariable("page")) > 0) { /* page = parseInt(getQueryVariable("page")); window.history.pushState("", "", window.location.pathname + window.location.search.replace("page=" + page, "page=2")); */ } else { window.history.pushState("", "", window.location.pathname + "?page=2"); } getItems(true); }); function getItems(setLastCount) { $('li').removeClass("submenu-active"); $(".overlay-loader").show(); $.ajax({ url: window.location.href + (window.location.href.indexOf("?") === -1 ? "?" : "&") + "ajax=1", contentType: "application/json", success: function(result){ $("#see-more").hide(); if(lastCount === result.watches.length || result.watches.length % 4 !== 0) $("#see-more").hide(); if(setLastCount) lastCount = result.watches.length; else lastCount = 0; $("#items-thumbs").html(displayItems(result)); //$('h1').text($(result.h1).text()); document.title = document.title + " - Page 2"; $('meta[name=description]').attr('content', $('meta[name=description]').attr('content') + " Page 2"); $("#see-more").prop('disabled', false); $("#see-more").text("See More Watches"); setTimeout(function(){ $(".overlay-loader").hide(); }, 0); }, error: function (jqXHR, textStatus, errorThrown) { //console.log(textStatus); location.reload(); } }); } function displayItems(obj) { var itemsObj = obj.watches; var out = ""; for (var i = 0; i < itemsObj.length; i++) { out = out + '
'; } if(itemsObj.length >= 12 && itemsObj.length % 4 === 0) { //$("#see-more").show(); } else { $("#see-more").hide(); } return out; } //reload on back $(window).bind("popstate", function(e) { var state = e.originalEvent.state; if(state) { } else { location.reload(); } }); if(findBootstrapEnvironment()=== 'xs') { $(window).scroll(function() { var y_scroll_pos = window.pageYOffset; var scroll_pos_test = 5000; // set to whatever you want it to be if(loadedMore === false && y_scroll_pos > scroll_pos_test) { //alert("loading more"); $("#see-more").trigger("click"); loadedMore = true; } }); } }); function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i