Video.js, Infinite Scroll, and Masonry: Videos do not load on newly loaded content - jquery-masonry

I am using infinite-scroll.js, video.js, and masonry.js. The first page loads correctly (i.e., images of videos load within video players within "pintrest-style" boxes. However, as the user scrolls down, only the pintrest-style" boxes load with empty video players (i.e., no images and videos do not play). I think I should be reinitializing video.js somehow, but I can't figure out how to do so properly with multiple videos. My js code is below. How would I get the newly loaded boxes to load video players?
$container.infinitescroll({
debug: false,
//extraScrollPx: 40,
bufferPx: 40,
navSelector : '#navigation', // selector for the paged navigation
nextSelector : '#navigation a', // selector for the NEXT link (to page 2)
itemSelector : '.masonry_object', // selector for all items you'll retrieve
loading: {
finishedMsg: null,
img: "img/loader.gif",
msg: null,
msgText: " ",
speed: 'fast',
}
},
// trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({display:"none"},{ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$container.masonry( 'appended', $newElems, true );
$newElems.show().delay(1000).animate({ opacity: 1 },1000);
$newElems.videojs("example_video_number", { "controls": true, "autoplay": false, "preload": "auto" });
});
}
);

Related

ZingChart how to modify node upon click/select

I am using ZingChart for a standard bar graph. I have the selected state for individual bars working as I would like but for one thing. Is there a way to show the value box (set to visible:false globally) to show just for the selected node when it is clicked/selected? I was able to make the value box for every node show in a click event I added to call an outside function using the modifyplot method but I don't see a similar method for nodes such as modifynode. If this is not an option, is there any way to insert a "fake" value box the markup of which would be created on the fly during the click event and have that element show above the selected node? Below is my render code for the chart in question. Thanks for your time!
zingchart.render({
id: "vsSelfChartDiv",
width: '100%',
height: '100%',
output: 'svg',
data: myChartVsSelf,
events:{
node_click:function(p){
zingchart.exec('vsSelfChartDiv', 'modifyplot', {
graphid : 0,
plotindex : p.plotindex,
nodeindex : p.nodeindex,
data : {
"value-box":{
"visible":true
}
}
});
var indexThis = p.nodeindex;
var indexDateVal = $('#vsSelfChartDiv-graph-id0-scale_x-item_'+indexThis).find('tspan').html();
updateTop(indexDateVal);
}
}
});
You'd probably be better off using a label instead of a value-box. I've put together a demo here.
I'm on the ZingChart team. Feel free to hit me up if you have any more questions.
// Set up your data
var myChart = {
"type":"line",
"title":{
"text":"Average Metric"
},
// The label below will be your 'value-box'
"labels":[
{
// This id allows you to access it via the API
"id":"label1",
"text":"",
// The hook describes where it attaches
"hook":"node:plot=0;index=2",
"border-width":1,
"background-color":"white",
"callout":1,
"offset-y":"-30%",
// Hide it to start
"visible":false,
"font-size":"14px",
"padding":"5px"
}
],
// Tooltips are turned off so we don't have
// hover info boxes and click info boxes
"tooltip":{
"visible":false
},
"series":[
{
"values":[69,68,54,48,70,74,98,70,72,68,49,69]
}
]
};
// Render the chart
zingchart.render({
id:"myChart",
data:myChart
});
// Bind your events
// Shows label and sets it to the plotindex and nodeindex
// of the clicked node
zingchart.bind("myChart","node_click",function(p){
zingchart.exec("myChart","updateobject", {
"type":"label",
"data":{
"id":"label1",
"text":p.value,
"hook":"node:plot="+p.plotindex+";index="+p.nodeindex,
"visible":true
}
});
});
// Hides callout label when click is not on a node
zingchart.bind("myChart","click",function(p){
if (p.target != 'node') {
zingchart.exec("myChart","updateobject", {
"type":"label",
"data":{
"id":"label1",
"visible":false
}
});
}
});
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<div id="myChart" style="width:100%;height:300px;"></div>

How to remove certain elements or elements with particluar class or ID in masonry?

