Edit part of page loaded by ajax

Subscribe to Edit part of page loaded by ajax 11 posts, 4 voices

 
psyched Scriptwright

Hello again!

Another problem:
This time, I have the following elements:

<ul id="friendList" class="friendList">
	<li id="friend4244" class="fakeLink3">
</ul>

<ul id="friendList" class="friendList" />

The first ul will be filled with a lot of li elements which are requested by an XHR. They're all alike, have the same className and similar IDs (only the number will change).
Now, if you click on one of the lis, the id will be moved to the other ul.

I want to make my Monkey do that for me without having to click 1000 times ;-)

The code on the page which is responsible for that gimmick is the following:

	function addInvite(id) {
	  eleInv = $('friend'+id);
	  if (eleInv) {
		 	JGroupsHelper.addGroupInvite([id]);
		 	
		 	o = loadedFriends.get(id);
		 	selectedFriends.set(id, o); 
		 	loadedFriends.unset(id);
		 	
			var container = $('invites');
			if (container) {
				var li = createInviteNode(id, o);  	
				container.appendChild(li);
			}
		 	
	  	eleInv.remove();
	  }
	}

Not exactly sure what JGroupsHelper does or is. It might be another AJAX fancy for the server to send the friend ID.

/edit: It is.

The easiest way to do it will probably be just to execute addInvite(id).
But since this specific part of the site is being loaded using AJAX Greasemonkey seems to not work with this code. If I open Firebug and inspect the ul element, the li elements are all inside.

Just executing unsafeWindow.addInvite("myid"); did not work.

Any other way to do this? :)

Thanks a lot, people.

 
Yansky Scriptwright

<ul id="friendList" class="friendList">
	<li id="friend4244" class="fakeLink3">
</ul>

<ul id="friendList" class="friendList" />

You can't have two elements with the same ID.

Once the ajax request is complete, something like this should work:


var listArray = document.getElementById('friendList').getElementsByTagName('li');

var newUL = document.getElementById('friendList2');

for(var i = 0; i<listArray.length; i++){

  newUL.appedChild(listArray[i]);

}

 
psyched Scriptwright

My bad, the second ul has the id invites.
I'll see what I can do.

/edit: Nope: alert(document.getElementById("friendList").getElementsByTagName("li").length); will only show "1", which makes it quite impossible to add new childNodes to the second ul.
I need to find some way to wait for the ajax request to complete.... I'll try timeout

 
Yansky Scriptwright

Nope: alert(document.getElementById("friendList").getElementsByTagName("li").length); will only show "1".

Then there must only be one li descendant element.

 
psyched Scriptwright

Sweeeeet, it worked. (setTimeout())
I love JS.

 
Yansky Scriptwright

Sweeeeet, it worked. (setTimeout())
I love JS.

Cool, glad i could help. :)

 
psyched Scriptwright

Ah, nevermind:
The li elements are now being shifted to the second ul.

But unfortunately, one needs to actually click the li items in the first ul, so the request is started.
The moving and the requests is one whole function.
So:

Is there a way to fake an event? In this case, click all the lis?
That would really, REALLY help.

 
Yansky Scriptwright

Can you post a link to the page?

 
no0n Scriptwright

psyched wrote:

Is there a way to fake an event? In this case, click all the lis? That would really, REALLY help.

Here's an example mouse event creation on mozdev

Between that example and what Mikado showed us I think you can accomplish whatever it is youre exactly doing

 
psyched Scriptwright

no0n wrote:

psyched wrote:

Is there a way to fake an event? In this case, click all the lis? That would really, REALLY help.

Here's an example mouse event creation on mozdev

Between that example and what Mikado showed us I think you can accomplish whatever it is youre exactly doing

Awesome, I finally figured it out. This will make things much much easier for everyone. Thank you so much.
 
LouCypher Scriptwright
no0n wrote:

Here's an example mouse event creation on mozdev

OT

It's MDC (Mozilla Development Center) — previously known as devmo (developer.mozilla.org) — don't call it mozdev (www.mozdev.org).