Created
December 21, 2011 19:45
-
-
Save rickydazla/1507382 to your computer and use it in GitHub Desktop.
Shopify View All (wtf? seriously!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------View all button script----------------------------------------------*/ | |
var _PageUrls = []; | |
var _Index = 0; | |
function loadUrlInAjax(url,requestType,dataType,functionToBeExecutedBefore,functionToBeExecutedAfter){ | |
$.ajax({ | |
type: requestType, | |
url: url, | |
beforeSend: function(){ | |
//functionToBeExecutedBefore(); | |
}, | |
success: function(data){ | |
functionToBeExecutedAfter(data); | |
}, | |
dataType: dataType, | |
}); | |
} | |
var beforeSendFunction = function(){ | |
} | |
var displayData = function(data){ | |
var filteredData = $(data).find(".collection"); | |
filteredData.insertBefore( $("#product-list-foot") ); | |
$('li.more').each(function(){ | |
$(this).remove(); | |
}); | |
_Index ++; | |
//Load Next page if available | |
if(_Index < _PageUrls.length){ | |
initUrlLoader(_PageUrls[_Index]); | |
} | |
} | |
$('.view-all').click(function(){ | |
loadAllUrls(); | |
var url = _PageUrls[_Index]; | |
initUrlLoader(url); | |
$('#pagination').remove(); | |
}); | |
function initUrlLoader(url){ | |
var requestType = 'GET'; | |
var dataType = 'html'; | |
loadUrlInAjax(url,requestType,dataType,beforeSendFunction,displayData); | |
} | |
function loadAllUrls(){ | |
var currentPage = getQueryVariable('page'); | |
var maxPageNumber = 2; | |
var maxPageUrl = ''; | |
$('#pagination a').each(function(){ | |
var currentValue = parseInt($(this).text()); | |
if(currentValue > 0 && currentValue > maxPageNumber){ | |
maxPageNumber = currentValue; | |
maxPageUrl = $(this).attr('href'); | |
} | |
}); | |
var urlFormat = maxPageUrl.substring(0,maxPageUrl.indexOf("=")+1); | |
var j=0; | |
for(var i=1;i<maxPageNumber + 1;i++){ | |
if(currentPage != i){ | |
_PageUrls[j] = urlFormat + i; | |
j++; | |
} | |
} | |
} | |
function getQueryVariable(variable) { | |
var query = window.location.search.substring(1); | |
var vars = query.split("&"); | |
for (var i=0;i<vars.length;i++) { | |
var pair = vars[i].split("="); | |
if (pair[0] == variable) { | |
return pair[1]; | |
} | |
} | |
return 1; | |
} | |
/*------------------------End view all button script----------------------------------------------*/ | |
$(document).ready(function () { | |
attachClickEvent(); | |
}); |
getting error on attachClickEvent(). Can you please help how to resolve it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Superceded by this repo: https://github.com/Tricky3/Shopify-AJAX_paginate