Using this syntax to load Masonry items:
var msnry = new Masonry( "#container-div",
{
columnWidth: 300,
gutter: 10,
isFitWidth: true,
isAnimates: true,
itemSelector: '.items',
animationOptions:
{
duration: 600
}
});
On click of a button or link I need to remove some items with .sample or #sample and this syntax does not works.
msnry.remove('.sample');
How to resolve?
To remove masonry boxes with particular selector use this,
var remove=$('.sample'); // Use your removal class or ID here
msnry.remove(remove); // Attempting removal of the occurrences
msnry.reloadItems(); // Reload the layout

toggleClass odd behavior after infinite scroll and masonry load

Have a toggleClass on click that works fine for content loaded before infinite scroll and works fine on content appended to masonry after infinite scroll, but won't work any longer of previously loaded content.
For example//
Page Loads
<article></article>
<article></article>
<article></article>
(Toggle Class works fine on all above article elements)
but then add infinite scroll and appended masonry
load more article elements
<article></article>
<article></article>
<article></article>
(toggleClass works fine on the last loaded content, but not the article elements from page load.)
If done a third time,
<article></article>
<article></article>
<article></article>
(toggleClass works on above, and initial page loaded article elements, but not elements in the middle, which were the first elements loaded from infinite scroll)
I'm adding and removing an ID when element is clicked so ScrollTo works, and that seems to work fine all the time. So there is something off with the toggleClass().
Here is the code in the .js file.
jQuery(window).load( function() {
/**
Add ID to Genesis main.content
*/
jQuery('main.content').attr('id', 'grid');
/**
Adding div and class grid-sizer - utility element for Masonry to size correctly
*/
jQuery('main#grid article:first-of-type').before('<div class="grid-sizer"></div>');
/**
Initialize Masonry
*/
var $container = $('#grid');
$container.imagesLoaded(function(){
$container.masonry({
"itemSelector": "article",
"columnWidth": ".grid-sizer",
"animation": "true",
"isResizable": "true",
});
});
activeArticle();
});
function activeArticle() {
jQuery('article .entry-content a').click(function(event) {
event.preventDefault();
// Add id to clicked articles
jQuery(this).closest('article').attr('id','active');
// Add the giant class to resize element
jQuery(this).closest('article').toggleClass('giant');
jQuery('#grid').masonry();
jQuery('#grid').masonry('on','layoutComplete', function( msnryInstance, laidOutItems) {
jQuery('html, body').animate({
scrollTop: jQuery('#active').offset().top
}, 500);
jQuery('article').removeAttr('id');
});
});
}
Here is the code in the call back function for the WordPress Infinite Scroll Plugin.
var $newElems = jQuery(newElements).css({ opacity: 0 });
$newElems.imagesLoaded(function(){
$newElems.animate({ opacity: 1 });
jQuery('#grid').masonry( 'appended', $newElems, true );
});
activeArticle();
Ended up just writing another function and putting that in the call back. Here is the other function. This appears to work second, third, loads w/o issue.
function activeArticleInfinite() {
jQuery('#infscr-loading').nextAll('article').find('img').click(function(event) {
event.preventDefault();
// Add id to clicked articles
jQuery(this).closest('article').attr('id','active');
// Add the giant class to resize element
jQuery(this).closest('article').toggleClass('giant');
jQuery('#grid').masonry();
jQuery('#grid').masonry('on','layoutComplete', function( msnryInstance, laidOutItems) {
jQuery('html, body').animate({
scrollTop: jQuery('#active').offset().top
}, 500);
jQuery('article').removeAttr('id');
});
});
}

jQuery Masonry infinite scroll and picture overlap problems with my tumblr theme

