-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick AJAX problem fix #75
base: master
Are you sure you want to change the base?
Conversation
…rse the CSS after loading pages via AJAX.
Why ain't this pulled in yet? |
Author could be busy, just look at the commit... |
Maybe the author died? |
@stevenvachon You should check his activity before saying so I would consider he has abandoned this if I got no response from him after Chinese New Year Related: #80 |
Ah, well that's good to hear at least. Still a bummer that he hasn't merged this and bower support, 'cuz that's really all we need added. |
This isn't a viable fix for handling modifications to the DOM. Running selectivizr a second time in this way won't remove any CSS class names applied during the first execution. This means any elements targeted with a pseudo-class that have moved since the first call won't receive the correct style updates. It also means event handlers aren't removed which could lead to memory leaks and ultimately a browser crash if called enough times. If this works for your individual use cases then carry on using this method but I'm not going to merge this as a fix in this state. A better fix would be to expose something like |
Hello, if you're using Modernizr too, then this seems to do the trick. Admittedly another hack, but a work around at least. In your Ajax callback, place: yepnope([{ load: ['ie6!ie7!ie8!/js/libs/selectivizr.min.js'] }]); |
Selectivizr.init() is not available anymore? |
@witwit try the above solution with Modernizr? |
@mstephens What's yepnope?? The only workaround that has worked for me is: |
YepNope is a tiny lib to conditionally load other libs. Modernizr bundles it but it can also be downloaded separately: http://yepnopejs.com/ |
Combining the patch here with the following does the job for me (preventing memory leaks). (function($) {
$.fn.removeClassRegEx = function(regex) {
var classes = $(this).attr('class');
if(!classes || !regex) return false;
var classArray = [];
classes = classes.split(' ');
for(var i=0, len=classes.length; i<len; i++)
if(!classes[i].match(regex)) classArray.push(classes[i]);
$(this).attr('class', classArray.join(' '));
return $(this);
};
})(jQuery); To keep changes to Selectivizr to a minimum I then use the following $("*").removeClassRegEx(/^slvzr-/);
Selectivizr.init(); This could all be combined of course. The key here is it removes all the slvzr-* classes from all elements and then initialises Selectivizr. |
Thank you for your valuable contribution, @jasonmarston. |
Adding to the update from @jasonmarston , I've created a solution to automatically reapply Selectivizr whenever an Ajax request completes under jQuery. I put his two lines of code into a function, and registered that with the .ajaxSuccess global handler. Works beautifully. function refreshSelectivizrCssForIE() { And in the <head>: <!--[if lt IE 9]> Now any time I load Ajax-based content it is properly styled in IE8. |
@keithclark disappeared so I'm going to try and maintain this project at https://github.com/corysimmons/selectivizr2 Would you please reopen/rebase your PR over there? |
Added a few lines of code to allow calling Selectivizr.init() after a page is loaded via AJAX. It calls selectivizr's init() method and reparses the CSS. I used it in my project at work, thought I'd share :)