jQuery removeClass re-renders video player in Firefox - javascript

I have this most annoying issue with removeClass in Firefox.
I am using it to change some of the elements on the page so that when I resize my player the layout looks good. I am using JW player API to resize the player using the jQuery click method, then it starts playing automatically or from the position it was at.
Now all of that works perfectly in IE (surprising), Chrome, Opera, Safari. It's seemless with no hiccup. But Firefox will reinitialize the player and it starts over. I have a removeClass that I perform on a div that surrounds the player. If I take that out, Firefox does what it's supposed to do. I have to use the removeClass to realign my layout. It works fine with addClass, just not with removeClass.
Any ideas why it won't work with removeClass() properly?
Below is my code how I want it to work and it does for EVERY browser but FF.
jQuery(document).ready(function(){
jQuery("#expand").live("click",function(event){
var time = jwplayer().getPosition();
var cont = $('#lcontents').html();
$('#tleft').html(cont);
$('#pleft').addClass("centerText videoWide");
$('#pleft').removeClass("column-video-left");
$('#lcontents').html("");
$('#tleft').addClass("column-video-left");
jwplayer().resize("854","480");
if(time > 0){
jwplayer().onReady(function() {
jwplayer().seek(time);
});
}else if(time < 1){
jwplayer().play();
};
event.preventDefault();
});
});
Edit- The code below is the html
<div id="pleft" class="column-video-left">
<div id="rsplayer" class="video">jwplayer code renders here</div>
<div id="expand" style="text-align:center">Expand Player</div>
<div id="lcontents">
regular html code here.... which gets moved to div tleft
</div>
</div>
<div id="expand1"></div>
<div id="tleft"></div>

Have you tried manually modify the class attribute and seeing if that works?

It's possible this is a known bug in Firefox 3.6. You could try it in the Firefox 4 release candidate and see if you still have the same problem. If you don't, then someone who's good at doing Bugzilla searches could figure out what the bug was, and whether the fix will be backported to the 3.6 branch.

Related

Safari Scrolling issue with jQuery .remove()

I'm developing a plugin for a website building program, and am building the preview page for it. It's sort of a parallax scrolling plugin and the issue I'm having is that in Safari, when you scroll down to a certain point, it wont allow you to scroll any further. It's fine in firefox and chrome, but I saw the same issue in opera. I've managed to narrow it down to the function that's causing it, but I have no idea why or how to fix it.
When I comment out this function, the page scrolls fine, but it doesn't remove the empty divs like I need it to do:
function removeStuff() {
$('.conP').each(function(){
var divDad = $(this),
divses = $(this).children();
if (divses.hasClass('empty'))
divDad.remove();
});
}
here's the preview page where the issue can be observed:
http://reveriesrefined.com/myftp/dack_stev/
//////////EDIT:
I've simplified the code to this:
$('.conP_%id% > .empty').parent().remove();
however, it's still causing scrolling issues in safari and opera, but not the other browsers.
Any help is VERY VERY appreciated!
Actually, I found the issue already. Somehow even though commenting out the function mentioned above seemed to solve it, it was actually a line of code in another function.
I had this function:
function autoPlay() {
var backDiv = $('#outterLax div:first');
backDiv.hide();
$('.conP').hide();
backDiv.remove();
$('#outterLax').append(backDiv);
backDiv.show();
}
but the line:
$('.conP').hide();
was unnecessary as that was already being accomplished elsewhere in my code.

Setting an image source via Javascript unreliable in Internet Explorer

