Div doesn't display when using jScrollPane() - php

This should be exceedingly simple, but here goes. I have a simple div container that gets populated by a Twitter feed (jTweetsAnywhere):
<div id='twitter-feed'></div>
This functionality works fine and gives me a simple container with a Twitter feed, with overflow:auto. Again: works fine, overflow is scrollable with the standard ugly scrollbar.
After loading jquery.jScrollPane.min.js, jquery.scrollpane.css, jquery.mousewheel.js, and mwheelintent.js, and initializing like so:
$(document).ready(function(){
. . .
$("#twitter-feed").jScrollPane();
});
...the #twitter-feed div no longer displays, and no runtime error is thrown.
Thoughts?

My initial guess is that .jsScrollPane() is getting called long before jTweets returns anything. This means that there is a good chance that it is setting the height of the container while its empty, so it probebly is set to 0. Have you tried to give #twitter-feed a static height?

Having the same exact issue..and viewing Chrome built in debugger i've found our problem and posted in the jscrollpane google group..I'm almost afraid we might have to alter jTweetsAnywhere code to get this to work correctly..If this is true, I'll do it and make sure I post the solution here and a link...in a nutshell:
jTweetsAnywhere dynamically creates this before your jScrollPane call:
<div id="twitter-feed">
<div class="jta-tweets-list">
<ul><li>tweet</li><li>tweet</li></ul>
</div>
</div>
After the jScrollPane call, your code inside the #twitter-feed container is modified to function like this:
<div id="twitter-feed">
<div class="jta-tweets-list">
<div class="jspContainer"><!-- I believe this is where the tweets <ul> needs to be loaded? --><div class="jspPane"></div></div>
<ul><li>tweet</li><li>tweet</li></ul>
</div>
</div>

jScrollPane.js has a nifty little method autoReinitialise, that when set to true basically adds a setInterval() that is constantly checking for the content within your target div.
Just make your call to jScrollPane AFTER your jTweetsAnywhere call:
$('.jta-tweets-list').jTweetsAnywhere({ stuff in here })
and pass it an object with autoReinitialise: true-
$('.jta-tweets-list').jScrollPane(
{
autoReinitialise: true
}
);
Hope this helps!

Related

Lazy load images on include content

