Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Make loader flash so all resolutions get inView effect
- var LoaderPaused = false; // 'Pause' flashing loader when unnecessary (not paused by default)
- function checkLoader() {
- if(!LoaderPaused) {
- $('#Loader').is(':visible') ? $('#Loader').hide() : $('#Loader').show();
- } else {
- $('#Loader').hide();
- }
- }
- clearInterval(InventoryLoader); // Reset loader after cleared
- var InventoryLoader = setInterval(checkLoader, 500); // Loader will flash every 500ms
- // Get values of checked filters when 'selected'
- function GetFilter(event) {
- var filter = [];
- $('.' + event + ':checked').each(function() {
- filter.push($(this).val());
- });
- return filter;
- }
- function Inventory() {
- wtRange(); // Run jQuery UI function in Filters.js
- // When Loader is inView begin delegating paging [with filters]
- $(document).on('inview', '#Loader', function(event, isInView) {
- if(isInView) {
- var NextPage = parseInt($('#PageNo').val()) + 1; // Add 1 to the page number
- // Filters
- var ItemSearch = $('#ItemSearch').val();
- var minimum_wt = $('#wtMin').val();
- var maximum_wt = $('#wtMax').val();
- var shape = GetFilter('shape');
- var color = GetFilter('color');
- var enhancement = GetFilter('enhancement');
- var matching = GetFilter('matching');
- $.ajax({
- url: '/vendors/pages/Inventory/Pagination.php',
- type: 'POST',
- data:
- (ItemSearch == 0) ? {
- PageNo: NextPage,
- minimum_wt: minimum_wt,
- maximum_wt: maximum_wt,
- shape: shape,
- color: color,
- enhancement: enhancement,
- matching: matching
- } : {
- PageNo: NextPage,
- ItemSearch: ItemSearch
- },
- dataType: 'HTML',
- async: true,
- cache: false,
- error:
- function(strError) {
- if(strError == 'timeout') {
- alert('Seems like there was an error loading the next page.'); // Do something. Try again perhaps?
- }
- },
- success:
- function(data) {
- $('#PageNo').val(NextPage);
- $('#StoneContainer').append(data);
- // If each .Stone's data attribute's contents both match then hide #Loader
- $('.Stone').each(function(index, element) {
- // Elements found on Listing.php
- var TotalRowCount = $('[data-totalrows]').data('totalrows');
- var ListingCount = $('[data-listing]').data('listing');
- if(TotalRowCount != ListingCount) {
- LoaderPaused = false; // If there are more listings flash loader
- } else {
- LoaderPaused = true; // If there are no more listings hide loader
- }
- $('.Error').hide(); // Hide .Error so data doesn't show with .Error
- });
- // If data has .Error hide Loader
- if(data.indexOf('class="Error"') > -1) {
- LoaderPaused = true; // Hide the loader
- // Hide Loader after 500ms
- setTimeout(function() {
- $('#Loader').hide();
- }, 500);
- $('.Error').slice(1).remove(); // Only show once
- }
- },
- timeout: 3000
- });
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment