From 0d1da4356173e926fdcac42462daa4fcb7617109 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 21 Dec 2020 16:11:17 +0100 Subject: Initial commit --- src/index.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/index.js (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..eecabf6 --- /dev/null +++ b/src/index.js @@ -0,0 +1,49 @@ +/* global jQuery ajaxurl */ + +import './index.scss'; + +( function ( $ ) { + const overlay = $( '
' ).appendTo( 'body' ); + $( '#the-list' ).sortable( { + items: 'tr', + axis: 'y', + cursor: 'move', + + // @see https://stackoverflow.com/a/57611747/6114451 + start( e, ui ) { + const $originals = ui.helper.children(); + ui.placeholder.children().each( function ( index ) { + $( this ).width( $originals.eq( index ).width() ); + $( this ).height( $originals.eq( index ).height() ); + } ); + }, + helper( e, tr ) { + const $helper = tr.clone(); + const $originals = tr.children(); + $helper.children().each( function ( index ) { + $( this ).width( $originals.eq( index ).outerWidth( true ) ); + } ); + return $helper; + }, + + update() { + // show overlay + overlay.addClass( 'post-order-overlay--visible' ); + + // update posts + $.post( + ajaxurl, + { + action: 'update-post-order', + page: $( '#current-page-selector' ).val(), + perPage: $( '#edit_post_per_page' ).val(), + postOrder: $( '#the-list' ).sortable( 'serialize' ), + }, + () => { + // hide overlay after updating + overlay.removeClass( 'post-order-overlay--visible' ); + } + ); + }, + } ); +} )( jQuery ); -- cgit v1.2.3