infinite scroll + isotope - scroll

I need help: I use isotope with infinite scroll to display thumbnails for a gallery. Everything works when all items are displayed (without isotope filter). By cons, when one uses the isotope filter (that is to say at the opening of my page), animation to view thumbnails runs for all new elements even those that should be filtered !
In short: we see animation bits for each new item loaded, it expands and then shrinks, becoming opaque and hides, creating sparkles ...
How to disable and hide the animation from the beginning each new element that should be filtered?
Thanks for your help ! (sorry for my English)
/*Masonry*/
var $containermasonry = $('.masonry');
$containermasonry.imagesLoaded( function() {
$containermasonry.masonry({
itemSelector: '.item',
});
$containermasonry.isotope({
transitionDuration: '0.8s',
animationEngine: 'best-available',
itemSelector : '.item',
layoutMode : 'masonry',
filter : '.new',
getSortData: {
date: '[data-date]',
categories:'[data-categ]',
}
});
});
/*infinitescroll*/
$containermasonry.infinitescroll({
navSelector : '#page-nav',
nextSelector : '#page-nav a',
itemSelector : '.item',
loading: {
finishedMsg: '',
img: '_include/img/supersized/progress.gif'
}
},
function( newElements ) {
var $newElems = $( newElements ).css({'display': 'none', 'visibility': 'hide', opacity: 0});
$newElems.imagesLoaded(function(){
/*$newElems.animate({ opacity: 1 });*/
$containermasonry.infinitescroll('retrieve');
$containermasonry.masonry( 'appended', $newElems, true );
$containermasonry.isotope( 'appended', $newElems, true );
});
}
);
// filter items
var $optionSets = $('#options .option-set'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('.option-set');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
var filterValue = $(this).attr('data-option-value');
$containermasonry.isotope({ filter: filterValue });
});

It is difficult to answer well without a jsfiddle or link.
The big issue is that you are using calling masonry.js and isotope.js at the same time! They are two separate plugins, not designed to be used together. Isotope has a masonry layout which is where your confusion lies, it is not called with masonry.js. Choose one or the other.
Also, if your using isotope v2, animationEngine has been removed from that version.
Here is the code you should use for isotope use:
var $containermasonry = $('.masonry');
$containermasonry.imagesLoaded( function() {
$containermasonry.isotope({
transitionDuration: '0.8s',
itemSelector : '.item',
layoutMode : 'masonry',
filter : '.new',
getSortData: {
date: '[data-date]',
categories:'[data-categ]',
}
});
});
//infinitescroll
$containermasonry.infinitescroll({
navSelector : '#page-nav',
nextSelector : '#page-nav a',
itemSelector : '.item',
loading: {
finishedMsg: '',
img: '_include/img/supersized/progress.gif'
}
},
function( newElements ) {
var $newElems = $( newElements ).css({'display': 'none', 'visibility': 'hide', opacity: 0});
$newElems.imagesLoaded(function(){
//$newElems.animate({ opacity: 1 });
$containermasonry.infinitescroll('retrieve');
$containermasonry.isotope( 'appended', $newElems, true );
});
}
);
// filter items
var $optionSets = $('#options .option-set'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('.option-set');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
var filterValue = $(this).attr('data-option-value');
$containermasonry.isotope({ filter: filterValue });
});

Related

Load more posts with AJAX and also add pagination in URL

