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.settings.js
302 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | |
| 3 | /** |
| 4 | * Settings |
| 5 | * @package Nested Pages |
| 6 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 7 | */ |
| 8 | NestedPages.Settings = function() |
| 9 | { |
| 10 | var plugin = this; |
| 11 | var $ = jQuery; |
| 12 | |
| 13 | plugin.selectors = { |
| 14 | postTypeToggle : '[data-toggle-nestedpages-pt-settings]', // Toggle Button for Post Type Settings |
| 15 | postTypeCheckbox : '[data-nestedpages-settings-row-checkbox]', // Checkbox for enabling post type |
| 16 | customFieldsCheckbox : '[data-toggle-nestedpages-cf-settings]', // Checkbox for toggling custom fields settings |
| 17 | standardFieldsCheckbox : '[data-toggle-nestedpages-sf-settings]', // Checkbox for toggling standard field settings |
| 18 | taxonomiesFieldCheckbox : '[data-hide-taxonomies]', // Checkbox for disabling taxonomies from quick edit |
| 19 | thumbnailsCheckbox : '[data-enable-thumbnails]', // Checkbox for enabling thumbnails in sort view |
| 20 | menuEnabledOption : '[data-menu-enabled-option]', // Options when the menu is enabled |
| 21 | disableMenuCheckbox : '[data-disable-menu-checkbox]', // Checkbox for disabling menus completely |
| 22 | disableAutoCheckbox : '[data-menu-disable-auto-checkbox]', // Checkbox for disabling auto menu sync |
| 23 | |
| 24 | // Page Assignment for Post Types |
| 25 | assignPostTypeCheckbox : '[data-nestedpages-assign-post-type]', // Checkbox for assigning a post type to a page |
| 26 | assignPostTypeId : '[data-nested-pages-assign-post-type-id]', // Hidden field containing the assigned page id |
| 27 | assignPostTypeTitle : '[data-nested-pages-assign-post-type-title]', // Hidden field containing the assigned page title |
| 28 | assignPostTypeOption : '[data-assignment-page-id]', // Option within the listing to select page for post type assignment |
| 29 | assignPostTypeRemove : '[data-nestedpages-page-pt-assignment-remove]', // Link to remove the assigned page for the post type, |
| 30 | assignPostTypeSelection : '[data-nestedpages-page-pt-assignment-selection]', // The div displaying the selection |
| 31 | |
| 32 | enableMaximumNestingLevel : '[data-nested-pages-enable-maximum-nesting]', // Checkbox to enable maximum nesting level depth, |
| 33 | maximumNestingLevel : '[data-nested-pages-maximum-nesting]', // Input for setting maximum nesting level depth |
| 34 | |
| 35 | // Sort Options for Post Types |
| 36 | sortOptionCheckbox : '[data-nestedpages-sort-option-checkbox]', // Checkbox for enabling a sort option |
| 37 | defaultSortOptions : '[data-nestedpages-sort-option-default]', // Default sort options (containing div) |
| 38 | } |
| 39 | |
| 40 | plugin.bindEvents = function() |
| 41 | { |
| 42 | $(document).ready(function(){ |
| 43 | plugin.toggleAllSettingsButtons(); |
| 44 | plugin.toogleAllFieldSettings('.custom-fields'); |
| 45 | plugin.toogleAllFieldSettings('.standard-fields'); |
| 46 | plugin.toggleMenuCheckboxes(); |
| 47 | plugin.toggleHideCheckbox(); |
| 48 | plugin.toggleAssignPostType(); |
| 49 | plugin.toggleAllDefaultSortOptions(); |
| 50 | }); |
| 51 | $(document).on('click', plugin.selectors.postTypeToggle, function(e){ |
| 52 | e.preventDefault(); |
| 53 | plugin.toggleRow($(this)); |
| 54 | }); |
| 55 | $(document).on('change', plugin.selectors.postTypeCheckbox, function(){ |
| 56 | plugin.toggleSettingsButton($(this)); |
| 57 | }); |
| 58 | $(document).on('change', plugin.selectors.customFieldsCheckbox, function(){ |
| 59 | plugin.toogleFieldSettings($(this), '.custom-fields'); |
| 60 | }); |
| 61 | $(document).on('change', plugin.selectors.standardFieldsCheckbox, function(){ |
| 62 | plugin.toogleFieldSettings($(this), '.standard-fields'); |
| 63 | }); |
| 64 | $(document).on('change', plugin.selectors.taxonomiesFieldCheckbox, function(){ |
| 65 | plugin.toggleTaxonomyCheckboxes($(this)); |
| 66 | }); |
| 67 | $(document).on('change', plugin.selectors.thumbnailsCheckbox, function(){ |
| 68 | plugin.toggleThumbnailSettings($(this)); |
| 69 | }); |
| 70 | $(document).on('change', plugin.selectors.disableMenuCheckbox, function(){ |
| 71 | plugin.toggleMenuCheckboxes(); |
| 72 | }); |
| 73 | $(document).on('change', plugin.selectors.disableAutoCheckbox, function(){ |
| 74 | plugin.toggleHideCheckbox(); |
| 75 | }); |
| 76 | $(document).on('change', plugin.selectors.assignPostTypeCheckbox, function(){ |
| 77 | plugin.toggleAssignPostType(); |
| 78 | }); |
| 79 | $(document).on('click', plugin.selectors.assignPostTypeOption, function(e){ |
| 80 | e.preventDefault(); |
| 81 | plugin.chooseAssignPostType($(this)); |
| 82 | }); |
| 83 | $(document).on('click', plugin.selectors.assignPostTypeRemove, function(e){ |
| 84 | e.preventDefault(); |
| 85 | plugin.removeAssignPostType($(this)); |
| 86 | }); |
| 87 | $(document).on('change', plugin.selectors.sortOptionCheckbox, function(){ |
| 88 | plugin.toggleDefaultSortOptions($(this)); |
| 89 | }); |
| 90 | $(document).on('change', plugin.selectors.enableMaximumNestingLevel, function(){ |
| 91 | plugin.toggleMaximumNesting($(this)); |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Toggle Individual Post Type Settings |
| 97 | */ |
| 98 | plugin.toggleRow = function(button) |
| 99 | { |
| 100 | $(button).parent('.head').siblings('.body').toggle(); |
| 101 | $(button).parents('.row-container').toggleClass('active'); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Show/Hide the settings toggle button for enabled/disabled post types |
| 106 | */ |
| 107 | plugin.toggleSettingsButton = function(checkbox) |
| 108 | { |
| 109 | var button = $(checkbox).parents('.head').find(plugin.selectors.postTypeToggle); |
| 110 | if ( $(checkbox).is(':checked') ){ |
| 111 | $(button).show(); |
| 112 | $(button).parents('.head').siblings('.body').find('input[type="hidden"]').attr('disabled', false); |
| 113 | return; |
| 114 | } |
| 115 | $(button).hide(); |
| 116 | $(button).parents('.head').siblings('.body').hide(); |
| 117 | $(button).parents('.row-container').removeClass('active'); |
| 118 | $(button).parents('.head').siblings('.body').find('input[type="checkbox"]').attr('checked', false); |
| 119 | $(button).parents('.head').siblings('.body').find('input[type="hidden"]').attr('disabled', true); |
| 120 | $(button).parents('.head').siblings('.body').find('select').val(false); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Toggle all the settings toggle buttons |
| 125 | */ |
| 126 | plugin.toggleAllSettingsButtons = function() |
| 127 | { |
| 128 | var checkboxes = $(plugin.selectors.postTypeCheckbox); |
| 129 | $.each(checkboxes, function(){ |
| 130 | plugin.toggleSettingsButton($(this)); |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Toggle Custom Field Choices |
| 136 | */ |
| 137 | plugin.toogleFieldSettings = function(checkbox, fieldGroupClass) |
| 138 | { |
| 139 | var choices = $(checkbox).parents('.body').find(fieldGroupClass); |
| 140 | if ( $(checkbox).is(':checked') ){ |
| 141 | $(choices).show(); |
| 142 | return; |
| 143 | } |
| 144 | $(choices).hide(); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Toggle All the Custom Field Choices |
| 149 | */ |
| 150 | plugin.toogleAllFieldSettings = function(fieldGroupClass) |
| 151 | { |
| 152 | var checkboxes = $(plugin.selectors.customFieldsCheckbox); |
| 153 | if ( fieldGroupClass == '.standard-fields' ){ |
| 154 | var checkboxes = $(plugin.selectors.standardFieldsCheckbox); |
| 155 | } |
| 156 | $.each(checkboxes, function(){ |
| 157 | plugin.toogleFieldSettings($(this), fieldGroupClass); |
| 158 | }); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Toggle Taxonomy Checkboxes |
| 163 | */ |
| 164 | plugin.toggleTaxonomyCheckboxes = function(checkbox) |
| 165 | { |
| 166 | var choices = $(checkbox).parents('ul').find($('*[data-taxonomy-single]')); |
| 167 | if ( $(checkbox).is(':checked') ){ |
| 168 | $(choices).hide(); |
| 169 | return; |
| 170 | } |
| 171 | $(choices).show(); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Toggle the Thumbnail Settings |
| 176 | */ |
| 177 | plugin.toggleThumbnailSettings = function(checkbox) |
| 178 | { |
| 179 | var settings = $(checkbox).parents('.field').find($('*[data-thumbnail-options]')); |
| 180 | if ( $(checkbox).is(':checked') ){ |
| 181 | $(settings).show(); |
| 182 | return; |
| 183 | } |
| 184 | $(settings).hide(); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Toggle the Menu Checkboxes |
| 189 | */ |
| 190 | plugin.toggleMenuCheckboxes = function() |
| 191 | { |
| 192 | var checkbox = $(plugin.selectors.disableMenuCheckbox); |
| 193 | var menuCheckboxes = $(plugin.selectors.menuEnabledOption); |
| 194 | if ( $(checkbox).is(':checked') ){ |
| 195 | $(menuCheckboxes).hide(); |
| 196 | return; |
| 197 | } |
| 198 | $(menuCheckboxes).show(); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Toggle the hide checkbox option |
| 203 | */ |
| 204 | plugin.toggleHideCheckbox = function() |
| 205 | { |
| 206 | var checkbox = $(plugin.selectors.disableAutoCheckbox); |
| 207 | var hideCheckboxOption = $('[data-menu-hide-checkbox]'); |
| 208 | if ( $(checkbox).is(':checked') ){ |
| 209 | $(hideCheckboxOption).hide(); |
| 210 | return; |
| 211 | } |
| 212 | $(hideCheckboxOption).show(); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Toggle the Assign Page to a Post Type Listing |
| 217 | */ |
| 218 | plugin.toggleAssignPostType = function() |
| 219 | { |
| 220 | var checkboxes = $(plugin.selectors.assignPostTypeCheckbox); |
| 221 | $.each(checkboxes, function(){ |
| 222 | var checkbox = $(this); |
| 223 | var listing = $(this).parents('.field').find('.nestedpages-assignment-display'); |
| 224 | if ( $(checkbox).is(':checked') ){ |
| 225 | $(listing).show(); |
| 226 | } else { |
| 227 | $(listing).hide(); |
| 228 | } |
| 229 | }); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Choose a page assignment |
| 234 | */ |
| 235 | plugin.chooseAssignPostType = function(element) |
| 236 | { |
| 237 | var pageId = $(element).attr('data-assignment-page-id'); |
| 238 | var pageTitle = $(element).attr('data-assignment-page-title'); |
| 239 | var container = $(element).parents('.field'); |
| 240 | var html = nestedpages.currently_assigned_to + ' ' + pageTitle + ' <a href="#" data-nestedpages-page-pt-assignment-remove>(' + nestedpages.remove + ')</a>'; |
| 241 | $(container).find(plugin.selectors.assignPostTypeId).val(pageId); |
| 242 | $(container).find(plugin.selectors.assignPostTypeTitle).val(pageTitle); |
| 243 | $(container).find(plugin.selectors.assignPostTypeSelection).html(html).show(); |
| 244 | $(container).find('[data-nestedpages-post-search-form]').hide(); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Remove a page assignment |
| 249 | */ |
| 250 | plugin.removeAssignPostType = function(element) |
| 251 | { |
| 252 | var container = $(element).parents('.field'); |
| 253 | $(container).find(plugin.selectors.assignPostTypeSelection).hide(); |
| 254 | $(container).find('[data-nestedpages-post-search-form]').show(); |
| 255 | $(container).find(plugin.selectors.assignPostTypeId).val(''); |
| 256 | $(container).find(plugin.selectors.assignPostTypeTitle).val(''); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Toggle all the default sort options |
| 261 | */ |
| 262 | plugin.toggleAllDefaultSortOptions = function() |
| 263 | { |
| 264 | var checkboxes = $(plugin.selectors.sortOptionCheckbox); |
| 265 | $.each(checkboxes, function(){ |
| 266 | plugin.toggleDefaultSortOptions($(this)); |
| 267 | }); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Toggle the default sort options |
| 272 | */ |
| 273 | plugin.toggleDefaultSortOptions = function(checkbox) |
| 274 | { |
| 275 | var checked = ( $(checkbox).is(':checked') ) ? true : false; |
| 276 | var options = $(checkbox).parent('label').next(plugin.selectors.defaultSortOptions); |
| 277 | if ( $(options).length < 1 ) return; |
| 278 | if ( checked ) { |
| 279 | $(options).show(); |
| 280 | return; |
| 281 | } |
| 282 | $(options).hide(); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Toggle the Maximum Nesting Level Option |
| 287 | */ |
| 288 | plugin.toggleMaximumNesting = function(checkbox) |
| 289 | { |
| 290 | var checked = ( $(checkbox).is(':checked') ) ? true : false; |
| 291 | var input = $(checkbox).parents('.field').find(plugin.selectors.maximumNestingLevel); |
| 292 | if ( checked ){ |
| 293 | $(input).show(); |
| 294 | return; |
| 295 | } |
| 296 | $(input).hide(); |
| 297 | } |
| 298 | |
| 299 | return plugin.bindEvents(); |
| 300 | } |
| 301 | |
| 302 | new NestedPages.Settings; |