I am simply trying to change the SRC attribute of an image via javascript like so:
document.getElementById('fooImage').src = img;
Where img is a variable that has a link to the file.
In all other browsers (Chrome, Firefox, Safari) this works. In IE (7+) this also works too sometimes.
Using IE's built-in developer tools, I can see that the image's SRC tag is set. Is there something else in the locals window that could help me debug why the image doesn't actually show on screen?
I've also tried using jQuery to do this and same outcome:
$("#fooImage").attr("src", img);
An ideas?
In debugging this I would hard code it first...
document.getElementById('fooImage').src = "myimage.png";
I've used the following in my website and it works like this...
var imgCounter = document.getElementById('formtimer');
imgCounter.src = "graphics/odometers/1.png";
Some other things to check:
Make sure your ID= tag is not in the <DIV section but inside the <IMG section... for example <div class="style1"><img src="yourpicture" id="someid">. If `id='someid' is in the div tag then you can't change the picture / the picture won't show up.
are you using window.onload?, body onload? the proper way to use the first is..
window.onload = function () { YourFunctionHere(); };
Try a different test image. I had issues in the past with showing png's, I changed it to a gif or jpg and it worked. I don't understand how that was "way back" but it doesn't seem to be an issue anymore but hey... something to try.
try a full url
using https?
try sticking the image somewhere else in your program and see what happens.
try adding this to your HTML (put your website in place of mine - lookup BASE href on google for more info)
<BASE href="http://perrycs/" />
Make sure the image isn't hidden behind a layer (I know it works in some browsers)
tell us the website so we can check it out and get more info to help you in debugging this, seeing context (surrounding code) helps...
Given that it works in other browsers, searching on this topic it seems that often the problem is how IE caches images (ref. Epascarello's comment). Your code is the same as what I have - it works fine except in IE10.
I too, faced this conundrum. Then discovered that it works in 'Page Inspector', so after some digging discovered that (in Internet Explorer) by going to Tools.Internet Options.Advanced
uncheck the 'Disable script debugging (Internet Explorer)' and the one below it.
I found that with IE9 after changing an image.src with
var strVar="C:Users/x/Desktop/caution.png"
image.src=strVar
and calling an alert(image.src) I would get something like this n the alertbox:
file:///C:Users/x/Desktop/"C:Users/x/Desktop/caution.png"
So I tried
image.src=strVar.replace(/\"/g,"")
to remove qoutemarks
and it worked!
alert(image.src)
file:///C:Users/x/Desktop/caution.png

Why does IE8 hangs on jquery window.resize event?

I discovered a problem that seems to reproduce always when opening a piece of html and javascript in IE8.
<html>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(window).resize(function() {
console.log('Handler for .resize() called');
});
});
</script>
<div id="log">
</div>
</body>
</html>
Loading this file in IE8 and opening Developer Tools will show that the log message is printed continuously after one resize of the browser window.
Does anyone has an idea why? This is not happening in IE7 or IE9, nor in other browsers (or at least their latest versions).
UPDATE
One solution to prevent the continuos trigger of resize() is to add handler on document.body.onresize if the browser is IE8.
var ieVersion = getInternetExplorerVersion();
if (ieVersion == 8) {
document.body.onresize = function () {
};
}
else {
$(window).resize(function () {
});
}
But this does not answer my question: is the continuous firing of resize() a bug in IE8?
If "show window contents while dragging" is switched on, you will be inundated with resize events. I guess you're testing IE8 on a separate Windows machine which has this effect enabled (Display Properties -> Appearance -> Effects...).
To counteract this, you can wrap & trap the resize events to tame them: http://paulirish.com/demo/resize
This article says Chrome, Safari & Opera suffer from this too.
I only see the issue you are describing if an element on the page is resized (as described in this question). Your example doesn't work for me, but I assume for you it is appending the console message in the log div that you have there, which means that it is resizing the div and triggering the window resize event.
The answer that Lee gave is correct, but the method in the link didn't work for me. Here's what I did:
var handleResize = function(){
$(window).one("resize", function() {
console.log('Handler for .resize() called');
setTimeout("handleResize()",100);
});
}
handleResize();
This way, the handler is unbound as soon as it fires, and is only re-bound after you've finished all your actions that might re-trigger a page resize. I threw in a setTimeout to provide additional throttling. Increase the value in case your scripts need more time.

IE8 breaking on hover of select box's options

Okay, so I have the following code that works fine in all browsers except IE..
$('input[title!=], select[title!=]').mouseenter(function(){
if ($(this).data('focused')!='y') {
$(this).data('t', this.title).data('focused', 'y');
this.title = '';
var pos = $(this).position();
$('body').append('<div id="toolTip" class="round-5 shadow-heavy"><img class="arrow" src="/images/bg/toolTip.png" alt="" />'+($(this).data('t'))+'</div>');
$('#toolTip').css('top',(pos.top+($(this).height()/2)-($('#toolTip').innerHeight()/2))+'px').css('left',(pos.left+($(this).innerWidth())+20)+'px');
}
}).mouseleave(function(){
if ($(this).data('focused')!='n') {
$(this).data('focused', 'n');
this.title = $(this).data('t');
$('#toolTip').remove();
}
}).focus(function(){if($(this).data('focused')!='y'){$(this).trigger('mouseenter');}}).blur(function(){if($(this).data('focused')!='n'){$(this).trigger('mouseleave');}});
Now, in IE if you open the select box and move your mouse over one of the options the box closes. What's causing it is the IE apparently doesn't count the dropdown box of options as part of the select element so it triggers the mouseleave event.
Does anyone know a fix around this?
IE in particular has a very bizarre implementation of <select>, since IE6 (possibly earlier) it was pulled in from winforms...which is also the reason it sits on top of anything but an <iframe> in older versions.
Unfortunately, events on or involving <option> elements are unreliable at best (like you're seeing)...and can't be trusted in IE. You could disable the behavior in IE, but that's about the only "fix" there is.
The all-out alternative is to replace the <select> completely, there are a few jQuery plugins out there that do this, check out this question for options around that.

iPhone Webkit jQuery strangeness: Can't update content

Running into the strangest problem on iPhone using jQuery with my WebViewController.
I have a div into which I append content:
<div id="thumbnails">
Here are your thumbnails:
<div id="mythumbs"></div>
</div>
The code looks like:
for (var i = 0; i < thumbs.length; i++) {
var item = thumbs[i];
$('<img class="imgthumb" />').data('url', item.Url).attr({
"src": item.Thumbnail.Url,
}).appendTo($('#mythumbs'));
};
Works great.
Then I switch to other divs ($('#thumbnails').hide(); $('#someotherdiv').show()), go on about my business, and eventually switch back to the thumbnails div.
At this point I can't seem to append any content to that div using jQuery anymore. I can remove just fine, but the append no longer works.
The exact same code works great on Firefox and Safari outside of the iPhone, but once in the embedded WebKit it fails.
If I modify the DOM directly using JavaScript it works, but if I use jQuery it fails:
var x = document.createTextNode('THE FIRST THING');
document.getElementById('thumbspage').appendChild(x);
$('#thumbspage').append('-- THE SECOND THING');
"THE FIRST THING" shows up but "THE SECOND THING" doesn't.
Any ideas? This thing is driving me nuts.
Finally found a work-around:
I was calling my objective-c function using window.location . It turned out if I added a setTimeout around the call to window.location everything started working again. I'm guessing calling window.location would immediately call the objective-C code, interrupting the javascript thread, leaving things in a bad state. By adding the setTimeout it allows the javascript thread to finish before jumping into the objective-C code. Or something like that.

Categories

Resources