1

我想要做的是有两个可拖动的、可排序的列表,在我对它们重新排序后,我可以单击“保存”或“提交”,将新列表保存到单独的文件中。我是 YUI 的新手和 PHP 的新手,但我遇到的问题是试图弄清楚如何使用它们的新属性导出这些列表(类从“list1”更改为“list2”)。

我正在使用来自YUI 博客的模板,但它并没有完全提供信息。

这是示例中的相关代码(我所做的基本上是从模板中更改一些名称):

<div id="play">
<ul id="list1">
    <li class="list1">Item #1</li>
    <li class="list1">Item #2</li>
    <li class="list1">Item #3</li>
    <li class="list1">Item #4</li>
    <li class="list1">Item #5</li>
</ul>
<ul id="list2">
    <li class="list2">Item #1</li>
    <li class="list2">Item #2</li>
    <li class="list2">Item #3</li>
    <li class="list2">Item #4</li>
    <li class="list2">Item #5</li>
</ul>
</div>

<script type="text/javascript">
YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', function(Y) {
//Listen for all drop:over events
Y.DD.DDM.on('drop:over', function(e) {
    //Get a reference to our drag and drop nodes
    var drag = e.drag.get('node'),
        drop = e.drop.get('node');

    //Are we dropping on a li node?
    if (drop.get('tagName').toLowerCase() === 'li') {
        //Are we not going up?
        if (!goingUp) {
            drop = drop.get('nextSibling');
        }
        //Add the node to this list
        e.drop.get('node').get('parentNode').insertBefore(drag, drop);
        //Resize this nodes shim, so we can drop on it later.
        e.drop.sizeShim();
    }
});
//Listen for all drag:drag events
Y.DD.DDM.on('drag:drag', function(e) {
    //Get the last y point
    var y = e.target.lastXY[1];
    //is it greater than the lastY var?
    if (y < lastY) {
        //We are going up
        goingUp = true;
    } else {
        //We are going down.
        goingUp = false;
    }
    //Cache for next check
    lastY = y;
});
//Listen for all drag:start events
Y.DD.DDM.on('drag:start', function(e) {
    //Get our drag object
    var drag = e.target;
    //Set some styles here
    drag.get('node').setStyle('opacity', '.25');
    drag.get('dragNode').set('innerHTML', drag.get('node').get('innerHTML'));
    drag.get('dragNode').setStyles({
        opacity: '.5',
        borderColor: drag.get('node').getStyle('borderColor'),
        backgroundColor: drag.get('node').getStyle('backgroundColor')
    });
});
//Listen for a drag:end events
Y.DD.DDM.on('drag:end', function(e) {
    var drag = e.target;
    //Put our styles back
    drag.get('node').setStyles({
        visibility: '',
        opacity: '1'
    });
});
//Listen for all drag:drophit events
Y.DD.DDM.on('drag:drophit', function(e) {
    var drop = e.drop.get('node'),
        drag = e.drag.get('node');

    //if we are not on an li, we must have been dropped on a ul
    if (drop.get('tagName').toLowerCase() !== 'li') {
        if (!drop.contains(drag)) {
            drop.appendChild(drag);
        }
    }
});

//Static Vars
var goingUp = false, lastY = 0;

//Get the list of li's in the lists and make them draggable
var lis = Y.Node.all('#play ul li');
lis.each(function(v, k) {
    var dd = new Y.DD.Drag({
        node: v,
        target: {
            padding: '0 0 0 20'
        }
    }).plug(Y.Plugin.DDProxy, {
        moveOnEnd: false
    }).plug(Y.Plugin.DDConstrained, {
        constrain2node: '#play'
    });
});

//Create simple targets for the 2 lists.
var uls = Y.Node.all('#play ul');
uls.each(function(v, k) {
    var tar = new Y.DD.Drop({
        node: v
    });
});

});

4

0 回答 0