diff --git a/Tests/jqueryui-tests.ts b/Tests/jqueryui-tests.ts new file mode 100644 index 000000000..f23317ffd --- /dev/null +++ b/Tests/jqueryui-tests.ts @@ -0,0 +1,709 @@ +/// + +declare var $: any; + + +// Draggable ////////////////////////////////////////////////// + +$("#draggable").draggable({ axis: "y" }); +$("#draggable2").draggable({ axis: "x" }); +$("#draggable3").draggable({ containment: "#containment-wrapper", scroll: false }); +$("#draggable5").draggable({ containment: "parent" }); +$("#draggable").draggable({ cursor: "move", cursorAt: { top: 56, left: 56 } }); +$("#draggable2").draggable({ cursor: "crosshair", cursorAt: { top: -5, left: -5 } }); +$("#draggable3").draggable({ cursorAt: { bottom: 0 } }); +$("#draggable").draggable(); +$("#draggable").draggable({ distance: 20 }); +$("#draggable2").draggable({ delay: 1000 }); +$(".ui-draggable").disableSelection(); +$("#draggable").draggable({ + start: () => { + counts[0]++; + updateCounterStatus($start_counter, counts[0]); + }, + drag: () => { + counts[1]++; + updateCounterStatus($drag_counter, counts[1]); + }, + stop: () => { + counts[2]++; + updateCounterStatus($stop_counter, counts[2]); + } +}); +$("#draggable").draggable({ handle: "p" }); +$("#draggable2").draggable({ cancel: "p.ui-widget-header" }); +$("div, p").disableSelection(); +$("#draggable").draggable({ revert: true }); +$("#draggable2").draggable({ revert: true, helper: "clone" }); +$("#draggable").draggable({ scroll: true }); +$("#draggable2").draggable({ scroll: true, scrollSensitivity: 100 }); +$("#draggable3").draggable({ scroll: true, scrollSpeed: 100 }); +$("#draggable").draggable({ snap: true }); +$("#draggable2").draggable({ snap: ".ui-widget-header" }); +$("#draggable3").draggable({ snap: ".ui-widget-header", snapMode: "outer" }); +$("#draggable4").draggable({ grid: [20, 20] }); +$("#draggable5").draggable({ grid: [80, 80] }); +$("#sortable").sortable({ + revert: true +}); +$("#draggable").draggable({ + connectToSortable: "#sortable", + helper: "clone", + revert: "invalid" +}); +$("ul, li").disableSelection(); +$("#draggable").draggable({ helper: "original" }); +$("#draggable2").draggable({ opacity: 0.7, helper: "clone" }); +$("#draggable3").draggable({ + cursor: "move", + cursorAt: { top: -12, left: -20 }, + helper: (event) => { + return $("
I'm a custom helper
"); + } +}); +$("#set div").draggable({ stack: "#set div" }); + + +// Droppable ////////////////////////////////////////////////// + +$( "#draggable, #draggable-nonvalid" ).draggable(); +$( "#droppable" ).droppable({ + accept: "#draggable", + activeClass: "ui-state-hover", + hoverClass: "ui-state-active", + drop:( event, ui ) => { + $( this ) + .addClass( "ui-state-highlight" ) + .find( "p" ) + .html( "Dropped!" ); + } +}); +$( "#draggable" ).draggable(); +$( "#droppable" ).droppable({ + drop: ( event, ui ) => { + $( this ) + .addClass( "ui-state-highlight" ) + .find( "p" ) + .html( "Dropped!" ); + } +}); + + // there's the gallery and the trash + var $gallery = $( "#gallery" ), + $trash = $( "#trash" ); + + // let the gallery items be draggable + $( "li", $gallery ).draggable({ + cancel: "a.ui-icon", // clicking an icon won't initiate dragging + revert: "invalid", // when not dropped, the item will revert back to its initial position + containment: "document", + helper: "clone", + cursor: "move" + }); + + // let the trash be droppable, accepting the gallery items + $trash.droppable({ + accept: "#gallery > li", + activeClass: "ui-state-highlight", + drop: ( event, ui ) => { + deleteImage( ui.draggable ); + } + }); + + // let the gallery be droppable as well, accepting items from the trash + $gallery.droppable({ + accept: "#trash li", + activeClass: "custom-state-active", + drop: ( event, ui ) => { + recycleImage( ui.draggable ); + } + }); + + // image deletion function + var recycle_icon = "Recycle image"; + function deleteImage( $item ) { + $item.fadeOut(() => { + var $list = $( "ul", $trash ).length ? + $( "ul", $trash ) : + $( "