On load more button, posts load without page load using AJAX, but wanted to implement Wordpress pagination on load more along with URL changing. Suggestions are welcome.
/* Category/tag page Masonry Grid */
var $mgrid = $( '.post-grid' ).masonry();
$mgrid.masonry( {
itemSelector: '.post-outer',
} );
/* ------------------ Load More Posts Category/tag page ------------------ */
$( document ).on( 'click', '#post-button', function(e) {
e.preventDefault();
var offset = $( this ).attr( 'data-value' );
var cat = $( this ).attr( 'data-cat' ); //load more button attribute
var tag = $( this ).attr( 'data-tag' ); //load more button attribute
var page = $( this ).attr( 'data-page' ); //load more button attribute
var $content;
$.ajax( {
type: "post",
async: false,
dataType: "json",
url: localizeObj.ajaxurl, //localize script in functions.php
data: {
action: 'fetch_posts', //ajax load more function in functions.php
offset: offset,
cat: cat,
tag: tag,
page: page,
search_term: localizeObj.search_term,
current_page: localizeObj.current_page
},
beforeSend: function() {
},
success: function(response) {
/* Adding page numbers on ajax load more */
var pathname = window.location.pathname;
if ( response.success == 'yes' ) {
$content = $(response.posts);
$( '.post-masonry-grid' ).append( $content ).masonry( 'appended', $content );
page = parseInt(page) + 1;
offset = parseInt(offset) + 6;
$('.post-grid-outer').each( function() {
$('.post-grid-outer').addClass(offset);
});
$( '#post-grid-button' ).attr( 'data-value', offset );
$( '#post-grid-button' ).attr( 'data-page', page );
var page_num = '';
if(page <= 2) {
var page_num = 'page/'+ page;
} else {
var page_num = page;
}
window.history.pushState("URL", "Title", page_num); // Add page numbers to URL
} else {
$( '#post-button' ).hide();
}
},
complete : function() {
}
} );
} );

Ajax query not working after page is reloaded

I have 2 ajax query as below, and both the ajax query is working on the initial page loading, after loading data using 1st AJAX query the 2nd ajax query does not work after the page content is loaded, so request your help and advice as to home to resolve this issue such that both the ajax query works after every page load.
Ajax Query : 1
<script type="text/javascript">
$(document).ready(function(){
$("input[type='radio']").on('click', function(){
var radioValue = $("input[name='Gender']:checked").val();
var surl = '/fdata/' + radioValue;
var dsurl = encodeURI(surl, "UTF-8");
var hurl = '/Summary';
var dhurl = encodeURI(hurl, "UTF-8");
if (radioValue == "Male" ) { $('#DGender').load('dsurl #DGender'); };
if (radioValue == "Female" ) { $('#DGender').load('dsurl #DGender'); };
if (radioValue == "Summary" ) { $('#DGender').load('dhurl #summary'); };
});
});
</script>
Ajax Query : 2
<script type="text/javascript">
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('input[type=search]').val('');
$('#DGender thead tr').clone(true).appendTo( '#DGender thead' );
$('#DGender thead tr:eq(1) th').each( function (i) {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+'" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
} );
var table = $('#DGender').DataTable( {
ordering: false,
orderCellsTop: true,
fixedHeader: true,
filter: false,
searching: true,
info: false,
paging: false,
scrollX: "80vh",
scrollCollapse: false
});
} );
</script>
From,
Vino

adding event to image in EaselJS

I was hoping that I could get a little help with something I'm trying to do. I'm learning EaselJS, Extjs but still a little new. I'm trying to create an extJS window, inside the window I added a canvas which I use easelJS to manipulate. On a button1 I added an event handler that will overlay an image... what I am trying to do is make that overlayed image have events. In the long run I'd like to be able to highlight that image, and store the number of overlayed images from mouseclick onto that image.
here is my code
var stage;
var overlay;
var overImage;
var myImage;
var bgrd;
Ext.onDocumentReady( function () {
//var myImage = new createjs.Bitmap("dbz.jpg");
//stage.addChild(myImage);
//stage.update();
function setBG(){
myImage = new Image();
myImage.src = "dbz.jpg";
bg();
}
function bg(){
bgrd = new createjs.Bitmap(myImage);
stage.addChild(bgrd);
stage.update();
}
Ext.define('EaselWindow', {
width: 1000,
height: 750,
extend: 'Ext.Window',
html: '<canvas id="demoCanvas" width="1000" height="750">'
+ 'alternate content'
+ '</canvas>',
afterRender: function() {
this.callParent(arguments);
stage = new createjs.Stage("demoCanvas");
stage.onload = setBG();
}, // end after render func
listeners: {
click: {
element: 'body',
fn: function(){
var seed = new createjs.Bitmap("seed.jpg");
seed.alpha = 0.5;
seed.x = stage.mouseX-10 ;
seed.y = stage.mouseY-10 ;
stage.addChild(seed);
stage.update();
} //end addeventlistener
}
},
items:[{
itemId: 'button1',
xtype: 'button',
text: 'click the button',
visible: true,
enableToggle: true,
toggleHandler:
function(button, pressed){
if(button.pressed==true){
overImage = new Image();
overImage.src = "stuff.jpg";
overlay = new createjs.Bitmap(overImage);
stage.addChild(overlay);
stage.update();
}
else
{stage.removeChild(overlay);
stage.update();
}
}// end func
},{
itemId: 'button2',
xtype: 'button',
text: 'button2'
}]
}); // end define
Ext.create('EaselWindow', {
title: "Ext+Easel",
autoShow: true,
}); //end easelwindow
overImage.addEventListener("mouseover", function(){
overlay.alpha=0.7;
}); // this function isn't working
});
edit to add: itemId: 'button2',
xtype: 'button',
text: 'addSeed',
enableToggle: true,
handler: function(button, pressed){
if(button.pressed==true){
bgrd.addEventListener('click', function(){
seed = new createjs.Bitmap("seed.jpg");
seed.alpha = 0.5;
seed.x = stage.mouseX-10 ;
seed.y = stage.mouseY-10 ;
storex= seed.x;
storey= seed.y;
console.log(storex +","+ storey);
stage.addChild(seed);
stage.update();
})
}
} //end addeventlistener
but but once the button is pressed the ability to click remains on if w/ the if statement condition I don't understand why, is there a way to say else ( turn off)
You can add EventListeners in EaselJS as follows:
function bg(){
bgrd = new createjs.Bitmap(myImage);
bgrd.addEventListener('click', onClick);
stage.addChild(bgrd);
stage.update();
}
function onClick() {
console.log('bgrd was clicked.');
}
This is btw. very well documented in the EaselJS-docs: http://www.createjs.com/Docs/EaselJS/classes/EventDispatcher.html and there are tons of examples for this and most other cases you are looking for on Github at:
https://github.com/CreateJS/EaselJS/tree/master/examples
and
https://github.com/CreateJS/sandbox

