javascript - 保存位置的可排序 Div

标签 javascript jquery firefox swap html

我正在尝试制作我的第一个 Firefox 扩展,它将新的标签页替换为更像 Chrome 的标签页。其中一项功能是“最常访问的网站”的图 block ,您可以拖放以重新排序。我将它们拖放,但我不知道如何保存 DIV 的新位置。

这是我正在使用的脚本:

$(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
    });
});

这是我的 HTML:

<div id="1box" class="item">
    <a href="http://www.google.com/reader/view"><img src="thumbs/01.png" border="0" />
    <h1>Google Reader</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
<div id="2box" class="item">
    <a href="https://mail.google.com/"><img src="thumbs/02.png" border="0" />
    <h1>Gmail</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
<div id="3box" class="item">
    <a href="http://calendar.google.com/"><img src="thumbs/03.png" border="0" />
    <h1>Google Calendar</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
<div id="4box" class="item">
    <a href="http://www.twitter.com/"><img src="thumbs/04.png" border="0" />
    <h1>Twitter</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>

HTML 尚未最终确定,但可以进行拖放操作。知道如何保存 DIV 的新顺序,以便当我关闭并再次打开它时,它是新配置吗?如果这个脚本不能完成,那么我很高兴被指向一个新版本。

请记住,我对 JavaScript 非常陌生,所以请像对待白痴一样对待我:)

此外,如果您有兴趣帮助我完成编码部分,请给我发送消息。

最佳答案

听起来您正在寻找某种存储来包含您的序列信息。

本文 Stack Overflow question 讨论了适用于 Firefox 扩展的三种方法。

我认为 SQLite 或文件系统选项都适合您的应用程序。

关于javascript - 保存位置的可排序 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5267371/

相关文章:

javascript - 将 javascript block 附加到 DOM 在生产中会失败 - 但在开发中不会

jquery - 我该如何调用:parent for this tooltip?

google-chrome - 什么是 ROUNDED-UNICODE 字符的正确显示?

jquery - 反向 CSS 更改完成我的 jQuery

javascript - 在 contenteditable div 中的图像后面设置光标

javascript - 如何使用 delete 键从 XUL 中的树中删除对象?

java - 无法使用 FireFox 浏览器启动 geckodriver - java.lang.NoClassDefFoundError : org/openqa/selenium/os/WindowsUtils

javascript - 防止 Backbone.history.navigate 解码 URL 片段

javascript - 将 EventEmitter 跨步到调试器中的监听器

javascript - ReactJS 错误 : Invariant violation