simple-page-ordering
Last commit date
localization
13 years ago
readme.txt
13 years ago
screenshot-1.png
13 years ago
screenshot-2.png
13 years ago
simple-page-ordering.css
13 years ago
simple-page-ordering.dev.js
13 years ago
simple-page-ordering.js
13 years ago
simple-page-ordering.php
13 years ago
simple-page-ordering.dev.js
103 lines
| 1 | function update_simple_ordering_callback(response) { |
| 2 | if ( 'children' === response ) { |
| 3 | window.location.reload(); |
| 4 | return; |
| 5 | } |
| 6 | |
| 7 | var changes = jQuery.parseJSON( response ); |
| 8 | |
| 9 | var new_pos = changes.new_pos; |
| 10 | for ( var key in new_pos ) { |
| 11 | if ( 'next' === key ) |
| 12 | continue; |
| 13 | |
| 14 | var inline_key = document.getElementById('inline_' + key); |
| 15 | if ( null !== inline_key && new_pos.hasOwnProperty(key) ) { |
| 16 | var dom_menu_order = inline_key.querySelector('.menu_order'); |
| 17 | |
| 18 | if ( undefined !== new_pos[key]['menu_order'] ) { |
| 19 | if ( null !== dom_menu_order ) |
| 20 | dom_menu_order.innerHTML = new_pos[key]['menu_order']; |
| 21 | |
| 22 | var dom_post_parent = inline_key.querySelector('.post_parent'); |
| 23 | if ( null !== dom_post_parent ) |
| 24 | dom_post_parent.innerHTML = new_pos[key]['post_parent']; |
| 25 | |
| 26 | var post_title = null; |
| 27 | var dom_post_title = inline_key.querySelector('.post_title'); |
| 28 | if ( null !== dom_post_title ) |
| 29 | post_title = dom_post_title.innerHTML; |
| 30 | |
| 31 | var dashes = 0; |
| 32 | while (dashes < new_pos[key]['depth']) { |
| 33 | post_title = '— ' + post_title; |
| 34 | dashes++; |
| 35 | } |
| 36 | var dom_row_title = inline_key.parentNode.querySelector('.row-title'); |
| 37 | if ( null !== dom_row_title && null !== post_title ) |
| 38 | dom_row_title.innerHTML = post_title; |
| 39 | } else if ( null !== dom_menu_order ) { |
| 40 | dom_menu_order.innerHTML = new_pos[key]; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if ( changes.next ) { |
| 46 | jQuery.post( ajaxurl, { |
| 47 | action: 'simple_page_ordering', |
| 48 | id: changes.next['id'], |
| 49 | previd: changes.next['previd'], |
| 50 | nextid: changes.next['nextid'], |
| 51 | start: changes.next['start'], |
| 52 | excluded: changes.next['excluded'] |
| 53 | }, update_simple_ordering_callback ); |
| 54 | } else { |
| 55 | jQuery(document.querySelector('.spo-updating-row')).removeClass('spo-updating-row'); |
| 56 | sortable_post_table.removeClass('spo-updating').sortable('enable'); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | var sortable_post_table = jQuery( document.querySelector(".wp-list-table tbody") ); |
| 61 | sortable_post_table.sortable({ |
| 62 | items: '> tr', |
| 63 | cursor: 'move', |
| 64 | axis: 'y', |
| 65 | containment: 'table.widefat', |
| 66 | scrollSensitivity: 40, |
| 67 | cancel: '.inline-edit-row', |
| 68 | distance: 5, |
| 69 | opacity: .85, |
| 70 | forceHelperSize: true, |
| 71 | update: function(event, ui) { |
| 72 | sortable_post_table.sortable('disable').addClass('spo-updating'); |
| 73 | ui.item.addClass('spo-updating-row'); |
| 74 | |
| 75 | var postid = ui.item[0].id.substr(5); // post id |
| 76 | |
| 77 | var prevpostid = false; |
| 78 | var prevpost = ui.item.prev(); |
| 79 | if ( prevpost.length > 0 ) { |
| 80 | prevpostid = prevpost.attr('id').substr(5); |
| 81 | } |
| 82 | |
| 83 | var nextpostid = false; |
| 84 | var nextpost = ui.item.next(); |
| 85 | if ( nextpost.length > 0 ) { |
| 86 | nextpostid = nextpost.attr('id').substr(5); |
| 87 | } |
| 88 | |
| 89 | // go do the sorting stuff via ajax |
| 90 | jQuery.post( ajaxurl, { action: 'simple_page_ordering', id: postid, previd: prevpostid, nextid: nextpostid }, update_simple_ordering_callback ); |
| 91 | |
| 92 | // fix cell colors |
| 93 | var table_rows = document.querySelectorAll('tr.iedit'), |
| 94 | table_row_count = table_rows.length; |
| 95 | while( table_row_count-- ) { |
| 96 | if ( table_row_count%2 == 0 ) { |
| 97 | jQuery( table_rows[table_row_count]).addClass('alternate'); |
| 98 | } else { |
| 99 | jQuery( table_rows[table_row_count]).removeClass('alternate'); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | }); |