darcy — 2010-03-12T17:21:29-05:00 — #1
The Class is being applied. Likewise, the styles ARE being applied to the elements when I look in the Web Inspector, but the styles don't actually change unless I check/uncheck a style within the inspector.
Has anyone come across this before? Is there some way I can trigger a refresh of the rendering?
No, sorry, I really can't share source code, but it's all fairly standard anyhow.
ryanreese — 2010-03-12T17:35:59-05:00 — #2
Well unless we see the code we won't know :). This could possibly be a JS issue though most likely CSS.
It's nearly impossible to tell without any source code or a link :).
markbrown4 — 2010-03-12T21:39:03-05:00 — #3
You are asking about Reflow / Repaint if you want to look it up.
Changing a class is such a common task there must be a simple error in the HTML / CSS, try validation.
darcy — 2010-03-15T08:42:56-04:00 — #4
I understand Ryan, but posting what amounts to hundreds of K worth of JS/CSS/HTML on the off chance that you'll find the offending line(s) before I do really isn't going to help much. Also might make the people I work for more than a little miffed.
Thanks Mark, that's what I expected but hadn't been able to track anything down yet. I'll just keep digging.
ryanreese — 2010-03-15T09:35:33-04:00 — #5
Wel even posting a link to a test page would help :). We can't debug otherwise .
darcy — 2010-03-15T09:46:15-04:00 — #6
Can't right now, it's still under lock and key in our development environment. If the bug persists once it's pushed out to production I'll link it up.
picnictutorials — 2010-03-15T10:07:05-04:00 — #7
jQuery val works just fine in Safari 4
darcy — 2010-03-15T10:42:57-04:00 — #8
Thanks Eric, but the site was built with Prototype, and the validation I'm using is custom. It does work in Safari, except when the form is within a lightbox. That's obviously the variable causing the problems, but wrangling position: and display: values does nothing - the usual fixes are ineffective at triggering a repaint.
picnictutorials — 2010-03-15T11:06:33-04:00 — #9
Your welcome. How is your lightbox form being called? Is the form in an outside page or hidden within the same page? I just did this, I went with the form in an outside page and poped up in the lightbox (mainly because I couldn't get it to work inside the page). It also worked in safari with jquery. Have you tested this live? Because when using js my safari only works sometimes live.
darcy — 2010-03-15T11:24:04-04:00 — #10
The lightbox is inserted into the DOM via JS once the page has finished loading. Since the lightbox is a fundamental tool on the app and there can be more than one link on a page that triggers the lightbox, it's content is loaded via AJAX after it's called. In this instance, everything loads and is inserted properly into the DOM.
Once I start filling out the form the validation performs as expected and the JS applies the appropriate classes to the broken form fields. If I check the Web Inspector the styles are being applied, but Safari isn't actually redrawing/repainting the elements themselves, so the background isn't changing color, text color isn't being applied, and some margins are being ignored. It seems to have trouble with styles that are being overridden by the new class (and before you asked, yes I've checked the cascade — the styles I want have the right specificity and according to the Web Inspector are the ones being show, but they actually aren't).
I can trigger a redraw/repaint by un/checking styles (related or not/on the offending DOM elements or not) within the inspector. But that's not good enough.
Short of throwing in some extra JS (like a display:none back to display:block flip) to trigger the repaint, do you have any suggestions?
picnictutorials — 2010-03-15T12:43:00-04:00 — #11
darcy — 2010-03-15T15:07:55-04:00 — #12
Disappointingly I learned that hiding/showing an element wouldn't work because of the same basic issue — styles, whether inline or in a stylesheet, wouldn't cause Safari to repaint.
But with big thanks to the hit new game show Will it reflow? I found a solution. I hope it helps someone else.
var ss = document.styleSheets;
ss.addRule('.xxxxxx', 'position: relative');
ss.removeRule(ss.rules.length - 1);
I haven't fully tested this cross browser yet, but here's the jist of it: I'm collecting an already existing stylesheet and adding a new rule to it that doesn't actually apply to any elements, but the addition of this rule will cause browsers to redraw/repaint the entire page (twice — once when you add the rule, once when you take it away). This could quickly become a source of slowdown though, so I'm leaving it up to you to optimize the code for what you need. However, it works.
Edit: A couple other points — Chrome was affected as well, and addRule doesn't work in Firefox so I wrapped it in a try/catch block. Otherwise the code is safe for IE6 as well (bless his soul).