保存位置的可排序 Div

发布于 2024-10-21 02:26:28 字数 3138 浏览 4 评论 0原文

我正在尝试制作我的第一个 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 非常陌生,所以请像对待白痴一样对待我:)

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

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.

This is the script I'm using:

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

And this is my 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>

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.

Keep in mind I'm very very new to JavaScript, so please treat me like I'm an idiot :)

Also, if you're interested in helping me on the coding part of things, send me a message.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云雾 2024-10-28 02:26:28

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

堆栈溢出问题

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

It sounds like you're looking for some sort of storage to contain your sequence information.

Three approaches that are applicable to Firefox extensions are discussed in this Stack Overflow question

Either the SQLite or File System option would work well for your application, I think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文