I'm working on this [page][1]
The problem is that Homepage has a lot of items to show, so it loads really slow. The solution I found is to use lazy load on images (I'm using this plugin). It works on the left column (Which is not content included. You can see the images load as you scroll down) but it is not working with the items of the center and right columns which is the content I'm including.
I'm including the center and right column content this way:
<?php include("parts/backbone_tmpl_productos_main.php"); ?>
And this is the contents of the backbone_tmpl_productos_main.php file:
<script id="tmpl_Post" type="template">
<div class="image"><img src="<%= post_item.image_url.url %>" /></div>
<div class="obra_meta">
<span class="nombre_artista"><%
_.each(taxonomy_product_cat, function(item){
if(item.parent === 146){%><%= item.title %><% }
if(item.parent === 216){%><%= item.title %><% }
})
%></span>
<span class="nombre_obra"><%= title %></span>
</div>
<div class="descripcion_obra"></div>
<div class="buy_opts">
<?php if (ICL_LANGUAGE_CODE == 'en') {
echo '<div class="precio pull-left">From: 24.99 €</div>';
}else{
echo '<% if(price != "") {%><div class="precio pull-left"><%= price %></div><% } %>';
}
?>
<div class="pull-right"><button class="btn btn-default boton_comprar comprar"><?=__('COMPRAR');?></button></div>
</div>
</script>
I think the problem that the plugin doesn't work with the include content is because the content is loaded after the plugin loads.
Any idea what's the real problem? how can I fix it?
This wordpress plugin - https://wordpress.org/plugins/unveil-lazy-load/ uses the data-src attribute for lazy-loading. Hence,
Change
<div class="image"><img src="<%= post_item.image_url.url %>" /></div>
To
<div class="image"><img data-src="<%= post_item.image_url.url %>" /></div>
Reference - https://github.com/luis-almeida/unveil/blob/master/jquery.unveil.js
Lazy loading is a JavaScript (browser-side) effect. If has nothing to do with the "include" in PHP.
Basically PHP generates the page, including all includes, and passes to browser. Browser then executes JS and initiates lazy loading.[1] The exact method with how PHP generates the page is irrelevant.
Where the problem lies is most likely with the fact you have another script that appears to be positioning the "product" classes absolutely - presumable from the "datos" object you have in code. The datos script itself might be forcing the loading as otherwise it won't know the size in order to position them - check what's going on in this script.
Also, there's no guarantee what script is going to win; when your lazy-load script runs through all the products, finds they are "top 0" which is "above the fold" and so loads the images straight away. Then the datos script presumably then goes and positions those products below the fold, but it's too late, they are loading (if not already loaded). Can't be sure of the exact mechanics, but this is the most likely scenario.
Solution:
Firstly, check the datos script isn't forcing a load in order to position the item. If it is, do you really need them absolutely positioned? Why not let them flow, then you can remove the src as below? If you do need absolutely position, I think it's "tough".
Secondly: Assuming the datos script is not forcing a load, copy a bit of what coding-idiot suggested, and move the "src" into "data-src", but then you need to modify the lazy-load script to pull the image from there. The code references a "settings.data_attribute" but there is nothing in the documentation. A quick read suggests that setting "dettings.data_atribute" to "src" may work, or ask the developer how to use those settings. (You may also need settings-placeholder at the same time). But by moving out of "src" and into a data attribute you stop the browser from loading initially and let the script do it's job, because...
Finally: Add a timeout in the lazy-load script so it triggers after the other script that positions the products.
Other note: Plugins are great, but if you have this many, you'd probably be better off programming some of these yourself. They appear to conflict. Also, the lazy load plugin could be improved by storing/caching the $(element) jQuery object as opposed to repeatedly recreating it. You also have malformed HTML by adding scripts after the HTML closing tag. Some small improvements that may encourage you to dig deeper into exactly what is going on.
[1] Note: to avoid comments, this is simplifying things as it IS possible to get JS to start before the entire page is loaded; buy you have the include at the bottom of the body so argument is mute.
You could try to add later-reload-script to reload any failed to load
images, that sometime the server refuse to process the incoming request.
Here is the workaround that help me solved the problem.
Add below javascript snippet in your template or view page
function reload_img(idx, no_of_try)
{
console.log("Reload fired " + idx);
var MAX_RETRIES = 100;
var glob = true;
$.each($("img"), function(index, value){
if ( this.naturalWidth == 0)
{
$(this).attr("src", $(this).attr("src"));
console.log( $(this).attr('src'));
glob = false;
}
} );
if ( !glob && no_of_try < MAX_RETRIES )
setTimeout(function(){ reload_img(idx + 1, no_of_try + 1); }, 1500);
}
setTimeout(function(){ reload_img(1,1); }, 1500); // start the reload_img() here
The code simply checks if an element is loaded and rendered.
If not, then retry to load the image with max of 100 retries.

How to add alt text to an image inserted from PHP

I have an html file with this line:
<div >%%GLOBAL_ProductThumb%%</div>
and live it generates this:
<img width="200px" height="200px" alt="" src="[I removed the URL]">
In a PHP file, I see the variable being assigned on this line
$GLOBALS['ProductThumb'] = ImageThumb200x200($rowimg['imagefile']);
I don't know much about PHP, but how can I add fill the "alt" property with text? In what step/where would this occur? If this were Java I wouldn't have a problem figuring out how to set the property of an object, but I'm not quite sure what's going on here. If the context helps, it's custom shopping cart software designed for our business.
PHP has no standard means to add some HTML attribute to a HTML tag. All you can do is build the HTML code as a string, then printing out the string. Which is something your software does by grabbing some other variables, giving you little direct influence on the generated code.
That said, the only thing you can do is inspecting what exactly all those custom functions are returning. If you are lucky, you find the exact HTML code that will land on the page in the end somewhere. From there, it's just a matter of programmatically searching and replacing before handing the final string further down the line.
A jquery hack can do that for you. If you can penetrate that third party app. You can embed a Jquery code that can take care of it on DOM Ready event.
Example:
<script type="text/javascript">
$(document).ready(function(){
$("img[width='200px'][height='200px']").prop("alt", "Your ALT value");
})
</script>

Change DIV's height via JavaScript when word-wrap occurs

I don't even know whether this is possible, however, I am hoping that JavaScript could provide a solution to this problem. I have a DIV, that shows the title for each page within a WordPress template that I am working on.
<div class="grid-block" id="page">
<div id="page-info">
<h3>#<?php is_home() ? bloginfo('description') : wp_title("",true); ?></h3>
</div><!-- #page-info -->
</div><!-- .grid-block #page -->
The text that is called into the DIV comes in at various lengths, and sometimes over-exceeds the DIV. When the text exceeds the DIV, it wraps, just as it should, however, I am attempting to adjust the 'height' of this DIV, after a word is wrapped. I do not know if I could add some type of eventListener or something, however, pure HTML and/or CSS does not seem to have the components I need to solve this problem.
In addition, I understand that I 'could' use #media (media queries) to sort of emulate this effect, however, as far as I know, this can only be done in relation to the width of the Window, and I want the DIV to re-size 'only' when a string exceeds the width of this DIV. A demo of what I am attempting to do can be found at http://jsfiddle.net/justinbyrne001/SP3Q2/4/. I appreciate any comments, recommendations, and advice that anyone has regarding this matter. Thanks in advance.
Do you need the fix height on #page-info? If you just use padding:10, the div#page-info would automatically wrap around the text.

Preloading a DIV with image loading

I have a problem. I am working on a CMS, its name is Dolphin. In few words I have created a block that contains an heavy code (jQuery, javascript, php, HTML, images...etc..).
What I want to do is to show a loading image until the content of this block is fully loaded. So even if it could seem strange, I need a preload function for a DIV. I need to do it because if I do not use it I can see the div composing slowly, and that's terrible. Do you know a good jQuery or javascript function that can help me with this? Just a loading image in the center of the DIV until its content is fully loaded. As soon as it is loaded then it will be shown.. Thank you!
The trick is setting the real div hidden by default and above it put the "Please wait" div.. in the end of the heavy coding add a line hiding the "Please wait" div and showing the real one.
Sample code for the required HTML:
<div id="pnlPleaseWait">
Loading please wait...
<div>
<div id="pnlMain" style="display: none;">
....heavy stuff going on here...
....heavy stuff going on here...
....heavy stuff going on here...
</div>
And the jQuery lines in the end of heavy processing:
$("#pnlPleaseWait").hide();
$("#pnlMain").show();
Check others questions:
How to show loading spinner in jQuery?
How do I display an animated image during Page Load using jQuery
and so on

"Body Onload" to send "ScrollHeight" not working properly in Chrome and Safari

I just asked a question here, about why an iframe_resize function wasn't working.
After troubleshooting, I found out that the problem is not the function, so I am posting a new question.
I have an index.html with this resize function:
function resize_iframe(new_height){
document.getElementById('iframe001').style.height=parseInt(new_height) + 20 + 'px';
}
Then I have a form in index.html with target set to an iframe, and action set to query.php:
<form action='query.php' target='iframe001'>
The in my query.php:
//ALOT OF PHP HERE
<body onload="parent.resize_iframe(document.body.scrollHeight)">
<?php echo $results_table; ?>
</body>
The problem is, in Chrome and Safari, the scrollHeight isn't changed at all.
In all other browsers, scrollHeight changes and the function works.
However, in Chrome/Safari, when clicking on a link anywhere on the page, and then clicking on the browser back button to return to the search results (iframe content), THEN the iframe is resized properly even in Chrome/Safari... ?
This is very strange behaviour for me.
Can somebody explain this?
Thanks
PS: I think this person has the same problem: iframe resizing with scrollheight in chrome/safari
Did you try offsetHeight property?
It seems there is a bug in general with webkit browsers. https://bugs.chromium.org/p/chromium/issues/detail?id=34224&can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=
WORKAROUND(!): I had margin applied to a wrapping element like this inside the iframe:
<div class="wrapper" style="margin-top: 30px"><!-- ... content --></div>
changed it to be instead:
<div class="wrapper" style="padding-top: 30px"><!-- ... content --></div>
then scrollHeight is correct :)

Categories