Perhaps this is more of a theory question than a code question, but the underlying solution will be code based so I hope it fits in here ok.
The basic construct is that I have an unordered list of controls, that update depending on what is happening. The information is coming in via a JSON packet of [[url,text].[url2,text2]] arrarys to build on the anchor:
$.each( controls, function( i, item ) {
$("<li id=\"control_"+i+"_"+ID+"\"><a href=\""+item[0]+"\">"+item[1]+"</a></li>").appendTo("#ul_controls_"+ID);
});
I have a document.on
listener responding to the click events so re-attachment doesn't have to happen here.
This creates a basic list of links ie,
Start
Edit
View
are the default case.
When start is pressed, start and edit go away, and stop comes in
View
Stop
After it ends, the controls update again, removing stop and returning the edit and start options.
View
Start
Edit
As you can see, I've lost position from my original state (view is now on top instead of the bottom because it persists and appendTo, well, appends).
I have over-simplified this example, as there are MANY other controls for various stages being added in to the loop.
So, how do I keep position where start/stop trade places, edit comes and goes as it pleases, and view stays at the end (And remember, i have 5-10 more controls in this list depending on state, so relying on appending to just that 1 element is probably unreliable)
Some thoughts I had were:
- Always bring all controls physically into the DOM, and toggle visibility instead
- Instead of JSON url/name pairs, send a full
$("#ul").html("<li> ... to last </li>");
style injection from the server for the whole bock every time instead of attaching and detaching individual li elements as needed (performance hit? JSON formatting concerns?) - Come up with an ID scheme that can be sorted, or a slot-like solution, but the how-to on this is drawing blanks from my brain.
I appreciate any thoughts or advice on this.