可存储位置的可排序分区

时间:2011-03-10 23:50:09

标签: javascript jquery firefox swap html

我正在尝试制作我的第一个Firefox扩展程序,它将新的标签页替换为更像Chrome的标签页。其中一个功能是“访问量最大的网站”的图块,您可以拖放以重新排序。我让它们拖放,但我不知道如何保存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非常陌生,所以请像对待我一样对待我:)

另外,如果您有兴趣帮我编写部分内容,请给我发消息。

1 个答案:

答案 0 :(得分:0)

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

Stack Overflow question

中讨论了适用于Firefox扩展的三种方法

我认为SQLite或File System选项适用于您的应用程序。

相关问题