function draggable(element, onmove, onstart, onstop, baseElement) {
        onmove = onmove || function () { };
        onstart = onstart || function () { };
        onstop = onstop || function () { };
        var doc = (baseElement !== undefined) ? $(baseElement) : $('body'); // element.ownerDocument || document;
        var dragging = false;
        var offset = {};
        var maxHeight = 0;
        var maxWidth = 0;
        var hasTouch = ('ontouchstart' in window);

        var duringDragEvents = {};
        duringDragEvents["selectstart"] = prevent;
        duringDragEvents["dragstart"] = prevent;
        duringDragEvents["touchmove mousemove"] = move;
        duringDragEvents["touchend mouseup"] = stop;

        function prevent(e) {
            if (e.stopPropagation) {
                e.stopPropagation();
            }
            if (e.preventDefault) {
                e.preventDefault();
            }
            e.returnValue = false;
        }

        function move(e) {
            if (dragging) {
                // Mouseup happened outside of window
                if (IE && doc.documentMode < 9 && !e.button) {
                    return stop();
                }

                var touches = e.originalEvent && e.originalEvent.touches;
                var pageX = touches ? touches[0].pageX : e.pageX;
                var pageY = touches ? touches[0].pageY : e.pageY;

                var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
                var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));

                if (hasTouch) {
                    // Stop scrolling in iOS
                    prevent(e);
                }

                onmove.apply(element, [dragX, dragY, e]);
            }
        }

        function start(e) {
            var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);

            if (!rightclick && !dragging) {
                if (onstart.apply(element, arguments) !== false) {
                    dragging = true;
                    maxHeight = $(element).height();
                    maxWidth = $(element).width();
                    offset = $(element).offset();

                    $(doc).bind(duringDragEvents);
                    $(doc).addClass("sp-dragging");

                    move(e);

                    prevent(e);
                }
            }
        }

        function stop() {
            if (dragging) {
                $(doc).unbind(duringDragEvents);
                $(doc).removeClass("sp-dragging");
                onstop.apply(element, arguments);
            }
            dragging = false;
        }

        $(element).bind("touchstart mousedown", start);
    }
/**
    * Lightweight drag helper.  Handles containment within the element, so that
    * when dragging, the x is within [0,element.width] and y is within [0,element.height]
    */
Lightweight drag helper.  Handles containment within the element, so that
when dragging, the x is within [0,element.width] and y is within [0,element.height]
Lightweight drag helper . Handles containment within the element so that when dragging the x is within [ 0 element . width ] and y is within [ 0 element . height ]
function draggable(element, onmove, onstart, onstop, baseElement) {
        onmove = onmove || function () { };
        onstart = onstart || function () { };
        onstop = onstop || function () { };
        var doc = (baseElement !== undefined) ? $(baseElement) : $('body'); 
        var dragging = false;
        var offset = {};
        var maxHeight = 0;
        var maxWidth = 0;
        var hasTouch = ('ontouchstart' in window);
        var duringDragEvents = {};
        duringDragEvents["selectstart"] = prevent;
        duringDragEvents["dragstart"] = prevent;
        duringDragEvents["touchmove mousemove"] = move;
        duringDragEvents["touchend mouseup"] = stop;
        function prevent(e) {
            if (e.stopPropagation) {
                e.stopPropagation();
            }
            if (e.preventDefault) {
                e.preventDefault();
            }
            e.returnValue = false;
        }
        function move(e) {
            if (dragging) {
                if (IE && doc.documentMode < 9 && !e.button) {
                    return stop();
                }
                var touches = e.originalEvent && e.originalEvent.touches;
                var pageX = touches ? touches[0].pageX : e.pageX;
                var pageY = touches ? touches[0].pageY : e.pageY;
                var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
                var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));
                if (hasTouch) {
                    prevent(e);
                }
                onmove.apply(element, [dragX, dragY, e]);
            }
        }
        function start(e) {
            var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);
            if (!rightclick && !dragging) {
                if (onstart.apply(element, arguments) !== false) {
                    dragging = true;
                    maxHeight = $(element).height();
                    maxWidth = $(element).width();
                    offset = $(element).offset();
                    $(doc).bind(duringDragEvents);
                    $(doc).addClass("sp-dragging");
                    move(e);
                    prevent(e);
                }
            }
        }
        function stop() {
            if (dragging) {
                $(doc).unbind(duringDragEvents);
                $(doc).removeClass("sp-dragging");
                onstop.apply(element, arguments);
            }
            dragging = false;
        }
        $(element).bind("touchstart mousedown", start);
    }
function draggable ( element , onmove , onstart , onstop , baseElement ) { onmove = onmove || function ( ) { } ; onstart = onstart || function ( ) { } ; onstop = onstop || function ( ) { } ; var doc = ( baseElement !== undefined ) ? $ ( baseElement ) : $ ( 'body' ) ; var dragging = false ; var offset = { } ; var maxHeight = 0 ; var maxWidth = 0 ; var hasTouch = ( 'ontouchstart' in window ) ; var duringDragEvents = { } ; duringDragEvents [ "selectstart" ] = prevent ; duringDragEvents [ "dragstart" ] = prevent ; duringDragEvents [ "touchmove mousemove" ] = move ; duringDragEvents [ "touchend mouseup" ] = stop ; function prevent ( e ) { if ( e . stopPropagation ) { e . stopPropagation ( ) ; } if ( e . preventDefault ) { e . preventDefault ( ) ; } e . returnValue = false ; } function move ( e ) { if ( dragging ) { if ( IE && doc . documentMode < 9 && ! e . button ) { return stop ( ) ; } var touches = e . originalEvent && e . originalEvent . touches ; var pageX = touches ? touches [ 0 ] . pageX : e . pageX ; var pageY = touches ? touches [ 0 ] . pageY : e . pageY ; var dragX = Math . max ( 0 , Math . min ( pageX - offset . left , maxWidth ) ) ; var dragY = Math . max ( 0 , Math . min ( pageY - offset . top , maxHeight ) ) ; if ( hasTouch ) { prevent ( e ) ; } onmove . apply ( element , [ dragX , dragY , e ] ) ; } } function start ( e ) { var rightclick = ( e . which ) ? ( e . which == 3 ) : ( e . button == 2 ) ; if ( ! rightclick && ! dragging ) { if ( onstart . apply ( element , arguments ) !== false ) { dragging = true ; maxHeight = $ ( element ) . height ( ) ; maxWidth = $ ( element ) . width ( ) ; offset = $ ( element ) . offset ( ) ; $ ( doc ) . bind ( duringDragEvents ) ; $ ( doc ) . addClass ( "sp-dragging" ) ; move ( e ) ; prevent ( e ) ; } } } function stop ( ) { if ( dragging ) { $ ( doc ) . unbind ( duringDragEvents ) ; $ ( doc ) . removeClass ( "sp-dragging" ) ; onstop . apply ( element , arguments ) ; } dragging = false ; } $ ( element ) . bind ( "touchstart mousedown" , start ) ; }
Lightweight drag helper.
Lightweight drag helper .
// element.ownerDocument || document; // Mouseup happened outside of window // Stop scrolling in iOS