jquery.mjs.nestedSortable.js
4 years ago
jquery.ui.touch-punch.min.js
11 years ago
nestedpages-factory.js
3 years ago
nestedpages.bulk-actions.js
4 years ago
nestedpages.check-all.js
9 years ago
nestedpages.clone.js
3 years ago
nestedpages.confirm-delete.js
8 years ago
nestedpages.dropdowns.js
8 years ago
nestedpages.formatter.js
3 years ago
nestedpages.hidden-item-count.js
9 years ago
nestedpages.manual-sync.js
9 years ago
nestedpages.menu-links.js
3 years ago
nestedpages.menu-search.js
1 year ago
nestedpages.menu-toggle.js
8 years ago
nestedpages.modals.js
8 years ago
nestedpages.move-post.js
8 years ago
nestedpages.nesting.js
3 years ago
nestedpages.new-post.js
6 years ago
nestedpages.page-toggle.js
4 years ago
nestedpages.post-search.js
9 years ago
nestedpages.quickedit-link.js
8 years ago
nestedpages.quickedit-post.js
3 years ago
nestedpages.settings-admin-customization.js
6 years ago
nestedpages.settings-reset.js
6 years ago
nestedpages.settings.js
3 years ago
nestedpages.sync-menu-setting.js
8 years ago
nestedpages.tabs.js
6 years ago
nestedpages.trash-with-children.js
6 years ago
nestedpages.trash.js
8 years ago
nestedpages.userprefs-reset.js
7 years ago
nestedpages.wpml.js
8 years ago
nestedpages.modals.js
113 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | /** |
| 3 | * Modal Windows |
| 4 | * |
| 5 | * @author Kyle Phillips |
| 6 | * |
| 7 | * To use, include a modal backdrop and modal content window with the appropriate data-attributes |
| 8 | * The data attributes should match the value of the toggle buttons data-modal-toggle attribute |
| 9 | */ |
| 10 | NestedPages.Modals = function() |
| 11 | { |
| 12 | var self = this; |
| 13 | var $ = jQuery; |
| 14 | |
| 15 | self.activeBtn = ''; |
| 16 | self.activeModal = ''; |
| 17 | self.modalOpen = false; |
| 18 | |
| 19 | self.selectors = { |
| 20 | toggleBtn : '[data-nestedpages-modal-toggle]', |
| 21 | backdrop : '[data-nestedpages-modal-backdrop]', |
| 22 | closeBtn : '[data-nestedpages-modal-close]', |
| 23 | title : 'data-nestedpages-modal-title', |
| 24 | content : 'data-nestedpages-modal-content' |
| 25 | } |
| 26 | |
| 27 | self.bindEvents = function() |
| 28 | { |
| 29 | $(document).on('click', self.selectors.toggleBtn, function(e){ |
| 30 | e.preventDefault(); |
| 31 | self.activeBtn = $(this); |
| 32 | self.openModal(); |
| 33 | }); |
| 34 | $(document).on('click', self.selectors.closeBtn, function(e){ |
| 35 | e.preventDefault(); |
| 36 | self.closeModals(); |
| 37 | }); |
| 38 | $(document).on('open-modal-manual', function(e, modal){ |
| 39 | self.activeModal = $('[data-nestedpages-modal="' + modal + '"]'); |
| 40 | self.openModal(); |
| 41 | }); |
| 42 | $(document).on('close-modal-manual', function(e){ |
| 43 | self.closeModals(); |
| 44 | }); |
| 45 | $(document).on('click', self.selectors.backdrop, function(e){ |
| 46 | self.closeModals(); |
| 47 | }); |
| 48 | $(document).ready(function(){ |
| 49 | self.checkHash(); |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Open the Modal Window |
| 55 | */ |
| 56 | self.openModal = function() |
| 57 | { |
| 58 | if ( self.modalOpen ){ |
| 59 | self.closeModals(); |
| 60 | return; |
| 61 | } |
| 62 | if ( $(self.activeBtn).length > 0 ){ |
| 63 | var modal = $(self.activeBtn).attr('data-nestedpages-modal-toggle'); |
| 64 | self.activeModal = $('*[data-nestedpages-modal="' + modal + '"]'); |
| 65 | } |
| 66 | $(self.activeModal).addClass('active'); |
| 67 | self.modalOpen = true; |
| 68 | self.populateModal(); |
| 69 | $(document).trigger('open-modal', [self.activeBtn, self.activeModal]); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Close the Modal Window |
| 74 | */ |
| 75 | self.closeModals = function() |
| 76 | { |
| 77 | self.modalOpen = false; |
| 78 | $('[data-nestedpages-modal]').removeClass('active'); |
| 79 | self.activeModal = ''; |
| 80 | self.activeBtn = ''; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Populate the Modal if needed |
| 85 | */ |
| 86 | self.populateModal = function() |
| 87 | { |
| 88 | var title = $(self.activeBtn).attr(self.selectors.title); |
| 89 | if ( typeof title !== 'undefined' && title !== '' ){ |
| 90 | $(self.activeModal).find('[data-nestedpages-modal-title]').text(title); |
| 91 | } |
| 92 | var content = $(self.activeBtn).attr(self.selectors.content); |
| 93 | if ( typeof content !== 'undefined' && content !== '' ){ |
| 94 | $(self.activeModal).find('[data-nestedpages-modal-content]').html(content); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Check for Hash |
| 100 | */ |
| 101 | self.checkHash = function() |
| 102 | { |
| 103 | if ( !window.location.hash ) return; |
| 104 | var hashType = window.location.hash.substring(0, 6); |
| 105 | if ( hashType !== '#modal' ) return; |
| 106 | |
| 107 | var modalId = window.location.hash.substring(7); |
| 108 | self.activeModal = $('*[data-nestedpages-modal="' + modalId + '"]'); |
| 109 | self.openModal(); |
| 110 | } |
| 111 | |
| 112 | return self.bindEvents(); |
| 113 | } |