[ 5 posts ]

Cameron

  • Username: pcm2a
  • Joined: Tue Mar 06, 2012 5:50 am
  • Posts: 3
  • Offline
  • Profile

How to catch a sortable event?

Post Posted: Tue Mar 06, 2012 6:39 am
+0-
I am a super YUI3 novice and I have gotten a drag-n-drop sortable list to work. That was the easy part. Now I would like to catch when something has been dragged. Is this possible?

I tried to use these events for nodesChange and containerChange but I clearly have no idea the correct way since this does not work.

Code:
YUI().use('sortable', function(Y) {
    var sortable1 = new Y.Sortable({
        container: '#demo1',
        nodes: 'li',
      on: {
            nodesChange: function() {
                alert('nodes');
            }
        },
        after: {
            containerChange: function() {
                alert('container');
            }
        },
        after: {
            moveTypeChange: function() {
                alert('moveType');
            }
        }
    });
}

Cameron

  • Username: pcm2a
  • Joined: Tue Mar 06, 2012 5:50 am
  • Posts: 3
  • Offline
  • Profile

Re: How to catch a sortable event?

Post Posted: Tue Mar 06, 2012 8:24 am
+0-
The above event stuff just doesn't work at all. The documentation says the copy event is for when a node is moved:
copy
copy ( event )
A Sortable node was moved.

I tried this code and the click event works, the copy does not.
Code:
YUI().use('event', 'node', function (Y) {
    var clickedNode = Y.one('#save-order-quicklink');
   
    var draggedNodes = Y.all('.results-row');
    if (draggedNodes) {
       draggedNodes.each( function(node) {
          node.on('click', function(eventFacade) {
             alert('click');
          });
          node.after('copy', function(eventFacade) {
             alert('copy');
          });
       });
    }
});

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: How to catch a sortable event?

Post Posted: Tue Mar 06, 2012 8:46 am
+0-
Here's a fiddle that show's it working:

http://jsfiddle.net/davglass/f2tnm/

Cameron

  • Username: pcm2a
  • Joined: Tue Mar 06, 2012 5:50 am
  • Posts: 3
  • Offline
  • Profile

Re: How to catch a sortable event?

Post Posted: Tue Mar 06, 2012 9:23 am
+0-
Well that works amazing and thanks for the link to the jsfiddle site! I was able to get rid of all my garbage code and use that moved event. Where did you find the list of what events you can call like 'moved'?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: How to catch a sortable event?

Post Posted: Tue Mar 06, 2012 10:33 am
+0-
Since I wrote it, I kind of knew it ;)

However, they are listed here:
http://yuilibrary.com/yui/docs/api/clas ... table.html

(I did see a bug in the doc parsing for it & I checked in a fix for the next release)
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum