PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 1.3.4
Nested Pages v1.3.4
3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / assets / js / lib / nestedpages.js
wp-nested-pages / assets / js / lib Last commit date
bs-modal.js 11 years ago jquery.mjs.nestedSortable.js 11 years ago jquery.ui.touch-punch.min.js 11 years ago nestedpages.js 11 years ago
nestedpages.js
1611 lines
1 /**
2 * Scripts Required by Nested Pages Plugin
3 * @author Kyle Phillips
4 */
5 jQuery(function($){
6
7 /**
8 * ------------------------------------------------------------------------
9 * Sortable and Toggline
10 * ------------------------------------------------------------------------
11 **/
12
13
14 /**
15 * Add the Submenu Toggles (using JS to prevent additional DB Queries)
16 */
17 $(document).ready(function(){
18 add_remove_submenu_toggles();
19 np_set_borders();
20 set_nested_margins();
21 np_make_nestable();
22 });
23
24 /**
25 * Toggle the Submenus
26 */
27 $(document).on('click', '.child-toggle a', function(e){
28 e.preventDefault();
29 var submenu = $(this).parent('.child-toggle').parent('.row').siblings('ol');
30 $(this).find('i').toggleClass('np-icon-arrow-down').toggleClass('np-icon-arrow-right');
31 $(submenu).toggle();
32 np_set_borders();
33 np_sync_user_toggles();
34 set_nested_margins();
35 });
36
37 /**
38 * Toggle all pages (Expand All)
39 */
40 $(document).on('click', '.nestedpages-toggleall a', function(e){
41 e.preventDefault();
42 if ( $(this).attr('data-toggle') == 'closed' )
43 {
44 $('.nestedpages ol li ol').show();
45 $(this).attr('data-toggle', 'opened');
46 $(this).text(nestedpages.collapse_text);
47 $('.child-toggle i').removeClass('np-icon-arrow-right').addClass('np-icon-arrow-down');
48 revert_quick_edit();
49 np_set_borders();
50 } else
51 {
52 $('.nestedpages ol li ol').hide();
53 $(this).attr('data-toggle', 'closed');
54 $(this).text(nestedpages.expand_text);
55 $('.child-toggle i').removeClass('np-icon-arrow-down').addClass('np-icon-arrow-right');
56 revert_quick_edit();
57 np_set_borders();
58 }
59 np_sync_user_toggles();
60 });
61
62 /**
63 * Toggle hidden pages
64 */
65 $(document).on('click', '.np-toggle-hidden', function(e){
66 e.preventDefault();
67 var action = $(this).attr('href');
68 if ( action === 'show' ){
69 $(this).attr('href', 'hide');
70 $(this).text(nestedpages.show_hidden);
71 $('.np-hide').removeClass('shown').hide();
72 np_set_borders();
73 } else {
74 $(this).attr('href', 'show');
75 $(this).text(nestedpages.hide_hidden);
76 $('.np-hide').addClass('shown').show();
77 np_set_borders();
78 }
79 });
80
81 /**
82 * Tabs
83 */
84 $('.np-tabs a').on('click', function(e){
85 e.preventDefault();
86 $('.np-tabs a').removeClass('active');
87 $(this).addClass('active');
88
89 var target = $(this).attr('href');
90 $('.np-tabbed-content').hide();
91 $(target).show();
92 });
93
94 /**
95 * Fix :visible :first css limitation when toggling various options
96 */
97 function np_set_borders()
98 {
99 var lists = $('.nplist');
100 $('.page-row').removeClass('no-border');
101 $.each(lists, function(){
102 $(this).find('.page-row:visible:first').addClass('no-border');
103 });
104 }
105
106 /**
107 * Adjust nested margins
108 * @since 1.1.10
109 */
110 function set_nested_margins()
111 {
112 var lists = $('.nestedpages').find('.nplist');
113 $.each(lists, function(i, v){
114
115 var parent_count = $(this).parents('.nplist').length;
116 var padding = 56;
117 if ( parent_count > 0 ){
118 var padding = ( parent_count * 20 ) + padding;
119 $(this).find('.row-inner').css('padding-left', padding + 'px');
120 } else {
121 $(this).find('.row-inner').css('padding-left', '0px');
122 }
123
124 });
125 }
126
127 /**
128 * Get Post Type from List ID
129 */
130 function np_get_post_type()
131 {
132 var sortableID = $('.sortable').attr('id');
133 return sortableID.substring(3);
134 }
135
136 /**
137 * Is the Post Type Hierarchical
138 */
139 function np_is_hierarchical()
140 {
141 var post_type = np_get_post_type();
142 return ( max_levels(post_type) === 0 ) ? true : false;
143 }
144
145 /**
146 * Toggle between showing published pages and all
147 */
148 $(document).on('click', '.np-toggle-publish', function(e){
149 e.preventDefault();
150 var target = $(this).attr('href');
151 $('.np-toggle-publish').removeClass('active');
152 $(this).addClass('active');
153 if ( target == '#published' ){
154 $('.nplist .page-row').hide();
155 $('.nplist .published').show();
156 } else {
157 $('.nplist .page-row').show();
158 }
159 });
160
161
162 /**
163 * Toggle Responsive Action Buttons (Quick edit, add child, etc)
164 */
165 $(document).on('click', '.np-toggle-edit', function(e){
166 e.preventDefault();
167 var buttons = $(this).siblings('.action-buttons');
168 if ( $(buttons).is(':visible') ){
169 $(this).removeClass('active');
170 $(buttons).hide();
171 } else {
172 $(this).addClass('active');
173 $(buttons).show();
174 }
175 });
176 /**
177 * Remove display block on action buttons when sizing up
178 */
179 var actiondelay = (function(){
180 var timer = 0;
181 return function(callback, ms){
182 clearTimeout (timer);
183 timer = setTimeout(callback, ms);
184 };
185 })();
186 $(window).resize(function() {
187 actiondelay(function(){
188 $('.action-buttons').removeAttr('style');
189 $('.np-toggle-edit').removeClass('active');
190 }, 500);
191 });
192
193
194 /**
195 * Make the Menu sortable
196 */
197 function np_make_nestable()
198 {
199 $('.sortable').not('.no-sort').nestedSortable({
200 items : '.page-row',
201 toleranceElement: '> .row',
202 handle: '.handle',
203 placeholder: "ui-sortable-placeholder",
204 maxLevels: max_levels(np_get_post_type()),
205 start: function(e, ui){
206 ui.placeholder.height(ui.item.height());
207 },
208 sort: function(e, ui){
209 update_placeholder_width(ui);
210 },
211 stop: function(e, ui){
212 setTimeout(
213 function(){
214 add_remove_submenu_toggles();
215 np_set_borders();
216 set_nested_margins();
217 }, 100
218 );
219 submit_sortable_form();
220 },
221 });
222 }
223
224 /**
225 * Disable Nesting
226 */
227 function np_disable_nesting()
228 {
229 $('.sortable').sortable('destroy');
230 }
231
232 /**
233 * Is Post Type Nestable?
234 */
235 function max_levels(post_type)
236 {
237 var levels = 1;
238 $.each(nestedpages.post_types, function(i, v){
239 if ( v.name === post_type ){
240 if ( v.hierarchical === true ) levels = 0;
241 if ( v.disable_nesting === true ) levels = 1;
242 }
243 });
244 return levels;
245 }
246
247 /**
248 * Update the width of the placeholder
249 */
250 function update_placeholder_width(ui)
251 {
252 if ( max_levels(np_get_post_type()) === 0 ){
253 var parentCount = $(ui.placeholder).parents('ol').length;
254 var listWidth = $('.sortable').width();
255 var offset = ( parentCount * 40 ) - 40;
256 var newWidth = listWidth - offset;
257 $(ui.placeholder).width(newWidth).css('margin-left', offset + 'px');
258 }
259 update_list_visibility(ui);
260 }
261
262 /**
263 * Make new list items visible
264 */
265 function update_list_visibility(ui)
266 {
267 var parentList = $(ui.placeholder).parent('ol');
268 if ( !$(parentList).is(':visible') ){
269 $(parentList).addClass('nplist');
270 $(parentList).show();
271 }
272 }
273
274
275 /**
276 * Add or Remove the submenu toggle after the list has changed
277 */
278 function add_remove_submenu_toggles()
279 {
280 $('.child-toggle').each(function(i, v){
281 var row = $(this).parent('.row').parent('li');
282
283 if ( $(row).children('ol').length > 0 ){
284 var icon = ( $(row).children('ol:visible').length > 0 ) ? 'np-icon-arrow-down' : 'np-icon-arrow-right';
285 $(this).html('<a href="#"><i class="' + icon + '"></i></a>');
286 } else {
287 $(this).empty();
288 }
289 });
290 }
291
292
293 /**
294 * Submit Sortable Form
295 * @todo add error div, pass message to it and show on error
296 */
297 function submit_sortable_form()
298 {
299 $('#np-error').hide();
300 $('#nested-loading').show();
301 var syncmenu = ( $('.np-sync-menu').is(':checked') ) ? 'sync' : 'nosync';
302
303 list = $('ol.sortable').nestedSortable('toHierarchy', {startDepthCount: 0});
304 np_disable_nesting();
305
306 $.ajax({
307 url: ajaxurl,
308 type: 'post',
309 datatype: 'json',
310 data: {
311 action : 'npsort',
312 nonce : nestedpages.np_nonce,
313 list : list,
314 post_type : np_get_post_type(),
315 syncmenu : syncmenu
316 },
317 success: function(data){
318 np_make_nestable();
319 if (data.status === 'error'){
320 $('#np-error').text(data.message).show();
321 $('#nested-loading').hide();
322 } else {
323 $('#nested-loading').hide();
324 }
325 }
326 });
327 }
328
329
330
331
332
333 /**
334 * ------------------------------------------------------------------------
335 * Sync Menu
336 * ------------------------------------------------------------------------
337 **/
338
339 /**
340 * Sync menu to catch any trash updates
341 */
342 $(document).ready(function(){
343 if ( nestedpages.syncmenu === '1' ) np_updated_sync_menu('sync');
344 });
345
346 /**
347 * Sync Menu Checkbox Toggle
348 */
349 $('.np-sync-menu').on('change', function(){
350 var setting = ( $(this).is(':checked') ) ? 'sync' : 'nosync';
351 np_updated_sync_menu(setting);
352 });
353
354 function np_updated_sync_menu(setting)
355 {
356 $.ajax({
357 url: ajaxurl,
358 type: 'post',
359 datatype: 'json',
360 data: {
361 action : 'npsyncMenu',
362 nonce : nestedpages.np_nonce,
363 post_type : np_get_post_type(),
364 syncmenu : setting
365 },
366 success: function(data){
367 if (data.status === 'error'){
368 alert('There was an error saving the sync setting.')
369 }
370 }
371 });
372 }
373
374
375
376
377
378
379 /**
380 * ------------------------------------------------------------------------
381 * Quick Edit - Posts
382 * ------------------------------------------------------------------------
383 **/
384
385 // Show the form
386 $(document).on('click', '.np-quick-edit', function(e){
387 e.preventDefault();
388 revert_quick_edit();
389 set_quick_edit_data($(this));
390 });
391
392 // Hide the form when clicking modal overlay
393 $(document).on('click', '.np-inline-overlay', function(e){
394 revert_quick_edit();
395 revert_new_child();
396 });
397
398 // Cancel the form
399 $(document).on('click', '.np-cancel-quickedit', function(e){
400 var row = $(this).parents('.page-row');
401 revert_quick_edit(row);
402 e.preventDefault();
403 });
404
405 // Submit the form
406 $(document).on('click', '.np-save-quickedit', function(e){
407 e.preventDefault();
408 $('.row').removeClass('np-updated').removeClass('np-updated-show');
409 var form = $(this).parents('form');
410 $(this).attr('disabled', 'disabled');
411 $(form).find('.np-qe-loading').show();
412 submit_np_quickedit(form);
413 });
414
415 // Toggle the Taxonomies
416 $(document).on('click', '.np-toggle-taxonomies', function(e){
417 $(this).parents('form').find('.np-taxonomies').toggle();
418 e.preventDefault();
419 });
420
421 // Toggle the Menu Options
422 $(document).on('click', '.np-toggle-menuoptions', function(e){
423 e.preventDefault();
424 $(this).parents('form').find('.np-menuoptions').toggle();
425 });
426
427 // Toggle password/private
428 $(document).on('change', '.keep_private', function(){
429 if ( this.checked ){
430 $('.post_password').val('').prop('readonly', true);
431 } else {
432 $('.post_password').prop('readonly', false);
433 }
434 });
435
436
437 /**
438 * Set Quick Edit data
439 */
440 function set_quick_edit_data(item)
441 {
442 var data = {
443 id : $(item).attr('data-id'),
444 title : $(item).attr('data-title'),
445 slug : $(item).attr('data-slug'),
446 author : $(item).attr('data-author'),
447 cs : $(item).attr('data-commentstatus'),
448 status : $(item).attr('data-status'),
449 template : $(item).attr('data-template'),
450 month : $(item).attr('data-month'),
451 day : $(item).attr('data-day'),
452 year : $(item).attr('data-year'),
453 hour : $(item).attr('data-hour'),
454 minute : $(item).attr('data-minute'),
455 navstatus : $(item).attr('data-navstatus'),
456 npstatus : $(item).attr('data-np-status'),
457 navtitle : $(item).attr('data-navtitle'),
458 navtitleattr : $(item).attr('data-navtitleattr'),
459 navcss : $(item).attr('data-navcss'),
460 linktarget : $(item).attr('data-linktarget'),
461 password : $(item).attr('data-password'),
462 datepicker : $(item).attr('data-datepicker'),
463 time: $(item).attr('data-formattedtime'),
464 ampm: $(item).attr('data-ampm')
465 };
466 var parent_li = $(item).closest('.row').parent('li');
467
468 // Add Array of Taxonomies to the data object
469 data.h_taxonomies = [];
470 data.f_taxonomies = [];
471
472 var classes = $(parent_li).attr('class').split(/\s+/);
473 for ( i = 0; i < classes.length; i++ ){
474 if ( classes[i].substring(0, 3) === 'in-'){
475 data.h_taxonomies.push(classes[i]);
476 }
477 if ( classes[i].substring(0, 4) === 'inf-' ){
478 data.f_taxonomies.push(classes[i]);
479 }
480 }
481
482 // Append the form to the list item
483 if ( $(parent_li).children('ol').length > 0 ){
484 var child_ol = $(parent_li).children('ol');
485 var newform = $('.quick-edit-form').clone().insertBefore(child_ol);
486 } else {
487 var newform = $('.quick-edit-form').clone().appendTo(parent_li);
488 }
489
490 var row = $(newform).siblings('.row').hide();
491 populate_quick_edit(newform, data);
492 }
493
494
495 /**
496 * Populate the Quick Edit Form and show it
497 */
498 function populate_quick_edit(form, data)
499 {
500 $(form).find('.page_id').html('<em>ID:</em> ' + data.id);
501 $(form).find('.np_id').val(data.id);
502 $(form).find('.np_title').val(data.title);
503 $(form).find('.np_slug').val(data.slug);
504 $(form).find('.np_author select').val(data.author);
505 $(form).find('.np_status').val(data.status);
506 $(form).find('.np_nav_title').val(data.navtitle);
507 $(form).find('.np_title_attribute').val(data.navtitleattr);
508 $(form).find('.np_nav_css_classes').val(data.navcss);
509 $(form).find('.post_password').val(data.password);
510 $(form).find('.np_datepicker').val(data.datepicker);
511 $(form).find('.np_time').val(data.time);
512 $(form).find('.np_ampm').val(data.ampm);
513 if ( data.cs === 'open' ) $(form).find('.np_cs').prop('checked', 'checked');
514
515 if ( data.template !== '' ){
516 $(form).find('.np_template').val(data.template);
517 } else {
518 $(form).find('.np_template').val('default');
519 }
520
521 if ( data.status === 'private' ){
522 $(form).find('.post_password').prop('readonly', true);
523 $(form).find('.keep_private').prop('checked', true);
524 }
525
526 if ( data.npstatus === 'hide' ){
527 $(form).find('.np_status').prop('checked', 'checked');
528 } else {
529 $(form).find('.np_status').removeAttr('checked');
530 }
531
532 if ( data.navstatus === 'hide' ) {
533 $(form).find('.np_nav_status').prop('checked', 'checked');
534 } else {
535 $(form).find('.np_nav_status').removeAttr('checked');
536 }
537
538 if ( data.linktarget === "_blank" ) {
539 $(form).find('.link_target').prop('checked', 'checked');
540 } else {
541 $(form).find('.link_target').removeAttr('checked');
542 }
543
544 if ( data.status === "private" ) {
545 $(form).find('.np_status').val('publish');
546 }
547
548 // Date Fields
549 $(form).find('select[name="mm"]').val(data.month);
550 $(form).find('input[name="jj"]').val(data.day);
551 $(form).find('input[name="aa"]').val(data.year);
552 $(form).find('input[name="hh"]').val(data.hour);
553 $(form).find('input[name="mn"]').val(data.minute);
554
555 // Populate Hierarchical Taxonomy Checkboxes
556 if ( data.hasOwnProperty('h_taxonomies') ){
557 var taxonomies = data.h_taxonomies;
558 for ( i = 0; i < taxonomies.length; i++ ){
559 var tax = '#' + taxonomies[i];
560 $(form).find(tax).prop('checked', 'checked');
561 }
562 }
563
564 show_quick_edit_overlay();
565
566 $(form).show();
567 $(form).find('.np_datepicker').datepicker({
568 beforeShow: function(input, inst) {
569 $('#ui-datepicker-div').addClass('nestedpages-datepicker');
570 }
571 });
572
573
574 // Populate Flat Taxonomies (makes ajax request, so do this after showing form)
575 if ( data.hasOwnProperty('f_taxonomies') ){
576 create_taxonomy_object(data.f_taxonomies);
577 set_wp_suggest(form);
578 }
579 }
580
581
582 /**
583 * Create object of flat taxonomies out of class names
584 */
585 function create_taxonomy_object(taxonomies)
586 {
587 var out = "";
588 var terms = {};
589 for ( i = 0; i < taxonomies.length; i++ ){
590 // Get the term
591 var tax_array = taxonomies[i].split('-'); // split the string into an array
592 var splitter = tax_array.indexOf('nps'); // find the index of the name splitter
593 var term = tax_array.splice(splitter + 1); // Splice off the name
594 term = term.join('-'); // Join the name back into a string
595
596 // Get the taxonomy
597 var tax = taxonomies[i].split('-').splice(0, splitter);
598 tax.shift('inf');
599 var taxonomy = tax.join('-');
600
601 // Add taxonomy array to object
602 if ( !(taxonomy in terms) ){
603 terms[taxonomy] = [];
604 }
605 // push term to taxonomy array
606 var term_array = terms[taxonomy];
607 term_array.push(term);
608 }
609 get_taxonomy_names(terms);
610 }
611
612
613
614 /**
615 * Get Taxonomy Names
616 * @param array of term slugs
617 */
618 function get_taxonomy_names(taxonomies)
619 {
620 $.ajax({
621 url: ajaxurl,
622 type: 'post',
623 datatype: 'json',
624 data : {
625 action : 'npgetTaxonomies',
626 nonce : nestedpages.np_nonce,
627 terms : taxonomies
628 },
629 success: function(data){
630 populate_flat_taxonomies(data.terms);
631 }
632 });
633 }
634
635 /**
636 * Populate flat taxonomy textareas
637 * @param object
638 */
639 function populate_flat_taxonomies(terms)
640 {
641 if ( terms ){
642 $.each(terms, function(i, v){
643 var textarea = $('#' + i);
644 $(textarea).val(v.join(','));
645 });
646 }
647 }
648
649
650 /**
651 * Set WP Taxonomy Suggest (Flat taxonomies)
652 */
653 function set_wp_suggest(form)
654 {
655 var tagfields = $(form).find('[data-autotag]');
656 $.each(tagfields, function(i, v){
657 var taxonomy = $(this).attr('data-taxonomy');
658 $(this).suggest(ajaxurl + '?action=ajax-tag-search&tax=' + taxonomy , {multiple:true, multipleSep: ","});
659 });
660 }
661
662
663 /**
664 * Remove the quick edit form and restore the row
665 */
666 function revert_quick_edit()
667 {
668 $('.np-quickedit-error').hide();
669 remove_quick_edit_overlay();
670 $('.sortable .quick-edit').remove();
671 $('.row').show();
672 }
673
674 /**
675 * Show the Quick edit overlay
676 */
677 function show_quick_edit_overlay()
678 {
679 $('body').append('<div class="np-inline-overlay"></div>');
680 setTimeout(function(){
681 $('.np-inline-overlay').addClass('active');
682 }, 50);
683 }
684
685 /**
686 * Remove the Quick edit overlay
687 */
688 function remove_quick_edit_overlay()
689 {
690 $('.np-inline-overlay').removeClass('active').remove();
691 }
692
693
694 /**
695 * Submit the Quick Edit Form
696 */
697 function submit_np_quickedit(form)
698 {
699 $('.np-quickedit-error').hide();
700 var syncmenu = ( $('.np-sync-menu').is(':checked') ) ? 'sync' : 'nosync';
701
702 $.ajax({
703 url: ajaxurl,
704 type: 'post',
705 datatype: 'json',
706 data: $(form).serialize() + '&action=npquickEdit&nonce=' + nestedpages.np_nonce + '&syncmenu=' + syncmenu + '&post_type=' + np_get_post_type(),
707 success: function(data){
708 if (data.status === 'error'){
709 np_remove_qe_loading(form);
710 $(form).find('.np-quickedit-error').text(data.message).show();
711 } else {
712 np_remove_qe_loading(form);
713 np_update_qe_data(form, data.post_data);
714 np_qe_update_animate(form);
715 }
716 },
717 error: function(data){
718 console.log(data);
719 }
720 });
721 }
722
723
724 /**
725 * Update Row Data after Quick Edit
726 */
727 function np_update_qe_data(form, data)
728 {
729 var row = $(form).parent('.quick-edit').siblings('.row');
730 $(row).find('.title').text(data.post_title);
731
732 var status = $(row).find('.status');
733 if ( (data._status !== 'publish') && (data._status !== 'future') ){
734 $(status).text('(' + data._status + ')');
735 } else if (data.keep_private === 'private') {
736 $(status).text('(' + data.keep_private + ')');
737 } else {
738 $(status).text('');
739 }
740
741 // Password Lock Icon
742 if ( data.post_password !== "" ){
743 var statustext = $(status).text();
744 statustext += ' <i class="np-icon-lock"></i>';
745 $(status).html(statustext);
746 }
747
748 // Hide / Show in Nav
749 var nav_status = $(row).find('.nav-status');
750 if ( (data.nav_status == 'hide') ){
751 $(nav_status).text('(Hidden)');
752 } else {
753 $(nav_status).text('');
754 }
755
756 // Hide / Show in Nested Pages
757 var li = $(row).parent('li');
758 if ( (data.np_status == 'hide') ){
759 $(li).addClass('np-hide');
760 $(row).find('.status').after('<i class="np-icon-eye-blocked"></i>');
761 } else {
762 $(li).removeClass('np-hide');
763 $(row).find('.np-icon-eye-blocked').remove();
764 }
765
766 // Author for Non-Hierarchical Types
767 if ( !np_is_hierarchical() ){
768 $(row).find('.np-author-display').text(data.author_name);
769 }
770
771 var button = $(row).find('.np-quick-edit');
772
773 $(button).attr('data-id', data.post_id);
774 $(button).attr('data-template', data.page_template);
775 $(button).attr('data-title', data.post_title);
776 $(button).attr('data-slug', data.post_name);
777 $(button).attr('data-commentstatus', data.comment_status);
778 $(button).attr('data-status', data._status);
779
780 // Private Status
781 if ( data.keep_private === 'private' ) {
782 $(button).attr('data-status', 'private');
783 }
784
785 $(button).attr('data-author', data.post_author);
786 $(button).attr('data-np-status', data.np_status);
787 $(button).attr('data-password', data.post_password);
788
789 $(button).attr('data-navstatus', data.nav_status);
790 $(button).attr('data-navtitle', data.np_nav_title);
791 $(button).attr('data-linktarget', data.link_target);
792 $(button).attr('data-navtitleattr', data.np_title_attribute);
793 $(button).attr('data-navcss', data.np_nav_css_classes);
794
795 $(button).attr('data-month', data.mm);
796 $(button).attr('data-day', data.jj);
797 $(button).attr('data-year', data.aa);
798 $(button).attr('data-hour', data.hh);
799 $(button).attr('data-minute', data.mn);
800 $(button).attr('data-datepicker', data.np_date);
801 $(button).attr('data-time', data.np_time);
802 $(button).attr('data-formattedtime', data.np_time);
803 $(button).attr('data-ampm', data.np_ampm);
804
805 np_remove_taxonomy_classes(li);
806 np_add_category_classes(li, data);
807 np_add_h_taxonomy_classes(li, data);
808 np_add_f_taxonomy_classes(li, data);
809
810 }
811
812
813 /**
814 * Remove taxonomy classes from the row
815 */
816 function np_remove_taxonomy_classes(row)
817 {
818 taxonomies = [];
819 var classes = $(row).attr('class').split(/\s+/);
820 for ( i = 0; i < classes.length; i++ ){
821 if ( classes[i].substring(0, 3) === 'in-'){
822 $(row).removeClass(classes[i]);
823 }
824 if ( classes[i].substring(0, 4) === 'inf-'){
825 $(row).removeClass(classes[i]);
826 }
827 }
828 }
829
830
831 /**
832 * Add category classes to the row
833 */
834 function np_add_category_classes(row, data)
835 {
836 if ( data.hasOwnProperty('post_category') ){
837 var cats = data.post_category;
838 for ( i = 0; i < cats.length; i++ ){
839 var taxclass = 'in-category-' + cats[i];
840 $(row).addClass(taxclass);
841 }
842 }
843 }
844
845
846 /**
847 * Add Hierarchical Taxonomy Classes to the row
848 */
849 function np_add_h_taxonomy_classes(row, data)
850 {
851 if ( data.hasOwnProperty('tax_input') )
852 {
853 var taxonomies = data.tax_input;
854 $.each(taxonomies, function(tax, terms){
855 for (i = 0; i < terms.length; i++){
856 var taxclass = 'in-' + tax + '-' + terms[i];
857 $(row).addClass(taxclass);
858 }
859 });
860
861 }
862 }
863
864
865 /**
866 * Add Flat Taxonomy Classes to the row
867 */
868 function np_add_f_taxonomy_classes(row, data)
869 {
870 if ( data.hasOwnProperty('flat_tax') )
871 {
872 var taxonomies = data.flat_tax;
873 $.each(taxonomies, function(tax, terms){
874 for (i = 0; i < terms.length; i++){
875 var taxclass = 'inf-' + tax + '-nps-' + terms[i];
876 $(row).addClass(taxclass);
877 }
878 });
879
880 }
881 }
882
883
884 /**
885 * Remove loading state from Quick Edit form
886 */
887 function np_remove_qe_loading(form)
888 {
889 $(form).find('.np-save-quickedit, .np-save-quickedit-redirect, .np-save-newchild').removeAttr('disabled');
890 $(form).find('.np-qe-loading').hide();
891 }
892
893 /**
894 * Show quick edit update animation
895 */
896 function np_qe_update_animate(form)
897 {
898 var row = $(form).parent('.quick-edit, .new-child').siblings('.row');
899 $(row).addClass('np-updated');
900 $(row).show();
901 $(form).parent('.quick-edit, .new-child').remove();
902 remove_quick_edit_overlay();
903 np_set_borders();
904 setTimeout(function(){
905 $(row).addClass('np-updated-show');
906 }, 1500);
907 }
908
909
910
911
912
913 /**
914 * ------------------------------------------------------------------------
915 * Quick Edit - Redirect
916 * ------------------------------------------------------------------------
917 **/
918 $(document).on('click', '.np-quick-edit-redirect', function(e){
919 e.preventDefault();
920 revert_quick_edit();
921 set_redirect_quick_edit_data($(this));
922 });
923
924 // Submit the form
925 $(document).on('click', '.np-save-quickedit-redirect', function(e){
926 e.preventDefault();
927 $('.row').removeClass('np-updated').removeClass('np-updated-show');
928 var form = $(this).parents('form');
929 $(this).attr('disabled', 'disabled');
930 $(form).find('.np-qe-loading').show();
931 submit_np_quickedit_redirect(form);
932 });
933
934 /**
935 * Set the Redirect Quick edit data & create form
936 */
937 function set_redirect_quick_edit_data(item)
938 {
939 var data = {
940 id : $(item).attr('data-id'),
941 url : $(item).attr('data-url'),
942 title : $(item).attr('data-title'),
943 status : $(item).attr('data-status'),
944 navstatus : $(item).attr('data-navstatus'),
945 npstatus : $(item).attr('data-np-status'),
946 linktarget : $(item).attr('data-linktarget'),
947 parentid : $(item).attr('data-parentid'),
948 navtitleattr : $(item).attr('data-navtitleattr'),
949 navcss : $(item).attr('data-navcss')
950 };
951 var parent_li = $(item).closest('.row').parent('li');
952
953 // Append the form to the list item
954 if ( $(parent_li).children('ol').length > 0 ){
955 var child_ol = $(parent_li).children('ol');
956 var newform = $('.quick-edit-form-redirect').clone().insertBefore(child_ol);
957 } else {
958 var newform = $('.quick-edit-form-redirect').clone().appendTo(parent_li);
959 }
960
961 var row = $(newform).siblings('.row').hide();
962 $(newform).show();
963
964 populate_redirect_quick_edit(newform, data);
965 }
966
967 /**
968 * Populate the Quick Edit Form
969 */
970 function populate_redirect_quick_edit(form, data)
971 {
972 $(form).find('.np_id').val(data.id);
973 $(form).find('.np_title').val(data.title);
974 $(form).find('.np_author select').val(data.author);
975 $(form).find('.np_status').val(data.status);
976 $(form).find('.np_content').val(data.url);
977 $(form).find('.np_parent_id').val(data.parentid);
978 $(form).find('.np_title_attribute').val(data.navtitleattr);
979 $(form).find('.np_nav_css_classes').val(data.navcss);
980
981 if ( data.npstatus === 'hide' ){
982 $(form).find('.np_status').prop('checked', 'checked');
983 } else {
984 $(form).find('.np_status').removeAttr('checked');
985 }
986
987 if ( data.navstatus === 'hide' ) {
988 $(form).find('.np_nav_status').prop('checked', 'checked');
989 } else {
990 $(form).find('.np_nav_status').removeAttr('checked');
991 }
992
993 if ( data.linktarget === "_blank" ) {
994 $(form).find('.link_target').prop('checked', 'checked');
995 } else {
996 $(form).find('.link_target').removeAttr('checked');
997 }
998
999 show_quick_edit_overlay();
1000
1001 $(form).show();
1002 }
1003
1004
1005 /**
1006 * Submit the Quick Edit Form for Redirects
1007 */
1008 function submit_np_quickedit_redirect(form)
1009 {
1010 $('.np-quickedit-error').hide();
1011 var syncmenu = ( $('.np-sync-menu').is(':checked') ) ? 'sync' : 'nosync';
1012 $.ajax({
1013 url: ajaxurl,
1014 type: 'post',
1015 datatype: 'json',
1016 data: $(form).serialize() + '&action=npquickEditLink&nonce=' + nestedpages.np_nonce + '&syncmenu=' + syncmenu + '&post_type=' + np_get_post_type(),
1017 success: function(data){
1018 console.log(data);
1019 if (data.status === 'error'){
1020 np_remove_qe_loading(form);
1021 $(form).find('.np-quickedit-error').text(data.message).show();
1022 } else {
1023 np_remove_qe_loading(form);
1024 np_update_qe_redirect_data(form, data.post_data);
1025 np_qe_update_animate(form);
1026 }
1027 },
1028 error: function(){
1029 np_remove_qe_loading(form);
1030 $(form).find('.np-quickedit-error').text('The form could not be saved at this time.').show();
1031 }
1032 });
1033 }
1034
1035
1036 /**
1037 * Update Row Data after Quick Edit (Redirect)
1038 */
1039 function np_update_qe_redirect_data(form, data)
1040 {
1041 var row = $(form).parent('.quick-edit').siblings('.row');
1042 $(row).find('.title').html(data.post_title + ' <i class="np-icon-link"></i>');
1043
1044 var status = $(row).find('.status');
1045 if ( (data._status !== 'publish') && (data._status !== 'future') ){
1046 $(status).text('(' + data._status + ')');
1047 } else {
1048 $(status).text('');
1049 }
1050
1051 // Hide / Show in Nav
1052 var nav_status = $(row).find('.nav-status');
1053 if ( (data.nav_status == 'hide') ){
1054 $(nav_status).text('(Hidden)');
1055 } else {
1056 $(nav_status).text('');
1057 }
1058
1059 // Hide / Show in Nested Pages
1060 var li = $(row).parent('li');
1061 if ( (data.np_status == 'hide') ){
1062 $(li).addClass('np-hide');
1063 $(row).find('.status').after('<i class="np-icon-eye-blocked"></i>');
1064 } else {
1065 $(li).removeClass('np-hide');
1066 $(row).find('.np-icon-eye-blocked').remove();
1067 }
1068
1069 var button = $(row).find('.np-quick-edit-redirect');
1070
1071 $(button).attr('data-id', data.post_id);
1072 $(button).attr('data-title', data.post_title);
1073 $(button).attr('data-url', data.post_content);
1074 $(button).attr('data-status', data._status);
1075 $(button).attr('data-navstatus', data.nav_status);
1076 $(button).attr('data-np-status', data.np_status);
1077 $(button).attr('data-linktarget', data.link_target);
1078 $(button).attr('data-navtitleattr', data.np_title_attribute);
1079 $(button).attr('data-navcss', data.np_nav_css_classes);
1080 }
1081
1082
1083
1084
1085
1086 /**
1087 * ------------------------------------------------------------------------
1088 * Add new Redirect link (modal)
1089 * ------------------------------------------------------------------------
1090 **/
1091 $(document).on('click', '.open-redirect-modal', function(e){
1092 e.preventDefault();
1093 var parent_id = $(this).attr('data-parentid');
1094 $('#np-link-modal').find('input').val('');
1095 $('#np-link-modal .parent_id').val(parent_id);
1096 if (parent_id === '0'){
1097 $('#np-add-link-title').text(nestedpages.add_link);
1098 } else {
1099 $('#np-add-link-title').text(nestedpages.add_child_link);
1100 }
1101 $('#np-link-modal').modal('show');
1102 });
1103
1104 $(document).on('click', '.np-save-link', function(e){
1105 e.preventDefault();
1106 $('.np-new-link-error').hide();
1107 $('.np-link-loading').show();
1108 $(this).attr('disabled', 'disabled');
1109 np_save_new_link();
1110 });
1111
1112 /**
1113 * Remove loading state from link form
1114 */
1115 function np_remove_link_loading()
1116 {
1117 $('.np-link-loading').hide();
1118 $('.np-save-link').removeAttr('disabled');
1119 }
1120
1121 /**
1122 * Set new link data
1123 */
1124 function np_save_new_link()
1125 {
1126 $('.np-new-link-error').hide();
1127 var data = $('.np-new-link-form').serialize();
1128 var syncmenu = ( $('.np-sync-menu').is(':checked') ) ? 'sync' : 'nosync';
1129
1130 $.ajax({
1131 url: ajaxurl,
1132 type: 'post',
1133 datatype: 'json',
1134 data: data + '&action=npnewLink&nonce=' + nestedpages.np_nonce + '&syncmenu=' + syncmenu + '&post_type=' + np_get_post_type(),
1135 success: function(data){
1136 if (data.status === 'error'){
1137 np_remove_link_loading();
1138 $('.np-new-link-error').text(data.message).show();
1139 } else {
1140 np_remove_link_loading();
1141 np_create_redirect_row(data.post_data);
1142 }
1143 }
1144 });
1145 }
1146
1147 /**
1148 * Create the new row and append where needed
1149 */
1150 function np_create_redirect_row(data)
1151 {
1152 var html = '<li id="menuItem_' + data.id + '" class="page-row';
1153 if ( data._status === 'publish' ){
1154 html += ' published';
1155 }
1156 html += '">'
1157
1158 html += '<div class="row"><div class="child-toggle"></div><div class="row-inner"><i class="np-icon-sub-menu"></i><i class="handle np-icon-menu"></i><a href="' + data.np_link_content + '" class="page-link page-title" target="_blank"><span class="title">' + data.np_link_title + ' <i class="np-icon-link"></i></span>';
1159
1160 // Post Status
1161 if ( data._status !== 'publish' ){
1162 html += '<span class="status">' + data._status + '</span>';
1163 } else {
1164 html += '<span class="status"></span>';
1165 }
1166
1167 // Nested Pages Status
1168 if ( data.np_status === "hide" ){
1169 html += '<i class="np-icon-eye-blocked"></i>';
1170 }
1171
1172 // Nav Menu Status
1173 if ( data.nav_status === "hide" ){
1174 html += '<span class="nav-status">(Hidden)</span>';
1175 } else {
1176 html += '<span class="nav-status"></span>';
1177 }
1178
1179 // Quick Edit Button
1180 html += '</a><a href="#" class="np-toggle-edit"><i class="np-icon-pencil"></i></a><div class="action-buttons"><a href="#" class="np-btn np-quick-edit-redirect" ';
1181 html += 'data-id="' + data.id + '"';
1182 html += 'data-parentid="' + data.parent_id + '"';
1183 html += 'data-title="' + data.np_link_title + '" ';
1184 html += 'data-url="' + data.np_link_content + '" ';
1185 html += 'data-status="' + data._status + '" ';
1186 html += 'data-np-status="' + data.np_status + '" ';
1187 html += 'data-navstatus="' + data.nav_status + '" ';
1188 html += 'data-linktarget="' + data.link_target + '">'
1189 html += 'Quick Edit</a>';
1190
1191 // Delete Link
1192 html += '<a href="' + data.delete_link + '" class="np-btn np-btn-trash"><i class="np-icon-remove"></i></a>';
1193
1194 html += '</div></div></div></li>';
1195
1196 if ( data.parent_id === "0" ){
1197 $('.nplist:first li:first').after(html);
1198 } else {
1199 np_append_child_link(html, data);
1200 }
1201
1202 $('#np-link-modal').modal('hide');
1203
1204 var row = $('#menuItem_' + data.id).find('.row');
1205 np_qe_update_redirect_animate(row);
1206 }
1207
1208
1209 /**
1210 * Append a child link
1211 */
1212 function np_append_child_link(html, data)
1213 {
1214 var parent_row = $('#menuItem_' + data.parent_id);
1215 if ( $(parent_row).children('ol').length === 0 ){
1216 html = '<ol class="sortable nplist" style="display:block;">' + html + '</ol>';
1217 $(parent_row).append(html);
1218 } else {
1219 $(parent_row).find('ol:first').prepend(html);
1220 }
1221 add_remove_submenu_toggles();
1222 np_sync_user_toggles();
1223 }
1224
1225
1226 /**
1227 * Show quick edit update animation after adding redirect
1228 */
1229 function np_qe_update_redirect_animate(row)
1230 {
1231 $(row).addClass('np-updated');
1232 np_set_borders();
1233 setTimeout(function(){
1234 $(row).addClass('np-updated-show');
1235 }, 1500);
1236 }
1237
1238
1239
1240
1241
1242 /**
1243 * ------------------------------------------------------------------------
1244 * Sync User's Toggled Pages
1245 * ------------------------------------------------------------------------
1246 **/
1247
1248 /**
1249 * Get an array of visible pages' ids
1250 * @return array
1251 */
1252 function np_get_visible_rows()
1253 {
1254 var visible_ids = [];
1255 var visible = $('.page-row:visible');
1256 $.each(visible, function(i, v){
1257 var id = $(this).attr('id');
1258 visible_ids.push(id.replace("menuItem_", ""));
1259 });
1260 return visible_ids;
1261 }
1262
1263 /**
1264 * Sync the user's stored toggle status
1265 */
1266 function np_sync_user_toggles()
1267 {
1268 var ids = np_get_visible_rows();
1269 var posttype = np_get_post_type();
1270 $.ajax({
1271 url: ajaxurl,
1272 type: 'post',
1273 datatype: 'json',
1274 data: {
1275 action : 'npnestToggle',
1276 nonce : nestedpages.np_nonce,
1277 ids : ids,
1278 posttype : posttype
1279 },
1280 success: function(data){
1281 if ( data.status !== 'success' ){
1282 console.log('There was an error saving toggled pages.');
1283 }
1284 }
1285 });
1286 }
1287
1288
1289
1290
1291
1292 /**
1293 * ------------------------------------------------------------------------
1294 * New Child Page(s)
1295 * ------------------------------------------------------------------------
1296 **/
1297
1298 /**
1299 * Remove the new page form and restore the row
1300 */
1301 function revert_new_child()
1302 {
1303 $('.np-newchild-error').hide();
1304 remove_quick_edit_overlay();
1305 $('#np-bulk-modal .modal-body').empty();
1306 $('.sortable .new-child').remove();
1307 $('.row').show();
1308 }
1309
1310 /**
1311 * Reset the bulk modal on close
1312 */
1313 $('#np-bulk-modal').on('hide.bs.modal', function(){
1314 revert_new_child();
1315 });
1316
1317 $(document).on('click', '.np-cancel-newchild', function(e){
1318 e.preventDefault();
1319 revert_new_child();
1320 $('#np-bulk-modal').modal('hide');
1321 });
1322
1323 /**
1324 * Show the New Page Form
1325 */
1326 $(document).on('click', '.add-new-child', function(e){
1327 e.preventDefault();
1328 populate_new_child($(this));
1329 });
1330
1331 /**
1332 * Show the Add Bulk Modal Form
1333 */
1334 $(document).on('click', '.open-bulk-modal', function(e){
1335 e.preventDefault();
1336 var newform = $('.new-child-form').clone().find('.np-new-child-form').addClass('in-modal');
1337 $('#np-bulk-modal .modal-body').html(newform);
1338 $('#np-bulk-modal .new-child-form').show();
1339 $('#np-bulk-modal').find('h3').text(nestedpages.add_multiple);
1340 $('#np-bulk-modal').find('.page_parent_id').val('0');
1341 $('#np-bulk-modal').modal('show');
1342 });
1343
1344
1345 /**
1346 * Set the Form Data for adding new child & Show it
1347 */
1348 function populate_new_child(item)
1349 {
1350 var parent_li = $(item).closest('.row').parent('li');
1351
1352 // Append the form to the list item
1353 if ( $(parent_li).children('ol').length > 0 ){
1354 var child_ol = $(parent_li).children('ol');
1355 var newform = $('.new-child-form').not('.np-modal .new-child-form').clone().insertBefore(child_ol);
1356 } else {
1357 var newform = $('.new-child-form').not('.np-modal .new-child-form').clone().appendTo(parent_li);
1358 }
1359
1360 var row = $(newform).siblings('.row').hide();
1361
1362 show_quick_edit_overlay();
1363
1364 $(newform).find('.parent_name').html('<em>Parent:</em> ' + $(item).attr('data-parentname'));
1365 $(newform).find('.page_parent_id').val($(item).attr('data-id'));
1366 $(newform).show();
1367 }
1368
1369
1370 /**
1371 * Add a Page Title Field
1372 */
1373 $(document).on('click', '.add-new-child-row', function(e){
1374 e.preventDefault();
1375 add_new_title_field($(this));
1376 var form = $(this).parents('form');
1377 update_pages_text(form);
1378 });
1379
1380 /**
1381 * Add a new title field
1382 */
1383 function add_new_title_field(item)
1384 {
1385 var html = '<li><i class="handle np-icon-menu"></i><div class="form-control new-child-row"><label>' + nestedpages.title + '</label><div><input type="text" name="post_title[]" class="np_title" placeholder="' + nestedpages.title + '" value="" /><a href="#" class="button-secondary np-remove-child">-</a></div></div></li>';
1386 var container = $(item).siblings('.new-page-titles').append(html);
1387 // Make sortable
1388 $('.new-page-titles').sortable({
1389 items : 'li',
1390 handle: '.handle',
1391 });
1392 }
1393
1394 /**
1395 * Update Pages Text
1396 * Toggle between singular and plural text for adding new page(s)
1397 */
1398 function update_pages_text(form)
1399 {
1400 var count = $(form).find($('.new-child-row')).length;
1401 if ( count > 1 ){
1402 $(form).find('.add-edit').hide();
1403 $(form).find('h3 strong').text(nestedpages.add_child_pages);
1404 $(form).find('.np-save-newchild').text(nestedpages.add + ' (' + count + ')');
1405 } else {
1406 $(form).find('.add-edit').show();
1407 $(form).find('h3 strong').text(nestedpages.add_child);
1408 $(form).find('.np-save-newchild').text(nestedpages.add);
1409 }
1410 }
1411
1412 /**
1413 * Remove New Child Page Field
1414 */
1415 $(document).on('click', '.np-remove-child', function(e){
1416 e.preventDefault();
1417 var form = $(this).parents('form');
1418 $(this).parents('.new-child-row').parent('li').remove();
1419 update_pages_text(form);
1420 });
1421
1422
1423 /**
1424 * Prevent New Child Page form Submission
1425 */
1426 $(document).on('submit', '.np-new-child-form', function(e){
1427 e.preventDefault();
1428 });
1429
1430
1431 /**
1432 * Submit the new child page form
1433 */
1434 $(document).on('click', '.np-save-newchild', function(e){
1435 e.preventDefault();
1436 $(this).prop('disabled', 'disabled');
1437 var form = $(this).parents('form');
1438 $(form).find('.np-qe-loading').show();
1439 var addedit = ( $(this).hasClass('add-edit') ) ? true : false;
1440 submit_new_child_form(form, addedit);
1441 });
1442
1443
1444 /**
1445 * Process New Child Form
1446 */
1447 function submit_new_child_form(form, addedit)
1448 {
1449 $('.np-quickedit-error').hide();
1450 var syncmenu = ( $('.np-sync-menu').is(':checked') ) ? 'sync' : 'nosync';
1451 $.ajax({
1452 url: ajaxurl,
1453 type: 'post',
1454 datatype: 'json',
1455 data: $(form).serialize() + '&action=npnewChild&nonce=' + nestedpages.np_nonce + '&syncmenu=' + syncmenu + '&post_type=' + np_get_post_type(),
1456 success: function(data){
1457 if (data.status === 'error'){
1458 np_remove_qe_loading(form);
1459 $(form).find('.np-quickedit-error').text(data.message).show();
1460 } else {
1461 if ( addedit === true ){ // Redirect to Edit Screen
1462 var link = data.new_pages[0].edit_link;
1463 link = link.replace(/&amp;/g, '&');
1464 window.location.replace(link);
1465 } else {
1466 np_remove_qe_loading(form);
1467 add_new_child_pages(form, data);
1468 }
1469 }
1470 },
1471 error: function(){
1472 np_remove_qe_loading(form);
1473 $(form).find('.np-quickedit-error').text('The form could not be saved at this time.').show();
1474 }
1475 });
1476 }
1477
1478
1479 /**
1480 * Add the Child New Pages
1481 */
1482 function add_new_child_pages(form, data)
1483 {
1484 var pages = data.new_pages;
1485 var parent_li = $(form).parent('.new-child').parent('.page-row');
1486
1487 // If parent li doesn't have a child ol, add one
1488 if ( $(parent_li).children('ol').length === 0 ){
1489 $(parent_li).append('<ol class="nplist"></ol>');
1490 }
1491
1492 if ( $(form).hasClass('in-modal') ){
1493 var appendto = $('.nplist.sortable li.page-row:first');
1494 } else {
1495 var appendto = $(parent_li).children('ol');
1496 }
1497
1498 for (i = 0; i < pages.length; i++){
1499 append_new_child_row(appendto, pages[i]);
1500 }
1501
1502 // Show the child page list and reset submenu toggles
1503 $(appendto).show();
1504 add_remove_submenu_toggles();
1505 revert_new_child();
1506 $('#np-bulk-modal').modal('hide');
1507 np_qe_update_animate(form);
1508 }
1509
1510
1511 /**
1512 * Append the Row to the View
1513 */
1514 function append_new_child_row(appendto, page)
1515 {
1516 var html = '<li id="menuItem_' + page.id + '" class="page-row';
1517 if ( page.status === 'publish' ) html += ' published';
1518 html += '">';
1519
1520 if ( max_levels(np_get_post_type()) === 0 ){
1521 html += '<div class="row">';
1522 html += '<div class="child-toggle"></div>';
1523 } else {
1524 html += '<div class="row non-hierarchical">';
1525 }
1526
1527 html += '<div class="row-inner">';
1528 html += '<i class="np-icon-sub-menu"></i><i class="handle np-icon-menu"></i>';
1529 html += '<a href="' + page.edit_link + '" class="page-link page-title">';
1530 html += '<span class="title">' + page.title + '</span>';
1531
1532 // Status
1533 if ( page.status !== 'Publish' ){
1534 html += '<span class="status">(' + page.status + ')</span>';
1535 } else {
1536 html += '<span class="status"></span>';
1537 }
1538
1539 html += '<span class="nav-status"></span><span class="edit-indicator"><i class="np-icon-pencil"></i>Edit</span>';
1540 html += '</a>';
1541
1542 // Action Buttons
1543 html += '<div class="action-buttons">';
1544 html += '<a href="#" class="np-btn open-redirect-modal" data-parentid="' + page.id + '"><i class="np-icon-link"></i></a>';
1545 html += '<a href="#" class="np-btn add-new-child" data-id="' + page.id + '" data-parentname="' + page.title + '">' + nestedpages.add_child_short + '</a>';
1546
1547 // Quick Edit (data attrs)
1548 html += '<a href="#" class="np-btn np-quick-edit" data-id="' + page.id + '" data-template="' + page.page_template + '" data-title="' + page.title + '" data-slug="' + page.slug + '" data-commentstatus="closed" data-status="' + page.status.toLowerCase() + '" data-np-status="show" data-navstatus="show" data-author="' + page.author + '" data-template="' + page.template + '" data-month="' + page.month + '" data-day="' + page.day + '" data-year="' + page.year + '" data-hour="' + page.hour + '" data-minute="' + page.minute + '" data-datepicker="' + page.datepicker + '" data-time="' + page.time + '" data-formattedtime="' + page.formattedtime + '" data-ampm="' + page.ampm + '">' + nestedpages.quick_edit + '</a>';
1549
1550 html += '<a href="' + page.view_link + '" class="np-btn" target="_blank">' + nestedpages.view + '</a>';
1551 html += '<a href="' + page.delete_link + '" class="np-btn np-btn-trash"><i class="np-icon-remove"></i></a>';
1552 html += '</div><!-- .action-buttons -->';
1553
1554 html += '</div><!-- .row-inner --></div><!-- .row -->';
1555 html += '</li>';
1556
1557 $(appendto).append(html);
1558 }
1559
1560
1561
1562
1563
1564 /**
1565 * ------------------------------------------------------------------------
1566 * Empty Trash
1567 * ------------------------------------------------------------------------
1568 **/
1569 $('.np-empty-trash').on('click', function(e){
1570 e.preventDefault();
1571 $('#np-trash-modal').modal('show');
1572 });
1573
1574 // Confirm
1575 $('.np-trash-confirm').on('click', function(e){
1576 e.preventDefault();
1577 $('#np-trash-modal').hide();
1578 $('#nested-loading').show();
1579 $('#np-error').hide();
1580 empty_trash();
1581 });
1582
1583 /**
1584 * Empty the trash
1585 */
1586 function empty_trash()
1587 {
1588 var posttype = $('#np-trash-posttype').val();
1589 $.ajax({
1590 url: ajaxurl,
1591 type: 'post',
1592 datatype: 'json',
1593 data: {
1594 action : 'npEmptyTrash',
1595 nonce : nestedpages.np_nonce,
1596 posttype : posttype
1597 },
1598 success: function(data){
1599 $('#nested-loading').hide();
1600 if (data.status === 'error'){
1601 $('#np-error').text(data.message).show();
1602 } else {
1603 $('.np-trash-links').hide();
1604 }
1605 }
1606 });
1607 }
1608
1609
1610
1611 }); //$