diff options
author | Daniel Weipert <code@drogueronin.de> | 2020-12-21 16:11:17 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2020-12-21 16:11:17 +0100 |
commit | 0d1da4356173e926fdcac42462daa4fcb7617109 (patch) | |
tree | 79535a3dca38b60c1ca93ff351c00e1464b0536b /src/index.js |
Initial commit
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 49 |
1 files changed, 49 insertions, 0 deletions
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 = $( '<div class="post-order-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 ); |