fancybox disable image preloading - fancybox

Started to try out this fancybox3 plugin to zoom thumbnail images in our app that works perfectly on desktop and mobile browsers.
In the app where the cart has thumbnail images of the products added to it that can be purchased. If I remove a product(image of it)from the cart, it gets removed from the cart, however, if I zoom one of the remaining product images of the cart and navigate through it, still showing the removed product there. I am expecting to see only the product images present in cart.
I tried using the preload: 0 option but that does not work for me. Fancybox is initiated in following way
$('[data-fancybox="images"]').fancybox({
idleTime : false,
loop: true,
transitionEffect : "fade",
animationDuration: 333,
buttons: [
'close'
],
protect: true,
infobar: false,
preload: 0
});
Any help to make this work is really appreciated.
Thank you

Looks like you have misunderstood the concept of "preloading". The script preloads images before displaying, but what that means is that it is showing loading icon before displaying full image. If you disable preloading and provide dimensions (width/height) of full image, then the script will display thumbnail image while full image is loading. This is a great feature if you want to make your app/webpage look more interactive (e.g., user would not stare at black overlay with loading icon but will see something useful instead).
But what you have described sounds like "caching" and fancyBox is not caching dom elements. So, if you see something in the gallery, that means that corresponding element exists in your page.
So, make sure that your product is actually removed from the dom or try to tweak the selector to match only "actual" products using "selector" option, e.g., something like:
$().fancybox({
selector : '.fancybox:not(.removed)'
});
Obviously, you should tweak this to suit your needs. Since you have not provided any details, I can not create a full example.

#Janis, Thank you so much for the clarification on 'preloading' concept.
You were right about dom still holding the removed item. Upon removal, the div is simple being set as display none.
First, I added code to remove the div form the dom but that resulted in page getting refresh which we don't want.
Next tried, the selector option and it worked perfectly.
function hideCartItem(id) {
var divItem = document.getElementById("divCartItem" + id);
var elem = "#divCartItem" + id
if (divItem != null) {
$(elem).hide();
$(elem).remove();
// added code
$('[data-fancybox="images"]').fancybox({
divItem: '.fancybox:not(.removed)'
});
}
}
Thank you so mcuh for your help. Much appreciated!!

Related

Protractor cannot select element on overlay

I'm having trouble locating elements on an overlay. I've tried locating via by.id and it still doesn't find the element. I tried element(by.id('some-element'));
I'm not sure how this overlay is generated but it does go underneath a header menu on top of the page when you scroll. Not sure if that'll help any. Its not an iframe.
One more thing. Its a drupal app and specifically on the add user overlay. I think there something special going on there. Can someone see if they have the same issue?
Any help would be appreciated. Thanks.
Since the overlay is inside an iframe, you first need to switch to it's context:
// wait for the frame to be present
var EC = protractor.ExpectedConditions;
var iframe = $("iframe.overlay-active");
browser.wait(EC.presenceOf(iframe), 5000);
// switch to the iframe
browser.switchTo().frame(iframe);
// do something
// get back to the main context
browser.switchTo().defaultContent();

Reduce initial load time - google web designer

We are developing some ads using google web designer tool
so far its good but one main issue with it is, slow loading.
its taking almost 3 seconds to load and we feel very bad about that.
can anyone know how to optimize it?
thanks.
In developing html5 banners, by default the 'polite load' is checked.
Which means you banner will not be visible and will not load until the page is loaded.
And when testing your banner, there is some moments before showing the banner to simulate the webpage load.
Why?
Because no publisher(Website) allows you to make their website slow. That is the rule. There is no way for you to force yourself to show first on a publisher website.
If you want this option. You should directly talk to the publisher/ when you get approval from them, you can uncheck 'Polite Load' when you are publishing your ad. Then your banner will show faster without any delay.
#cnu - I have experienced the same issue. The only workaround I have at the moment is to set an initial loading image - while the Ad is loading
Try adding a div with an ID of 'loading' immediately after your opening body tag.
<div id="loading" class="loading-image">
<img src="default.png"/>
</div>
Then find the following function, and set the div to block display
function handleDomContentLoaded(event) {
// This is a good place to show a loading or branding image while
// the ad loads.
document.getElementById('loading').style.display = 'block';
}
Then find the following function, and set the div to none - to hide the image after loading
function handleAdInitialized(event) {
// This marks the end of the polite load phase of the Ad. If a
// loading image was shown to the user, this is a good place to
// remove it.
document.getElementById('loading').style.display = 'none';
}
The official GWD instructions don’t match the functions actually generated in the source, which initially made this setup confusing. The code comments in the source indicate these are the correct functions to use. You can use the first frame of the Ad as the loading image, rather than a loading gif - so the user experience isn't affected too much.
Hope this helps.

Re-rendering Facebook plugins using FB.XFBML.parse