WordPress remove manual Ajax trigger and use infinite scroll

I have a problem with my script. I want to remove the load more button and instead do an infinite scroll when I get to bottom of the page.
I'm using a WordPress template and without support I'm stuck on this nonsense.
What should I change to do to this script?
jQuery(document).ready(function($){
var $container = $('#hentry-wrapper');
// Isotope
// modified Isotope methods for gutters in masonry
$.Isotope.prototype._getMasonryGutterColumns = function() {
var gutter = this.options.masonry && this.options.masonry.gutterWidth || 0;
containerWidth = this.element.width();
this.masonry.columnWidth = this.options.masonry && this.options.masonry.columnWidth ||
// or use the size of the first item
this.$filteredAtoms.outerWidth(true) ||
// if there's no items, use size of container
containerWidth;
this.masonry.columnWidth += gutter;
this.masonry.cols = Math.floor( ( containerWidth + gutter ) / this.masonry.columnWidth );
this.masonry.cols = Math.max( this.masonry.cols, 1 );
};
$.Isotope.prototype._masonryReset = function() {
// layout-specific props
this.masonry = {};
// FIXME shouldn't have to call this again
this._getMasonryGutterColumns();
var i = this.masonry.cols;
this.masonry.colYs = [];
while (i--) {
this.masonry.colYs.push( 0 );
}
};
$.Isotope.prototype._masonryResizeChanged = function() {
var prevSegments = this.masonry.cols;
// update cols/rows
this._getMasonryGutterColumns();
// return if updated cols/rows is not equal to previous
return ( this.masonry.cols !== prevSegments );
};
var loadMore = $('#load-more');
var posts_per_page = parseInt(loadMore.attr('data-perpage'));
var offset = posts_per_page;
var totalPosts = parseInt(loadMore.attr('data-total-posts'));
var author = parseInt(loadMore.attr('data-author'));
var category = parseInt(loadMore.attr('data-category'));
var tag = loadMore.attr('data-tag');
var datemonth = loadMore.attr('data-month');
var dateyear = loadMore.attr('data-year');
var search = loadMore.attr('data-search');
var loader = $('#posts-count').attr('data-loader');
if (!author) author = 0;
if (!category) category = 0;
if (!tag) tag = '';
if (!datemonth) datemonth = 0;
if (!dateyear) dateyear = 0;
if (!search) search = '';
// cache jQuery window
var $window = $(window);
// start up isotope with default settings
$(window).load(function(){
reLayout();
$window.smartresize( reLayout );
if (offset < totalPosts) {
$('#nav-pagination-load-more').fadeIn(200);
mega_initLoadMore();
}
});
function reLayout() {
var mediaQueryId = getComputedStyle( document.body, ':after' ).getPropertyValue('content');
// fix for firefox, remove double quotes "
//mediaQueryId = mediaQueryId.replace( /"/g, '' );
//console.log( mediaQueryId );
var windowSize = $window.width();
var masonryOpts;
// update sizing options
switch ( mediaQueryId ) {
case 'large' :
masonryOpts = {
gutterWidth: 0
};
break;
case 'big' :
masonryOpts = {
//columnWidth: 297,
gutterWidth: 0
};
break;
case 'medium' :
masonryOpts = {
//columnWidth: 269,
gutterWidth: 0
};
break;
case 'small' :
masonryOpts = {
//columnWidth: $container.width() / 4,
gutterWidth: 0
};
break;
case 'tiny' :
masonryOpts = {
//columnWidth: $container.width() / 1,
gutterWidth: 0
};
break;
}
$container.isotope({
resizable: false, // disable resizing by default, we'll trigger it manually
itemSelector : '.type-post',
transformsEnabled: false, // Firefox Vimeo issue
masonry: masonryOpts
}).isotope( 'reLayout' );
}
function mega_initLoadMore(){
loadMore.click(function(e) {
$(this).unbind("click").addClass('active');
$('#posts-count').html('<img src="'+ loader +'"/>');
e.preventDefault();
mega_loadMorePosts();
});
}
function mega_reLayout(){
$container.isotope( 'reLayout' );
}
function mega_loadMorePosts(){
jQuery.ajax({
url: megaAjax.ajaxurl,
type: 'POST',
data: {
action : 'mega_ajax_blog',
nonce : megaAjax.nonce,
category: category,
author: author,
tag: tag,
datemonth: datemonth,
dateyear: dateyear,
search: search,
offset: offset
},
success: function( data ) {
var $newElems = $(data);
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded( function(){
// FitVids
$('.fluid-video, .entry-content', $newElems).fitVids();
$container.append($newElems).isotope( 'appended', $newElems );
// Flex Slider
$('.flexslider', $newElems).flexslider({
animation: "fade",
slideshow: false,
keyboard: false,
directionNav: true,
touch: true,
prevText: "",
nextText: ""
});
setTimeout(function(){
mega_reLayout();
}, 1000);
offset = offset + posts_per_page;
loadMore.removeClass('active');
if (offset < totalPosts){
$('#posts-count').text('');
loadMore.bind("click", mega_initLoadMore());
}
else {
setTimeout(function(){
loadMore.parent().remove();
}, 1000 );
}
});
}
});
return false;
}
});
I think this script is taken from "HEAT WORDPRESS THEME" directly which is located in js folder of the theme. Its simple to modify,you just need to remove Ajax post loading function and keep Isotop initializing function only. For help see this link
http://www.shambix.com/en/isotope-twitter-bootstrap-infinite-scroll-fluid-responsive-layout/

