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

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();
});
});
}
);

Related

infinite scroll + isotope

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 });
});

Ckeditor Get Content From Iframe

I have a iframe and i'm trying to use Dialog to get data in Iframe and output to current html, but i don't know how to get Ckeditor Content from the Iframe.
I tried to using CKEDITOR.instances['editor'].getData(); but look like cannot get it.
This is my code:
<textarea class='editor' name='description' id='description'></textarea>
$( "#dialog_custom" ).dialog({
autoOpen: false,
modal: true,
height: 768,
width: 1024,
buttons: {
Add: function() {
var model = $('.dialog_custom').contents().find('#model').val();
var product_id = $('.dialog_custom').contents().find('#product_id').val();
var product_name = $('.dialog_custom').contents().find('#product_name').val();
var qty = $('.dialog_custom').contents().find('#qty').val();
var total = $('.dialog_custom').contents().find('#total').val();
var category = $('.dialog_custom').contents().find('#category').val();
if(qty=='') { qty = '0'; }
if(total=='') { total = '0.00'; }
if(model=='') {
alert('Please input the correct Model Number.');
} else {
$(".product").append(InsertTableGetFromIframe);
$('.delete_custom_row').click(function() {
if(confirm("Are you sure want to delete this data?")) {
$(this).parents('.custom_row').next('.parts_row').remove();
$(this).parents('.custom_row').remove();
}
});
$('.dialog_custom').contents().find('#model').val('');
$('.dialog_custom').contents().find('#product_id').val('');
$('.dialog_custom').contents().find('#product_name').val('');
$('.dialog_custom').contents().find('#qty').val('');
$('.dialog_custom').contents().find('#total').val('');
$('.dialog_custom').contents().find('#category').val('');
$(this).dialog("close");
i++;
}
},
Close: function() {
$(this).dialog("close");
}
}
});
$( "#open_custom" ).click(function() {
$( "#dialog_custom" ).dialog( "open" );
});
</script>
Finally, I found out the solution to get the content in the iframe, i used jquery to submit the form then POST the value on the field and get it by Jquery again.
It's the most simple way that i found, actually I think we have another way better to do it...

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

Passing "href" as data in jQuery UI tabs() through Ajax

I have some tabs (jQuery UI tabs) in the "index.php" of a page. This page not only shows content, but also retrieves the $_GET variable to show some other content below the tabs.
The problem is how to tell jQuery UI that the href (attr of the clicked ) is a value for the key "href" that has to send (GET) to the current index.php page, called in JS has window.location.pathname (I can't use PHP generated JavaScript).
The code is this, and i'm out of options for how to make things work.
jQuery('#front-tab').tabs({
spinner: "Loading...",
select: '#tab-one',
cache: true,
fx: { height: 'toggle', opacity: 'toggle' },
url: window.location.pathname,
ajaxOptions: {
type: 'get',
success: function(){alert('Sucess');},
error: function(){alert('I HAZ FAIL');};
},
dataType: 'html'
}
});
The HTML:
<div id="front-tab">
<ul>
<li><span>Home</span></li>
<li><span>Tab Content 1</span></li>
<li><span>Tab Content 2</span></li>
<li><span>Tab Content 3</span></li>
<li><span>Tab Content 4</span></li>
</ul>
<div id="tab-home">
content...
</div>
</div>
Yep, this gets me full of "I HAZ FAIL" every time I try to load other tabs. The first tab is inline HTML, but the rest is Ajax. url: window.location.pathname doesn't seems to work or point to the right direction. Well, I don't know if that does what I am looking for.
function initTabs(elementHref) {
jQuery('#front-tab').tabs({
spinner: "Loading...",
select: '#tab-one',
cache: true,
fx: { height: 'toggle', opacity: 'toggle' },
url: elementHref,
ajaxOptions: {
type: 'get',
success: function(){alert('Sucess');},
error: function(){alert('I HAZ FAIL');};
},
dataType: 'html'
}
});
}
jQuery('yourLink').on('click', function() {
initTabs(jQuery(this).attr('href'));
});
Well, after noting the inflexibility of jQuery UI Tabs I had to replicate the action on my own. Better yet, few lines of code compared to two plugins.
front_tab.click(function(e) {
// Content parent
tab_content = $('#tab-content');
// other variables
var tab_visible = tab_content.children('div.visible'),
span = $(this).children('span'),
span_value = span.html(),
value = $(this).attr('href'),
// This gets our target div (if exists)
target = tab_content.children(value);
// There is no anchor
e.preventDefault();
// Don't do nothing if we are animating or "ajaxing"
if (tab_content.children().is(':animated') || is_ajaxing) { return; };
// Put the "selected" style to the clicked tab
if (!$(this).hasClass('selected')) {
front_tab.removeClass('selected');
$(this).addClass('selected');
}
// If is target div, call it
if (target.length > 0) {
is_ajaxing = true;
span.html('Loading...');
tab_content.children().removeAttr('class');
tab_visible.slideUp('slow', 'swing', function(){
// Some timeout to slow down the animation
setTimeout(function() {
target.attr('class', 'visible').slideDown('slow');
if (value = '#tpopular') { update_postbox(); }
is_ajaxing = false;
span.html(span_value)
}, 400);
});
// So, the target div doesn't exists. We have to call it.
} else {
is_ajaxing = true;
span.html('Cargando...');
$.get(
window.location.pathname,
{ href : value },
function(data) {
tab_visible.slideUp('slow', 'swing', function(){
setTimeout(function() {
tab_content.children().removeAttr('class');
tab_content
.append(unescape(data))
.children(value)
.css('display', 'none')
.attr('class', 'visible')
.slideDown('slow');
if (value = '#tpopular') { update_postbox(); }
is_ajaxing = false;
span.html(span_value)
}, 800);
});
},
'html');
}
});
The next problem is to make a nice error warning, but that is the solution.

imagesLoaded method not working with JQuery masonry and infinite scroll

I've been using JQuery masonry and now I'm adding infinite scroll. There are images in nearly every masonry "brick" and before I was using infinite scroll the images loaded fine and everything was great. I added the next part of the javascript for the infinite scroll and added the imagesLoaded method inside but when the new bricks are appended they come out all piled on top. My assumption is that I am not adding the imagesLoaded method properly in the infinite scroll callback but I haven't been able to find my error. Here's the code
<script type="text/javascript">
$(function(){
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector : '.tile',
columnWidth : 240
});
});
var $container = $('#container');
$container.infinitescroll({
navSelector : ".flickr_pagination",
// selector for the paged navigation (it will be hidden)
nextSelector : "a.next_page",
// selector for the NEXT link (to page 2)
itemSelector : "div.tile"
// selector for all items you'll retrieve
},
// trigger Masonry as a callback
function( newElements ) {
var $newElems = $( newElements );
$container.imagesLoaded(function() {
masonry( 'appended', $newElems );
});
}
);
});
</script>
The first JQuery masonry call works fine and hasn't been touched. It's the second part where there seems to be a problem. Thanks for the help and let me know if you need more information.
Here's the answer
$(function(){
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector : '.tile',
columnWidth : 240
});
});
$container.infinitescroll({
navSelector : '.flickr_pagination', // selector for the paged navigation
nextSelector : 'a.next_page', // selector for the NEXT link (to page 2)
itemSelector : '.tile', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// trigger Masonry as a callback
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 );
});
}
);
});
The problem was I was calling .imagesLoaded() on $container in the infinite scroll callback function and I should have been calling it on $newElements.

Resources