Is there a way to use FB.XFBML.parse without rendering the a Facebook plugin again which cause it to "flicker" (disappear et reappear).
Will be using the Facebook Like button or Facebook Recommandations Bar.
Live example: http://www.gablabelle.com/eve-d
Slide to view the flickering in the lower right corner.
$.address.state(ajax_object.path).crawlable(true).value(whereiam);
$(".fb-recommendations-bar").data("href",whereiamurl);
//$(".fb-like").data("href",whereiamurl);
fburl = $(".fb-recommendations-bar").data("href");
//fburl = $(".fb-like").data("href");
console.log(fburl);
FB.XFBML.parse();
Many thanks for your help.
You can limit the scope of the re-parse by passing in the parent DOM element to FB.XFBML.parse.
Add an opacticy layer over the top of the facebook plugin div when a "page change" is needed. Animate it to fully opaque. Call the FB.XFBML.parse() and give it a few moments to re-render. Animate the layer to non-opaque, then remove the opacity layer from over the top of the facebook plugin div (or leave it there for the next time you need to do a "page change" without actually reloading the page.
This technique will give you a gracefully disappearing/reappearing plugin, rather than a jarringly harsh "flicker".
Cache the Facebook likes of the previous slide + current slide + next slide on a slide change event. So that when you go to the next or previous one and its Facebook like should already be ready/loaded, the user should not see a flickering. Unless he/she goes to fast with the slides.
I've had this recently.
I got around it by wrapping the XFMBL in a variable... don't know why but without it it seemed to flicker... a total hack of a way to stop the flickering but worked for me!!
if(call == 0){
FB.XFBML.parse();
call = 1;
}
DMCS provided what seems to be the only half-proper answer, but it's butt ugly. You don't know how long it'll take on each persons web browser to render the stuff. The callback which supposedly says it's rendered doesn't work either. Also the flicker isn't seen in firefox but only in google chrome.

Images disappear when clicked on iPhone Safari

Ok, weird issue:
1) Go here on an iPhone (Safari browser): http://powellcreative.com/our-team/
2) Click any of the team images to get to the team member page
3) Click the back button on the browser
4) The image is disappeared on the Team page now
I know this question is kind of old, but I was looking for a solution to a similar problem and after searching, I found a solution. Hopefully this helps other people with the same problem. The problem is when you give iOS a javascript event like onmouseover or onmouseout it doesn't like it, mainly because when your finger is "mousing over" an element in iOS, you are actually clicking on it, so this is the solution I came up with that seems to reload images after hitting the back button in iOS.
Here it is:
Make sure all images are in their own separate div with a distinctive name.
Example:
<div name="div1"><img src="yourimage" onmouseover="javascript:this.src='yourimage2';" onmouseout="javascript:this.src='yourimage';"></div>
In the javascript head part of your page you want to insert this:
window.onpageshow =
function(event){
if (event.persisted){
//for every div and image you want changed back you can add a loop here to change all at once or just one div by name//
document.getElementById('div1').innerHTML = '<img src="yourimage" onmouseover="this.src="yourimage2";" onmouseout="this.src="yourimage";">';
}
}
This will check for page back since Mobile Safari uses bfcache and reload your image into the div. Hopefully this helps OP or someone else.

SIMPLIFIED: jqtouch mobile app ajax loading issue

In jqtouch and iui, what do you do if you want to follow a link like This is a FEED AND dynamically load the content of the <div id="feed-49"></div>?
I've tried bind/live a click handler onto the "a" and onto a parent "div" but it never gets fired, just the event for actually following the link. Thanks.
This is a simplified version of my other question:
jqtouch mobile app ajax loading issue
It depends whether you want the page pre-loaded or load-on-demand.
If you want it pre-loaded, you might want to fill in the page upon, say, $(document).ready:
$(document).ready(function(){
$('#feed-49').load('feed-49.html');
});
If you want it to load on-demand, you can listen to the pageAnimationStart event:
$('#feed-49').bind('pageAnimationStart', function(event, info){
if (info.direction == 'in')
$(this).load('feed-49.html');
});
You may want to read the jQTouch's documentation on callback events.
I just went through what you are going through and know exactly how to solve it. You need to turn that XML into JSON objects, which will be numbered [0],[1], etc.
This JQuery plugin works and rocks : http://www.fyneworks.com/jquery/xml-to-json/ Add that JS to your app. Your parse XML function will then convert the XML nodes you want (like item nodes within a channel) into JSON objects and then numbers the items.
So look how I then empty the current list of items, build a list of the items and add a custom CLICK function to the list items with a class of "sun" (i love jquery). That function then will add it's parent node title and desc to the divs that need it. The href will push it to the new jqtouch DIV which will handle all the detail info. Cool 'eh? Vote me up if this works. It did for me, like a charm.
function parseXml(xml)
{
$('#feedList').html('');
var rss = $.xml2json(xml);
$.each(rss.channel.item, function(i, item)
{
$('#feedList').empty().append('<li class=sun'+i'><a href=#contentDiv>'+item.title+'</a></li>');
$('.sun'+i).click(function() {
$('#titleDiv').empty().append(item.title);
$('#descDiv').empty().append(item.description);
});
});
};