$newElems.imagesLoaded is not a function When I using lightbox in Masonry

I am making a music sharing website like pinterest.
I use Masonry to make the grid layout and Infinite-Scroll load the next page. When I click a music album, it pops a lightbox (using fancybox) and loads some information with ajax.
On the first page, everything goes right. But after I click one music album, closed it and scrolled down the page, the new loaded part has this problem: $newElems.imagesLoaded is not a function
I'm not sure how to fix this.
Any help will be appreciated!
Here is my code:
var $container = $('#container');
// masonry init
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.item',
columnWidth: 100
});
});
// ancybox fancybox
function init(){
$("a.inline").fancybox({
'transitionIn' : 'fade',
'transitionOut' : 'none',
'speedOut' : 0,
'hideOnOverlayClick': true,
'hideOnContentClick': false,
'overlayColor' : '#FFF',
'overlayOpacity' : 0.5,
'showCloseButton' : true,
'showNavArrows' : false
});
}
init();
$container.infinitescroll({
// infinitescroll init
navSelector : '#page-nav',
nextSelector : '#page-nav a',
itemSelector : '.item',
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// infinitescroll callback
function( newElements ) {
var $newElems = $( newElements ).css({ opacity: 0 });
$newElems.imagesLoaded(function(){
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, {
isAnimated: false
}, function () {
// for new loaded part
init();
});
});
}
);

Resources