Hello. So here's the stitch. I was asked to modify some existing code to only prompt the user to save changes when a change was actually made and not every time the new page button was pressed - which was what it was currently doing.

I've ran into a bit of a snag with one part. It uses this plugin http://mjsarfatti.com/sandbox/nestedSortable/ to allow the user to sort pages that are created.

It also runs a separate javascript function to hide and delete pages. So I added a global var that gets changed from 0 to 1 when either of these two functions are called and changed it so it only prompts if the var == 1. So this part works fine.

The trouble is with the sorting function. Is there a way for me to monitor when it's triggered - without having to mess around with the plugin code? Something like:

            if(nestedSortable is triggered){
                changed = 1;
                }

Recommended Answers

All 3 Replies

It appears to trigger a sort event, but I am not sure where you can trap it yet (I have never used this plugin before).

so I had an idea, not sure if its something that can be done - the internet has been less than helpful when I search. The draggable elements are in this format .sortable li div, so I was thinking if it were possible to bind the drag event for these divs and have var change accordingly.

            $('.sortable li div').bind('click', function(){
                alert( "this is a drag");
                changed = 1;
            });

This is the test code I've been playing with, just not sure if 'drag' is something that can be captured - since it didn't seem to work when I tried. The only problem with binding the click function is that there a couple icons on the div that shouldn't trigger a change. I thought about doing this:

            $('.sortable li div').bind('click', function(){
                alert( "this is a drag");
                changed = 1;
            });
            $('.sortable li div .none').bind('click', function(){
                alert( "this is none");
                changed = 0;
            });

but the second event is fired first followed by the other so changed is always equal to one. Don't mind the testing alerts :P

In the end I modified the plugin script :D Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.