Javascript not working
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #1
Javascript not working
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
			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);
			}



Attached File(s)
.php  class_imageresizer_gd.php (Size: 11.07 KB / Downloads: 357)
.js  imageresizer_gd.js (Size: 1.48 KB / Downloads: 363)
.php  imageresizer_gd.php (Size: 7.46 KB / Downloads: 339)

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
07-09-2012 09:26 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Javascript not working
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.


My Blog
07-10-2012 07:30 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #3
RE: Javascript not working
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.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
07-11-2012 08:46 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Javascript not working
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.


My Blog
07-11-2012 10:16 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #5
RE: Javascript not working
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.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
07-15-2012 01:42 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: Javascript not working
I'm saying that the plugin has horrible performance implications.

My Blog
07-15-2012 09:36 AM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #7
RE: Javascript not working
May you explain it better? I mean, the reasons.

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
(This post was last modified: 07-15-2012 11:17 AM by Sama34.)
07-15-2012 11:16 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Javascript not working
I could, but that would sound boring.  Let's see if you or anyone else is willing to identify them =P

My Blog
(This post was last modified: 07-15-2012 04:37 PM by ZiNgA BuRgA.)
07-15-2012 04:36 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: