I'm modifying this plugin file to use a external js file instead of hard-coded JavaScript.
The thing is, showing an alert will now work at all. I'm not very good with JavaScript.
Can someone take a look at the code?
This is what I mean (imageresizer_gd.js):
Javascript Code
if(imageresizer_gd_showwarning == 1)
{
var position = 'img[i]'
if(imageresizer_gd_warningposition == 1)
{
position = 'img[i].nextSibling';
}
var parent = img[i].parentNode;
var warning = document.createElement("div");
var align = parent.getAttribute("style");
var setalign = "";
if(align == "text-align: center;" || align == "text-align: right;" ) {
if(align == "text-align: center;") setalign = "center";
if(align == "text-align: right;") setalign = "right";}
warning.innerHTML = '<div class="' + imageresizer_gd_warningclass + '" style="width:' + imageresizer_gd_resizewidth + 'px;"><a href="+imgURL+ " target="_blank">' + imageresizer_gd_warningtext + '</a></div>';
warning.setAttribute("align", setalign);
parent.insertBefore(warning, position);
}
|
You may wish to post up whatever error messages you get. Install Firebug or whatever to display Javascript errors if necessary.
I cbf looking through all the code. This part looks totally pointless to me:
PHP Code:
while(!img[i].complete )
{
break;
}
|
You may need to bind to the image's onload function, though I'm unsure whether the window.load event is triggered before or after all images are loaded.
Though this seriously doesn't look like a job Javascript should be doing.
Well, the thing is that this is a modified version of
this plugin. Javascript works just fine in the original plugin, but passing it to a js file doesn't work.
You still didn't post an error message.
Never mind, the issue is this:
Javascript Code
var position = 'img[i]'
if(imageresizer_gd_warningposition == 1)
{
position = 'img[i].nextSibling';
}
|
position is meant to be an object, not a string, so remove the quotes around them.
Oh, and the code is absolute shit, from a performance perspective. You're probably better off not using it at all.
Sorry for completely ignoring you Firebug recommendation.
For about the issue, it is solved now, it makes sense to use quotes in php but o here and I didn't think about it being the problem.
And what do you mean the code is not worth? The GD resize code, the JavaScript part, or altogether?
I extracted the js automatic resize and dropped the GD optimization.
I'm saying that the plugin has horrible performance implications.
May you explain it better? I mean, the reasons.
I could, but that would sound boring. Let's see if you or anyone else is willing to identify them =P