Alright so i have a bookmarklet that opens a loader img then creates/load/appends 5 included JS/CSS files.
In chrome,FF,IE,Opera it works fine. however in safari it has a problem.
Since firebug lite is pretty useless and safari developer tool did not throw any error i had to try and console.log()
certain output to see where the problem is.
I've found out that the problem is with the loading of the includes or the way i check if the includes are loaded.
If you'll look closer on the code you'll see its the CSS includes. whats weirder is when i inspect element and scroll to the header it shows that the included file is there.
I know i could probably create a function to make this code more efficient but for now i didn't.
The code is a bit long so here is a gisthube link for it: https://gist.github.com/b443582b1ced537b7612
/* creating loading and appending include files for the bookmarklet*/
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var jquery_load = document.createElement("script");
jquery_load.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
jquery_load.setAttribute('id', 'yk_bookmarklet_jquery');
jquery_load.onload = jquery_load.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
loaded_headers++;
console.log("Next1"); // <-- is being printed to console
if(loaded_headers >= total_headers){
done = true;
$.getJSON("xxxx",
function(data){
/* more variables*/
window.mbm = false;
initMyBookmarklet(); // function that has the bookmarklet info.
});
}
}
};
var CssScript = document.createElement("link");
CssScript.href = "xx;
CssScript.setAttribute('type', 'text/css');
CssScript.setAttribute('rel', 'stylesheet');
CssScript.setAttribute('media', 'all');
CssScript.setAttribute('id', 'yk_bookmarklet_css');
CssScript.onload = CssScript.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
loaded_headers++;
console.log('Next2');// <-- DOES NOT print to console
if(loaded_headers >= total_headers){
done = true;
$.getJSON("xxxx",
function(data){
/* more variables*/
window.mbm = false;
initMyBookmarklet(); // function that has the bookmarklet info.
});
}
}
};
/*appending the created elements*/
document.getElementsByTagName("head")[0].appendChild(jquery_load);
document.getElementsByTagName("head")[0].appendChild(yk_bookmarklet);
}
I know the code is a bit long so i will include a gist hub link to it: https://gist.github.com/b443582b1ced537b7612
Thanks.