lib
1 week ago
src
1 week ago
nestedpages.js
1 week ago
nestedpages.min.js
1 week ago
nestedpages.settings.js
1 week ago
nestedpages.js
2875 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | NestedPages.Formatter = function() { |
| 3 | var plugin = this; |
| 4 | var $ = jQuery; |
| 5 | plugin.updateSubMenuToggle = function() { |
| 6 | var allButtons = $(NestedPages.selectors.childToggle); |
| 7 | for (var i2 = 0; i2 < allButtons.length; i2++) { |
| 8 | var button = allButtons[i2]; |
| 9 | var row = $(button).parent(".row").parent("li"); |
| 10 | if ($(row).children("ol").length > 0) { |
| 11 | if ($(row).children("ol").find("li.page-row").length < 1) { |
| 12 | $(row).children("ol").hide(); |
| 13 | continue; |
| 14 | } |
| 15 | var open = $(row).children("ol:visible").length > 0 ? true : false; |
| 16 | var html = '<div class="child-toggle-spacer"></div>'; |
| 17 | html += '<a href="#"'; |
| 18 | if (open) html += ' class="open"'; |
| 19 | html += '><span class="np-icon-arrow"></span></a>'; |
| 20 | $(button).html(html); |
| 21 | if ($(row).children("ol").children(".np-hide").length > 0 && $(row).children("ol").children(".np-hide.shown").length === 0) { |
| 22 | $(button).find("a").hide(); |
| 23 | } else if ($(row).children("ol").children(".np-hide").length > 0 && $(row).children("ol").children(".np-hide.shown").length > 0) { |
| 24 | $(button).find("a").show(); |
| 25 | } |
| 26 | if ($(row).children("ol").find(".page-row").not(".np-hide").length > 0) { |
| 27 | $(button).find("a").show(); |
| 28 | } |
| 29 | continue; |
| 30 | } |
| 31 | $(button).empty().html('<div class="child-toggle-spacer"></div>'); |
| 32 | } |
| 33 | }; |
| 34 | plugin.setBorders = function() { |
| 35 | $(NestedPages.selectors.rows).removeClass(NestedPages.cssClasses.noborder); |
| 36 | $.each($(NestedPages.selectors.lists), function() { |
| 37 | $(this).find(".page-row:visible:first").addClass(NestedPages.cssClasses.noborder); |
| 38 | }); |
| 39 | }; |
| 40 | plugin.setNestedMargins = function() { |
| 41 | plugin.setIndent(); |
| 42 | }; |
| 43 | plugin.setIndent = function() { |
| 44 | var amount = nestedpages.non_indent === "1" ? 20 : 30; |
| 45 | var indent_element = nestedpages.non_indent === "1" ? ".row-inner" : ".child-toggle"; |
| 46 | $.each($(NestedPages.selectors.lists), function(i2, v) { |
| 47 | var parent_count = $(this).parents(NestedPages.selectors.lists).length; |
| 48 | var padding = 0; |
| 49 | if (!NestedPages.jsData.sortable) padding = 10; |
| 50 | if (parent_count > 0) { |
| 51 | var padding = parent_count * amount + padding; |
| 52 | $(this).find(indent_element).css("padding-left", padding + "px"); |
| 53 | return; |
| 54 | } |
| 55 | if (parent_count < 1) { |
| 56 | $(this).find(indent_element).css("padding-left", "0px"); |
| 57 | } |
| 58 | if (!NestedPages.jsData.sortable || $(this).hasClass("no-sort")) { |
| 59 | $(this).find(".row-inner").css("padding-left", "10px"); |
| 60 | return; |
| 61 | } |
| 62 | $(this).find(".row-inner").css("padding-left", "0px"); |
| 63 | }); |
| 64 | }; |
| 65 | plugin.setClassicIndent = function() { |
| 66 | $.each($(NestedPages.selectors.lists), function(i2, v) { |
| 67 | var parent_count = $(this).parents(NestedPages.selectors.lists).length; |
| 68 | var padding = 0; |
| 69 | if (!NestedPages.jsData.sortable) padding = 10; |
| 70 | if (parent_count > 0) { |
| 71 | var padding = parent_count * 20 + padding; |
| 72 | $(this).find(".row-inner").css("padding-left", padding + "px"); |
| 73 | return; |
| 74 | } |
| 75 | if (!NestedPages.jsData.sortable || $(this).hasClass("no-sort")) { |
| 76 | $(this).find(".row-inner").css("padding-left", "10px"); |
| 77 | return; |
| 78 | } |
| 79 | $(this).find(".row-inner").css("padding-left", "0px"); |
| 80 | }); |
| 81 | }; |
| 82 | plugin.updatePlaceholderWidth = function(ui) { |
| 83 | if (NestedPages.jsData.nestable) { |
| 84 | var parentCount = $(ui.placeholder).parents("ol").length; |
| 85 | var listWidth = $(NestedPages.selectors.sortable).width(); |
| 86 | var offset = parentCount * 40 - 40; |
| 87 | var newWidth = listWidth - offset; |
| 88 | $(ui.placeholder).width(newWidth).css("margin-left", offset + "px"); |
| 89 | } |
| 90 | plugin.updateListVisibility(ui); |
| 91 | }; |
| 92 | plugin.updateListVisibility = function(ui) { |
| 93 | var parentList = $(ui.placeholder).parent("ol"); |
| 94 | if (!$(parentList).is(":visible")) { |
| 95 | $(parentList).addClass("nplist"); |
| 96 | $(parentList).show(); |
| 97 | } |
| 98 | }; |
| 99 | plugin.removeQuickEdit = function() { |
| 100 | $(NestedPages.selectors.quickEditOverlay).removeClass("active").remove(); |
| 101 | $(".sortable .quick-edit").remove(); |
| 102 | $(".row").show(); |
| 103 | }; |
| 104 | plugin.showQuickEdit = function() { |
| 105 | $("body").append('<div class="np-inline-overlay"></div>'); |
| 106 | setTimeout(function() { |
| 107 | $(".np-inline-overlay").addClass("active"); |
| 108 | }, 50); |
| 109 | }; |
| 110 | plugin.flashRow = function(row) { |
| 111 | $(row).addClass("np-updated"); |
| 112 | plugin.setBorders(); |
| 113 | setTimeout(function() { |
| 114 | $(row).addClass("np-updated-show"); |
| 115 | }, 1500); |
| 116 | }; |
| 117 | plugin.showAjaxError = function(message) { |
| 118 | $(NestedPages.selectors.ajaxError).find("p").text(message); |
| 119 | $(NestedPages.selectors.ajaxError).show(); |
| 120 | }; |
| 121 | plugin.hideAjaxError = function(message) { |
| 122 | $(NestedPages.selectors.ajaxError).hide(); |
| 123 | }; |
| 124 | plugin.sizeLinkThumbnails = function() { |
| 125 | var thumbnail = $(NestedPages.selectors.thumbnailContainer).not(NestedPages.selectors.thumbnailContainerLink).first().find("img"); |
| 126 | var width = $(thumbnail).width(); |
| 127 | var height = $(thumbnail).height(); |
| 128 | $.each($(NestedPages.selectors.thumbnailContainerLink), function() { |
| 129 | $(this).width(width); |
| 130 | $(this).height(height); |
| 131 | }); |
| 132 | }; |
| 133 | }; |
| 134 | var NestedPages = NestedPages || {}; |
| 135 | NestedPages.Dropdowns = function() { |
| 136 | var self = this; |
| 137 | var $ = jQuery; |
| 138 | self.dropdown = ""; |
| 139 | self.activeBtn = ""; |
| 140 | self.activeContent = ""; |
| 141 | self.toggleBtn = "[data-dropdown-toggle]"; |
| 142 | self.dropdownContainer = "[data-dropdown]"; |
| 143 | self.dropdownContent = "[data-dropdown-content]"; |
| 144 | self.selectors = { |
| 145 | caret_up: "icon-arrow_drop_up", |
| 146 | caret_down: "icon-arrow_drop_down" |
| 147 | }; |
| 148 | self.bindEvents = function() { |
| 149 | $(document).on("click", self.toggleBtn, function(e) { |
| 150 | e.preventDefault(); |
| 151 | self.activeBtn = $(this); |
| 152 | self.dropdown = $(this).parents(self.dropdownContainer); |
| 153 | self.toggleDropdown(); |
| 154 | }); |
| 155 | $(document).on("click", function(e) { |
| 156 | self.closeDropdowns(e.target); |
| 157 | }); |
| 158 | $(document).on("dropdown-opened", function(e, content) { |
| 159 | if ($(content).parents(NestedPages.selectors.row).length > 0) { |
| 160 | $(content).parents(NestedPages.selectors.row).addClass("active"); |
| 161 | } |
| 162 | }); |
| 163 | $(document).on("dropdown-closed", function() { |
| 164 | $(NestedPages.selectors.row).removeClass("active"); |
| 165 | }); |
| 166 | }; |
| 167 | self.toggleDropdown = function() { |
| 168 | $("." + self.selectors.caret_up).attr("class", self.selectors.caret_down); |
| 169 | var content = $(self.dropdown).find(self.dropdownContent); |
| 170 | self.activeContent = content; |
| 171 | if ($(content).hasClass("active")) { |
| 172 | $(content).removeClass("active"); |
| 173 | $(self.activeBtn).removeClass("active"); |
| 174 | $(self.activeBtn).find("." + self.selectors.caret_up).attr("class", self.selectors.caret_down); |
| 175 | $(document).trigger("dropdown-closed", content); |
| 176 | return; |
| 177 | } |
| 178 | self.setPositioning(); |
| 179 | $(self.toggleBtn).removeClass("active"); |
| 180 | $(self.dropdownContent).removeClass("active"); |
| 181 | $(content).addClass("active"); |
| 182 | $(self.activeBtn).find("." + self.selectors.caret_down).attr("class", self.selectors.caret_up); |
| 183 | $(self.activeBtn).addClass("active"); |
| 184 | $(document).trigger("dropdown-opened", content); |
| 185 | }; |
| 186 | self.setPositioning = function() { |
| 187 | var buttonHeight = $(self.activeBtn).outerHeight(); |
| 188 | $(self.activeContent).css("top", buttonHeight + "px"); |
| 189 | }; |
| 190 | self.closeDropdowns = function(target) { |
| 191 | if ($(target).parents(self.dropdownContainer).length === 0) { |
| 192 | $(self.dropdownContent).removeClass("active"); |
| 193 | $(self.toggleBtn).removeClass("active"); |
| 194 | $(self.activeBtn).find("." + self.selectors.caret_up).attr("class", self.selectors.caret_down); |
| 195 | var content; |
| 196 | $(document).trigger("dropdown-closed", content); |
| 197 | } |
| 198 | }; |
| 199 | return self.bindEvents(); |
| 200 | }; |
| 201 | var NestedPages = NestedPages || {}; |
| 202 | NestedPages.Modals = function() { |
| 203 | var self = this; |
| 204 | var $ = jQuery; |
| 205 | self.activeBtn = ""; |
| 206 | self.activeModal = ""; |
| 207 | self.modalOpen = false; |
| 208 | self.selectors = { |
| 209 | toggleBtn: "[data-nestedpages-modal-toggle]", |
| 210 | backdrop: "[data-nestedpages-modal-backdrop]", |
| 211 | closeBtn: "[data-nestedpages-modal-close]", |
| 212 | title: "data-nestedpages-modal-title", |
| 213 | content: "data-nestedpages-modal-content" |
| 214 | }; |
| 215 | self.bindEvents = function() { |
| 216 | $(document).on("click", self.selectors.toggleBtn, function(e) { |
| 217 | e.preventDefault(); |
| 218 | self.activeBtn = $(this); |
| 219 | self.openModal(); |
| 220 | }); |
| 221 | $(document).on("click", self.selectors.closeBtn, function(e) { |
| 222 | e.preventDefault(); |
| 223 | self.closeModals(); |
| 224 | }); |
| 225 | $(document).on("open-modal-manual", function(e, modal) { |
| 226 | self.activeModal = $('[data-nestedpages-modal="' + modal + '"]'); |
| 227 | self.openModal(); |
| 228 | }); |
| 229 | $(document).on("close-modal-manual", function(e) { |
| 230 | self.closeModals(); |
| 231 | }); |
| 232 | $(document).on("click", self.selectors.backdrop, function(e) { |
| 233 | self.closeModals(); |
| 234 | }); |
| 235 | $(document).ready(function() { |
| 236 | self.checkHash(); |
| 237 | }); |
| 238 | }; |
| 239 | self.openModal = function() { |
| 240 | if (self.modalOpen) { |
| 241 | self.closeModals(); |
| 242 | return; |
| 243 | } |
| 244 | if ($(self.activeBtn).length > 0) { |
| 245 | var modal = $(self.activeBtn).attr("data-nestedpages-modal-toggle"); |
| 246 | self.activeModal = $('*[data-nestedpages-modal="' + modal + '"]'); |
| 247 | } |
| 248 | $(self.activeModal).addClass("active"); |
| 249 | self.modalOpen = true; |
| 250 | self.populateModal(); |
| 251 | $(document).trigger("open-modal", [self.activeBtn, self.activeModal]); |
| 252 | }; |
| 253 | self.closeModals = function() { |
| 254 | self.modalOpen = false; |
| 255 | $("[data-nestedpages-modal]").removeClass("active"); |
| 256 | self.activeModal = ""; |
| 257 | self.activeBtn = ""; |
| 258 | }; |
| 259 | self.populateModal = function() { |
| 260 | var title = $(self.activeBtn).attr(self.selectors.title); |
| 261 | if (typeof title !== "undefined" && title !== "") { |
| 262 | $(self.activeModal).find("[data-nestedpages-modal-title]").text(title); |
| 263 | } |
| 264 | var content = $(self.activeBtn).attr(self.selectors.content); |
| 265 | if (typeof content !== "undefined" && content !== "") { |
| 266 | $(self.activeModal).find("[data-nestedpages-modal-content]").html(content); |
| 267 | } |
| 268 | }; |
| 269 | self.checkHash = function() { |
| 270 | if (!window.location.hash) return; |
| 271 | var hashType = window.location.hash.substring(0, 6); |
| 272 | if (hashType !== "#modal") return; |
| 273 | var modalId = window.location.hash.substring(7); |
| 274 | self.activeModal = $('*[data-nestedpages-modal="' + modalId + '"]'); |
| 275 | self.openModal(); |
| 276 | }; |
| 277 | return self.bindEvents(); |
| 278 | }; |
| 279 | var NestedPages = NestedPages || {}; |
| 280 | NestedPages.CheckAll = function() { |
| 281 | var plugin = this; |
| 282 | var $ = jQuery; |
| 283 | plugin.activeCheckbox = ""; |
| 284 | plugin.selectors = { |
| 285 | checkbox: "[data-np-check-all]" |
| 286 | }; |
| 287 | plugin.bindEvents = function() { |
| 288 | $(document).on("change", plugin.selectors.checkbox, function() { |
| 289 | plugin.activeCheckbox = $(this); |
| 290 | plugin.toggleCheckboxes(); |
| 291 | }); |
| 292 | $(document).on("change", "input[type=checkbox]", function() { |
| 293 | plugin.checkAllStatus($(this)); |
| 294 | }); |
| 295 | }; |
| 296 | plugin.init = function() { |
| 297 | plugin.bindEvents(); |
| 298 | }; |
| 299 | plugin.toggleCheckboxes = function() { |
| 300 | var checked = $(plugin.activeCheckbox).is(":checked") ? true : false; |
| 301 | var name = $(plugin.activeCheckbox).attr("data-np-check-all"); |
| 302 | var checkboxes = $('*[name="' + name + '"]'); |
| 303 | $.each(checkboxes, function() { |
| 304 | var row = $(this).parents(NestedPages.selectors.rows); |
| 305 | $(this).prop("checked", checked); |
| 306 | if ($(row).hasClass("np-hide") && !$(row).is(":visible")) { |
| 307 | $(row).find(NestedPages.selectors.bulkActionsCheckbox).prop("checked", false); |
| 308 | } |
| 309 | ; |
| 310 | }); |
| 311 | plugin.toggleCheckAll(); |
| 312 | }; |
| 313 | plugin.toggleCheckAll = function() { |
| 314 | var name = $(plugin.activeCheckbox).attr("data-np-check-all"); |
| 315 | var checkboxes_total = $('*[name="' + name + '"]').length; |
| 316 | var hidden_checkboxes = $(".np-hide").find(NestedPages.selectors.bulkActionsCheckbox).length; |
| 317 | var hidden_checkboxes_visible = $(".np-hide:visible").find(NestedPages.selectors.bulkActionsCheckbox).length; |
| 318 | checkboxes_total = checkboxes_total - hidden_checkboxes + hidden_checkboxes_visible; |
| 319 | var checkboxes_checked = $('*[name="' + name + '"]:checked').length; |
| 320 | if (checkboxes_total == checkboxes_checked) { |
| 321 | $(plugin.activeCheckbox).prop("checked", true); |
| 322 | $(plugin.activeCheckbox).removeClass("check-all-partial"); |
| 323 | return; |
| 324 | } |
| 325 | if (checkboxes_checked > 0) { |
| 326 | $(plugin.activeCheckbox).addClass("check-all-partial"); |
| 327 | return; |
| 328 | } |
| 329 | $(plugin.activeCheckbox).attr("checked", false); |
| 330 | $(plugin.activeCheckbox).removeClass("check-all-partial"); |
| 331 | }; |
| 332 | plugin.checkAllStatus = function(checkbox) { |
| 333 | var name = $(checkbox).attr("name"); |
| 334 | var toggleAllCheckbox = $('*[data-np-check-all="' + name + '"]'); |
| 335 | if (toggleAllCheckbox.length === 0) return; |
| 336 | plugin.activeCheckbox = $(toggleAllCheckbox)[0]; |
| 337 | plugin.toggleCheckAll(); |
| 338 | }; |
| 339 | return plugin.init(); |
| 340 | }; |
| 341 | var NestedPages = NestedPages || {}; |
| 342 | NestedPages.BulkActions = function() { |
| 343 | var plugin = this; |
| 344 | var $ = jQuery; |
| 345 | plugin.selectedNumber = 0; |
| 346 | plugin.selectedLinks = []; |
| 347 | plugin.selectedPosts = []; |
| 348 | plugin.bindEvents = function() { |
| 349 | $(document).on("change", NestedPages.selectors.bulkActionsCheckbox, function() { |
| 350 | plugin.toggleBulkForm(); |
| 351 | }); |
| 352 | $(document).on("submit", NestedPages.selectors.bulkActionsForm, function(e) { |
| 353 | if ($("select[name=np_bulk_action]").val() === "edit") { |
| 354 | e.preventDefault(); |
| 355 | plugin.toggleBulkEdit(true); |
| 356 | } |
| 357 | }); |
| 358 | $(document).on("click", NestedPages.selectors.bulkEditRemoveItem, function(e) { |
| 359 | e.preventDefault(); |
| 360 | var id = $(this).siblings("input[type=hidden]").val(); |
| 361 | plugin.uncheckBulkItem(id); |
| 362 | }); |
| 363 | $(document).on("click", NestedPages.selectors.bulkEditCancel, function(e) { |
| 364 | e.preventDefault(); |
| 365 | plugin.uncheckAllBulkItems(); |
| 366 | }); |
| 367 | }; |
| 368 | plugin.toggleBulkForm = function() { |
| 369 | var checked = false; |
| 370 | var checked_ids = ""; |
| 371 | var checked_redirect_ids = ""; |
| 372 | plugin.selectedPosts = []; |
| 373 | plugin.selectedLinks = []; |
| 374 | $.each($(NestedPages.selectors.bulkActionsCheckbox), function() { |
| 375 | if ($(this).is(":checked")) { |
| 376 | var row = $(this).parents(NestedPages.selectors.rows); |
| 377 | checked = true; |
| 378 | if (!$(this).parent("div").hasClass("np-check-all") && !$(row).hasClass("post-type-np-redirect")) checked_ids += $(this).val() + ","; |
| 379 | if ($(row).hasClass("post-type-np-redirect")) { |
| 380 | checked_redirect_ids += $(this).val() + ","; |
| 381 | plugin.selectedLinks.push($(this).val()); |
| 382 | } |
| 383 | if ($(this).attr("data-np-post-type") !== "np-redirect" && !$(this).parent("div").hasClass("np-check-all")) { |
| 384 | var post = []; |
| 385 | post["title"] = $(this).attr("data-np-bulk-checkbox"); |
| 386 | post["id"] = $(this).val(); |
| 387 | plugin.selectedPosts.push(post); |
| 388 | } |
| 389 | } |
| 390 | }); |
| 391 | plugin.setBulkEditPosts(); |
| 392 | plugin.toggleEditOption(); |
| 393 | plugin.toggleLinkCountAlert(); |
| 394 | if (checked) { |
| 395 | $(NestedPages.selectors.bulkActionsForm).show(); |
| 396 | $(NestedPages.selectors.bulkActionsIds).val(checked_ids); |
| 397 | $(NestedPages.selectors.bulkActionRedirectIds).val(checked_redirect_ids); |
| 398 | plugin.setSelectedNumber(); |
| 399 | return; |
| 400 | } |
| 401 | $(NestedPages.selectors.bulkActionsIds).val(""); |
| 402 | $(NestedPages.selectors.bulkActionsForm).hide(); |
| 403 | }; |
| 404 | plugin.setBulkEditPosts = function() { |
| 405 | var html = ""; |
| 406 | for (var i2 = 0; i2 < plugin.selectedPosts.length; i2++) { |
| 407 | html += '<li><a href="#" class="np-remove" data-np-remove-bulk-item>×</a>'; |
| 408 | html += plugin.selectedPosts[i2].title; |
| 409 | html += '<input type="hidden" name="post_ids[]" value="' + plugin.selectedPosts[i2].id + '"></li>'; |
| 410 | } |
| 411 | $(NestedPages.selectors.bulkEditTitles).html(html); |
| 412 | }; |
| 413 | plugin.uncheckBulkItem = function(id) { |
| 414 | $.each($(NestedPages.selectors.bulkActionsCheckbox), function() { |
| 415 | if ($(this).val() == id) { |
| 416 | $(this).prop("checked", false).change(); |
| 417 | } |
| 418 | }); |
| 419 | if ($(NestedPages.selectors.bulkEditRemoveItem).length === 0) { |
| 420 | plugin.toggleBulkEdit(false); |
| 421 | } |
| 422 | }; |
| 423 | plugin.uncheckAllBulkItems = function() { |
| 424 | $.each($(NestedPages.selectors.bulkActionsCheckbox), function() { |
| 425 | $(this).prop("checked", false).change(); |
| 426 | }); |
| 427 | plugin.toggleBulkEdit(false); |
| 428 | }; |
| 429 | plugin.setSelectedNumber = function() { |
| 430 | var checkedLength = $(NestedPages.selectors.bulkActionsCheckbox + ":checked").not(".np-check-all input").length; |
| 431 | var option = $(NestedPages.selectors.bulkActionsForm).find("select option").first(); |
| 432 | $(option).text(nestedpages.bulk_actions + " (" + checkedLength + ")"); |
| 433 | }; |
| 434 | plugin.toggleEditOption = function() { |
| 435 | var checkedLength = $(NestedPages.selectors.bulkActionsCheckbox + ":checked").not(".np-check-all input").not(".np-redirect-bulk").length; |
| 436 | var option = $(NestedPages.selectors.bulkActionsForm).find("select option[value=edit]"); |
| 437 | if (checkedLength === 0) { |
| 438 | $(option).prop("disabled", true); |
| 439 | $(NestedPages.selectors.bulkActionsForm).find("select option").first().prop("selected", true); |
| 440 | plugin.toggleBulkEdit(false); |
| 441 | return; |
| 442 | } |
| 443 | $(option).prop("disabled", false); |
| 444 | }; |
| 445 | plugin.toggleBulkEdit = function(visible) { |
| 446 | plugin.toggleLinkCountAlert(); |
| 447 | if (visible) { |
| 448 | plugin.disableParentOptions(); |
| 449 | $(NestedPages.selectors.bulkEditForm).show(); |
| 450 | $(NestedPages.selectors.bulkActionsForm).hide(); |
| 451 | plugin.setWPSuggest(); |
| 452 | return; |
| 453 | } |
| 454 | $(NestedPages.selectors.bulkEditForm).hide(); |
| 455 | $(NestedPages.selectors.bulkActionsForm).show(); |
| 456 | $(NestedPages.selectors.bulkEditLinkCount).parent("div").hide(); |
| 457 | $(NestedPages.selectors.bulkActionsForm).find("select option").first().text(nestedpages.bulk_actions); |
| 458 | plugin.resetBulkEditFields(); |
| 459 | }; |
| 460 | plugin.toggleLinkCountAlert = function() { |
| 461 | var selectedLinkCount = plugin.selectedLinks.length; |
| 462 | if (selectedLinkCount === 0) { |
| 463 | $(NestedPages.selectors.bulkEditLinkCount).parent("div").hide(); |
| 464 | return; |
| 465 | } |
| 466 | $(NestedPages.selectors.bulkEditLinkCount).parent("div").show(); |
| 467 | }; |
| 468 | plugin.disableParentOptions = function() { |
| 469 | var selectElement = $(NestedPages.selectors.bulkEditForm).find("select[name=post_parent]"); |
| 470 | for (var i2 = 0; i2 < plugin.selectedPosts.length; i2++) { |
| 471 | $(selectElement).find("option[value=" + plugin.selectedPosts[i2].id + "]").attr("disabled", true); |
| 472 | } |
| 473 | }; |
| 474 | plugin.setWPSuggest = function() { |
| 475 | var tagfields = $(NestedPages.selectors.bulkEditForm).find("[data-autotag]"); |
| 476 | $.each(tagfields, function(i2, v) { |
| 477 | var taxonomy = $(this).attr("data-taxonomy"); |
| 478 | $(this).suggest(ajaxurl + "?action=ajax-tag-search&tax=" + taxonomy, { multiple: true, multipleSep: "," }); |
| 479 | }); |
| 480 | }; |
| 481 | plugin.resetBulkEditFields = function() { |
| 482 | var selectFields = $(NestedPages.selectors.bulkEditForm).find("select"); |
| 483 | $.each(selectFields, function() { |
| 484 | $(this).find("option").first().prop("selected", true); |
| 485 | $(this).find("option").removeAttr("disabled"); |
| 486 | }); |
| 487 | var categoryChecklists = $(NestedPages.selectors.bulkEditForm).find(".cat-checklist"); |
| 488 | $.each(categoryChecklists, function() { |
| 489 | $(this).find("input[type=checkbox]").prop("checked", false); |
| 490 | }); |
| 491 | }; |
| 492 | return plugin.bindEvents(); |
| 493 | }; |
| 494 | var NestedPages = NestedPages || {}; |
| 495 | NestedPages.HiddenItemCount = function() { |
| 496 | var plugin = this; |
| 497 | var $ = jQuery; |
| 498 | plugin.init = function() { |
| 499 | plugin.bindEvents(); |
| 500 | }; |
| 501 | plugin.bindEvents = function() { |
| 502 | $(document).on("change", NestedPages.selectors.bulkActionsCheckbox, function() { |
| 503 | plugin.toggleHiddenCount(); |
| 504 | }); |
| 505 | $(document).on("click", NestedPages.selectors.toggleAll, function() { |
| 506 | plugin.toggleHiddenCount(); |
| 507 | }); |
| 508 | $(document).on("click", NestedPages.selectors.pageToggle, function() { |
| 509 | plugin.toggleHiddenCount(); |
| 510 | }); |
| 511 | }; |
| 512 | plugin.toggleHiddenCount = function() { |
| 513 | var hiddenCount = 0; |
| 514 | $.each($(NestedPages.selectors.bulkActionsCheckbox), function() { |
| 515 | if ($(this).is(":checked")) { |
| 516 | if ($(this).parent("div").hasClass("np-check-all")) return; |
| 517 | var row = $(this).closest(".page-row"); |
| 518 | if (!$(row).is(":visible")) hiddenCount++; |
| 519 | } |
| 520 | }); |
| 521 | if (hiddenCount < 1) { |
| 522 | $(NestedPages.selectors.hiddenItemCountParent).hide(); |
| 523 | return; |
| 524 | } |
| 525 | $(NestedPages.selectors.hiddenItemCount).text(hiddenCount); |
| 526 | $(NestedPages.selectors.hiddenItemCountParent).show(); |
| 527 | }; |
| 528 | return plugin.init(); |
| 529 | }; |
| 530 | var NestedPages = NestedPages || {}; |
| 531 | NestedPages.MenuToggle = function() { |
| 532 | var plugin = this; |
| 533 | var $ = jQuery; |
| 534 | plugin.formatter = new NestedPages.Formatter(); |
| 535 | plugin.bindEvents = function() { |
| 536 | $(document).on("click", NestedPages.selectors.childToggleLink, function(e) { |
| 537 | e.preventDefault(); |
| 538 | plugin.toggleSingleMenu($(this)); |
| 539 | }); |
| 540 | $(document).on("click", NestedPages.selectors.toggleAll, function(e) { |
| 541 | e.preventDefault(); |
| 542 | plugin.toggleAllMenus(); |
| 543 | }); |
| 544 | }; |
| 545 | plugin.toggleSingleMenu = function(button) { |
| 546 | var submenu = $(button).parent(NestedPages.selectors.childToggle).parent(NestedPages.selectors.row).siblings("ol"); |
| 547 | $(button).toggleClass("open"); |
| 548 | $(submenu).toggle(); |
| 549 | plugin.formatter.setBorders(); |
| 550 | plugin.formatter.setNestedMargins(); |
| 551 | plugin.syncUserToggles(); |
| 552 | }; |
| 553 | plugin.toggleAllMenus = function() { |
| 554 | var button = NestedPages.selectors.toggleAll; |
| 555 | if ($(button).attr("data-toggle") === "closed") { |
| 556 | $(NestedPages.selectors.lists).show(); |
| 557 | $(button).attr("data-toggle", "opened").text(NestedPages.jsData.collapseText); |
| 558 | $(NestedPages.selectors.childToggle + " a").addClass("open"); |
| 559 | plugin.formatter.setBorders(); |
| 560 | plugin.syncUserToggles(); |
| 561 | return; |
| 562 | } |
| 563 | $(NestedPages.selectors.lists).not($(NestedPages.selectors.lists)[0]).hide(); |
| 564 | $(button).attr("data-toggle", "closed").text(NestedPages.jsData.expandText); |
| 565 | $(NestedPages.selectors.childToggle + " a").removeClass("open"); |
| 566 | plugin.formatter.setBorders(); |
| 567 | plugin.syncUserToggles(); |
| 568 | }; |
| 569 | plugin.visibleRowIDs = function() { |
| 570 | var visible_ids = []; |
| 571 | var visible = $(NestedPages.selectors.rows + ":visible"); |
| 572 | $.each(visible, function(i2, v) { |
| 573 | var id = $(this).attr("id"); |
| 574 | visible_ids.push(id.replace("menuItem_", "")); |
| 575 | }); |
| 576 | return visible_ids; |
| 577 | }; |
| 578 | plugin.syncUserToggles = function() { |
| 579 | $.ajax({ |
| 580 | url: NestedPages.jsData.ajaxurl, |
| 581 | type: "post", |
| 582 | datatype: "json", |
| 583 | data: { |
| 584 | action: NestedPages.formActions.syncToggles, |
| 585 | nonce: NestedPages.jsData.nonce, |
| 586 | ids: plugin.visibleRowIDs(), |
| 587 | posttype: NestedPages.jsData.posttype |
| 588 | }, |
| 589 | success: function(data) { |
| 590 | if (data.status !== "success") { |
| 591 | console.log("There was an error saving toggled pages."); |
| 592 | } |
| 593 | } |
| 594 | }); |
| 595 | }; |
| 596 | return plugin.bindEvents(); |
| 597 | }; |
| 598 | var NestedPages = NestedPages || {}; |
| 599 | NestedPages.PageToggle = function() { |
| 600 | var plugin = this; |
| 601 | var $ = jQuery; |
| 602 | plugin.activeButton = ""; |
| 603 | plugin.formatter = new NestedPages.Formatter(); |
| 604 | plugin.bindEvents = function() { |
| 605 | $(document).on("click", NestedPages.selectors.toggleHidden, function(e) { |
| 606 | e.preventDefault(); |
| 607 | plugin.activeButton = $(this); |
| 608 | plugin.toggleHidden(); |
| 609 | }); |
| 610 | $(document).on("click", NestedPages.selectors.toggleStatus, function(e) { |
| 611 | e.preventDefault(); |
| 612 | plugin.toggleStatus($(this)); |
| 613 | }); |
| 614 | }; |
| 615 | plugin.toggleHidden = function() { |
| 616 | var button = $(plugin.activeButton); |
| 617 | var action = $(button).attr("href"); |
| 618 | if (action == "#show") { |
| 619 | $(button).attr("href", "#hide").text(NestedPages.jsData.showHiddenText); |
| 620 | $(NestedPages.selectors.hiddenRows).removeClass("shown").hide(); |
| 621 | plugin.formatter.updateSubMenuToggle(); |
| 622 | plugin.formatter.setBorders(); |
| 623 | return; |
| 624 | } |
| 625 | if (action == "#hide") { |
| 626 | $(button).attr("href", "#show").text(NestedPages.jsData.hideHiddenText); |
| 627 | $(NestedPages.selectors.hiddenRows).addClass("shown").show(); |
| 628 | plugin.formatter.updateSubMenuToggle(); |
| 629 | plugin.formatter.setBorders(); |
| 630 | } |
| 631 | }; |
| 632 | plugin.toggleStatus = function(button) { |
| 633 | var target = $(button).attr("href"); |
| 634 | target = target.substring(1); |
| 635 | $(NestedPages.selectors.syncCheckbox).attr("disabled", false); |
| 636 | $(NestedPages.selectors.toggleStatus).removeClass("active"); |
| 637 | $(button).addClass("active"); |
| 638 | plugin.saveStatusPreference(target); |
| 639 | if (target == "draft") { |
| 640 | $(NestedPages.selectors.syncCheckbox).attr("disabled", true); |
| 641 | $("." + target).addClass("nested-visible"); |
| 642 | } |
| 643 | if (target == "all") { |
| 644 | $(NestedPages.selectors.rows).show(); |
| 645 | return; |
| 646 | } |
| 647 | $(NestedPages.selectors.rows).hide(); |
| 648 | $("." + target).show(); |
| 649 | return; |
| 650 | }; |
| 651 | plugin.saveStatusPreference = function(status) { |
| 652 | $.ajax({ |
| 653 | url: ajaxurl, |
| 654 | type: "post", |
| 655 | datatype: "json", |
| 656 | data: { |
| 657 | action: NestedPages.formActions.toggleStatusDisplay, |
| 658 | nonce: NestedPages.jsData.nonce, |
| 659 | status, |
| 660 | post_type: NestedPages.jsData.posttype |
| 661 | } |
| 662 | }); |
| 663 | }; |
| 664 | return plugin.bindEvents(); |
| 665 | }; |
| 666 | var NestedPages = NestedPages || {}; |
| 667 | NestedPages.Nesting = function() { |
| 668 | var plugin = this; |
| 669 | var $ = jQuery; |
| 670 | plugin.formatter = new NestedPages.Formatter(); |
| 671 | plugin.initializeSortable = function() { |
| 672 | if (!NestedPages.jsData.nestable) return plugin.initializeSortableFlat(); |
| 673 | var maxLevels = 0; |
| 674 | if (typeof nestedpages.post_types[NestedPages.jsData.posttype] !== "undefined") { |
| 675 | var post_type = nestedpages.post_types[NestedPages.jsData.posttype]; |
| 676 | if (typeof post_type.enable_max_nesting !== "undefined" && post_type.enable_max_nesting && typeof post_type.maximum_nesting !== "undefined" && post_type.maximum_nesting > 1) maxLevels = post_type.maximum_nesting; |
| 677 | } |
| 678 | $(NestedPages.selectors.sortable).not(NestedPages.selectors.notSortable).nestedSortable({ |
| 679 | items: NestedPages.selectors.rows, |
| 680 | toleranceElement: "> .row", |
| 681 | handle: NestedPages.selectors.handle, |
| 682 | placeholder: "ui-sortable-placeholder", |
| 683 | tabSize: 56, |
| 684 | maxLevels, |
| 685 | isAllowed: function(placeholder, placeholderParent, currentItem) { |
| 686 | return $(placeholderParent).hasClass("post-type-np-redirect") && !$(currentItem).hasClass("post-type-np-redirect") ? false : true; |
| 687 | }, |
| 688 | start: function(e, ui) { |
| 689 | ui.placeholder.height(ui.item.height()); |
| 690 | }, |
| 691 | sort: function(e, ui) { |
| 692 | plugin.formatter.updatePlaceholderWidth(ui); |
| 693 | }, |
| 694 | stop: function(e, ui) { |
| 695 | setTimeout( |
| 696 | function() { |
| 697 | plugin.formatter.updateSubMenuToggle(); |
| 698 | plugin.formatter.setBorders(); |
| 699 | plugin.formatter.setNestedMargins(); |
| 700 | }, |
| 701 | 100 |
| 702 | ); |
| 703 | plugin.syncNesting(); |
| 704 | } |
| 705 | }); |
| 706 | }; |
| 707 | plugin.initializeSortableFlat = function() { |
| 708 | var lists = $(NestedPages.selectors.lists).not(NestedPages.selectors.notSortable); |
| 709 | $.each(lists, function() { |
| 710 | $(this).sortable({ |
| 711 | items: ">" + NestedPages.selectors.rows, |
| 712 | handle: NestedPages.selectors.handle, |
| 713 | placeholder: "ui-sortable-placeholder", |
| 714 | forcePlaceholderSize: true, |
| 715 | start: function(e, ui) { |
| 716 | ui.placeholder.height(ui.item.height()); |
| 717 | }, |
| 718 | sort: function(e, ui) { |
| 719 | plugin.formatter.updatePlaceholderWidth(ui); |
| 720 | }, |
| 721 | stop: function(e, ui) { |
| 722 | setTimeout( |
| 723 | function() { |
| 724 | plugin.formatter.updateSubMenuToggle(); |
| 725 | plugin.formatter.setBorders(); |
| 726 | plugin.formatter.setNestedMargins(); |
| 727 | }, |
| 728 | 100 |
| 729 | ); |
| 730 | plugin.syncNesting(); |
| 731 | } |
| 732 | }); |
| 733 | }); |
| 734 | }; |
| 735 | plugin.disableNesting = function() { |
| 736 | $(NestedPages.selectors.sortable).sortable("destroy"); |
| 737 | }; |
| 738 | plugin.syncNesting = function(manual, callback) { |
| 739 | var list, filtered; |
| 740 | if (nestedpages.manual_order_sync === "1" && !manual) return; |
| 741 | $(NestedPages.selectors.errorDiv).hide(); |
| 742 | $(NestedPages.selectors.loadingIndicator).show(); |
| 743 | filtered = $(NestedPages.selectors.lists).first().hasClass("filtered") ? true : false; |
| 744 | if (NestedPages.jsData.nestable && !filtered) { |
| 745 | list = $(NestedPages.selectors.sortable).nestedSortable("toHierarchy", { startDepthCount: 0 }); |
| 746 | } else { |
| 747 | list = plugin.setNestingArray(); |
| 748 | } |
| 749 | plugin.disableNesting(); |
| 750 | var syncmenu = NestedPages.jsData.syncmenu; |
| 751 | if (nestedpages.manual_menu_sync === "1") syncmenu = "nosync"; |
| 752 | $.ajax({ |
| 753 | url: ajaxurl, |
| 754 | type: "post", |
| 755 | datatype: "json", |
| 756 | data: { |
| 757 | action: NestedPages.formActions.syncNesting, |
| 758 | nonce: NestedPages.jsData.nonce, |
| 759 | list, |
| 760 | post_type: NestedPages.jsData.posttype, |
| 761 | syncmenu, |
| 762 | filtered |
| 763 | }, |
| 764 | success: function(data, callback2) { |
| 765 | plugin.initializeSortable(); |
| 766 | if (data.status === "error") { |
| 767 | $(NestedPages.selectors.errorDiv).text(data.message).show(); |
| 768 | $(NestedPages.selectors.loadingIndicator).hide(); |
| 769 | } else { |
| 770 | if (callback2 && typeof callback2 === "function") { |
| 771 | callback2(); |
| 772 | return; |
| 773 | } |
| 774 | $(NestedPages.selectors.loadingIndicator).hide(); |
| 775 | } |
| 776 | } |
| 777 | }); |
| 778 | }; |
| 779 | plugin.setNestingArray = function(list) { |
| 780 | ret = []; |
| 781 | $(NestedPages.selectors.lists).first().children("li.page-row").each(function() { |
| 782 | var level = plugin.recursiveNesting(this); |
| 783 | ret.push(level); |
| 784 | }); |
| 785 | return ret; |
| 786 | }; |
| 787 | plugin.recursiveNesting = function(item) { |
| 788 | var id = $(item).attr("id"); |
| 789 | var currentItem; |
| 790 | if (id) { |
| 791 | id = id.replace("menuItem_", ""); |
| 792 | currentItem = { |
| 793 | "id": id |
| 794 | }; |
| 795 | if ($(item).children(NestedPages.selectors.lists).children(NestedPages.selectors.rows).length > 0) { |
| 796 | currentItem.children = []; |
| 797 | $(item).children(NestedPages.selectors.lists).children(NestedPages.selectors.rows).each(function() { |
| 798 | var level = plugin.recursiveNesting(this); |
| 799 | currentItem.children.push(level); |
| 800 | }); |
| 801 | } |
| 802 | return currentItem; |
| 803 | } |
| 804 | }; |
| 805 | }; |
| 806 | var NestedPages = NestedPages || {}; |
| 807 | NestedPages.SyncMenuSetting = function() { |
| 808 | var plugin = this; |
| 809 | var $ = jQuery; |
| 810 | plugin.formatter = new NestedPages.Formatter(); |
| 811 | plugin.init = function() { |
| 812 | plugin.bindEvents(); |
| 813 | }; |
| 814 | plugin.bindEvents = function() { |
| 815 | $(document).ready(function() { |
| 816 | if (nestedpages.manual_menu_sync === "1") return; |
| 817 | if (nestedpages.syncmenu === "1") plugin.syncSetting(); |
| 818 | }); |
| 819 | $(document).on("change", NestedPages.selectors.syncCheckbox, function() { |
| 820 | plugin.syncSetting(); |
| 821 | }); |
| 822 | }; |
| 823 | plugin.syncSetting = function() { |
| 824 | if (NestedPages.jsData.posttype !== "page") return; |
| 825 | if ($(NestedPages.selectors.syncCheckbox).length === 0) return; |
| 826 | NestedPages.jsData.syncmenu = $(NestedPages.selectors.syncCheckbox).is(":checked") ? "sync" : "nosync"; |
| 827 | $.ajax({ |
| 828 | url: NestedPages.jsData.ajaxurl, |
| 829 | type: "post", |
| 830 | datatype: "json", |
| 831 | data: { |
| 832 | action: NestedPages.formActions.syncMenu, |
| 833 | nonce: NestedPages.jsData.nonce, |
| 834 | post_type: NestedPages.jsData.posttype, |
| 835 | syncmenu: NestedPages.jsData.syncmenu |
| 836 | }, |
| 837 | success: function(data) { |
| 838 | if (data.status === "error") { |
| 839 | plugin.formatter.showAjaxError(data.message); |
| 840 | } |
| 841 | }, |
| 842 | error: function(data) { |
| 843 | console.log(data); |
| 844 | } |
| 845 | }); |
| 846 | }; |
| 847 | return plugin.bindEvents(); |
| 848 | }; |
| 849 | var NestedPages = NestedPages || {}; |
| 850 | NestedPages.NewPost = function() { |
| 851 | var plugin = this; |
| 852 | var $ = jQuery; |
| 853 | plugin.formatter = new NestedPages.Formatter(); |
| 854 | plugin.parent_id = 0; |
| 855 | plugin.posts = ""; |
| 856 | plugin.form = ""; |
| 857 | plugin.bindEvents = function() { |
| 858 | $(document).on("open-modal", function(e, button, modal) { |
| 859 | var target = $(button).attr("data-nestedpages-modal-toggle"); |
| 860 | if (typeof target !== "undefined" && target == "np-bulk-modal") { |
| 861 | plugin.openModal(); |
| 862 | } |
| 863 | }); |
| 864 | $(document).on("submit", NestedPages.selectors.newPageForm, function(e) { |
| 865 | e.preventDefault(); |
| 866 | }); |
| 867 | $(document).on("click", NestedPages.selectors.newPageSubmitButton, function(e) { |
| 868 | e.preventDefault(); |
| 869 | plugin.submitForm($(this)); |
| 870 | }); |
| 871 | $(document).on("click", NestedPages.selectors.newPageTitle, function(e) { |
| 872 | e.preventDefault(); |
| 873 | plugin.addTitleField($(this)); |
| 874 | }); |
| 875 | $(document).on("click", NestedPages.selectors.newPageRemoveTitle, function(e) { |
| 876 | e.preventDefault(); |
| 877 | plugin.removeTitleField($(this)); |
| 878 | }); |
| 879 | $(document).on("click", NestedPages.selectors.addChildButton, function(e) { |
| 880 | e.preventDefault(); |
| 881 | plugin.openQuickEdit($(this)); |
| 882 | }); |
| 883 | $(document).on("click", NestedPages.selectors.cancelNewChildButton, function(e) { |
| 884 | e.preventDefault(); |
| 885 | plugin.cancelNewPage(); |
| 886 | }); |
| 887 | $(document).on("click", "[" + NestedPages.selectors.newBeforeButton + "]", function(e) { |
| 888 | e.preventDefault(); |
| 889 | plugin.openQuickEdit($(this)); |
| 890 | }); |
| 891 | $(document).on("click", "[" + NestedPages.selectors.newAfterButton + "]", function(e) { |
| 892 | e.preventDefault(); |
| 893 | plugin.openQuickEdit($(this)); |
| 894 | }); |
| 895 | $(document).on("keydown", function(e) { |
| 896 | if (e.keyCode === 27) { |
| 897 | plugin.cancelNewPage(); |
| 898 | $(document).click(); |
| 899 | } |
| 900 | }); |
| 901 | }; |
| 902 | plugin.openModal = function() { |
| 903 | var newform = $(NestedPages.selectors.newPageFormContainer).clone().find(NestedPages.selectors.newPageForm); |
| 904 | $(newform).addClass("in-modal"); |
| 905 | $(NestedPages.selectors.newPageModal).find(".modal-body").html(newform); |
| 906 | $(NestedPages.selectors.newPageModal).find("h3").text(nestedpages.add_multiple); |
| 907 | $(NestedPages.selectors.newPageModal).find(".page_parent_id").val(plugin.parent_id); |
| 908 | $(newform).find(".np_title").first().focus(); |
| 909 | $(newform).find(NestedPages.selectors.newPageTitle).first().prop("tabindex", "2"); |
| 910 | }; |
| 911 | plugin.openQuickEdit = function(button) { |
| 912 | var before = $(button).attr(NestedPages.selectors.newBeforeButton); |
| 913 | before = typeof before === "undefined" || before === "" ? false : before; |
| 914 | var after = $(button).attr(NestedPages.selectors.newAfterButton); |
| 915 | after = typeof after === "undefined" || after === "" ? false : after; |
| 916 | var parent_li = $(button).closest(NestedPages.selectors.row).parent("li"); |
| 917 | var newform = $(NestedPages.selectors.newPageFormContainer).clone(); |
| 918 | if ($(parent_li).children("ol").length > 0) { |
| 919 | var child_ol = $(parent_li).children("ol"); |
| 920 | $(newform).insertBefore(child_ol); |
| 921 | } else { |
| 922 | $(newform).appendTo(parent_li); |
| 923 | } |
| 924 | $(newform).siblings(NestedPages.selectors.row).hide(); |
| 925 | plugin.formatter.showQuickEdit(); |
| 926 | $(newform).find(".parent_name").html("<em>Parent:</em> " + $(button).attr("data-parentname")); |
| 927 | if (!before && !after) $(newform).find(".page_parent_id").val($(button).attr("data-id")); |
| 928 | if (before) { |
| 929 | $(newform).find(".page_before_id").val(before); |
| 930 | $(newform).find("[data-new-post-relation-title]").text(nestedpages.insert_before + ": " + $(button).attr("data-parentname")); |
| 931 | } |
| 932 | if (after) { |
| 933 | $(newform).find(".page_after_id").val(after); |
| 934 | $(newform).find("[data-new-post-relation-title]").text(nestedpages.insert_after + ": " + $(button).attr("data-parentname")); |
| 935 | } |
| 936 | $(newform).show(); |
| 937 | $(newform).find(".np_title").focus(); |
| 938 | $(newform).find(NestedPages.selectors.newPageTitle).prop("tabindex", "2"); |
| 939 | }; |
| 940 | plugin.cancelNewPage = function() { |
| 941 | plugin.formatter.removeQuickEdit(); |
| 942 | $(NestedPages.selectors.newChildError).hide(); |
| 943 | $(NestedPages.selectors.newPageModal).find(".modal-body").empty(); |
| 944 | $(NestedPages.selectors.sortable).find(".new-child").remove(); |
| 945 | $(NestedPages.selectors.row).show(); |
| 946 | }; |
| 947 | plugin.addTitleField = function(button) { |
| 948 | var form = $(button).parents("form"); |
| 949 | var fieldcount = $(button).siblings(".new-page-titles").children("li").length + 1; |
| 950 | var html = '<li><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="handle np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg><div class="form-control new-child-row"><label>' + NestedPages.jsData.titleText + '</label><div><input type="text" name="post_title[]" class="np_title" placeholder="' + NestedPages.jsData.titleText + '" value="" tabindex="' + fieldcount + '" /><a href="#" class="button-secondary np-remove-child">-</a></div></div></li>'; |
| 951 | var container = $(button).siblings(".new-page-titles").append(html); |
| 952 | $(form).find(".np_title").last().focus(); |
| 953 | $(form).find(NestedPages.selectors.newPageTitle).prop("tabindex", fieldcount++); |
| 954 | $(".new-page-titles").sortable({ |
| 955 | items: "li", |
| 956 | handle: ".handle" |
| 957 | }); |
| 958 | plugin.toggleAddEditButton(form); |
| 959 | }; |
| 960 | plugin.removeTitleField = function(button) { |
| 961 | var form = $(button).parents("form"); |
| 962 | $(button).parents(".new-child-row").parent("li").remove(); |
| 963 | plugin.toggleAddEditButton(form); |
| 964 | }; |
| 965 | plugin.submitForm = function(button) { |
| 966 | plugin.toggleLoading(true); |
| 967 | plugin.form = $(button).parents("form"); |
| 968 | var addedit = $(button).hasClass("add-edit") ? true : false; |
| 969 | var action = NestedPages.formActions.newPage; |
| 970 | if ($(plugin.form).find(".page_before_id").val() !== "") action = NestedPages.formActions.newBeforeAfter; |
| 971 | if ($(plugin.form).find(".page_after_id").val() !== "") action = NestedPages.formActions.newBeforeAfter; |
| 972 | $.ajax({ |
| 973 | url: NestedPages.jsData.ajaxurl, |
| 974 | type: "post", |
| 975 | datatype: "json", |
| 976 | data: $(plugin.form).serialize() + "&action=" + action + "&nonce=" + NestedPages.jsData.nonce + "&syncmenu=" + NestedPages.jsData.syncmenu + "&post_type=" + NestedPages.jsData.posttype, |
| 977 | success: function(data) { |
| 978 | if (data.status === "error") { |
| 979 | plugin.toggleLoading(false); |
| 980 | $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text(data.message).show(); |
| 981 | return; |
| 982 | } |
| 983 | if (addedit === true) { |
| 984 | var link = data.new_pages[0].edit_link; |
| 985 | link = link.replace(/&/g, "&"); |
| 986 | window.location.replace(link); |
| 987 | return; |
| 988 | } |
| 989 | plugin.toggleLoading(false); |
| 990 | plugin.posts = data.new_pages; |
| 991 | plugin.addPosts(); |
| 992 | }, |
| 993 | error: function(data) { |
| 994 | console.log(data); |
| 995 | plugin.toggleLoading(false); |
| 996 | $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text("The form could not be saved at this time.").show(); |
| 997 | } |
| 998 | }); |
| 999 | }; |
| 1000 | plugin.addPosts = function() { |
| 1001 | var before = $(plugin.form).find(".page_before_id").val(); |
| 1002 | before = before !== "" ? before : false; |
| 1003 | var after = $(plugin.form).find(".page_after_id").val(); |
| 1004 | after = after !== "" ? after : false; |
| 1005 | var parent_li = $(plugin.form).parent(".new-child").parent(".page-row"); |
| 1006 | if ($(parent_li).children("ol").length === 0 && !before && !after) { |
| 1007 | $(parent_li).append('<ol class="nplist"></ol>'); |
| 1008 | } |
| 1009 | if ($(plugin.form).hasClass("in-modal")) { |
| 1010 | var appendto = $(".nplist.sortable li.page-row:first"); |
| 1011 | } else { |
| 1012 | var appendto = $(parent_li).children("ol"); |
| 1013 | } |
| 1014 | for (i = 0; i < plugin.posts.length; i++) { |
| 1015 | plugin.appendRows(appendto, plugin.posts[i], before, after); |
| 1016 | } |
| 1017 | if (!before && !after) { |
| 1018 | $(appendto).show(); |
| 1019 | } |
| 1020 | plugin.formatter.updateSubMenuToggle(); |
| 1021 | plugin.formatter.setNestedMargins(); |
| 1022 | plugin.cancelNewPage(); |
| 1023 | $(document).trigger("close-modal-manual"); |
| 1024 | }; |
| 1025 | plugin.appendRows = function(appendto, post, before, after) { |
| 1026 | var html = '<li id="menuItem_' + post.id + '" class="page-row'; |
| 1027 | if (post.status === "publish") html += " published"; |
| 1028 | html += '">'; |
| 1029 | if (NestedPages.jsData.hierarchical) { |
| 1030 | html += '<div class="row">'; |
| 1031 | html += '<div class="child-toggle"></div>'; |
| 1032 | } else { |
| 1033 | html += '<div class="row non-hierarchical">'; |
| 1034 | html += '<div class="non-hierarchical-spacer"></div>'; |
| 1035 | } |
| 1036 | html += '<div class="row-inner">'; |
| 1037 | html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="np-icon-sub-menu"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M19 15l-6 6-1.42-1.42L15.17 16H4V4h2v10h9.17l-3.59-3.58L13 9l6 6z" class="arrow" /></svg>'; |
| 1038 | html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="handle np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg>'; |
| 1039 | html += '<a href="' + post.edit_link + '" class="page-link page-title">'; |
| 1040 | html += '<span class="title">' + post.title + "</span>"; |
| 1041 | if (post.status !== "Publish") { |
| 1042 | html += '<span class="status">(' + post.status + ")</span>"; |
| 1043 | } else { |
| 1044 | html += '<span class="status"></span>'; |
| 1045 | } |
| 1046 | html += '<span class="nav-status">'; |
| 1047 | if (post.np_nav_status === "hide") { |
| 1048 | html += " " + nestedpages.hidden; |
| 1049 | } |
| 1050 | html += "</span>"; |
| 1051 | html += '<span class="edit-indicator">Edit</span>'; |
| 1052 | html += "</a>"; |
| 1053 | if (!NestedPages.jsData.hierarchical) { |
| 1054 | html += '<div class="np-post-columns">'; |
| 1055 | html += '<ul class="np-post-info">'; |
| 1056 | html += '<li><span class="np-author-display">' + post.author_formatted + "</span></li>"; |
| 1057 | html += "<li>" + post.date_formatted + "</li>"; |
| 1058 | html += "</ul>"; |
| 1059 | html += "</div>"; |
| 1060 | } |
| 1061 | if ($(".nplist").first().hasClass("has-yoast")) { |
| 1062 | html += '<span class="np-seo-indicator na"></span>'; |
| 1063 | } |
| 1064 | html += '<div class="action-buttons">'; |
| 1065 | html += '<div class="nestedpages-dropdown" data-dropdown><a href="#" class="np-btn has-icon toggle" data-dropdown-toggle><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/></svg></a><ul class="nestedpages-dropdown-content" data-dropdown-content>'; |
| 1066 | html += '<li><a href="#" class="open-redirect-modal" data-parentid="' + post.id + '"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>' + nestedpages.add_link + "</a></li>"; |
| 1067 | html += '<li><a href="#" class="add-new-child" data-id="' + post.id + '" data-parentname="' + post.title + '"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M3 21h18v-2H3v2zM3 8v8l4-4-4-4zm8 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z"/><path d="M0 0h24v24H0z" fill="none"/></svg>' + nestedpages.add_child_short + "</a></li>"; |
| 1068 | html += "</ul></div>"; |
| 1069 | html += '<a href="#" class="np-btn np-quick-edit" data-id="' + post.id + '" data-template="' + post.page_template + '" data-title="' + post.title + '" data-slug="' + post.slug + '" data-commentstatus="closed" data-status="' + post.status.toLowerCase() + '" data-np-status="show" data-navstatus="show" data-author="' + post.author + '" data-template="' + post.template + '" data-month="' + post.month + '" data-day="' + post.day + '" data-year="' + post.year + '" data-hour="' + post.hour + '" data-minute="' + post.minute + '" data-datepicker="' + post.datepicker + '" data-time="' + post.time + '" data-formattedtime="' + post.formattedtime + '" data-ampm="' + post.ampm + '">' + nestedpages.quick_edit + "</a>"; |
| 1070 | html += '<a href="' + post.view_link + '" class="np-btn" target="_blank">' + nestedpages.view + "</a>"; |
| 1071 | html += '<a href="' + post.delete_link + '" class="np-btn np-btn-trash"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="np-icon-remove"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" class="icon"/><path d="M0 0h24v24H0z" fill="none"/></svg></a>'; |
| 1072 | html += "</div><!-- .action-buttons -->"; |
| 1073 | html += "</div><!-- .row-inner --></div><!-- .row -->"; |
| 1074 | html += "</li>"; |
| 1075 | if (before) { |
| 1076 | var row = plugin.findRowById(before); |
| 1077 | $(html).insertBefore(row); |
| 1078 | return; |
| 1079 | } |
| 1080 | if (after) { |
| 1081 | var row = plugin.findRowById(after); |
| 1082 | $(html).insertAfter(row); |
| 1083 | return; |
| 1084 | } |
| 1085 | $(appendto).append(html); |
| 1086 | }; |
| 1087 | plugin.findRowById = function(id) { |
| 1088 | var row = $(NestedPages.selectors.rows + "#menuItem_" + id); |
| 1089 | return row; |
| 1090 | }; |
| 1091 | plugin.toggleAddEditButton = function(form) { |
| 1092 | var titleCount = $(form).find(".np_title").length; |
| 1093 | if (titleCount < 1) { |
| 1094 | $(NestedPages.selectors.newPageSubmitButton).hide(); |
| 1095 | return; |
| 1096 | } |
| 1097 | $(NestedPages.selectors.newPageSubmitButton).show(); |
| 1098 | if (titleCount > 1) { |
| 1099 | $(NestedPages.selectors.newPageSubmitButton + ".add-edit").hide(); |
| 1100 | return; |
| 1101 | } |
| 1102 | $(NestedPages.selectors.newPageSubmitButton + ".add-edit").show(); |
| 1103 | }; |
| 1104 | plugin.toggleLoading = function(loading) { |
| 1105 | if (loading) { |
| 1106 | $(NestedPages.selectors.quickEditErrorDiv).hide(); |
| 1107 | $(NestedPages.selectors.newPageSubmitButton).attr("disabled", "disabled"); |
| 1108 | $(NestedPages.selectors.quickEditLoadingIndicator).show(); |
| 1109 | return; |
| 1110 | } |
| 1111 | $(NestedPages.selectors.newPageSubmitButton).attr("disabled", false); |
| 1112 | $(NestedPages.selectors.quickEditLoadingIndicator).hide(); |
| 1113 | }; |
| 1114 | return plugin.bindEvents(); |
| 1115 | }; |
| 1116 | var NestedPages = NestedPages || {}; |
| 1117 | NestedPages.QuickEditPost = function() { |
| 1118 | var plugin = this; |
| 1119 | var $ = jQuery; |
| 1120 | plugin.formatter = new NestedPages.Formatter(); |
| 1121 | plugin.button = ""; |
| 1122 | plugin.initialData = ""; |
| 1123 | plugin.parent_li = ""; |
| 1124 | plugin.form = ""; |
| 1125 | plugin.flatTerms = ""; |
| 1126 | plugin.termNames = ""; |
| 1127 | plugin.saveButton = ""; |
| 1128 | plugin.newData = ""; |
| 1129 | plugin.row = ""; |
| 1130 | plugin.bindEvents = function() { |
| 1131 | $(document).on("click", NestedPages.selectors.quickEditOpen, function(e) { |
| 1132 | e.preventDefault(); |
| 1133 | plugin.button = $(this); |
| 1134 | plugin.openForm(); |
| 1135 | }); |
| 1136 | $(document).on("click", NestedPages.selectors.quickEditCancel, function(e) { |
| 1137 | e.preventDefault(); |
| 1138 | plugin.formatter.removeQuickEdit(); |
| 1139 | }); |
| 1140 | $(document).on("change", ".keep_private", function() { |
| 1141 | if (this.checked) { |
| 1142 | $(".post_password").val("").prop("readonly", true); |
| 1143 | } else { |
| 1144 | $(".post_password").prop("readonly", false); |
| 1145 | } |
| 1146 | }); |
| 1147 | $(document).on("click", NestedPages.selectors.quickEditSaveButton, function(e) { |
| 1148 | e.preventDefault(); |
| 1149 | plugin.saveButton = $(this); |
| 1150 | plugin.save(); |
| 1151 | }); |
| 1152 | $(document).on("keydown", function(e) { |
| 1153 | if (e.keyCode === 27) plugin.formatter.removeQuickEdit(); |
| 1154 | }); |
| 1155 | }; |
| 1156 | plugin.openForm = function() { |
| 1157 | plugin.setInitialData(); |
| 1158 | plugin.createForm(); |
| 1159 | plugin.populateForm(); |
| 1160 | plugin.populateFlatTaxonomies(); |
| 1161 | }; |
| 1162 | plugin.setInitialData = function() { |
| 1163 | plugin.initialData = { |
| 1164 | id: $(plugin.button).attr("data-id"), |
| 1165 | title: $(plugin.button).attr("data-title"), |
| 1166 | slug: $(plugin.button).attr("data-slug"), |
| 1167 | author: $(plugin.button).attr("data-author"), |
| 1168 | cs: $(plugin.button).attr("data-commentstatus"), |
| 1169 | status: $(plugin.button).attr("data-status"), |
| 1170 | template: $(plugin.button).attr("data-template"), |
| 1171 | month: $(plugin.button).attr("data-month"), |
| 1172 | day: $(plugin.button).attr("data-day"), |
| 1173 | year: $(plugin.button).attr("data-year"), |
| 1174 | hour: $(plugin.button).attr("data-hour"), |
| 1175 | minute: $(plugin.button).attr("data-minute"), |
| 1176 | navstatus: $(plugin.button).attr("data-navstatus"), |
| 1177 | navCustomUrl: $(plugin.button).attr("data-custom-url"), |
| 1178 | npstatus: $(plugin.button).attr("data-np-status"), |
| 1179 | navtitle: $(plugin.button).attr("data-navtitle"), |
| 1180 | navtitleattr: $(plugin.button).attr("data-navtitleattr"), |
| 1181 | navcss: $(plugin.button).attr("data-navcss"), |
| 1182 | linktarget: $(plugin.button).attr("data-linktarget"), |
| 1183 | password: $(plugin.button).attr("data-password"), |
| 1184 | datepicker: $(plugin.button).attr("data-datepicker"), |
| 1185 | time: $(plugin.button).attr("data-formattedtime"), |
| 1186 | timeTwentyFour: $(plugin.button).attr("data-time"), |
| 1187 | ampm: $(plugin.button).attr("data-ampm"), |
| 1188 | timeFormat: $(plugin.button).attr("data-timeformat"), |
| 1189 | sticky: $(plugin.button).attr("data-sticky") |
| 1190 | }; |
| 1191 | var attrs = $(plugin.button)[0].attributes; |
| 1192 | $.each(attrs, function(i2, attr) { |
| 1193 | if (!attr.name.includes("data-npcustom")) return; |
| 1194 | plugin.initialData[attr.name] = attr.value; |
| 1195 | }); |
| 1196 | plugin.initialData.h_taxonomies = []; |
| 1197 | plugin.initialData.f_taxonomies = []; |
| 1198 | plugin.parent_li = $(plugin.button).closest(NestedPages.selectors.row).parent("li"); |
| 1199 | var classes = $(plugin.parent_li).attr("class").split(/\s+/); |
| 1200 | for (i = 0; i < classes.length; i++) { |
| 1201 | if (classes[i].substring(0, 3) === "in-") { |
| 1202 | plugin.initialData.h_taxonomies.push(classes[i]); |
| 1203 | } |
| 1204 | if (classes[i].substring(0, 4) === "inf-") { |
| 1205 | plugin.initialData.f_taxonomies.push(classes[i]); |
| 1206 | } |
| 1207 | } |
| 1208 | }; |
| 1209 | plugin.createForm = function() { |
| 1210 | plugin.form = $(NestedPages.selectors.quickEditPostForm).clone(); |
| 1211 | if ($(plugin.parent_li).children("ol").length > 0) { |
| 1212 | var child_ol = $(plugin.parent_li).children("ol"); |
| 1213 | $(plugin.form).insertBefore(child_ol); |
| 1214 | } else { |
| 1215 | $(plugin.form).appendTo(plugin.parent_li); |
| 1216 | } |
| 1217 | $(plugin.form).siblings(NestedPages.selectors.row).hide(); |
| 1218 | $(plugin.form).show(); |
| 1219 | }; |
| 1220 | plugin.populateForm = function() { |
| 1221 | $(plugin.form).find(".page_id").html("<em>ID:</em> " + plugin.initialData.id); |
| 1222 | $(plugin.form).find(".np_id").val(plugin.initialData.id); |
| 1223 | $(plugin.form).find(".np_title").val(plugin.initialData.title); |
| 1224 | $(plugin.form).find(".np_slug").val(plugin.initialData.slug); |
| 1225 | $(plugin.form).find(".np_author select").val(plugin.initialData.author); |
| 1226 | $(plugin.form).find(".np_status").val(plugin.initialData.status); |
| 1227 | $(plugin.form).find(".np_nav_title").val(plugin.initialData.navtitle); |
| 1228 | $(plugin.form).find(".np_nav_css_classes").val(plugin.initialData.navcss); |
| 1229 | $(plugin.form).find(".np_title_attribute").val(plugin.initialData.navtitleattr); |
| 1230 | $(plugin.form).find(".np_nav_custom_url").val(plugin.initialData.navCustomUrl); |
| 1231 | $(plugin.form).find(".post_password").val(plugin.initialData.password); |
| 1232 | $(plugin.form).find(".np_publish_date").val(plugin.initialData.datepicker); |
| 1233 | if (plugin.initialData.cs === "open") $(plugin.form).find(".np_cs").attr("checked", "checked"); |
| 1234 | if (plugin.initialData.template !== "") { |
| 1235 | $(plugin.form).find(".np_template").val(plugin.initialData.template); |
| 1236 | } else { |
| 1237 | $(plugin.form).find(".np_template").val("default"); |
| 1238 | } |
| 1239 | if (plugin.initialData.status === "private") { |
| 1240 | $(plugin.form).find(".post_password").attr("readonly", true); |
| 1241 | $(plugin.form).find(".keep_private").attr("checked", true); |
| 1242 | } |
| 1243 | if (plugin.initialData.npstatus === "hide") { |
| 1244 | $(plugin.form).find(".nested_pages_status").attr("checked", "checked"); |
| 1245 | } else { |
| 1246 | $(plugin.form).find(".nested_pages_status").removeAttr("checked"); |
| 1247 | } |
| 1248 | if (plugin.initialData.navstatus === "hide") { |
| 1249 | $(plugin.form).find(".np_nav_status").attr("checked", "checked"); |
| 1250 | } else { |
| 1251 | $(plugin.form).find(".np_nav_status").attr("checked", false); |
| 1252 | } |
| 1253 | if (plugin.initialData.linktarget === "_blank") { |
| 1254 | $(plugin.form).find(".link_target").attr("checked", "checked"); |
| 1255 | } else { |
| 1256 | $(plugin.form).find(".link_target").attr("checked", false); |
| 1257 | } |
| 1258 | if (plugin.initialData.status === "private") { |
| 1259 | $(plugin.form).find(".np_status").val("publish"); |
| 1260 | } |
| 1261 | if (plugin.initialData.sticky === "sticky") { |
| 1262 | $(plugin.form).find(".np-sticky").attr("checked", "checked"); |
| 1263 | } else { |
| 1264 | $(plugin.form).find(".np-sticky").removeAttr("checked"); |
| 1265 | } |
| 1266 | if (plugin.initialData.timeFormat === "H:i") { |
| 1267 | $(plugin.form).find(".np_time").val(plugin.initialData.timeTwentyFour); |
| 1268 | } else { |
| 1269 | $(plugin.form).find(".np_time").val(plugin.initialData.time); |
| 1270 | $(plugin.form).find(".np_ampm").val(plugin.initialData.ampm); |
| 1271 | $(plugin.form).find('select[name="mm"]').val(plugin.initialData.month); |
| 1272 | $(plugin.form).find('input[name="jj"]').val(plugin.initialData.day); |
| 1273 | $(plugin.form).find('input[name="aa"]').val(plugin.initialData.year); |
| 1274 | $(plugin.form).find('input[name="hh"]').val(plugin.initialData.hour); |
| 1275 | $(plugin.form).find('input[name="mn"]').val(plugin.initialData.minute); |
| 1276 | } |
| 1277 | for (var key in plugin.initialData) { |
| 1278 | if (!key.includes("npcustom")) continue; |
| 1279 | if (plugin.initialData.hasOwnProperty(key)) { |
| 1280 | var inputName = key.replace("data-npcustom-", ""); |
| 1281 | inputName = inputName.toLowerCase(); |
| 1282 | $(plugin.form).find('[data-np-custom-field="' + inputName + '"]').val(plugin.initialData[key]); |
| 1283 | } |
| 1284 | } |
| 1285 | plugin.populateFlatTaxonomies(); |
| 1286 | if (plugin.initialData.hasOwnProperty("h_taxonomies")) { |
| 1287 | var taxonomies2 = plugin.initialData.h_taxonomies; |
| 1288 | for (i = 0; i < taxonomies2.length; i++) { |
| 1289 | var tax = "#" + taxonomies2[i]; |
| 1290 | $(plugin.form).find(tax).attr("checked", "checked"); |
| 1291 | } |
| 1292 | } |
| 1293 | var datepickers = $(plugin.form).find(".np_datepicker"); |
| 1294 | $.each(datepickers, function() { |
| 1295 | var $this = $(this); |
| 1296 | $this.datepicker({ |
| 1297 | dateFormat: $this.attr("data-datepicker-format"), |
| 1298 | beforeShow: function(input, inst) { |
| 1299 | $("#ui-datepicker-div").addClass("nestedpages-datepicker"); |
| 1300 | } |
| 1301 | }); |
| 1302 | }); |
| 1303 | plugin.formatter.showQuickEdit(); |
| 1304 | $(plugin.form).show(); |
| 1305 | }; |
| 1306 | plugin.populateFlatTaxonomies = function() { |
| 1307 | if (!plugin.initialData.hasOwnProperty("f_taxonomies")) return; |
| 1308 | plugin.createTaxonomyObject(); |
| 1309 | plugin.getTermNames(); |
| 1310 | plugin.setWPSuggest(); |
| 1311 | }; |
| 1312 | plugin.createTaxonomyObject = function() { |
| 1313 | var out = ""; |
| 1314 | var terms = {}; |
| 1315 | for (i = 0; i < plugin.initialData.f_taxonomies.length; i++) { |
| 1316 | var singleTerm = plugin.initialData.f_taxonomies[i]; |
| 1317 | var tax_array = singleTerm.split("-"); |
| 1318 | var splitter = tax_array.indexOf("nps"); |
| 1319 | var term = tax_array.splice(splitter + 1); |
| 1320 | term = term.join("-"); |
| 1321 | var tax = singleTerm.split("-").splice(0, splitter); |
| 1322 | tax.shift("inf"); |
| 1323 | var taxonomy = tax.join("-"); |
| 1324 | if (!(taxonomy in terms)) { |
| 1325 | terms[taxonomy] = []; |
| 1326 | } |
| 1327 | var term_array = terms[taxonomy]; |
| 1328 | term_array.push(term); |
| 1329 | } |
| 1330 | plugin.flatTerms = terms; |
| 1331 | }; |
| 1332 | plugin.getTermNames = function() { |
| 1333 | $.ajax({ |
| 1334 | url: NestedPages.jsData.ajaxurl, |
| 1335 | type: "post", |
| 1336 | datatype: "json", |
| 1337 | data: { |
| 1338 | action: NestedPages.formActions.getTaxonomies, |
| 1339 | nonce: NestedPages.jsData.nonce, |
| 1340 | terms: plugin.flatTerms |
| 1341 | }, |
| 1342 | success: function(data) { |
| 1343 | plugin.termNames = data.terms; |
| 1344 | plugin.populateFlatTaxonomyFields(); |
| 1345 | } |
| 1346 | }); |
| 1347 | }; |
| 1348 | plugin.populateFlatTaxonomyFields = function() { |
| 1349 | if (!plugin.termNames) return; |
| 1350 | $.each(plugin.termNames, function(i2, v) { |
| 1351 | var textarea = $("#" + i2 + "-quickedit"); |
| 1352 | $(textarea).val(v.join(",")); |
| 1353 | }); |
| 1354 | }; |
| 1355 | plugin.setWPSuggest = function() { |
| 1356 | var tagfields = $(plugin.form).find("[data-autotag]"); |
| 1357 | $.each(tagfields, function(i2, v) { |
| 1358 | var taxonomy = $(this).attr("data-taxonomy"); |
| 1359 | $(this).suggest(ajaxurl + "?action=ajax-tag-search&tax=" + taxonomy, { multiple: true, multipleSep: "," }); |
| 1360 | }); |
| 1361 | }; |
| 1362 | plugin.save = function() { |
| 1363 | plugin.toggleLoading(true); |
| 1364 | $.ajax({ |
| 1365 | url: NestedPages.jsData.ajaxurl, |
| 1366 | type: "post", |
| 1367 | datatype: "json", |
| 1368 | data: $(plugin.form).find("form").serialize() + "&action=" + NestedPages.formActions.quickEditPost + "&nonce=" + NestedPages.jsData.nonce + "&syncmenu=" + NestedPages.jsData.syncmenu + "&post_type=" + NestedPages.jsData.posttype, |
| 1369 | success: function(data) { |
| 1370 | if (data.status === "error") { |
| 1371 | plugin.toggleLoading(false); |
| 1372 | $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text(data.message).show(); |
| 1373 | } else { |
| 1374 | plugin.toggleLoading(false); |
| 1375 | plugin.newData = data.post_data; |
| 1376 | plugin.updatePostRow(); |
| 1377 | } |
| 1378 | }, |
| 1379 | error: function(data) { |
| 1380 | console.log(data); |
| 1381 | } |
| 1382 | }); |
| 1383 | }; |
| 1384 | plugin.updatePostRow = function() { |
| 1385 | plugin.row = $(plugin.button).parents(".row-inner"); |
| 1386 | $(plugin.row).find(".title").text(plugin.newData.post_title); |
| 1387 | $(plugin.row).find(".np-view-button").attr("href", plugin.newData.permalink); |
| 1388 | var status = $(plugin.row).find(".status"); |
| 1389 | if (plugin.newData._status !== "publish" && plugin.newData._status !== "future") { |
| 1390 | var newStatus = nestedpages.post_statuses[plugin.newData._status].label; |
| 1391 | $(status).text("(" + newStatus + ")"); |
| 1392 | } else { |
| 1393 | $(status).text(""); |
| 1394 | } |
| 1395 | if (plugin.newData.keep_private === "private") { |
| 1396 | $(status).text(nestedpages.private); |
| 1397 | } |
| 1398 | if (plugin.newData.post_password !== "" && typeof plugin.newData.post_password !== "undefined") { |
| 1399 | var statustext = $(status).text(); |
| 1400 | statustext += ' <span class="locked">'; |
| 1401 | statustext += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/></svg>'; |
| 1402 | statustext += "</span>"; |
| 1403 | $(status).html(statustext); |
| 1404 | } |
| 1405 | var nav_status = $(plugin.row).find(".nav-status"); |
| 1406 | if (plugin.newData.nav_status == "hide") { |
| 1407 | $(nav_status).text("(Hidden)"); |
| 1408 | } else { |
| 1409 | $(nav_status).text(""); |
| 1410 | } |
| 1411 | var li = $(plugin.row).parent("li"); |
| 1412 | if (plugin.newData.np_status == "hide") { |
| 1413 | $(li).addClass("np-hide"); |
| 1414 | $(plugin.row).find(".status").after('<svg class="row-status-icon status-np-hidden" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0z" fill="none"/><path class="icon" d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"/></svg>'); |
| 1415 | } else { |
| 1416 | $(li).removeClass("np-hide"); |
| 1417 | $(plugin.row).find(".status-np-hidden").remove(); |
| 1418 | } |
| 1419 | var sticky = $(plugin.row).find(".sticky"); |
| 1420 | if (plugin.newData.sticky == "sticky") { |
| 1421 | $(sticky).show(); |
| 1422 | } else { |
| 1423 | $(sticky).hide(); |
| 1424 | } |
| 1425 | if (!NestedPages.jsData.hierarchical) { |
| 1426 | $(plugin.row).find(".np-author-display").text(plugin.newData.author_name); |
| 1427 | } |
| 1428 | var button = $(plugin.row).find(NestedPages.selectors.quickEditOpen); |
| 1429 | $(button).attr("data-id", plugin.newData.post_id); |
| 1430 | $(button).attr("data-template", plugin.newData.page_template); |
| 1431 | $(button).attr("data-title", plugin.newData.post_title); |
| 1432 | $(button).attr("data-slug", plugin.newData.post_name); |
| 1433 | $(button).attr("data-commentstatus", plugin.newData.comment_status); |
| 1434 | $(button).attr("data-status", plugin.newData._status); |
| 1435 | $(button).attr("data-sticky", plugin.newData.sticky); |
| 1436 | if (plugin.newData.keep_private === "private") { |
| 1437 | $(button).attr("data-status", "private"); |
| 1438 | } |
| 1439 | $(button).attr("data-author", plugin.newData.post_author); |
| 1440 | $(button).attr("data-np-status", plugin.newData.np_status); |
| 1441 | $(button).attr("data-password", plugin.newData.post_password); |
| 1442 | $(button).attr("data-navstatus", plugin.newData.nav_status); |
| 1443 | $(button).attr("data-navtitle", plugin.newData.np_nav_title); |
| 1444 | $(button).attr("data-linktarget", plugin.newData.link_target); |
| 1445 | $(button).attr("data-navtitleattr", plugin.newData.np_title_attribute); |
| 1446 | $(button).attr("data-navcss", plugin.newData.np_nav_css_classes); |
| 1447 | $(button).attr("data-month", plugin.newData.mm); |
| 1448 | $(button).attr("data-day", plugin.newData.jj); |
| 1449 | $(button).attr("data-year", plugin.newData.aa); |
| 1450 | $(button).attr("data-hour", plugin.newData.hh); |
| 1451 | $(button).attr("data-minute", plugin.newData.mn); |
| 1452 | $(button).attr("data-datepicker", plugin.newData.np_date); |
| 1453 | $(button).attr("data-time", plugin.newData.np_time); |
| 1454 | $(button).attr("data-formattedtime", plugin.newData.np_time); |
| 1455 | $(button).attr("data-ampm", plugin.newData.np_ampm); |
| 1456 | for (var key in plugin.newData) { |
| 1457 | if (!key.includes("np_custom")) continue; |
| 1458 | if (plugin.newData.hasOwnProperty(key)) { |
| 1459 | var attrName = key.replace("np_custom_", "data-npcustom-"); |
| 1460 | $(button).attr(attrName, plugin.newData[key]); |
| 1461 | } |
| 1462 | } |
| 1463 | plugin.removeTaxonomyClasses(); |
| 1464 | plugin.addCategoryClasses(); |
| 1465 | plugin.addHierarchicalClasses(); |
| 1466 | plugin.addFlatClasses(); |
| 1467 | plugin.addStatusClass(); |
| 1468 | plugin.formatter.removeQuickEdit(); |
| 1469 | plugin.formatter.flashRow(plugin.row); |
| 1470 | }; |
| 1471 | plugin.addStatusClass = function() { |
| 1472 | var statuses = ["published", "draft", "pending", "future"]; |
| 1473 | for (i = 0; i < statuses.length; i++) { |
| 1474 | $(plugin.row).removeClass(statuses[i]); |
| 1475 | } |
| 1476 | $(plugin.row).addClass(plugin.newData._status); |
| 1477 | }; |
| 1478 | plugin.removeTaxonomyClasses = function() { |
| 1479 | taxonomies = []; |
| 1480 | var classes = $(plugin.row).attr("class").split(/\s+/); |
| 1481 | for (i = 0; i < classes.length; i++) { |
| 1482 | if (classes[i].substring(0, 3) === "in-") { |
| 1483 | $(plugin.row).removeClass(classes[i]); |
| 1484 | } |
| 1485 | if (classes[i].substring(0, 4) === "inf-") { |
| 1486 | $(plugin.row).removeClass(classes[i]); |
| 1487 | } |
| 1488 | } |
| 1489 | }; |
| 1490 | plugin.addCategoryClasses = function() { |
| 1491 | if (!plugin.newData.hasOwnProperty("post_category")) return; |
| 1492 | var cats = plugin.newData.post_category; |
| 1493 | for (i = 0; i < cats.length; i++) { |
| 1494 | var taxclass = "in-category-" + cats[i]; |
| 1495 | $(plugin.row).addClass(taxclass); |
| 1496 | } |
| 1497 | }; |
| 1498 | plugin.addHierarchicalClasses = function() { |
| 1499 | if (!plugin.newData.hasOwnProperty("tax_input")) return; |
| 1500 | var taxonomies2 = plugin.newData.tax_input; |
| 1501 | $.each(taxonomies2, function(tax, terms) { |
| 1502 | for (i = 0; i < terms.length; i++) { |
| 1503 | var taxclass = "in-" + tax + "-" + terms[i]; |
| 1504 | $(plugin.row).addClass(taxclass); |
| 1505 | } |
| 1506 | }); |
| 1507 | }; |
| 1508 | plugin.addFlatClasses = function() { |
| 1509 | if (!plugin.newData.hasOwnProperty("flat_tax")) return; |
| 1510 | var taxonomies2 = plugin.newData.flat_tax; |
| 1511 | $.each(taxonomies2, function(tax, terms) { |
| 1512 | for (i = 0; i < terms.length; i++) { |
| 1513 | var taxclass = "inf-" + tax + "-nps-" + terms[i]; |
| 1514 | $(plugin.row).addClass(taxclass); |
| 1515 | } |
| 1516 | }); |
| 1517 | }; |
| 1518 | plugin.toggleLoading = function(loading) { |
| 1519 | if (loading) { |
| 1520 | $(NestedPages.selectors.quickEditErrorDiv).hide(); |
| 1521 | $(plugin.saveButton).attr("disabled", "disabled"); |
| 1522 | $(NestedPages.selectors.quickEditLoadingIndicator).show(); |
| 1523 | return; |
| 1524 | } |
| 1525 | $(plugin.saveButton).attr("disabled", false); |
| 1526 | $(NestedPages.selectors.quickEditLoadingIndicator).hide(); |
| 1527 | }; |
| 1528 | return plugin.bindEvents(); |
| 1529 | }; |
| 1530 | var NestedPages = NestedPages || {}; |
| 1531 | NestedPages.QuickEditLink = function() { |
| 1532 | var plugin = this; |
| 1533 | var $ = jQuery; |
| 1534 | plugin.formatter = new NestedPages.Formatter(); |
| 1535 | plugin.button = ""; |
| 1536 | plugin.postData = ""; |
| 1537 | plugin.newPostData = ""; |
| 1538 | plugin.form = ""; |
| 1539 | plugin.bindEvents = function() { |
| 1540 | $(document).on("click", NestedPages.selectors.quickEditButtonLink, function(e) { |
| 1541 | e.preventDefault(); |
| 1542 | plugin.formatter.removeQuickEdit(); |
| 1543 | plugin.button = $(this); |
| 1544 | plugin.openQuickEdit(); |
| 1545 | }); |
| 1546 | $(document).on("click", NestedPages.selectors.quickEditLinkSaveButton, function(e) { |
| 1547 | e.preventDefault(); |
| 1548 | plugin.submitForm(); |
| 1549 | }); |
| 1550 | $(document).on("keydown", function(e) { |
| 1551 | if (e.keyCode === 27) plugin.formatter.removeQuickEdit(); |
| 1552 | }); |
| 1553 | }; |
| 1554 | plugin.openQuickEdit = function() { |
| 1555 | plugin.setData(); |
| 1556 | plugin.createForm(); |
| 1557 | plugin.populateForm(); |
| 1558 | }; |
| 1559 | plugin.setData = function() { |
| 1560 | plugin.postData = { |
| 1561 | id: $(plugin.button).attr("data-id"), |
| 1562 | url: $(plugin.button).attr("data-url"), |
| 1563 | title: $(plugin.button).attr("data-title"), |
| 1564 | status: $(plugin.button).attr("data-status"), |
| 1565 | navstatus: $(plugin.button).attr("data-navstatus"), |
| 1566 | npstatus: $(plugin.button).attr("data-np-status"), |
| 1567 | linktarget: $(plugin.button).attr("data-linktarget"), |
| 1568 | parentid: $(plugin.button).attr("data-parentid"), |
| 1569 | navtitleattr: $(plugin.button).attr("data-navtitleattr"), |
| 1570 | navcss: $(plugin.button).attr("data-navcss"), |
| 1571 | navtype: $(plugin.button).attr("data-nav-type"), |
| 1572 | navobject: $(plugin.button).attr("data-nav-object"), |
| 1573 | navobjectid: $(plugin.button).attr("data-nav-object-id"), |
| 1574 | navoriginallink: $(plugin.button).attr("data-nav-original-link"), |
| 1575 | navoriginaltitle: $(plugin.button).attr("data-nav-original-title") |
| 1576 | }; |
| 1577 | }; |
| 1578 | plugin.createForm = function() { |
| 1579 | var parent_li = $(plugin.button).closest(NestedPages.selectors.row).parent("li"); |
| 1580 | plugin.form = $(NestedPages.selectors.quickEditLinkForm).clone(); |
| 1581 | if ($(parent_li).children("ol").length > 0) { |
| 1582 | var child_ol = $(parent_li).children("ol"); |
| 1583 | $(plugin.form).insertBefore(child_ol); |
| 1584 | } else { |
| 1585 | $(plugin.form).appendTo(parent_li); |
| 1586 | } |
| 1587 | var row = $(plugin.form).siblings(NestedPages.selectors.row).hide(); |
| 1588 | }; |
| 1589 | plugin.populateForm = function() { |
| 1590 | $(plugin.form).find(".np_id").val(plugin.postData.id); |
| 1591 | $(plugin.form).find(".np_title").val(plugin.postData.title); |
| 1592 | $(plugin.form).find(".np_author select").val(plugin.postData.author); |
| 1593 | $(plugin.form).find(".np_status").val(plugin.postData.status); |
| 1594 | $(plugin.form).find(".np_content").val(plugin.postData.url); |
| 1595 | $(plugin.form).find(".np_parent_id").val(plugin.postData.parentid); |
| 1596 | $(plugin.form).find(".np_title_attribute").val(plugin.postData.navtitleattr); |
| 1597 | $(plugin.form).find(".np_nav_css_classes").val(plugin.postData.navcss); |
| 1598 | if (plugin.postData.npstatus === "hide") { |
| 1599 | $(plugin.form).find(".np_status").prop("checked", "checked"); |
| 1600 | } else { |
| 1601 | $(plugin.form).find(".np_status").removeAttr("checked"); |
| 1602 | } |
| 1603 | if (plugin.postData.navstatus === "hide") { |
| 1604 | $(plugin.form).find(".np_nav_status").prop("checked", "checked"); |
| 1605 | } else { |
| 1606 | $(plugin.form).find(".np_nav_status").removeAttr("checked"); |
| 1607 | } |
| 1608 | if (plugin.postData.linktarget === "_blank") { |
| 1609 | $(plugin.form).find(".link_target").prop("checked", "checked"); |
| 1610 | } else { |
| 1611 | $(plugin.form).find(".link_target").removeAttr("checked"); |
| 1612 | } |
| 1613 | if (plugin.postData.navobject !== "custom" && plugin.postData.navobject !== "") { |
| 1614 | var html = '<div class="form-control original-link">Original: <a href="' + plugin.postData.navoriginallink + '" target="_blank">' + plugin.postData.navoriginaltitle + "</a></div>"; |
| 1615 | $(plugin.form).find("[data-url-field]").remove(); |
| 1616 | $(html).insertAfter($(plugin.form).find("h3")); |
| 1617 | $(plugin.form).find("[data-np-menu-object-input]").val(plugin.postData.navobject); |
| 1618 | $(plugin.form).find("[data-np-menu-objectid-input]").val(plugin.postData.navobjectid); |
| 1619 | $(plugin.form).find("[data-np-menu-type-input]").val(plugin.postData.navtype); |
| 1620 | $(plugin.form).find("h3").text("Link: " + plugin.postData.navoriginaltitle); |
| 1621 | } else { |
| 1622 | $(plugin.form).find("h3").text("Link"); |
| 1623 | $(plugin.form).find("[data-np-menu-object-input]").val("custom"); |
| 1624 | $(plugin.form).find("[data-np-menu-type-input]").val("custom"); |
| 1625 | } |
| 1626 | plugin.formatter.showQuickEdit(); |
| 1627 | $(plugin.form).show(); |
| 1628 | }; |
| 1629 | plugin.submitForm = function() { |
| 1630 | plugin.toggleLoading(true); |
| 1631 | $.ajax({ |
| 1632 | url: NestedPages.jsData.ajaxurl, |
| 1633 | type: "post", |
| 1634 | datatype: "json", |
| 1635 | data: $(plugin.form).find("form").serialize() + "&action=" + NestedPages.formActions.quickEditLink + "&nonce=" + NestedPages.jsData.nonce + "&syncmenu=" + NestedPages.jsData.syncmenu + "&post_type=" + NestedPages.jsData.posttype, |
| 1636 | success: function(data) { |
| 1637 | if (data.status === "error") { |
| 1638 | plugin.toggleLoading(false); |
| 1639 | $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text(data.message).show(); |
| 1640 | } else { |
| 1641 | plugin.toggleLoading(false); |
| 1642 | plugin.newPostData = data.post_data; |
| 1643 | plugin.updateRow(); |
| 1644 | } |
| 1645 | }, |
| 1646 | error: function(data) { |
| 1647 | plugin.toggleLoading(false); |
| 1648 | $(plugin.form).find(NestedPages.selectors.quickEditErrorDiv).text("The form could not be saved at this time.").show(); |
| 1649 | } |
| 1650 | }); |
| 1651 | }; |
| 1652 | plugin.updateRow = function() { |
| 1653 | var row = $(plugin.form).siblings(".row"); |
| 1654 | $(row).find(".title").html(plugin.newPostData.post_title + ' <svg class="link-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path class="icon" d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>'); |
| 1655 | var status = $(row).find(".status"); |
| 1656 | if (plugin.newPostData._status !== "publish" && plugin.newPostData._status !== "future") { |
| 1657 | $(status).text("(" + plugin.newPostData._status + ")"); |
| 1658 | } else { |
| 1659 | $(status).text(""); |
| 1660 | } |
| 1661 | var nav_status = $(row).find(".nav-status"); |
| 1662 | if (plugin.newPostData.nav_status == "hide") { |
| 1663 | $(nav_status).text("(" + NestedPages.jsData.hiddenText + ")"); |
| 1664 | } else { |
| 1665 | $(nav_status).text(""); |
| 1666 | } |
| 1667 | var li = $(row).parent("li"); |
| 1668 | if (plugin.newPostData.np_status == "hide") { |
| 1669 | $(li).addClass("np-hide"); |
| 1670 | $(row).find(".status").after('<svg class="row-status-icon status-np-hidden" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0zm0 0h24v24H0z" fill="none"/><path class="icon" d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"/></svg>'); |
| 1671 | } else { |
| 1672 | $(li).removeClass("np-hide"); |
| 1673 | $(row).find(".status-np-hidden").remove(); |
| 1674 | } |
| 1675 | var button = $(row).find(NestedPages.selectors.quickEditButtonLink); |
| 1676 | $(button).attr("data-id", plugin.newPostData.post_id); |
| 1677 | $(button).attr("data-title", plugin.newPostData.post_title); |
| 1678 | $(button).attr("data-url", plugin.newPostData.post_content); |
| 1679 | $(button).attr("data-status", plugin.newPostData._status); |
| 1680 | $(button).attr("data-navstatus", plugin.newPostData.nav_status); |
| 1681 | $(button).attr("data-np-status", plugin.newPostData.np_status); |
| 1682 | $(button).attr("data-linkTarget", plugin.newPostData.linkTarget); |
| 1683 | $(button).attr("data-navtitleattr", plugin.newPostData.titleAttribute); |
| 1684 | $(button).attr("data-navcss", plugin.newPostData.cssClasses); |
| 1685 | plugin.formatter.removeQuickEdit(); |
| 1686 | plugin.formatter.flashRow(row); |
| 1687 | }; |
| 1688 | plugin.toggleLoading = function(loading) { |
| 1689 | $(".row").removeClass("np-updated").removeClass("np-updated-show"); |
| 1690 | if (loading) { |
| 1691 | $(NestedPages.selectors.quickEditErrorDiv).hide(); |
| 1692 | $(NestedPages.selectors.quickEditLinkSaveButton).attr("disabled", "disabled"); |
| 1693 | $(NestedPages.selectors.quickEditLoadingIndicator).show(); |
| 1694 | return; |
| 1695 | } |
| 1696 | $(NestedPages.selectors.quickEditLinkSaveButton).attr("disabled", false); |
| 1697 | $(NestedPages.selectors.quickEditLoadingIndicator).hide(); |
| 1698 | }; |
| 1699 | return plugin.bindEvents(); |
| 1700 | }; |
| 1701 | var NestedPages = NestedPages || {}; |
| 1702 | NestedPages.Clone = function() { |
| 1703 | var plugin = this; |
| 1704 | var $ = jQuery; |
| 1705 | plugin.parent_id = ""; |
| 1706 | plugin.parent_title = ""; |
| 1707 | plugin.parentLi = null; |
| 1708 | plugin.formatter = new NestedPages.Formatter(); |
| 1709 | plugin.bindEvents = function() { |
| 1710 | $(document).on("click", NestedPages.selectors.cloneButton, function(e) { |
| 1711 | e.preventDefault(); |
| 1712 | plugin.parent_id = $(this).attr("data-id"); |
| 1713 | plugin.parent_title = $(this).attr("data-parentname"); |
| 1714 | plugin.parentLi = $(this).parent(".row").parent(".page-row").parent(".npList"); |
| 1715 | plugin.openModal(); |
| 1716 | }); |
| 1717 | $(document).on("click", NestedPages.selectors.confirmClone, function(e) { |
| 1718 | e.preventDefault(); |
| 1719 | plugin.clone(); |
| 1720 | }); |
| 1721 | }; |
| 1722 | plugin.openModal = function() { |
| 1723 | $("#" + NestedPages.selectors.cloneModal).find("[data-clone-parent]").text(plugin.parent_title); |
| 1724 | $(document).trigger("open-modal-manual", NestedPages.selectors.cloneModal); |
| 1725 | }; |
| 1726 | plugin.clone = function() { |
| 1727 | var clone_children = $(NestedPages.selectors.cloneChildren).is(":checked") ? true : false; |
| 1728 | plugin.toggleLoading(true); |
| 1729 | $.ajax({ |
| 1730 | url: NestedPages.jsData.ajaxurl, |
| 1731 | type: "post", |
| 1732 | data: { |
| 1733 | action: NestedPages.formActions.clonePost, |
| 1734 | parent_id: plugin.parent_id, |
| 1735 | quantity: $(NestedPages.selectors.cloneQuantity).val(), |
| 1736 | status: $(NestedPages.selectors.cloneStatus).val(), |
| 1737 | author: $(NestedPages.selectors.cloneAuthor).find("select").val(), |
| 1738 | clone_children, |
| 1739 | nonce: NestedPages.jsData.nonce, |
| 1740 | posttype: NestedPages.jsData.posttype |
| 1741 | }, |
| 1742 | success: function(data) { |
| 1743 | plugin.toggleLoading(false); |
| 1744 | $(document).trigger("close-modal-manual"); |
| 1745 | location.reload(); |
| 1746 | } |
| 1747 | }); |
| 1748 | }; |
| 1749 | plugin.toggleLoading = function(loading) { |
| 1750 | if (loading) { |
| 1751 | $("#" + NestedPages.selectors.cloneModal).find("[data-clone-loading]").show(); |
| 1752 | $(NestedPages.selectors.confirmClone).attr("disabled", "disabled"); |
| 1753 | return; |
| 1754 | } |
| 1755 | $("#" + NestedPages.selectors.cloneModal).find("[data-clone-loading]").hide(); |
| 1756 | $(NestedPages.selectors.confirmClone).attr("disabled", false); |
| 1757 | }; |
| 1758 | return plugin.bindEvents(); |
| 1759 | }; |
| 1760 | var NestedPages = NestedPages || {}; |
| 1761 | NestedPages.Tabs = function() { |
| 1762 | var self = this; |
| 1763 | var $ = jQuery; |
| 1764 | self.selectors = { |
| 1765 | tabToggle: "data-np-tab-toggle", |
| 1766 | tabPane: "data-np-tab-pane", |
| 1767 | tabGroup: "data-np-tab-group" |
| 1768 | }; |
| 1769 | self.bindEvents = function() { |
| 1770 | $(document).on("click", "[" + self.selectors.tabToggle + "]", function(e) { |
| 1771 | e.preventDefault(); |
| 1772 | self.toggleTabs($(this)); |
| 1773 | }); |
| 1774 | }; |
| 1775 | self.toggleTabs = function(tab) { |
| 1776 | var tabGroup = $(tab).attr(self.selectors.tabGroup); |
| 1777 | var tabPanes = $("*[" + self.selectors.tabGroup + "=" + tabGroup + "][" + self.selectors.tabPane + "]"); |
| 1778 | var activeTab = $(tab).attr(self.selectors.tabToggle); |
| 1779 | var buttons = $("*[" + self.selectors.tabGroup + "=" + tabGroup + "][" + self.selectors.tabToggle + "]"); |
| 1780 | var listItems = []; |
| 1781 | for (var i2 = 0; i2 < buttons.length; i2++) { |
| 1782 | listItems[i2] = $(buttons[i2]).parent("li")[0]; |
| 1783 | } |
| 1784 | $(tabPanes).hide(); |
| 1785 | $(buttons).removeClass("active"); |
| 1786 | $(listItems).removeClass("active"); |
| 1787 | $.each(tabPanes, function() { |
| 1788 | if ($(this).attr(self.selectors.tabPane) == activeTab) $(this).show(); |
| 1789 | }); |
| 1790 | $.each(buttons, function() { |
| 1791 | if ($(this).attr(self.selectors.tabToggle) == activeTab) { |
| 1792 | $(this).addClass("active"); |
| 1793 | $(this).parent("li").addClass("active"); |
| 1794 | } |
| 1795 | }); |
| 1796 | $(document).trigger("tabs-changed", [activeTab, tabGroup, tab]); |
| 1797 | }; |
| 1798 | return self.bindEvents(); |
| 1799 | }; |
| 1800 | jQuery(document).ready(function() { |
| 1801 | new NestedPages.Factory(); |
| 1802 | }); |
| 1803 | var NestedPages = NestedPages || {}; |
| 1804 | NestedPages.selectors = { |
| 1805 | childToggle: ".child-toggle", |
| 1806 | // Child Toggle Buttons |
| 1807 | childToggleLink: ".child-toggle a", |
| 1808 | // Actual link in button |
| 1809 | toggleAll: ".nestedpages-toggleall", |
| 1810 | // Toggle All Button |
| 1811 | toggleHidden: ".np-toggle-hidden", |
| 1812 | // Toggle Hidden Pages |
| 1813 | toggleStatus: ".np-toggle-publish", |
| 1814 | // Toggle Published Pages |
| 1815 | lists: ".nplist", |
| 1816 | // OL elements |
| 1817 | rows: ".page-row", |
| 1818 | // Page Row, |
| 1819 | row: ".row", |
| 1820 | // Inner row div element |
| 1821 | sortable: ".sortable", |
| 1822 | // Sortable List |
| 1823 | notSortable: ".no-sort", |
| 1824 | // Unsortable List |
| 1825 | handle: ".handle", |
| 1826 | // Sortable Handle |
| 1827 | published: ".published", |
| 1828 | // Published Rows |
| 1829 | hiddenRows: ".np-hide", |
| 1830 | // Hidden Rows |
| 1831 | errorDiv: "#np-error", |
| 1832 | // Error Alert |
| 1833 | loadingIndicator: "#nested-loading", |
| 1834 | // Loading Indicator, |
| 1835 | syncCheckbox: ".np-sync-menu", |
| 1836 | // Sync menu checkbox |
| 1837 | syncForm: ".np-sync-menu-cont", |
| 1838 | // The form/container for the sync menu element |
| 1839 | ajaxError: "[data-nestedpages-error]", |
| 1840 | // AJAX error notification |
| 1841 | trashWithChildrenButton: "[data-nestedpages-trash-children]", |
| 1842 | // Responsive Toggle |
| 1843 | toggleEditButtons: ".np-toggle-edit", |
| 1844 | // Button that toggles responsive buttons |
| 1845 | // Bulk Actions |
| 1846 | bulkActionsHeader: ".nestedpages-list-header", |
| 1847 | bulkActionsForm: "[data-np-bulk-form]", |
| 1848 | bulkActionsCheckbox: "[data-np-bulk-checkbox]", |
| 1849 | bulkActionsIds: "[data-np-bulk-ids]", |
| 1850 | bulkActionRedirectIds: "[data-np-bulk-redirect-ids]", |
| 1851 | hiddenItemCount: "[data-np-hidden-count]", |
| 1852 | hiddenItemCountParent: "[data-np-hidden-count-parent]", |
| 1853 | bulkEditForm: "[data-np-bulk-edit-form]", |
| 1854 | // The primary bulk edit form |
| 1855 | bulkEditTitles: "[data-np-bulk-titles]", |
| 1856 | // Titles to perform bulk edits on (includes hidden ids), |
| 1857 | bulkEditRemoveItem: "[data-np-remove-bulk-item]", |
| 1858 | // Remove an item from bulk edit |
| 1859 | bulkEditCancel: "[data-np-cancel-bulk-edit]", |
| 1860 | // Cancel button in bulk edit form |
| 1861 | bulkEditLinkCount: "[data-bulk-edit-link-count]", |
| 1862 | // Count of selected links in bulk edit |
| 1863 | // Quick Edit |
| 1864 | quickEditOverlay: ".np-inline-overlay", |
| 1865 | // The inline modal |
| 1866 | quickEditLoadingIndicator: ".np-qe-loading", |
| 1867 | // Loading indicator in Quick Edit |
| 1868 | quickEditErrorDiv: ".np-quickedit-error", |
| 1869 | // Error Div in Quick Edit |
| 1870 | quickEditCancel: ".np-cancel-quickedit", |
| 1871 | // Cancel button in quick edit |
| 1872 | // Quick Edit - Links |
| 1873 | quickEditButtonLink: ".np-quick-edit-redirect", |
| 1874 | // Button to open link quick edit |
| 1875 | quickEditLinkForm: ".quick-edit-form-redirect", |
| 1876 | // Form for link quick edits |
| 1877 | quickEditLinkSaveButton: ".np-save-quickedit-redirect", |
| 1878 | // Save button in link quick edit form |
| 1879 | // Quick Edit - Posts |
| 1880 | quickEditOpen: ".np-quick-edit", |
| 1881 | // Button to open post quick edit |
| 1882 | quickEditPostForm: ".quick-edit-form", |
| 1883 | // Form container |
| 1884 | quickEditSaveButton: ".np-save-quickedit", |
| 1885 | // Save button in quick edit (posts) |
| 1886 | // Link Items |
| 1887 | openLinkModal: ".open-redirect-modal", |
| 1888 | // Opens new link modal |
| 1889 | linkModal: "np-link-modal", |
| 1890 | // The add a link modal |
| 1891 | saveLink: ".np-save-link", |
| 1892 | // Save Link Button |
| 1893 | linkLoadingIndicator: ".np-link-loading", |
| 1894 | // Loading Indicator in Link Modal |
| 1895 | linkErrorDiv: ".np-new-link-error", |
| 1896 | // Error Div in Link Modal |
| 1897 | linkForm: ".np-new-link-form", |
| 1898 | // The form element for a new link |
| 1899 | // Link Deletion |
| 1900 | linkDeleteButton: "[data-np-confirm-delete]", |
| 1901 | linkDeleteConfirmationButton: "[data-delete-confirmation]", |
| 1902 | linkDeleteConfirmationModal: "np-delete-confirmation-modal", |
| 1903 | linkDeleteConfirmationModalText: "[data-np-link-delete-text]", |
| 1904 | // New Page Items |
| 1905 | openPageModal: ".open-bulk-modal", |
| 1906 | // Opens the new page(s) modal |
| 1907 | newPageModal: "#np-bulk-modal", |
| 1908 | // The modal with the new page form |
| 1909 | newPageFormContainer: ".new-child-form", |
| 1910 | // The new page form container |
| 1911 | newPageForm: ".np-new-child-form", |
| 1912 | // The form element |
| 1913 | newPageSubmitButton: ".np-save-newchild", |
| 1914 | // Submit button in new page form |
| 1915 | newPageTitle: ".add-new-child-row", |
| 1916 | // Button to add a new page title field to the form |
| 1917 | newPageRemoveTitle: ".np-remove-child", |
| 1918 | // Button to remove a title field in the form |
| 1919 | addChildButton: ".add-new-child", |
| 1920 | // Button to add child page(s) |
| 1921 | newChildError: ".np-newchild-error", |
| 1922 | // Error div in new child quick edit |
| 1923 | cancelNewChildButton: ".np-cancel-newchild", |
| 1924 | // Cancel button in new child quick edit |
| 1925 | newBeforeButton: "data-insert-before", |
| 1926 | // Add new post(s) before a post |
| 1927 | newAfterButton: "data-insert-after", |
| 1928 | // Add new post(s) after a post |
| 1929 | // Clone |
| 1930 | cloneButton: ".clone-post", |
| 1931 | // Button to clone a post |
| 1932 | confirmClone: "[data-confirm-clone]", |
| 1933 | // Button in modal to confirm clone |
| 1934 | cloneModal: "np-clone-modal", |
| 1935 | // Modal with clone options |
| 1936 | cloneQuantity: "[data-clone-quantity]", |
| 1937 | // Quantity to Clone |
| 1938 | cloneStatus: "[data-clone-status]", |
| 1939 | // Clone Status |
| 1940 | cloneAuthor: "[data-clone-author]", |
| 1941 | // Clone Author |
| 1942 | cloneChildren: "[data-clone-children]", |
| 1943 | // Checkbox to clone children |
| 1944 | // Tabs |
| 1945 | tabButtonParent: "[data-np-tabs]", |
| 1946 | // Tab Parent |
| 1947 | tabButton: "[data-np-tab]", |
| 1948 | // Tab Link |
| 1949 | tabContent: "[data-np-tab-pane]", |
| 1950 | // Tab Pane |
| 1951 | // Thumbnails |
| 1952 | thumbnailContainer: ".np-thumbnail", |
| 1953 | // Container for Thumbnail |
| 1954 | thumbnailContainerLink: ".np-thumbnail.link", |
| 1955 | // Link Thumbnail Container |
| 1956 | // Manual Sync Buttons |
| 1957 | manualMenuSync: "[data-np-manual-menu-sync]", |
| 1958 | // Button for Triggering Manual Menu Sync |
| 1959 | manualOrderSync: "[data-np-manual-order-sync]" |
| 1960 | // Button for Triggering Manual Order Sync |
| 1961 | }; |
| 1962 | NestedPages.cssClasses = { |
| 1963 | noborder: "no-border" |
| 1964 | }; |
| 1965 | NestedPages.jsData = { |
| 1966 | ajaxurl, |
| 1967 | nonce: nestedpages.np_nonce, |
| 1968 | allPostTypes: nestedpages.post_types, |
| 1969 | // Localized data with all post types |
| 1970 | syncmenu: "nosync", |
| 1971 | // Whether to sync the menu |
| 1972 | posttype: "", |
| 1973 | // current Screen's post type |
| 1974 | nestable: true, |
| 1975 | // boolean - whether post type is nestable |
| 1976 | sortable: true, |
| 1977 | // boolean - whether post type is sortable |
| 1978 | hierarchical: true, |
| 1979 | // boolean - whether post type is hierarchical |
| 1980 | expandText: nestedpages.expand_text, |
| 1981 | // Expand all button text |
| 1982 | collapseText: nestedpages.collapse_text, |
| 1983 | // Collapse all button text |
| 1984 | showHiddenText: nestedpages.show_hidden, |
| 1985 | // Show Hidden Pages Link Text |
| 1986 | hideHiddenText: nestedpages.hide_hidden, |
| 1987 | // Hide Hidden Pages Link Text |
| 1988 | quickEditText: nestedpages.quick_edit, |
| 1989 | // Quick Edit Button Text |
| 1990 | hiddenText: nestedpages.hidden, |
| 1991 | // Localized "Hidden" |
| 1992 | titleText: nestedpages.title |
| 1993 | // Localized "Title" |
| 1994 | }; |
| 1995 | NestedPages.formActions = { |
| 1996 | syncToggles: "npnestToggle", |
| 1997 | syncNesting: "npsort", |
| 1998 | syncMenu: "npsyncMenu", |
| 1999 | newPage: "npnewChild", |
| 2000 | newBeforeAfter: "npnewBeforeAfter", |
| 2001 | quickEditLink: "npquickEditLink", |
| 2002 | getTaxonomies: "npgetTaxonomies", |
| 2003 | quickEditPost: "npquickEdit", |
| 2004 | clonePost: "npclonePost", |
| 2005 | search: "npmenuSearch", |
| 2006 | newMenuItem: "npnewMenuItem", |
| 2007 | manualMenuSync: "npmanualMenuSync", |
| 2008 | postSearch: "nppostSearch", |
| 2009 | wpmlTranslations: "npWpmlTranslations", |
| 2010 | resetSettings: "npresetSettings", |
| 2011 | resetUserPrefs: "npresetUserPreferences", |
| 2012 | resetAdminMenuSettings: "npresetAdminMenuSettings", |
| 2013 | trashWithChildren: "nptrashWithChildren", |
| 2014 | toggleStatusDisplay: "nptoggleStatusDisplay" |
| 2015 | }; |
| 2016 | NestedPages.Factory = function() { |
| 2017 | var plugin = this; |
| 2018 | var $ = jQuery; |
| 2019 | plugin.formatter = new NestedPages.Formatter(); |
| 2020 | plugin.dropdowns = new NestedPages.Dropdowns(); |
| 2021 | plugin.modals = new NestedPages.Modals(); |
| 2022 | plugin.checkAll = new NestedPages.CheckAll(); |
| 2023 | plugin.bulkActions = new NestedPages.BulkActions(); |
| 2024 | plugin.menuToggle = new NestedPages.MenuToggle(); |
| 2025 | plugin.pageToggle = new NestedPages.PageToggle(); |
| 2026 | plugin.nesting = new NestedPages.Nesting(); |
| 2027 | plugin.syncMenuSetting = new NestedPages.SyncMenuSetting(); |
| 2028 | plugin.newPage = new NestedPages.NewPost(); |
| 2029 | plugin.quickEditLink = new NestedPages.QuickEditLink(); |
| 2030 | plugin.quickEditPost = new NestedPages.QuickEditPost(); |
| 2031 | plugin.clone = new NestedPages.Clone(); |
| 2032 | plugin.tabs = new NestedPages.Tabs(); |
| 2033 | plugin.menuLinks = new NestedPages.MenuLinks(); |
| 2034 | plugin.hiddenItemCount = new NestedPages.HiddenItemCount(); |
| 2035 | plugin.confirmDelete = new NestedPages.ConfirmDelete(); |
| 2036 | plugin.manualSync = new NestedPages.ManualSync(); |
| 2037 | plugin.postSearch = new NestedPages.PostSearch(); |
| 2038 | plugin.postMove = new NestedPages.MovePost(); |
| 2039 | plugin.wpml = new NestedPages.Wpml(); |
| 2040 | plugin.trashWithChildren = new NestedPages.TrashWithChildren(); |
| 2041 | plugin.init = function() { |
| 2042 | if (nestedpages.settings_page) return; |
| 2043 | plugin.bindEvents(); |
| 2044 | plugin.setPostType(); |
| 2045 | plugin.setMenuSync(); |
| 2046 | plugin.setNestable(); |
| 2047 | plugin.setSortable(); |
| 2048 | plugin.formatter.updateSubMenuToggle(); |
| 2049 | plugin.formatter.setBorders(); |
| 2050 | plugin.formatter.setNestedMargins(); |
| 2051 | plugin.nesting.initializeSortable(); |
| 2052 | }; |
| 2053 | plugin.bindEvents = function() { |
| 2054 | $(document).on("click", NestedPages.selectors.quickEditOverlay, function(e) { |
| 2055 | plugin.formatter.removeQuickEdit(); |
| 2056 | plugin.newPage.cancelNewPage(); |
| 2057 | }); |
| 2058 | $(document).ready(function() { |
| 2059 | plugin.formatter.hideAjaxError(); |
| 2060 | plugin.formatter.sizeLinkThumbnails(); |
| 2061 | }); |
| 2062 | }; |
| 2063 | plugin.setNestable = function() { |
| 2064 | var nestable = false; |
| 2065 | $.each(NestedPages.jsData.allPostTypes, function(i2, v) { |
| 2066 | if (v.name !== NestedPages.jsData.posttype) return; |
| 2067 | if (v.hierarchical === true) nestable = true; |
| 2068 | if (v.disable_nesting === true) nestable = false; |
| 2069 | }); |
| 2070 | NestedPages.jsData.nestable = nestable; |
| 2071 | }; |
| 2072 | plugin.setSortable = function() { |
| 2073 | var sortable = true; |
| 2074 | $.each(NestedPages.jsData.allPostTypes, function(i2, v) { |
| 2075 | if (v.name !== NestedPages.jsData.posttype) return; |
| 2076 | if (typeof v.disable_sorting === "undefined" || v.disable_sorting === "") return; |
| 2077 | if (v.disable_sorting === "true") sortable = false; |
| 2078 | }); |
| 2079 | NestedPages.jsData.sortable = sortable; |
| 2080 | }; |
| 2081 | plugin.setPostType = function() { |
| 2082 | NestedPages.jsData.posttype = nestedpages.current_post_type; |
| 2083 | if (typeof NestedPages.jsData.posttype === "undefined" || NestedPages.jsData.posttype === "") { |
| 2084 | NestedPages.jsData.posttype = $(NestedPages.selectors.sortable).attr("id").substring(3); |
| 2085 | } |
| 2086 | NestedPages.jsData.hierarchical = NestedPages.jsData.allPostTypes[NestedPages.jsData.posttype].hierarchical; |
| 2087 | }; |
| 2088 | plugin.setMenuSync = function() { |
| 2089 | NestedPages.jsData.syncmenu = nestedpages.syncmenu === "1" ? "sync" : "nosync"; |
| 2090 | }; |
| 2091 | return plugin.init(); |
| 2092 | }; |
| 2093 | var NestedPages = NestedPages || {}; |
| 2094 | NestedPages.MenuLinks = function() { |
| 2095 | var plugin = this; |
| 2096 | var $ = jQuery; |
| 2097 | plugin.typeButton = ""; |
| 2098 | plugin.post = ""; |
| 2099 | plugin.formatter = new NestedPages.Formatter(); |
| 2100 | plugin.selectors = { |
| 2101 | form: "[data-np-menu-item-form]", |
| 2102 | // The form element |
| 2103 | typeSelect: "[data-np-menu-selection]", |
| 2104 | // Link in left column to choose type of link |
| 2105 | accordion: "[data-np-menu-accordion]", |
| 2106 | // Accordion of objects |
| 2107 | accordionItem: "[data-np-menu-accordion-item]", |
| 2108 | // Single item in the accordion |
| 2109 | formPlaceholder: ".np-menu-link-object-placeholder", |
| 2110 | // Placeholder element |
| 2111 | formDetails: ".np-menu-link-details", |
| 2112 | // Right pane form details |
| 2113 | searchResults: "[data-np-search-result]", |
| 2114 | // Appended search result rows |
| 2115 | defaultResults: "[data-default-result]", |
| 2116 | // Default results, |
| 2117 | originalLink: "[data-np-original-link]", |
| 2118 | // Original Link Preview |
| 2119 | saveButton: "[data-np-save-link]", |
| 2120 | // The Form Submit Button |
| 2121 | urlInputCont: "[data-np-menu-url-cont]", |
| 2122 | // Container for URL input (only for custom links) |
| 2123 | errorDiv: "[data-np-error]" |
| 2124 | // The error notification |
| 2125 | }; |
| 2126 | plugin.fields = { |
| 2127 | object: "[data-np-menu-object-input]", |
| 2128 | // The object (ex: post/category/custom) |
| 2129 | objectid: "[data-np-menu-objectid-input]", |
| 2130 | // ex: term id, post id |
| 2131 | itemType: "[data-np-menu-type-input]", |
| 2132 | // ex: post_type, taxonomy |
| 2133 | url: "[data-np-menu-url]", |
| 2134 | // custom url |
| 2135 | navigationLabel: "[data-np-menu-navigation-label]", |
| 2136 | titleAttribute: "[data-np-menu-title-attr]", |
| 2137 | cssClasses: "[data-np-menu-css-classes]", |
| 2138 | npStatus: "[data-np-menu-np-status]", |
| 2139 | linkTarget: "[data-np-menu-link-target]", |
| 2140 | menuTitle: "[data-np-menu-title]", |
| 2141 | parentPostType: "[data-np-menu-parent-post-type]" |
| 2142 | }; |
| 2143 | plugin.search = new NestedPages.MenuSearch(); |
| 2144 | plugin.bindEvents = function() { |
| 2145 | $(document).on("click", NestedPages.selectors.openLinkModal, function(e) { |
| 2146 | e.preventDefault(); |
| 2147 | plugin.postParent = $(this).attr("data-parentid"); |
| 2148 | $(plugin.selectors.form).find(".parent_id").val($(this).attr("data-parentid")); |
| 2149 | plugin.openModal(); |
| 2150 | }); |
| 2151 | $(document).on("click", plugin.selectors.accordionItem, function(e) { |
| 2152 | e.preventDefault(); |
| 2153 | plugin.accordion($(this)); |
| 2154 | }); |
| 2155 | $(document).on("click", plugin.selectors.typeSelect, function(e) { |
| 2156 | e.preventDefault(); |
| 2157 | plugin.typeButton = $(this); |
| 2158 | plugin.setLinkType(); |
| 2159 | }); |
| 2160 | $(document).on("keyup", plugin.fields.navigationLabel, function() { |
| 2161 | plugin.updateTitle(); |
| 2162 | }); |
| 2163 | $(document).on("click", plugin.selectors.saveButton, function(e) { |
| 2164 | e.preventDefault(); |
| 2165 | plugin.submitForm(); |
| 2166 | }); |
| 2167 | $(document).on("keydown", function(e) { |
| 2168 | if (e.keyCode === 27) $(document).trigger("close-modal-manual"); |
| 2169 | }); |
| 2170 | }; |
| 2171 | plugin.openModal = function() { |
| 2172 | $(NestedPages.selectors.linkErrorDiv).hide(); |
| 2173 | $(NestedPages.selectors.linkModal).find("input").val(""); |
| 2174 | $(NestedPages.selectors.linkModal).find(".parent_id").val(plugin.postParent); |
| 2175 | plugin.clearForm(); |
| 2176 | $(plugin.selectors.accordion).find("ul").hide(); |
| 2177 | $(plugin.selectors.typeSelect).removeClass("active"); |
| 2178 | $(document).trigger("open-modal-manual", NestedPages.selectors.linkModal); |
| 2179 | }; |
| 2180 | plugin.accordion = function(button) { |
| 2181 | plugin.clearForm(); |
| 2182 | var submenu = $(button).siblings("ul"); |
| 2183 | if ($(submenu).is(":visible")) { |
| 2184 | $(button).removeClass("active"); |
| 2185 | $(submenu).slideUp("fast"); |
| 2186 | return; |
| 2187 | } |
| 2188 | $(plugin.selectors.accordionItem).removeClass("active"); |
| 2189 | $(button).addClass("active"); |
| 2190 | $(button).parents(plugin.selectors.accordion).find("ul").slideUp("fast"); |
| 2191 | $(submenu).slideDown("fast"); |
| 2192 | }; |
| 2193 | plugin.setLinkType = function() { |
| 2194 | if ($(plugin.typeButton).hasClass("active")) { |
| 2195 | plugin.clearForm(); |
| 2196 | return; |
| 2197 | } |
| 2198 | if ($(plugin.typeButton).hasClass("np-custom-link")) { |
| 2199 | $(plugin.selectors.accordionItem).removeClass("active"); |
| 2200 | $(plugin.selectors.accordion).find("ul").slideUp("fast"); |
| 2201 | } |
| 2202 | $(plugin.selectors.formPlaceholder).hide(); |
| 2203 | plugin.populateForm(); |
| 2204 | }; |
| 2205 | plugin.populateForm = function() { |
| 2206 | $(plugin.selectors.saveButton).show(); |
| 2207 | $(plugin.selectors.typeSelect).removeClass("active"); |
| 2208 | $(plugin.typeButton).addClass("active"); |
| 2209 | $(plugin.fields.menuTitle).text($(plugin.typeButton).text()).val($(plugin.typeButton).text()); |
| 2210 | $(plugin.selectors.form).find("h3").find("em").text($(plugin.typeButton).attr("data-np-object-name")); |
| 2211 | if ($(plugin.typeButton).attr("data-np-permalink") !== "") { |
| 2212 | $(plugin.selectors.form).find(plugin.selectors.urlInputCont).hide(); |
| 2213 | $(plugin.selectors.form).find(plugin.selectors.originalLink).html('<a href="' + $(plugin.typeButton).attr("data-np-permalink") + '">' + $(plugin.typeButton).text() + "</a>"); |
| 2214 | $(plugin.selectors.form).find(plugin.selectors.originalLink).parent(".original-link").show(); |
| 2215 | } else { |
| 2216 | $(plugin.selectors.form).find(plugin.selectors.urlInputCont).show(); |
| 2217 | $(plugin.selectors.form).find(plugin.selectors.originalLink).parent(".original-link").hide(); |
| 2218 | } |
| 2219 | $(plugin.fields.object).val($(plugin.typeButton).attr("data-np-menu-object")); |
| 2220 | $(plugin.fields.objectid).val($(plugin.typeButton).attr("data-np-menu-objectid")); |
| 2221 | $(plugin.fields.itemType).val($(plugin.typeButton).attr("data-np-menu-type")); |
| 2222 | $(plugin.selectors.formDetails).show(); |
| 2223 | }; |
| 2224 | plugin.clearForm = function() { |
| 2225 | $(plugin.selectors.form).find(plugin.selectors.errorDiv).hide(); |
| 2226 | $(plugin.selectors.saveButton).hide(); |
| 2227 | $(plugin.selectors.formDetails).hide(); |
| 2228 | $(plugin.selectors.formPlaceholder).show(); |
| 2229 | $(plugin.selectors.form).find("input").not(".parent_id").not(".parent-post-type").val(""); |
| 2230 | $(plugin.selectors.form).find(plugin.fields.linkTarget).val("_blank"); |
| 2231 | $(plugin.selectors.form).find('input[type="checkbox"]').attr("checked", false); |
| 2232 | $(plugin.selectors.typeSelect).removeClass("active"); |
| 2233 | plugin.search.toggleLoading(false); |
| 2234 | $(plugin.selectors.searchResults).remove(); |
| 2235 | $(plugin.selectors.defaultResults).show(); |
| 2236 | }; |
| 2237 | plugin.updateTitle = function() { |
| 2238 | var value = $(plugin.fields.navigationLabel).val(); |
| 2239 | var title = $(plugin.selectors.form).find("h3").find("span"); |
| 2240 | if (value !== "") { |
| 2241 | $(plugin.fields.menuTitle).val(value); |
| 2242 | $(title).text(value); |
| 2243 | } else { |
| 2244 | $(plugin.fields.menuTitle).val($(plugin.typeButton).text()); |
| 2245 | $(title).text($(plugin.typeButton).text()); |
| 2246 | } |
| 2247 | }; |
| 2248 | plugin.submitForm = function() { |
| 2249 | plugin.toggleLoading(true); |
| 2250 | $.ajax({ |
| 2251 | url: NestedPages.jsData.ajaxurl, |
| 2252 | type: "post", |
| 2253 | data: $(plugin.selectors.form).serialize() + "&action=" + NestedPages.formActions.newMenuItem + "&nonce=" + NestedPages.jsData.nonce + "&post_type=" + NestedPages.jsData.posttype + "&syncmenu=" + NestedPages.jsData.syncmenu, |
| 2254 | success: function(data) { |
| 2255 | plugin.toggleLoading(false); |
| 2256 | if (data.status === "error") { |
| 2257 | $(plugin.selectors.form).find(plugin.selectors.errorDiv).text(data.message).show(); |
| 2258 | return; |
| 2259 | } |
| 2260 | plugin.post = data.post_data; |
| 2261 | plugin.createRow(); |
| 2262 | }, |
| 2263 | error: function(data) { |
| 2264 | console.log(data); |
| 2265 | } |
| 2266 | }); |
| 2267 | }; |
| 2268 | plugin.createRow = function() { |
| 2269 | var html = '<li id="menuItem_' + plugin.post.id + '" class="page-row post-type-np-redirect published'; |
| 2270 | html += '">'; |
| 2271 | html += '<div class="row"><div class="child-toggle"><div class="child-toggle-spacer"></div></div><div class="row-inner">'; |
| 2272 | html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="np-icon-sub-menu"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M19 15l-6 6-1.42-1.42L15.17 16H4V4h2v10h9.17l-3.59-3.58L13 9l6 6z" class="arrow" /></svg>'; |
| 2273 | html += '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="handle np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg>'; |
| 2274 | html += '<a href="' + plugin.post.np_link_content + '" class="page-link page-title" target="_blank"><span class="title">' + plugin.post.menuTitle + ' <svg class="link-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path class="icon" d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg></span>'; |
| 2275 | html += '</a><div class="action-buttons"><a href="#" class="np-btn np-quick-edit-redirect" '; |
| 2276 | html += 'data-id="' + plugin.post.id + '"'; |
| 2277 | html += 'data-parentid="' + plugin.post.parent_id + '"'; |
| 2278 | html += 'data-title="' + plugin.post.menuTitle + '" '; |
| 2279 | html += 'data-url="' + plugin.post.url + '" '; |
| 2280 | html += 'data-status="publish" '; |
| 2281 | html += 'data-np-status="show" '; |
| 2282 | html += 'data-navstatus="show" '; |
| 2283 | html += 'data-navcss="' + plugin.post.cssClasses + '" '; |
| 2284 | html += 'data-navtitleattr="' + plugin.post.titleAttribute + '" '; |
| 2285 | html += 'data-nav-type="' + plugin.post.menuType + '" '; |
| 2286 | html += 'data-nav-object="' + plugin.post.objectType + '" '; |
| 2287 | html += 'data-nav-object-id="' + plugin.post.objectId + '" '; |
| 2288 | html += 'data-nav-original-link="' + plugin.post.original_link + '" '; |
| 2289 | html += 'data-nav-original-title="' + plugin.post.original_title + '" '; |
| 2290 | html += 'data-linktarget="' + plugin.post.link_target + '">'; |
| 2291 | html += NestedPages.jsData.quickEditText; |
| 2292 | html += "</a>"; |
| 2293 | html += '<a href="' + plugin.post.delete_link + '" class="np-btn np-btn-trash"><i class="np-icon-remove"></i></a>'; |
| 2294 | html += "</div></div></div></li>"; |
| 2295 | if (plugin.post.parent_id === "0") { |
| 2296 | $(".nplist:first li:first").after(html); |
| 2297 | } else { |
| 2298 | plugin.appendChildRow(html); |
| 2299 | } |
| 2300 | $(document).trigger("close-modal-manual"); |
| 2301 | plugin.row = $("#menuItem_" + plugin.post.id).find(".row"); |
| 2302 | plugin.formatter.flashRow(plugin.row); |
| 2303 | }; |
| 2304 | plugin.appendChildRow = function(html) { |
| 2305 | var parent_row = $("#menuItem_" + plugin.post.parent_id); |
| 2306 | if ($(parent_row).children("ol").length === 0) { |
| 2307 | html = '<ol class="sortable nplist" style="display:block;">' + html + "</ol>"; |
| 2308 | $(parent_row).append(html); |
| 2309 | } else { |
| 2310 | $(parent_row).find("ol:first").prepend(html); |
| 2311 | } |
| 2312 | plugin.formatter.updateSubMenuToggle(); |
| 2313 | }; |
| 2314 | plugin.toggleLoading = function(loading) { |
| 2315 | if (loading) { |
| 2316 | $(plugin.selectors.form).find(plugin.selectors.errorDiv).hide(); |
| 2317 | $(plugin.selectors.form).find(NestedPages.selectors.quickEditLoadingIndicator).show(); |
| 2318 | $(plugin.selectors.saveButton).attr("disabled", "disabled"); |
| 2319 | return; |
| 2320 | } |
| 2321 | $(plugin.selectors.form).find(NestedPages.selectors.quickEditLoadingIndicator).hide(); |
| 2322 | $(plugin.selectors.saveButton).attr("disabled", false); |
| 2323 | }; |
| 2324 | return plugin.bindEvents(); |
| 2325 | }; |
| 2326 | var NestedPages = NestedPages || {}; |
| 2327 | NestedPages.MenuSearch = function() { |
| 2328 | var plugin = this; |
| 2329 | var $ = jQuery; |
| 2330 | plugin.selectors = { |
| 2331 | searchForms: "*[data-np-menu-search]", |
| 2332 | // Search form selector |
| 2333 | defaultResults: "[data-default-result]", |
| 2334 | // Default results list items |
| 2335 | loadingIndicator: ".np-menu-search-loading", |
| 2336 | // loading indicator |
| 2337 | noResults: ".np-menu-search-noresults", |
| 2338 | // No results |
| 2339 | searchType: "data-search-type", |
| 2340 | // The search object type (post_type, taxonomy) |
| 2341 | searchObject: "data-search-object", |
| 2342 | // The object to search (post, category, etc) |
| 2343 | searchResults: "[data-np-search-result]" |
| 2344 | // Appended search result rows |
| 2345 | }; |
| 2346 | plugin.activeForm = ""; |
| 2347 | plugin.results = ""; |
| 2348 | plugin.defaultResults = ""; |
| 2349 | plugin.searchType = ""; |
| 2350 | plugin.searchObject = ""; |
| 2351 | plugin.formatter = new NestedPages.Formatter(); |
| 2352 | plugin.bindEvents = function() { |
| 2353 | $(document).on("keyup", plugin.selectors.searchForms, function() { |
| 2354 | plugin.activeForm = $(this); |
| 2355 | $(plugin.selectors.searchResults).remove(); |
| 2356 | plugin.performSearch(); |
| 2357 | }); |
| 2358 | }; |
| 2359 | plugin.performSearch = function() { |
| 2360 | plugin.defaultResults = $(plugin.activeForm).parent("li").siblings(plugin.selectors.defaultResults); |
| 2361 | if ($(plugin.activeForm).val().length > 2) { |
| 2362 | $(plugin.defaultResults).hide(); |
| 2363 | plugin.toggleLoading(true); |
| 2364 | plugin.query(); |
| 2365 | return; |
| 2366 | } |
| 2367 | plugin.toggleLoading(false); |
| 2368 | $(plugin.defaultResults).show(); |
| 2369 | }; |
| 2370 | plugin.query = function() { |
| 2371 | plugin.searchType = $(plugin.activeForm).attr(plugin.selectors.searchType); |
| 2372 | plugin.searchObject = $(plugin.activeForm).attr(plugin.selectors.searchObject); |
| 2373 | $.ajax({ |
| 2374 | url: NestedPages.jsData.ajaxurl, |
| 2375 | type: "post", |
| 2376 | datatype: "json", |
| 2377 | data: { |
| 2378 | action: NestedPages.formActions.search, |
| 2379 | nonce: NestedPages.jsData.nonce, |
| 2380 | term: $(plugin.activeForm).val(), |
| 2381 | searchType: plugin.searchType, |
| 2382 | searchObject: plugin.searchObject |
| 2383 | }, |
| 2384 | success: function(data) { |
| 2385 | if (data.results) { |
| 2386 | plugin.results = data.results; |
| 2387 | plugin.toggleLoading(false); |
| 2388 | if (plugin.searchType === "post_type") { |
| 2389 | plugin.appendPosts(); |
| 2390 | } else { |
| 2391 | plugin.appendTaxonomies(); |
| 2392 | } |
| 2393 | } else { |
| 2394 | plugin.toggleLoading(false); |
| 2395 | $(plugin.activeForm).siblings(plugin.selectors.noResults).show(); |
| 2396 | } |
| 2397 | } |
| 2398 | }); |
| 2399 | }; |
| 2400 | plugin.appendPosts = function() { |
| 2401 | $("[data-np-search-result]").remove(); |
| 2402 | var html = ""; |
| 2403 | $.each(plugin.results, function(i2, v) { |
| 2404 | html = '<li data-np-search-result><a href="#" data-np-menu-object="' + plugin.searchObject + '" data-np-menu-type="post_type" data-np-menu-objectid="' + v.ID + '" data-np-permalink="' + v.permalink + '" data-np-object-name="' + v.singular_name + '" data-np-menu-selection></a></li>'; |
| 2405 | $(html).insertAfter($(plugin.activeForm).parent("li")); |
| 2406 | $('[data-np-menu-objectid="' + v.ID + '"').text(v.post_title); |
| 2407 | }); |
| 2408 | plugin.toggleLoading(false); |
| 2409 | }; |
| 2410 | plugin.appendTaxonomies = function() { |
| 2411 | var html = ""; |
| 2412 | $.each(plugin.results, function(i2, v) { |
| 2413 | html += '<li data-np-search-result><a href="#" data-np-menu-object="' + plugin.searchObject + '" data-np-menu-type="post_type" data-np-menu-objectid="' + v.term_id + '" data-np-permalink="' + v.permalink + '" data-np-object-name="' + v.taxonomy + '" data-np-menu-selection>' + v.name + "</a></li>"; |
| 2414 | }); |
| 2415 | $(html).insertAfter($(plugin.activeForm).parent("li")); |
| 2416 | plugin.toggleLoading(false); |
| 2417 | }; |
| 2418 | plugin.toggleLoading = function(loading) { |
| 2419 | var loadingIndicator = $(plugin.activeForm).siblings(plugin.selectors.loadingIndicator); |
| 2420 | $(plugin.selectors.noResults).hide(); |
| 2421 | if (loading) { |
| 2422 | $(loadingIndicator).show(); |
| 2423 | return; |
| 2424 | } |
| 2425 | $(loadingIndicator).hide(); |
| 2426 | }; |
| 2427 | return plugin.bindEvents(); |
| 2428 | }; |
| 2429 | jQuery(document).ready(function() { |
| 2430 | new NestedPagesTrash(); |
| 2431 | }); |
| 2432 | var NestedPagesTrash = function() { |
| 2433 | var plugin = this; |
| 2434 | var $ = jQuery; |
| 2435 | plugin.trashButton = ".np-empty-trash"; |
| 2436 | plugin.confirmButton = ".np-trash-confirm"; |
| 2437 | plugin.warningModal = "#np-trash-modal"; |
| 2438 | plugin.errorAlert = "#np-error"; |
| 2439 | plugin.loadingIndicator = "#nested-loading"; |
| 2440 | plugin.trashLinks = ".np-trash-links"; |
| 2441 | plugin.postType = $("#np-trash-posttype").val(); |
| 2442 | plugin.nonce = nestedpages.np_nonce; |
| 2443 | plugin.formAction = "npEmptyTrash"; |
| 2444 | plugin.bindEvents = function() { |
| 2445 | $(document).on("click", plugin.confirmButton, function(e) { |
| 2446 | e.preventDefault(); |
| 2447 | plugin.confirmEmpty(); |
| 2448 | }); |
| 2449 | }; |
| 2450 | plugin.confirmEmpty = function() { |
| 2451 | plugin.loading(true); |
| 2452 | $(document).trigger("close-modal-manual"); |
| 2453 | $(plugin.errorAlert).hide(); |
| 2454 | plugin.emptyTrash(); |
| 2455 | }; |
| 2456 | plugin.emptyTrash = function() { |
| 2457 | $.ajax({ |
| 2458 | url: ajaxurl, |
| 2459 | type: "post", |
| 2460 | datatype: "json", |
| 2461 | data: { |
| 2462 | action: plugin.formAction, |
| 2463 | nonce: plugin.nonce, |
| 2464 | posttype: plugin.postType |
| 2465 | }, |
| 2466 | success: function(data) { |
| 2467 | plugin.loading(false); |
| 2468 | if (data.status === "error") { |
| 2469 | $(plugin.errorAlert).text(data.message).show(); |
| 2470 | } else { |
| 2471 | $(plugin.trashLinks).hide(); |
| 2472 | $(".notice-dismiss").click(); |
| 2473 | } |
| 2474 | } |
| 2475 | }); |
| 2476 | }; |
| 2477 | plugin.loading = function(loading) { |
| 2478 | if (loading) { |
| 2479 | $(plugin.loadingIndicator).show(); |
| 2480 | return; |
| 2481 | } |
| 2482 | $(plugin.loadingIndicator).hide(); |
| 2483 | }; |
| 2484 | return plugin.bindEvents(); |
| 2485 | }; |
| 2486 | var NestedPages = NestedPages || {}; |
| 2487 | NestedPages.ConfirmDelete = function() { |
| 2488 | var plugin = this; |
| 2489 | var $ = jQuery; |
| 2490 | plugin.deleteLink = ""; |
| 2491 | plugin.bindEvents = function() { |
| 2492 | $(document).on("click", NestedPages.selectors.linkDeleteButton, function(e) { |
| 2493 | e.preventDefault(); |
| 2494 | plugin.confirmSingle($(this)); |
| 2495 | }); |
| 2496 | $(document).on("click", NestedPages.selectors.linkDeleteConfirmationButton, function(e) { |
| 2497 | e.preventDefault(); |
| 2498 | if (!$(this).hasClass("bulk")) { |
| 2499 | plugin.deleteSingle(); |
| 2500 | return; |
| 2501 | } |
| 2502 | plugin.deleteMultiple(); |
| 2503 | }); |
| 2504 | $(document).on("submit", NestedPages.selectors.bulkActionsForm, function(e) { |
| 2505 | plugin.confirmMultiple(e); |
| 2506 | }); |
| 2507 | }; |
| 2508 | plugin.confirmSingle = function(button) { |
| 2509 | plugin.deleteLink = $(button).attr("href"); |
| 2510 | $(NestedPages.selectors.linkDeleteConfirmationModalText).text(nestedpages.link_delete_confirmation_singular); |
| 2511 | $(NestedPages.selectors.linkDeleteConfirmationButton).text(nestedpages.delete).removeClass("bulk"); |
| 2512 | $(document).trigger("open-modal-manual", NestedPages.selectors.linkDeleteConfirmationModal); |
| 2513 | }; |
| 2514 | plugin.confirmMultiple = function(event) { |
| 2515 | if ($('select[name="np_bulk_action"]').val() !== "trash") return; |
| 2516 | var linkCount = $(NestedPages.selectors.bulkActionRedirectIds).val(); |
| 2517 | if (linkCount === "") return; |
| 2518 | event.preventDefault(); |
| 2519 | $(NestedPages.selectors.linkDeleteConfirmationModalText).text(nestedpages.link_delete_confirmation); |
| 2520 | $(NestedPages.selectors.linkDeleteConfirmationButton).text(nestedpages.trash_delete_links).addClass("bulk"); |
| 2521 | $(document).trigger("open-modal-manual", [NestedPages.selectors.linkDeleteConfirmationModal]); |
| 2522 | }; |
| 2523 | plugin.deleteMultiple = function() { |
| 2524 | $(NestedPages.selectors.bulkActionsForm)[0].submit(); |
| 2525 | }; |
| 2526 | plugin.deleteSingle = function() { |
| 2527 | window.location.replace(plugin.deleteLink); |
| 2528 | }; |
| 2529 | return plugin.bindEvents(); |
| 2530 | }; |
| 2531 | var NestedPages = NestedPages || {}; |
| 2532 | NestedPages.ManualSync = function() { |
| 2533 | var plugin = this; |
| 2534 | var $ = jQuery; |
| 2535 | plugin.activeBtn = ""; |
| 2536 | plugin.bindEvents = function() { |
| 2537 | $(document).on("click", NestedPages.selectors.manualMenuSync, function(e) { |
| 2538 | e.preventDefault(); |
| 2539 | plugin.activeBtn = $(this); |
| 2540 | plugin.syncMenu(); |
| 2541 | }); |
| 2542 | $(document).on("click", NestedPages.selectors.manualOrderSync, function(e) { |
| 2543 | e.preventDefault(); |
| 2544 | plugin.activeBtn = $(this); |
| 2545 | plugin.syncOrder(); |
| 2546 | }); |
| 2547 | }; |
| 2548 | plugin.syncMenu = function() { |
| 2549 | plugin.loading(true); |
| 2550 | $.ajax({ |
| 2551 | url: ajaxurl, |
| 2552 | type: "post", |
| 2553 | datatype: "json", |
| 2554 | data: { |
| 2555 | action: NestedPages.formActions.manualMenuSync, |
| 2556 | nonce: NestedPages.jsData.nonce, |
| 2557 | post_type: NestedPages.jsData.posttype, |
| 2558 | syncmenu: "sync" |
| 2559 | }, |
| 2560 | success: function(data) { |
| 2561 | if (data.status === "error") { |
| 2562 | $(NestedPages.selectors.errorDiv).text(data.message).show(); |
| 2563 | $(NestedPages.selectors.loadingIndicator).hide(); |
| 2564 | } else { |
| 2565 | plugin.loading(false); |
| 2566 | } |
| 2567 | } |
| 2568 | }); |
| 2569 | }; |
| 2570 | plugin.syncOrder = function() { |
| 2571 | plugin.loading(true); |
| 2572 | var nestingClass = new NestedPages.Nesting(); |
| 2573 | nestingClass.syncNesting(true, plugin.loading(false)); |
| 2574 | }; |
| 2575 | plugin.loading = function(loading) { |
| 2576 | if (loading) { |
| 2577 | $(plugin.activeBtn).addClass("disabled"); |
| 2578 | $(NestedPages.selectors.loadingIndicator).show(); |
| 2579 | return; |
| 2580 | } |
| 2581 | $(plugin.activeBtn).removeClass("disabled"); |
| 2582 | $(NestedPages.selectors.loadingIndicator).hide(); |
| 2583 | }; |
| 2584 | return plugin.bindEvents(); |
| 2585 | }; |
| 2586 | var NestedPages = NestedPages || {}; |
| 2587 | NestedPages.PostSearch = function() { |
| 2588 | var plugin = this; |
| 2589 | var $ = jQuery; |
| 2590 | plugin.selectors = { |
| 2591 | input: "data-nestedpages-post-search", |
| 2592 | form: "data-nestedpages-post-search-form", |
| 2593 | loadingIndicator: "data-nestedpages-loading", |
| 2594 | noResults: "data-nestedpages-no-results", |
| 2595 | results: "data-nestedpages-search-results" |
| 2596 | }; |
| 2597 | plugin.changed = false; |
| 2598 | plugin.activeInput = ""; |
| 2599 | plugin.results = ""; |
| 2600 | plugin.defaultResults = ""; |
| 2601 | plugin.postType = ""; |
| 2602 | plugin.activeForm = ""; |
| 2603 | plugin.bindEvents = function() { |
| 2604 | $("[" + plugin.selectors.input + "]").on("input", function() { |
| 2605 | plugin.activeInput = $(this); |
| 2606 | plugin.setOptions(); |
| 2607 | if (!plugin.changed) plugin.setDefaultResults(); |
| 2608 | if ($(this).val() === "") { |
| 2609 | $(plugin.activeForm).find("[" + plugin.selectors.noResults + "]").hide(); |
| 2610 | plugin.showDefaultResults(); |
| 2611 | return; |
| 2612 | } |
| 2613 | plugin.query(); |
| 2614 | }); |
| 2615 | }; |
| 2616 | plugin.setDefaultResults = function() { |
| 2617 | plugin.defaultResults = $(plugin.activeForm).find("[" + plugin.selectors.results + "]").html(); |
| 2618 | plugin.changed = true; |
| 2619 | }; |
| 2620 | plugin.showDefaultResults = function() { |
| 2621 | $(plugin.activeForm).find("[" + plugin.selectors.results + "]").html(plugin.defaultResults); |
| 2622 | }; |
| 2623 | plugin.setOptions = function() { |
| 2624 | plugin.postType = $(plugin.activeInput).attr(plugin.selectors.input); |
| 2625 | plugin.activeForm = $(plugin.activeInput).parents("[" + plugin.selectors.form + "]"); |
| 2626 | }; |
| 2627 | plugin.performSearch = function() { |
| 2628 | plugin.defaultResults = $(plugin.activeForm).parent("li").siblings(plugin.selectors.defaultResults); |
| 2629 | if ($(plugin.activeForm).val().length > 2) { |
| 2630 | $(plugin.defaultResults).hide(); |
| 2631 | plugin.toggleLoading(true); |
| 2632 | plugin.query(); |
| 2633 | return; |
| 2634 | } |
| 2635 | plugin.toggleLoading(false); |
| 2636 | $(plugin.defaultResults).show(); |
| 2637 | }; |
| 2638 | plugin.query = function() { |
| 2639 | $(plugin.activeForm).find("[" + plugin.selectors.results + "]").empty(); |
| 2640 | plugin.toggleLoading(true); |
| 2641 | $.ajax({ |
| 2642 | url: NestedPages.jsData.ajaxurl, |
| 2643 | type: "post", |
| 2644 | datatype: "json", |
| 2645 | data: { |
| 2646 | action: NestedPages.formActions.postSearch, |
| 2647 | nonce: NestedPages.jsData.nonce, |
| 2648 | term: $(plugin.activeInput).val(), |
| 2649 | postType: plugin.postType |
| 2650 | }, |
| 2651 | success: function(data) { |
| 2652 | if (data.results) { |
| 2653 | plugin.results = data.results; |
| 2654 | plugin.loadResults(); |
| 2655 | plugin.toggleLoading(false); |
| 2656 | } else { |
| 2657 | plugin.toggleLoading(false); |
| 2658 | $(plugin.activeForm).find("[" + plugin.selectors.noResults + "]").show(); |
| 2659 | } |
| 2660 | } |
| 2661 | }); |
| 2662 | }; |
| 2663 | plugin.loadResults = function() { |
| 2664 | var html = "<ul>"; |
| 2665 | $.each(plugin.results, function(i2, v) { |
| 2666 | html += '<li><a href="#" data-assignment-page-id="' + v.ID + '" data-assignment-page-title="' + v.post_title + '">' + v.post_title + "</a></li>"; |
| 2667 | }); |
| 2668 | html += "</ul>"; |
| 2669 | $(plugin.activeForm).find("[" + plugin.selectors.results + "]").html(html); |
| 2670 | plugin.toggleLoading(false); |
| 2671 | }; |
| 2672 | plugin.toggleLoading = function(loading) { |
| 2673 | var loadingIndicator = $(plugin.activeForm).find("[" + plugin.selectors.loadingIndicator + "]"); |
| 2674 | var noResults = $(plugin.activeForm).find("[" + plugin.selectors.noResults + "]"); |
| 2675 | $(noResults).hide(); |
| 2676 | if (loading) { |
| 2677 | $(loadingIndicator).show(); |
| 2678 | return; |
| 2679 | } |
| 2680 | $(loadingIndicator).hide(); |
| 2681 | }; |
| 2682 | return plugin.bindEvents(); |
| 2683 | }; |
| 2684 | var NestedPages = NestedPages || {}; |
| 2685 | NestedPages.MovePost = function() { |
| 2686 | var plugin = this; |
| 2687 | var $ = jQuery; |
| 2688 | plugin.formatter = new NestedPages.Formatter(); |
| 2689 | plugin.nesting = new NestedPages.Nesting(); |
| 2690 | plugin.activeRow; |
| 2691 | plugin.selectors = { |
| 2692 | moveToTop: "data-push-to-top", |
| 2693 | moveToBottom: "data-push-to-bottom" |
| 2694 | }; |
| 2695 | plugin.bindEvents = function() { |
| 2696 | $(document).ready(function() { |
| 2697 | plugin.disableTopOnFirst(); |
| 2698 | plugin.disableBottomOnLast(); |
| 2699 | }); |
| 2700 | $(document).on("click", "[" + plugin.selectors.moveToTop + "]", function(e) { |
| 2701 | e.preventDefault(); |
| 2702 | if ($(this).hasClass("disabled")) return; |
| 2703 | plugin.activeRow = $(this).closest(NestedPages.selectors.rows); |
| 2704 | plugin.moveToTop(); |
| 2705 | }); |
| 2706 | $(document).on("click", "[" + plugin.selectors.moveToBottom + "]", function(e) { |
| 2707 | e.preventDefault(); |
| 2708 | if ($(this).hasClass("disabled")) return; |
| 2709 | plugin.activeRow = $(this).closest(NestedPages.selectors.rows); |
| 2710 | plugin.moveToBottom(); |
| 2711 | }); |
| 2712 | }; |
| 2713 | plugin.moveToTop = function() { |
| 2714 | var parent = $(plugin.activeRow).parent(NestedPages.selectors.lists); |
| 2715 | var first = $(parent).find(NestedPages.selectors.rows).first(); |
| 2716 | $(plugin.activeRow).insertBefore(first); |
| 2717 | plugin.formatter.setBorders(); |
| 2718 | $(document).click(); |
| 2719 | plugin.nesting.syncNesting(); |
| 2720 | plugin.disableTopOnFirst(); |
| 2721 | plugin.disableBottomOnLast(); |
| 2722 | }; |
| 2723 | plugin.moveToBottom = function() { |
| 2724 | var parent = $(plugin.activeRow).parent(NestedPages.selectors.lists); |
| 2725 | var last = $(parent).children(NestedPages.selectors.rows).last(); |
| 2726 | $(plugin.activeRow).insertAfter(last); |
| 2727 | plugin.formatter.setBorders(); |
| 2728 | $(document).click(); |
| 2729 | plugin.nesting.syncNesting(); |
| 2730 | plugin.disableTopOnFirst(); |
| 2731 | plugin.disableBottomOnLast(); |
| 2732 | }; |
| 2733 | plugin.disableTopOnFirst = function() { |
| 2734 | var lists = $(NestedPages.selectors.lists); |
| 2735 | $.each(lists, function() { |
| 2736 | $(this).find("[" + plugin.selectors.moveToTop + "]").removeClass("disabled"); |
| 2737 | var first = $(this).find(NestedPages.selectors.rows).first(); |
| 2738 | $(first).find("[" + plugin.selectors.moveToTop + "]").addClass("disabled"); |
| 2739 | }); |
| 2740 | }; |
| 2741 | plugin.disableBottomOnLast = function() { |
| 2742 | var lists = $(NestedPages.selectors.lists); |
| 2743 | $.each(lists, function() { |
| 2744 | $(this).find("[" + plugin.selectors.moveToBottom + "]").removeClass("disabled"); |
| 2745 | var last = $(this).find(NestedPages.selectors.rows).last(); |
| 2746 | $(last).find("[" + plugin.selectors.moveToBottom + "]").addClass("disabled"); |
| 2747 | }); |
| 2748 | }; |
| 2749 | return plugin.bindEvents(); |
| 2750 | }; |
| 2751 | var NestedPages = NestedPages || {}; |
| 2752 | NestedPages.TrashWithChildren = function() { |
| 2753 | var plugin = this; |
| 2754 | var $ = jQuery; |
| 2755 | plugin.post_id = ""; |
| 2756 | plugin.bindEvents = function() { |
| 2757 | $(document).on("click", NestedPages.selectors.trashWithChildrenButton, function(e) { |
| 2758 | e.preventDefault(); |
| 2759 | plugin.post_id = $(this).attr("data-post-id"); |
| 2760 | plugin.trash(); |
| 2761 | }); |
| 2762 | }; |
| 2763 | plugin.trash = function() { |
| 2764 | $.ajax({ |
| 2765 | url: NestedPages.jsData.ajaxurl, |
| 2766 | type: "post", |
| 2767 | data: { |
| 2768 | action: NestedPages.formActions.trashWithChildren, |
| 2769 | nonce: NestedPages.jsData.nonce, |
| 2770 | post_id: plugin.post_id, |
| 2771 | screen: nestedpages.current_page |
| 2772 | }, |
| 2773 | success: function(data) { |
| 2774 | window.location.replace(data.redirect); |
| 2775 | }, |
| 2776 | error: function(data) { |
| 2777 | console.log(data); |
| 2778 | } |
| 2779 | }); |
| 2780 | }; |
| 2781 | return plugin.bindEvents(); |
| 2782 | }; |
| 2783 | var NestedPages = NestedPages || {}; |
| 2784 | NestedPages.Wpml = function() { |
| 2785 | var plugin = this; |
| 2786 | var $ = jQuery; |
| 2787 | plugin.button = null; |
| 2788 | plugin.postData = null; |
| 2789 | plugin.modal = null; |
| 2790 | plugin.parent_li = null; |
| 2791 | plugin.formatter = new NestedPages.Formatter(); |
| 2792 | plugin.selectors = { |
| 2793 | translationsBtn: "data-nestedpages-translations", |
| 2794 | modal: "data-np-wpml-translations-modal", |
| 2795 | title: "data-wmpl-translation-title", |
| 2796 | table: "data-np-wpml-translations-modal-table" |
| 2797 | }; |
| 2798 | plugin.bindEvents = function() { |
| 2799 | if (!nestedpages.wpml) return; |
| 2800 | $(document).on("click", "[" + plugin.selectors.translationsBtn + "]", function(e) { |
| 2801 | e.preventDefault(); |
| 2802 | plugin.createTranslationsModal($(this)); |
| 2803 | }); |
| 2804 | }; |
| 2805 | plugin.createTranslationsModal = function(button) { |
| 2806 | plugin.parent_li = $(button).parents(".action-buttons").closest(NestedPages.selectors.row).parent("li"); |
| 2807 | plugin.button = $(plugin.parent_li).find(NestedPages.selectors.quickEditOpen); |
| 2808 | plugin.postData = { |
| 2809 | id: $(plugin.button).attr("data-id"), |
| 2810 | title: $(plugin.button).attr("data-title"), |
| 2811 | slug: $(plugin.button).attr("data-slug") |
| 2812 | }; |
| 2813 | plugin.modal = $("[" + plugin.selectors.modal + "]").clone(); |
| 2814 | if ($(plugin.parent_li).children("ol").length > 0) { |
| 2815 | var child_ol = $(plugin.parent_li).children("ol"); |
| 2816 | $(plugin.modal).insertBefore(child_ol); |
| 2817 | } else { |
| 2818 | $(plugin.modal).appendTo(plugin.parent_li); |
| 2819 | } |
| 2820 | $(plugin.modal).find("[" + plugin.selectors.title + "]").text(plugin.postData.title); |
| 2821 | plugin.formatter.showQuickEdit(); |
| 2822 | $(plugin.modal).show(); |
| 2823 | plugin.getTranslationData(); |
| 2824 | }; |
| 2825 | plugin.getTranslationData = function() { |
| 2826 | $.ajax({ |
| 2827 | url: NestedPages.jsData.ajaxurl, |
| 2828 | type: "post", |
| 2829 | datatype: "json", |
| 2830 | data: { |
| 2831 | action: NestedPages.formActions.wpmlTranslations, |
| 2832 | post_id: plugin.postData.id, |
| 2833 | nonce: NestedPages.jsData.nonce |
| 2834 | }, |
| 2835 | success: function(data) { |
| 2836 | console.log(data); |
| 2837 | console.log(plugin.postData.id); |
| 2838 | if (data.status === "success") { |
| 2839 | plugin.populateModal(data.translations); |
| 2840 | } else { |
| 2841 | $(plugin.modal).find(NestedPages.selectors.quickEditErrorDiv).text(data.message).show(); |
| 2842 | plugin.toggleLoading(false); |
| 2843 | } |
| 2844 | } |
| 2845 | }); |
| 2846 | }; |
| 2847 | plugin.populateModal = function(translations) { |
| 2848 | var html = "<tbody>"; |
| 2849 | $.each(translations, function(i2, v) { |
| 2850 | var translation = translations[i2]; |
| 2851 | html += "<tr>"; |
| 2852 | html += '<td><img src="' + translation.country_flag_url + '" alt="' + translation.translated_name + '" /> ' + translation.translated_name + "</td>"; |
| 2853 | html += "<td>"; |
| 2854 | if (translation.has_translation && translation.edit_link) { |
| 2855 | html += '<a href="' + translation.edit_link + '">' + translation.translation.post_title + " (" + nestedpages.edit + ")</a>"; |
| 2856 | } else { |
| 2857 | html += '<a href="' + translation.add_link + '" class="np-btn">+ ' + nestedpages.add_translation + "</a>"; |
| 2858 | } |
| 2859 | html += "</td>"; |
| 2860 | html += "</tr>"; |
| 2861 | }); |
| 2862 | html += "</tbody>"; |
| 2863 | $(plugin.modal).find("[" + plugin.selectors.table + "]").html(html); |
| 2864 | plugin.toggleLoading(false); |
| 2865 | }; |
| 2866 | plugin.toggleLoading = function(loading) { |
| 2867 | if (loading) { |
| 2868 | $(plugin.modal).addClass("loading"); |
| 2869 | return; |
| 2870 | } |
| 2871 | $(plugin.modal).removeClass("loading"); |
| 2872 | }; |
| 2873 | return plugin.bindEvents(); |
| 2874 | }; |
| 2875 |