Is there any Stack Exchange site where people can post solutions they found for they faced, particularly if they think it's the best solution for a specific problem?
For example, I needed to exchange all elements of a list (using all combinations) only having the initial order, and I found this solution:
PHP for the elements that must to spin (the i class=btn-info element is the element that trigger the spin function)
<div id="element-<?=$id; ?>" data-order="<?=$order; ?>" >
<i class="btn-info fa fa-refresh" data-id="<?=$id; ?>" data-function="true" data-action="spin"></i>
<ul class="soc" id="onspin-<?=$id; ?>">
<li id="title<?=$id; ?>">element-1</li>
<li id="<?=$type.$id;?>">element-2</li>
<li id="text<?=$id; ?>">element-3</li>
<li id="area<?=$id; ?>">element-4</li>
</ul>
</div>
Javascript for the action button (The i class btn-info has a attribute data-function="true", and data-action="spin" for this reason the spin function is called. This is made in this way because these elements are request by AJAX -but the javascript is load with the document-)
jQuery(".panel-body").on("click", '[data-function="true"]', function(){
eval(jQuery(this).attr("data-action"))(jQuery(this).attr("data-id"));
});
Javascript for the spin function
function spin(id)
{
obj = jQuery("#element-"+id);
it = 0;
if(!(old = obj.data("old-order")))
old = obj.data("order").split(",");
else
{
it = parseInt(obj.data("iter"));
old = old.split(",");
}
order = "";
del = old[it%old.length];
n_or = obj.data("order").split(",");
for(var i=0; i<n_or.length; i++)
{
if(n_or[i]==del)
{
del_aux = jQuery('#'+n_or[i]+id);
i_aux = i;
}
else
order += n_or[i] + ",";
}
order += n_or[i_aux];
jQuery("#onspin-"+id).append(del_aux);
obj.data("old-order",jQuery("#element-"+id).data("order"));
obj.data("iter", it+1)
obj.data("order",order);
}