I am new in programming(javascript) but I've done quite a research the past few days in order to make my tumblr theme work correctly. I know my question is common but as it seems I don't have enough knowledge to integrate correctly parts of code that were given in many similar examples.
My theme is supposed to override the "15 posts per page" limitation of tumblr and with an "endless scroll" option it should put all my posts (all of them pictures) in one endless page. Well, It doesn't. With a little help from here, I managed to wrap my {block:Posts} with the and with a couple of random changes in the masonry() call I ended up with this
As you can see my pictures are not overlapping (at last!) but after the 15 first posts it looks like a new page is created and the last pictures are not correctly aligned.
my jQuery masonry code is this:
<script type="text/javascript">
$(window).load(function () {
$('.autopagerize_page_element').masonry(),
$('.autopagerize_page_element').infinitescroll({
navSelector : "div.navigation",
// selector for the paged navigation (it will be hidden)
nextSelector : "div.navigation a#nextPage",
// selector for the NEXT link (to page 2)
itemSelector : ".autopagerize_page_element",
// selector for all items you'll retrieve
bufferPx : 10000,
extraScrollPx: 12000,
loadingImg : "http://b.imagehost.org/0548/Untitled-2.png",
loadingText : "<em></em>",
},
// call masonry as a callback.
function() { $('.autopagerize_page_element').masonry({ appendedContent: $(this) }); }
);
});
</script>
I know, its a mess...
Would really appreciate some help.
I'm not used to work with tumblr, but I can what is happening:
Line 110:
This script is creating a wrapper div around the entries each time you call to masonry, because of the script, each load looks like a new page, I think you can simply remove it.
Some tips:
You don't have to wait $(windows).load to execute masonry, change it by $(function()
To avoid image overlapping use appened masonry method and imagesLoad: Refer this
I see you're using masonry 1.0.1, be sure you're using masonry last version (2.1.06)
Example code:
$(function() {
//$('.autopagerize_page_element').masonry();
var $container = $('.autopagerize_page_element');
//wait until images are loaded
$container.imagesLoaded(function(){
$container.masonry({itemSelector: '.entry'});
});
$('.autopagerize_page_element').infinitescroll({
navSelector : "div.navigation",
// selector for the paged navigation (it will be hidden)
nextSelector : "div.navigation a#nextPage",
// selector for the NEXT link (to page 2)
itemSelector : ".entry",
// selector for all items you'll retrieve
bufferPx : 10000,
extraScrollPx: 12000,
loadingImg : "http://b.imagehost.org/0548/Untitled-2.png",
loadingText : "<em></em>",
},
// call masonry as a callback.
//function() { $('.autopagerize_page_element').masonry({ appendedContent: $(this) }); }
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
}
);
});
and be sure to remove the last script in this header block:
<script type="text/javascript" src="http://static.tumblr.com/imovwvl/dJWl20ley/jqueryformasonry.js"></script>
<script type="text/javascript" src="jquery.masonry.min.js"></script> <!-- last masonry version -->
<script src="http://static.tumblr.com/df28qmy/SHUlh3i7s/jquery.infinitescroll.js"></script>
<!--<script src="http://static.tumblr.com/thpaaos/lLwkowcqm/jquery.masonry.js"></script>-->
Hope it helps

Backbone events applied to an el that is an svg element

I have an SVG canvas with text that I would like to respond to clicks. The code below isn't getting the job done:
var MyView = Backbone.View.extend({
tagName : "text",
events : {
"click" : "clickhandler"
},
initialize : function() {
this.centerX = this.options.centerX;
this.centerY = this.options.centerY;
this.svg = this.options.svg;
this.tagText = this.model.get("tag_name");
this.render();
},
clickhandler : function(event) {
console.log("I was clicked!"); //This is not firing on click
},
render : function() {
this.el = this.svg.text(this.centerX, this.centerY, this.tagText, {});
return this;
}
});
This is being called in the render function of another view as such :
container.svg({
onLoad : function(svg) {
for ( var i = 1; i < that.relatedTags.length; i++) {
tagView = new MyView({
model : this.relatedTags.at(i),
centerX : 100,
centerY : 200,
svg : svg
});
}
container.append(tagView);
}
});
It shows up just fine and if I throw this in at the end of the for loop :
$(tagView.el).click(function() {
alert("xx");
});
Then the clicking works but I need to access the Backbone Model associated with the view so I'd much prefer the backbone event to a straight JQuery event.
The problem here is, that you set the element of the view in the render method. But backbone tries to add the events on initialization. So when backbone tries to add the events there is no element in you case. So either you have to start your view with your svg text, or you add the events by hand in your render method.
Maybe you can add the events on the svg itself and jquery is clever enough to handle the delegation. But I'm not sure in this case.

Resources