Note that there are some explanatory texts on larger screens.

plurals
  1. POSortable Divs That Save Locations
    primarykey
    data
    text
    <p>I'm trying to make my first Firefox extension, that replaces the new tab page with a more Chrome-like tab page. one of the features is tiles of your "most visited sites," that you can drag-and-drop to reorder. I have them dragging and dropping, but I have no idea how to save the new locations of the DIVs. </p> <p>This is the script I'm using:</p> <pre><code>$(document).ready(function(){ jQuery.fn.redswap = function(options){ var selectedItems=this; redsettings = jQuery.extend({ speed:"Medium", opacity:0.7 }, options); $(selectedItems).mouseover(function(){ $(selectedItems).disableSelection(); $(selectedItems).droppable({ drop: function(event, ui) { dropindex=$(selectedItems).index(this); var dragposition=$(selectedItems[dragindex]).position(); var dropposition=$(selectedItems[dropindex]).position(); withDifference=parseInt(dragposition.left)-parseInt(dropposition.left); heightDifference=parseInt(dragposition.top)-parseInt(dropposition.top); $(selectedItems[dropindex]).animate({ left:'+='+withDifference, top:'+='+heightDifference },redsettings.speed,function(){ }); $(selectedItems[dragindex]).animate({ left:'+='+(withDifference*(-1)), top:'+='+(heightDifference*(-1)) },redsettings.speed,function(){ //Complete }); }, }); $(this).draggable({ opacity:redsettings.opacity, helper: 'clone', containment: 'parent', scroll: false, drag:function(event, ui){ dragindex=$(selectedItems).index(this); } }); }); }; }); // Settings $(document).ready(function(){ $("#wrapper").tabs(); $("div[id*='box']").redswap({ speed:'slow', opacity:.75 }); }); </code></pre> <p>And this is my HTML:</p> <pre><code>&lt;div id="1box" class="item"&gt; &lt;a href="http://www.google.com/reader/view"&gt;&lt;img src="thumbs/01.png" border="0" /&gt; &lt;h1&gt;Google Reader&lt;/a&gt;&lt;/h1&gt;&lt;a href="#" class="x"&gt;&lt;/a&gt;&lt;a href="#" class="tack"&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="2box" class="item"&gt; &lt;a href="https://mail.google.com/"&gt;&lt;img src="thumbs/02.png" border="0" /&gt; &lt;h1&gt;Gmail&lt;/a&gt;&lt;/h1&gt;&lt;a href="#" class="x"&gt;&lt;/a&gt;&lt;a href="#" class="tack"&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="3box" class="item"&gt; &lt;a href="http://calendar.google.com/"&gt;&lt;img src="thumbs/03.png" border="0" /&gt; &lt;h1&gt;Google Calendar&lt;/a&gt;&lt;/h1&gt;&lt;a href="#" class="x"&gt;&lt;/a&gt;&lt;a href="#" class="tack"&gt;&lt;/a&gt; &lt;/div&gt; &lt;div id="4box" class="item"&gt; &lt;a href="http://www.twitter.com/"&gt;&lt;img src="thumbs/04.png" border="0" /&gt; &lt;h1&gt;Twitter&lt;/a&gt;&lt;/h1&gt;&lt;a href="#" class="x"&gt;&lt;/a&gt;&lt;a href="#" class="tack"&gt;&lt;/a&gt; &lt;/div&gt; </code></pre> <p>The HTML isn't final yet, but it does drag and drop. Any idea how I can save the new order of the DIVs, so that when I close out and open it up again, it's the new configuration? If it can't be done with this script, then I'm fine being pointed to a new version.</p> <p>Keep in mind I'm very very new to JavaScript, so please treat me like I'm an idiot :)</p> <p>Also, if you're interested in helping me on the coding part of things, send me a message.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload