custom.js
1143 lines
| 1 | var defaultFolderHtml; |
| 2 | var folderID = 0; |
| 3 | var fileAddUpdateStatus = "add"; |
| 4 | var fileFolderID = 0; |
| 5 | var folderNameDynamic = ''; |
| 6 | var totalFolders = -1; |
| 7 | var isKeyActive = 0; |
| 8 | var folderLimitation = 10; |
| 9 | |
| 10 | |
| 11 | var listFolderString = "<li class='grid-view' data-id='__folder_id__' id='folder___folder_id__'>" + |
| 12 | "<div class='folder-item is-folder' data-id='__folder_id__'>" + |
| 13 | "<a title='__folder_name__' id='folder_view___folder_id__'" + |
| 14 | "class='folder-view __append_class__'" + |
| 15 | "data-id='__folder_id__'>" + |
| 16 | "<span class='folder item-name'><span id='wcp_folder_text___folder_id__'" + |
| 17 | "class='folder-title'>__folder_name__</span></span>" + |
| 18 | "</a>" + |
| 19 | "</div>" + |
| 20 | "</li>"; |
| 21 | |
| 22 | function addFolder() { |
| 23 | if(isKeyActive == 0 && totalFolders >= folderLimitation) { |
| 24 | Swal.fire({ |
| 25 | title: "You've reached the "+totalFolders+" folder limitation!", |
| 26 | text: "Unlock unlimited amount of folders by upgrading to one of our pro plans.", |
| 27 | type: 'warning', |
| 28 | showCancelButton: true, |
| 29 | confirmButtonColor: '#3085d6', |
| 30 | cancelButtonColor: '#d33', |
| 31 | confirmButtonText: 'See Pro Plans' |
| 32 | }).then((result) => { |
| 33 | if (result.value) { |
| 34 | window.location = wcp_settings.register_url; |
| 35 | } |
| 36 | }); |
| 37 | return false; |
| 38 | } |
| 39 | folderOrder = jQuery("#space_"+fileFolderID+" > li").length+1; |
| 40 | ajaxURL = wcp_settings.ajax_url+"?parent_id=" + fileFolderID + "&type=" + wcp_settings.post_type + "&action=wcp_add_new_folder&nonce=" + wcp_settings.nonce + "&term_id=" + fileFolderID + "&order=" + folderOrder+"&name="; |
| 41 | Swal({ |
| 42 | title: 'Add Folder', |
| 43 | input: 'text', |
| 44 | inputAttributes: { |
| 45 | autocapitalize: 'off', |
| 46 | placeholder: "Folder name" |
| 47 | }, |
| 48 | showCancelButton: true, |
| 49 | confirmButtonText: 'Submit', |
| 50 | showLoaderOnConfirm: true, |
| 51 | reverseButtons: true, |
| 52 | preConfirm: (folderName) => { |
| 53 | if(folderName == "") { |
| 54 | swal.showValidationError( |
| 55 | 'Please enter folder name' |
| 56 | ) |
| 57 | return false; |
| 58 | } |
| 59 | return fetch(ajaxURL+folderName) |
| 60 | .then(response => { |
| 61 | if (!response.ok) { |
| 62 | throw new Error(response.statusText); |
| 63 | } |
| 64 | return response.json(); |
| 65 | }).catch(error => { |
| 66 | Swal.showValidationMessage( |
| 67 | "Request failed: "+error |
| 68 | ) |
| 69 | }); |
| 70 | }, |
| 71 | allowOutsideClick: () => !Swal.isLoading() |
| 72 | }).then((result) => { |
| 73 | if(result.value.error == 1) { |
| 74 | Swal({ |
| 75 | type: 'error', |
| 76 | title: 'Oops...', |
| 77 | text: result.value.message |
| 78 | }); |
| 79 | } else if(result.value.status == 1) { |
| 80 | jQuery("#space_"+result.value.parent_id).append(result.value.term_data); |
| 81 | jQuery("#wcp_folder_"+result.value.parent_id).addClass("active has-sub-tree"); |
| 82 | isKeyActive = parseInt(result.value.is_key_active); |
| 83 | totalFolders = parseInt(result.value.folders); |
| 84 | jQuery("#current-folder").text(totalFolders); |
| 85 | if(totalFolders > folderLimitation) { |
| 86 | folderLimitation = totalFolders; |
| 87 | } |
| 88 | jQuery("#total-folder").text(folderLimitation); |
| 89 | checkForExpandCollapse(); |
| 90 | add_menu_to_list(); |
| 91 | } |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | function updateFolder() { |
| 97 | folderName = jQuery.trim(jQuery("#wcp_folder_"+fileFolderID+" > h3").text()); |
| 98 | parentID = jQuery("#wcp_folder_"+fileFolderID).closest("li.route").data("folder-id"); |
| 99 | if(parentID == undefined) { |
| 100 | parentID = 0; |
| 101 | } |
| 102 | nonce = jQuery.trim(jQuery("#wcp_folder_"+fileFolderID).data("rename")); |
| 103 | ajaxURL = wcp_settings.ajax_url+"?parent_id=" + parentID + "&nonce=" + nonce + "&type=" + wcp_settings.post_type + "&action=wcp_update_folder&term_id=" + fileFolderID + "&name="; |
| 104 | Swal({ |
| 105 | title: 'Update Folder', |
| 106 | input: 'text', |
| 107 | inputValue: folderName, |
| 108 | inputAttributes: { |
| 109 | autocapitalize: 'off', |
| 110 | placeholder: "Folder name", |
| 111 | value: folderName |
| 112 | }, |
| 113 | showCancelButton: true, |
| 114 | confirmButtonText: 'Submit', |
| 115 | showLoaderOnConfirm: true, |
| 116 | reverseButtons: true, |
| 117 | preConfirm: (folderName) => { |
| 118 | if(folderName == "") { |
| 119 | swal.showValidationError( |
| 120 | 'Please enter folder name' |
| 121 | ) |
| 122 | return false; |
| 123 | } |
| 124 | return fetch(ajaxURL+folderName) |
| 125 | .then(response => { |
| 126 | if (!response.ok) { |
| 127 | throw new Error(response.statusText); |
| 128 | } |
| 129 | return response.json(); |
| 130 | }).catch(error => { |
| 131 | Swal.showValidationMessage( |
| 132 | "Request failed: "+error |
| 133 | ) |
| 134 | }); |
| 135 | }, |
| 136 | allowOutsideClick: () => !Swal.isLoading() |
| 137 | }).then((result) => { |
| 138 | if(result.value.error == 1) { |
| 139 | Swal({ |
| 140 | type: 'error', |
| 141 | title: 'Oops...', |
| 142 | text: result.value.message |
| 143 | }); |
| 144 | } else if(result.value.status == 1) { |
| 145 | jQuery("#wcp_folder_"+result.value.id+" > h3 > .title-text").text(result.value.term_title); |
| 146 | jQuery("#wcp_folder_"+result.value.id+" > h3").attr("title",result.value.term_title); |
| 147 | add_menu_to_list(); |
| 148 | } |
| 149 | }); |
| 150 | } |
| 151 | |
| 152 | function add_menu_to_list() { |
| 153 | folderId = 0; |
| 154 | if(jQuery(".active-term").length) { |
| 155 | folderId = jQuery(".active-term").data("folder-id"); |
| 156 | } |
| 157 | jQuery(".tree-structure ul").html(""); |
| 158 | jQuery("#space_"+folderId).children().each(function(){ |
| 159 | fID = jQuery(this).data("folder-id"); |
| 160 | fName = jQuery(this).find("h3.title:first .title-text").text() |
| 161 | liHtml = listFolderString.replace(/__folder_id__/g,fID); |
| 162 | liHtml = liHtml.replace(/__folder_name__/g,fName); |
| 163 | selectedClass = jQuery(this).hasClass("is-high")?"is-high":""; |
| 164 | liHtml = liHtml.replace(/__append_class__/g,selectedClass); |
| 165 | jQuery(".tree-structure ul").append(liHtml); |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | jQuery(document).ready(function(){ |
| 170 | |
| 171 | wcp_settings.folder_width = parseInt(wcp_settings.folder_width); |
| 172 | |
| 173 | if(wcp_settings.can_manage_folder == "0") { |
| 174 | jQuery(".wcp-custom-form a:not(.pink)").addClass("button-disabled"); |
| 175 | } |
| 176 | |
| 177 | isKeyActive = parseInt(wcp_settings.is_key_active); |
| 178 | totalFolders = parseInt(wcp_settings.folders); |
| 179 | |
| 180 | if(wcp_settings.post_type == "attachment") { |
| 181 | jQuery(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 182 | |
| 183 | add_menu_to_list(); |
| 184 | } |
| 185 | |
| 186 | calcWidth(jQuery('#title_0')); |
| 187 | |
| 188 | jQuery("#cancel-button").click(function(){ |
| 189 | jQuery(".wcp-form-data").hide(); |
| 190 | }); |
| 191 | |
| 192 | |
| 193 | jQuery(document).on("click", "h3.title", function(e) { |
| 194 | e.stopPropagation(); |
| 195 | window.location = wcp_settings.page_url+jQuery(this).closest("li.route").data("slug"); |
| 196 | }); |
| 197 | |
| 198 | jQuery(".tree-structure a").livequery(function(){ |
| 199 | jQuery(this).click(function(){ |
| 200 | fID = jQuery(this).data("id"); |
| 201 | jQuery("#title_"+fID).trigger("click"); |
| 202 | }); |
| 203 | }); |
| 204 | |
| 205 | jQuery(".wcp-parent > span").click(function(){ |
| 206 | window.location = wcp_settings.page_url |
| 207 | }); |
| 208 | jQuery("h3.title").livequery(function () { |
| 209 | jQuery(this).droppable({ |
| 210 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 211 | hoverClass: 'wcp-drop-hover', |
| 212 | classes: { |
| 213 | "ui-droppable-active": "ui-state-highlight" |
| 214 | }, |
| 215 | drop: function (event, ui) { |
| 216 | folderID = jQuery(this).closest("li.route").data('folder-id'); |
| 217 | if (ui.draggable.hasClass('wcp-move-multiple')) { |
| 218 | if (jQuery(".wp-list-table input:checked").length) { |
| 219 | chkStr = ""; |
| 220 | jQuery(".wp-list-table input:checked").each(function () { |
| 221 | chkStr += jQuery(this).val() + ","; |
| 222 | }); |
| 223 | nonce = jQuery.trim(jQuery("#wcp_folder_" + folderID).data("nonce")); |
| 224 | jQuery.ajax({ |
| 225 | url: wcp_settings.ajax_url, |
| 226 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 227 | method: 'post', |
| 228 | success: function (res) { |
| 229 | res = jQuery.parseJSON(res); |
| 230 | if (res.status == "1") { |
| 231 | window.location.reload(); |
| 232 | } else { |
| 233 | Swal.fire( |
| 234 | '', |
| 235 | res.message, |
| 236 | 'error' |
| 237 | ); |
| 238 | } |
| 239 | } |
| 240 | }); |
| 241 | } |
| 242 | } else if (ui.draggable.hasClass('wcp-move-file')) { |
| 243 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 244 | nonce = jQuery.trim(jQuery("#wcp_folder_" + folderID).data("nonce")); |
| 245 | jQuery.ajax({ |
| 246 | url: wcp_settings.ajax_url, |
| 247 | data: "post_id=" + postID + "&type=" + wcp_settings.post_type + "&action=wcp_change_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 248 | method: 'post', |
| 249 | success: function (res) { |
| 250 | res = jQuery.parseJSON(res); |
| 251 | if (res.status == "1") { |
| 252 | window.location.reload(); |
| 253 | } else { |
| 254 | Swal.fire( |
| 255 | '', |
| 256 | res.message, |
| 257 | 'error' |
| 258 | ); |
| 259 | } |
| 260 | } |
| 261 | }); |
| 262 | } else if (ui.draggable.hasClass('attachment')) { |
| 263 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 264 | nonce = jQuery.trim(jQuery("#wcp_folder_" + folderID).data("nonce")); |
| 265 | if (jQuery(".attachments-browser li.attachment.selected").length > 1) { |
| 266 | chkStr = ""; |
| 267 | jQuery(".attachments-browser li.attachment.selected").each(function () { |
| 268 | chkStr += jQuery(this).data("id") + ","; |
| 269 | }); |
| 270 | } |
| 271 | jQuery.ajax({ |
| 272 | url: wcp_settings.ajax_url, |
| 273 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 274 | method: 'post', |
| 275 | success: function (res) { |
| 276 | window.location.reload(); |
| 277 | } |
| 278 | }); |
| 279 | } |
| 280 | } |
| 281 | }); |
| 282 | }); |
| 283 | |
| 284 | jQuery(".attachments-browser li.attachment").livequery(function () { |
| 285 | jQuery(this).draggable({ |
| 286 | revert: "invalid", |
| 287 | containment: "document", |
| 288 | helper: function (event, ui) { |
| 289 | jQuery(".selected-items").remove(); |
| 290 | selectedItems = jQuery(".attachments-browser li.attachment.selected").length; |
| 291 | selectedItems = (selectedItems == 0 || selectedItems == 1) ? "1 Item" : selectedItems + " Items"; |
| 292 | return jQuery("<div class='selected-items'><span class='total-post-count'>" + selectedItems + " Selected</span></div>"); |
| 293 | }, |
| 294 | start: function (event, ui) { |
| 295 | |
| 296 | }, |
| 297 | cursor: "move", |
| 298 | cursorAt: { |
| 299 | left: 0, |
| 300 | top: 0 |
| 301 | }, |
| 302 | stop: function (event, ui) { |
| 303 | jQuery(".selected-items").remove(); |
| 304 | } |
| 305 | }); |
| 306 | jQuery(this).draggable("disable"); |
| 307 | }); |
| 308 | |
| 309 | jQuery(".media-button").livequery(function () { |
| 310 | jQuery(this).click(function () { |
| 311 | if (jQuery(".delete-selected-button").hasClass("hidden")) { |
| 312 | jQuery(".attachments-browser li.attachment").draggable("disable"); |
| 313 | } else { |
| 314 | jQuery(".attachments-browser li.attachment").draggable("enable"); |
| 315 | } |
| 316 | }); |
| 317 | }); |
| 318 | |
| 319 | jQuery(".header-posts").click(function(){ |
| 320 | window.location = wcp_settings.page_url; |
| 321 | }); |
| 322 | |
| 323 | jQuery(".un-categorised-items").click(function(){ |
| 324 | window.location = wcp_settings.page_url+"-1"; |
| 325 | }); |
| 326 | |
| 327 | jQuery(".un-categorised-items").livequery(function () { |
| 328 | jQuery(this).droppable({ |
| 329 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 330 | hoverClass: 'wcp-hover-list', |
| 331 | classes: { |
| 332 | "ui-droppable-active": "ui-state-highlight" |
| 333 | }, |
| 334 | drop: function (event, ui) { |
| 335 | folderID = -1; |
| 336 | nonce = wcp_settings.nonce; |
| 337 | if (ui.draggable.hasClass('wcp-move-multiple')) { |
| 338 | if (jQuery(".wp-list-table input:checked").length) { |
| 339 | chkStr = ""; |
| 340 | jQuery(".wp-list-table input:checked").each(function () { |
| 341 | chkStr += jQuery(this).val() + ","; |
| 342 | }); |
| 343 | jQuery.ajax({ |
| 344 | url: wcp_settings.ajax_url, |
| 345 | data: "post_id=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 346 | method: 'post', |
| 347 | success: function (res) { |
| 348 | window.location.reload(); |
| 349 | } |
| 350 | }); |
| 351 | } |
| 352 | } else if (ui.draggable.hasClass('wcp-move-file')) { |
| 353 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 354 | jQuery.ajax({ |
| 355 | url: wcp_settings.ajax_url, |
| 356 | data: "post_id=" + postID + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 357 | method: 'post', |
| 358 | success: function (res) { |
| 359 | window.location.reload(); |
| 360 | } |
| 361 | }); |
| 362 | } else if (ui.draggable.hasClass('attachment')) { |
| 363 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 364 | if (jQuery(".attachments-browser li.attachment.selected").length > 1) { |
| 365 | chkStr = ""; |
| 366 | jQuery(".attachments-browser li.attachment.selected").each(function () { |
| 367 | chkStr += jQuery(this).data("id") + ","; |
| 368 | }); |
| 369 | } |
| 370 | jQuery.ajax({ |
| 371 | url: wcp_settings.ajax_url, |
| 372 | data: "post_id=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 373 | method: 'post', |
| 374 | success: function (res) { |
| 375 | window.location.reload(); |
| 376 | } |
| 377 | }); |
| 378 | } |
| 379 | } |
| 380 | }); |
| 381 | }); |
| 382 | |
| 383 | |
| 384 | jQuery(".wcp-hide-show-buttons .toggle-buttons").click(function(){ |
| 385 | var folderStatus = "show"; |
| 386 | if(jQuery(this).hasClass("hide-folders")) { |
| 387 | folderStatus = "hide"; |
| 388 | } |
| 389 | jQuery(".wcp-hide-show-buttons .toggle-buttons").toggleClass("active"); |
| 390 | nonce = wcp_settings.nonce; |
| 391 | if(folderStatus == "show") { |
| 392 | jQuery("#wcp-content").addClass("no-transition"); |
| 393 | jQuery("#wcp-content").removeClass("hide-folders-area"); |
| 394 | if(wcp_settings.isRTL == "1") { |
| 395 | jQuery("#wpcontent").css("padding-right", (wcp_settings.folder_width + 20) + "px"); |
| 396 | jQuery("#wpcontent").css("padding-left", "0px"); |
| 397 | } else { |
| 398 | jQuery("#wpcontent").css("padding-left", (wcp_settings.folder_width + 20) + "px"); |
| 399 | } |
| 400 | setTimeout(function(){ |
| 401 | jQuery("#wcp-content").removeClass("no-transition"); |
| 402 | }, 250); |
| 403 | } else { |
| 404 | jQuery("#wcp-content").addClass("hide-folders-area"); |
| 405 | if(wcp_settings.isRTL == "1") { |
| 406 | jQuery("#wpcontent").css("padding-right", "20px"); |
| 407 | jQuery("#wpcontent").css("padding-left", "0px"); |
| 408 | } else { |
| 409 | jQuery("#wpcontent").css("padding-left", "20px"); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | jQuery.ajax({ |
| 414 | url: wcp_settings.ajax_url, |
| 415 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_folder_display_status&status=" + folderStatus +"&nonce="+nonce, |
| 416 | method: 'post', |
| 417 | success: function (res) { |
| 418 | setStickyHeaderForMedia(); |
| 419 | } |
| 420 | }); |
| 421 | }); |
| 422 | |
| 423 | //if(wcp_settings.can_manage_folder == "1") { |
| 424 | jQuery(".tree-structure .folder-item").livequery(function () { |
| 425 | jQuery(this).droppable({ |
| 426 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 427 | hoverClass: 'wcp-drop-hover-list', |
| 428 | classes: { |
| 429 | "ui-droppable-active": "ui-state-highlight" |
| 430 | }, |
| 431 | drop: function (event, ui) { |
| 432 | folderID = jQuery(this).data('id'); |
| 433 | if (ui.draggable.hasClass('wcp-move-multiple')) { |
| 434 | nonce = jQuery.trim(jQuery("#wcp_folder_" + folderID).data("nonce")); |
| 435 | if (jQuery(".wp-list-table input:checked").length) { |
| 436 | chkStr = ""; |
| 437 | jQuery(".wp-list-table input:checked").each(function () { |
| 438 | chkStr += jQuery(this).val() + ","; |
| 439 | }); |
| 440 | jQuery.ajax({ |
| 441 | url: wcp_settings.ajax_url, |
| 442 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 443 | method: 'post', |
| 444 | success: function (res) { |
| 445 | window.location.reload(); |
| 446 | } |
| 447 | }); |
| 448 | } |
| 449 | } else if (ui.draggable.hasClass('wcp-move-file')) { |
| 450 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 451 | nonce = jQuery.trim(jQuery("#wcp_folder_" + folderID).data("nonce")); |
| 452 | jQuery.ajax({ |
| 453 | url: wcp_settings.ajax_url, |
| 454 | data: "post_id=" + postID + "&type=" + wcp_settings.post_type + "&action=wcp_change_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 455 | method: 'post', |
| 456 | success: function (res) { |
| 457 | window.location.reload(); |
| 458 | } |
| 459 | }); |
| 460 | } else if (ui.draggable.hasClass('attachment')) { |
| 461 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 462 | nonce = jQuery.trim(jQuery("#wcp_folder_" + folderID).data("nonce")); |
| 463 | if (jQuery(".attachments-browser li.attachment.selected").length > 1) { |
| 464 | chkStr = ""; |
| 465 | jQuery(".attachments-browser li.attachment.selected").each(function () { |
| 466 | chkStr += jQuery(this).data("id") + ","; |
| 467 | }); |
| 468 | } |
| 469 | jQuery.ajax({ |
| 470 | url: wcp_settings.ajax_url, |
| 471 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce=" + nonce, |
| 472 | method: 'post', |
| 473 | success: function (res) { |
| 474 | window.location.reload(); |
| 475 | } |
| 476 | }); |
| 477 | } |
| 478 | } |
| 479 | }); |
| 480 | }); |
| 481 | //} |
| 482 | |
| 483 | jQuery("#expand-collapse-list").click(function(e){ |
| 484 | e.stopPropagation(); |
| 485 | statusType = 0; |
| 486 | if(jQuery(this).hasClass("all-open")) { |
| 487 | jQuery(this).removeClass("all-open"); |
| 488 | jQuery(".has-sub-tree").removeClass("active"); |
| 489 | statusType = 0; |
| 490 | } else { |
| 491 | jQuery(this).addClass("all-open"); |
| 492 | statusType = 1; |
| 493 | jQuery(".has-sub-tree").addClass("active"); |
| 494 | } |
| 495 | folderIDs = ""; |
| 496 | jQuery(".has-sub-tree").each(function(){ |
| 497 | folderIDs += jQuery(this).data("folder-id")+","; |
| 498 | }); |
| 499 | if(folderIDs != "") { |
| 500 | jQuery(".form-loader-count").css("width","100%"); |
| 501 | nonce = wcp_settings.nonce; |
| 502 | jQuery.ajax({ |
| 503 | url: wcp_settings.ajax_url, |
| 504 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_all_status&status=" + statusType + "&folders="+folderIDs+"&nonce="+nonce, |
| 505 | method: 'post', |
| 506 | success: function (res) { |
| 507 | jQuery(".form-loader-count").css("width","0"); |
| 508 | add_menu_to_list(); |
| 509 | res = jQuery.parseJSON(res); |
| 510 | if(res.status == "0") { |
| 511 | Swal.fire( |
| 512 | '', |
| 513 | res.message, |
| 514 | 'error' |
| 515 | ); |
| 516 | window.location.reload(true); |
| 517 | } |
| 518 | } |
| 519 | }); |
| 520 | } |
| 521 | }); |
| 522 | |
| 523 | resizeDirection = (wcp_settings.isRTL == "1" || wcp_settings.isRTL == 1)?"w":"e"; |
| 524 | jQuery(".wcp-content").resizable( { |
| 525 | resizeHeight: false, |
| 526 | handles: resizeDirection, |
| 527 | minWidth: 305, |
| 528 | maxWidth: 500, |
| 529 | resize: function( e, ui ) { |
| 530 | if(wcp_settings.isRTL == "1") { |
| 531 | jQuery("#wpcontent").css("padding-right", (ui.size.width + 20) + "px"); |
| 532 | jQuery("#wpcontent").css("padding-left", "0px"); |
| 533 | } else { |
| 534 | jQuery("#wpcontent").css("padding-left", (ui.size.width + 20) + "px"); |
| 535 | } |
| 536 | newWidth = ui.size.width - 40; |
| 537 | cssString = ""; |
| 538 | classString = ""; |
| 539 | for(i=0; i<=15; i++) { |
| 540 | classString += " .space > .route >"; |
| 541 | currentWidth = newWidth - (13+(20*i)); |
| 542 | cssString += "#custom-menu > "+classString+" .title { width: "+currentWidth+"px !important; } "; |
| 543 | setStickyHeaderForMedia(); |
| 544 | } |
| 545 | jQuery("#wcp-custom-style").html("<style>"+cssString+"</style>"); |
| 546 | }, |
| 547 | stop: function( e, ui ) { |
| 548 | nonce = wcp_settings.nonce; |
| 549 | wcp_settings.folder_width = ui.size.width; |
| 550 | jQuery.ajax({ |
| 551 | url: wcp_settings.ajax_url, |
| 552 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_post_width&width=" + ui.size.width+"&nonce="+nonce, |
| 553 | method: 'post', |
| 554 | success: function (res) { |
| 555 | setStickyHeaderForMedia(); |
| 556 | } |
| 557 | }); |
| 558 | } |
| 559 | }); |
| 560 | |
| 561 | jQuery(".wcp-move-file").draggable({ |
| 562 | /*cancel: "a.ui-icon",*/ |
| 563 | revert: "invalid", |
| 564 | containment: "document", |
| 565 | helper: "clone", |
| 566 | cursor: "move", |
| 567 | start: function( event, ui){ |
| 568 | jQuery(this).closest("td").addClass("wcp-draggable"); |
| 569 | }, |
| 570 | stop: function( event, ui ) { |
| 571 | jQuery(this).closest("td").removeClass("wcp-draggable"); |
| 572 | } |
| 573 | }); |
| 574 | |
| 575 | jQuery(".wcp-move-multiple").draggable({ |
| 576 | /*cancel: "a.ui-icon",*/ |
| 577 | revert: "invalid", |
| 578 | containment: "document", |
| 579 | helper: "clone", |
| 580 | cursor: "move" |
| 581 | }); |
| 582 | |
| 583 | jQuery("h3.title").livequery(function(){ |
| 584 | jQuery(this).on("contextmenu",function(e) { |
| 585 | e.preventDefault(); |
| 586 | if(wcp_settings.can_manage_folder == 0) { |
| 587 | return; |
| 588 | } |
| 589 | isHigh = jQuery(this).closest("li.route").hasClass("is-high"); |
| 590 | jQuery(".dynamic-menu").remove(); |
| 591 | jQuery(".active-menu").removeClass("active-menu"); |
| 592 | menuHtml = "<div class='dynamic-menu'><ul>" + |
| 593 | "<li class='new-folder'><a href='javascript:;'><span class='folder-icon-create_new_folder'></span> New Folder</a></li>" + |
| 594 | "<li class='rename-folder'><a href='javascript:;'><span class='folder-icon-border_color'><span class='path1'></span><span class='path2'></span></span> Rename</a></li>" + |
| 595 | "<li class='mark-folder'><a href='javascript:;'><span class='folder-icon-star_rate'></span>" + ((isHigh) ? " Remove Star" : "Add a Star") + "</a></li>" + |
| 596 | "<li class='remove-folder'><a href='javascript:;'><span class='folder-icon-delete'></span> Delete</a></li>" + |
| 597 | "</ul></div>"; |
| 598 | jQuery(this).after(menuHtml); |
| 599 | jQuery(this).parents("li.route").addClass("active-menu"); |
| 600 | return false; |
| 601 | }); |
| 602 | }); |
| 603 | |
| 604 | jQuery("body").click(function(){ |
| 605 | jQuery(".dynamic-menu").remove(); |
| 606 | jQuery(".active-menu").removeClass("active-menu"); |
| 607 | }); |
| 608 | |
| 609 | jQuery(".dynamic-menu").livequery(function(){ |
| 610 | jQuery(this).click(function(e){ |
| 611 | e.stopPropagation(); |
| 612 | }); |
| 613 | }); |
| 614 | |
| 615 | jQuery(".rename-folder").livequery(function(){ |
| 616 | jQuery(this).click(function(e){ |
| 617 | e.stopPropagation(); |
| 618 | fileFolderID = jQuery(this).closest("li.route").data("folder-id"); |
| 619 | updateFolder(); |
| 620 | add_menu_to_list(); |
| 621 | }); |
| 622 | }); |
| 623 | |
| 624 | jQuery(".mark-folder").livequery(function(){ |
| 625 | jQuery(this).click(function(e){ |
| 626 | e.stopPropagation(); |
| 627 | folderID = jQuery(this).closest("li.route").data("folder-id"); |
| 628 | nonce = jQuery.trim(jQuery("#wcp_folder_"+folderID).data("star")); |
| 629 | jQuery(".form-loader-count").css("width","100%"); |
| 630 | jQuery(".dynamic-menu").remove(); |
| 631 | jQuery(".active-menu").removeClass("active-menu"); |
| 632 | jQuery.ajax({ |
| 633 | url: wcp_settings.ajax_url, |
| 634 | data: "term_id=" + folderID + "&type=" + wcp_settings.post_type + "&action=wcp_mark_un_mark_folder&nonce="+nonce, |
| 635 | method: 'post', |
| 636 | cache: false, |
| 637 | success: function (res) { |
| 638 | res = jQuery.parseJSON(res); |
| 639 | jQuery(".form-loader-count").css("width","0%"); |
| 640 | if (res.status == '1') { |
| 641 | if(res.marked == '1') { |
| 642 | jQuery("#wcp_folder_"+res.id).addClass("is-high"); |
| 643 | } else { |
| 644 | jQuery("#wcp_folder_"+res.id).removeClass("is-high"); |
| 645 | } |
| 646 | add_menu_to_list(); |
| 647 | } else { |
| 648 | Swal.fire( |
| 649 | '', |
| 650 | res.message, |
| 651 | 'error' |
| 652 | ); |
| 653 | } |
| 654 | } |
| 655 | }); |
| 656 | }); |
| 657 | }); |
| 658 | |
| 659 | /* Add new folder */ |
| 660 | jQuery(".new-folder").livequery(function(){ |
| 661 | jQuery(this).click(function(e) { |
| 662 | e.stopPropagation(); |
| 663 | jQuery(".active-menu").removeClass("active-menu"); |
| 664 | fileFolderID = jQuery(this).closest("li.route").data("folder-id"); |
| 665 | jQuery(".dynamic-menu").remove(); |
| 666 | jQuery(".active-menu").removeClass("active-menu"); |
| 667 | addFolder(); |
| 668 | add_menu_to_list(); |
| 669 | }); |
| 670 | }); |
| 671 | |
| 672 | jQuery(".cancel-button").livequery(function(){ |
| 673 | jQuery(this).click(function(e){ |
| 674 | e.stopPropagation(); |
| 675 | jQuery(".form-li").remove(); |
| 676 | }); |
| 677 | }); |
| 678 | |
| 679 | |
| 680 | |
| 681 | jQuery("#add-new-folder").livequery(function(){ |
| 682 | jQuery(this).click(function() { |
| 683 | if(jQuery("#custom-menu li.active-item").length) { |
| 684 | fileFolderID = jQuery("#custom-menu li.active-item").data("folder-id"); |
| 685 | } else { |
| 686 | fileFolderID = 0; |
| 687 | } |
| 688 | addFolder(); |
| 689 | add_menu_to_list(); |
| 690 | }); |
| 691 | }); |
| 692 | |
| 693 | jQuery("#inline-update").click(function(){ |
| 694 | if(jQuery("#custom-menu li.active-item").length) { |
| 695 | fileFolderID = jQuery("#custom-menu li.active-item").data("folder-id"); |
| 696 | updateFolder(); |
| 697 | add_menu_to_list(); |
| 698 | } |
| 699 | }); |
| 700 | |
| 701 | jQuery("#inline-remove").click(function(){ |
| 702 | if(jQuery("#custom-menu li.active-item").length) { |
| 703 | fileFolderID = jQuery("#custom-menu li.active-item").data("folder-id"); |
| 704 | jQuery(".dynamic-menu").remove(); |
| 705 | jQuery(".active-menu").removeClass("active-menu"); |
| 706 | nonce = jQuery.trim(jQuery("#wcp_folder_"+fileFolderID).data("delete")); |
| 707 | Swal.fire({ |
| 708 | url: wcp_settings.ajax_url, |
| 709 | title: 'Are you sure you want to delete the selected folder?', |
| 710 | text: 'Items in the folder will not be deleted.', |
| 711 | type: 'warning', |
| 712 | showCancelButton: true, |
| 713 | confirmButtonText: 'Yes, delete it!', |
| 714 | cancelButtonText: 'No, keep it', |
| 715 | }).then((result) => { |
| 716 | if (result.value) { |
| 717 | Swal({ |
| 718 | title: 'Please wait..', |
| 719 | imageUrl: wcp_settings.ajax_image, |
| 720 | imageAlt: 'The uploaded picture', |
| 721 | showConfirmButton: false |
| 722 | }); |
| 723 | jQuery.ajax({ |
| 724 | url: wcp_settings.ajax_url, |
| 725 | data: "type=" + wcp_settings.post_type + "&action=wcp_remove_folder&term_id=" + fileFolderID+"&nonce="+nonce, |
| 726 | method: 'post', |
| 727 | success: function (res) { |
| 728 | res = jQuery.parseJSON(res); |
| 729 | if (res.status == '1') { |
| 730 | Swal.fire( |
| 731 | 'Deleted!', |
| 732 | 'Your folder has been deleted.', |
| 733 | 'success' |
| 734 | ); |
| 735 | jQuery("#wcp_folder_"+fileFolderID).remove(); |
| 736 | jQuery("#folder_"+fileFolderID).remove(); |
| 737 | isKeyActive = parseInt(res.is_key_active); |
| 738 | totalFolders = parseInt(res.folders); |
| 739 | jQuery("#current-folder").text(totalFolders); |
| 740 | if(totalFolders > folderLimitation) { |
| 741 | folderLimitation = totalFolders; |
| 742 | } |
| 743 | jQuery("#total-folder").text(folderLimitation); |
| 744 | add_menu_to_list(); |
| 745 | } else { |
| 746 | Swal.fire( |
| 747 | '', |
| 748 | res.message, |
| 749 | 'error' |
| 750 | ); |
| 751 | } |
| 752 | } |
| 753 | }); |
| 754 | } |
| 755 | }); |
| 756 | } |
| 757 | }); |
| 758 | |
| 759 | if(wcp_settings.can_manage_folder == "1") { |
| 760 | jQuery('.space').livequery(function () { |
| 761 | jQuery(this).sortable({ |
| 762 | placeholder: "ui-state-highlight", |
| 763 | connectWith: '.space', |
| 764 | tolerance: 'intersect', |
| 765 | over: function (event, ui) { |
| 766 | |
| 767 | }, |
| 768 | update: function (event, ui) { |
| 769 | thisId = ui.item.context.attributes['data-folder-id'].nodeValue; |
| 770 | orderString = ""; |
| 771 | jQuery(this).children().each(function () { |
| 772 | if (jQuery(this).hasClass("route")) { |
| 773 | orderString += jQuery(this).data("folder-id") + ","; |
| 774 | } |
| 775 | }); |
| 776 | if (orderString != "") { |
| 777 | jQuery(".form-loader-count").css("width", "100%"); |
| 778 | jQuery.ajax({ |
| 779 | url: wcp_settings.ajax_url, |
| 780 | data: "term_ids=" + orderString + "&action=wcp_save_folder_order&type=" + wcp_settings.post_type + "&nonce=" + wcp_settings.nonce, |
| 781 | method: 'post', |
| 782 | success: function (res) { |
| 783 | res = jQuery.parseJSON(res); |
| 784 | if (res.status == '1') { |
| 785 | jQuery("#wcp_folder_parent").html(res.options); |
| 786 | jQuery(".form-loader-count").css("width", "0"); |
| 787 | add_menu_to_list(); |
| 788 | } else { |
| 789 | Swal.fire( |
| 790 | '', |
| 791 | res.message, |
| 792 | 'error' |
| 793 | ); |
| 794 | window.location.reload(true); |
| 795 | } |
| 796 | } |
| 797 | }); |
| 798 | } |
| 799 | }, |
| 800 | receive: function (event, ui) { |
| 801 | calcWidth(jQuery(this).siblings('.title')); |
| 802 | check_for_sub_menu(); |
| 803 | jQuery(this).closest("li.route").addClass("active"); |
| 804 | jQuery(this).closest("li.route").find("ul.ui-sortable:first-child > li").slideDown(); |
| 805 | parentId = jQuery(this).closest("li.route").data("folder-id"); |
| 806 | thisId = ui.item.context.attributes['data-folder-id'].nodeValue; |
| 807 | if (parentId == undefined) { |
| 808 | parentId = 0; |
| 809 | } |
| 810 | orderString = ""; |
| 811 | if (jQuery("#wcp_folder_" + parentId + " .ui-sortable li").length) { |
| 812 | jQuery("#wcp_folder_" + parentId + " .ui-sortable li").each(function () { |
| 813 | orderString += jQuery(this).data("folder-id") + ","; |
| 814 | }); |
| 815 | } else if (parentId == 0) { |
| 816 | jQuery("#custom-menu > ul.space > li").each(function () { |
| 817 | orderString += jQuery(this).data("folder-id") + ","; |
| 818 | }); |
| 819 | } |
| 820 | jQuery(".form-loader-count").css("width", "100%"); |
| 821 | nonce = jQuery.trim(jQuery("#wcp_folder_" + thisId).data("nonce")); |
| 822 | jQuery.ajax({ |
| 823 | url: wcp_settings.ajax_url, |
| 824 | data: "term_id=" + thisId + "&action=wcp_update_parent_information&parent_id=" + parentId + "&type=" + wcp_settings.post_type + "&nonce=" + nonce, |
| 825 | method: 'post', |
| 826 | success: function (res) { |
| 827 | jQuery(".form-loader-count").css("width", "0%"); |
| 828 | res = jQuery.parseJSON(res); |
| 829 | if (res.status == 0) { |
| 830 | Swal.fire( |
| 831 | '', |
| 832 | res.message, |
| 833 | 'error' |
| 834 | ); |
| 835 | } else { |
| 836 | add_menu_to_list(); |
| 837 | } |
| 838 | } |
| 839 | }); |
| 840 | } |
| 841 | }); |
| 842 | jQuery(this).disableSelection(); |
| 843 | }); |
| 844 | } |
| 845 | jQuery(".update-inline-record").livequery(function(){ |
| 846 | jQuery(this).click(function(e){ |
| 847 | e.stopPropagation(); |
| 848 | isHigh = jQuery(this).closest("li.route").hasClass("is-high"); |
| 849 | jQuery(".dynamic-menu").remove(); |
| 850 | jQuery(".active-menu").removeClass("active-menu"); |
| 851 | menuHtml = "<div class='dynamic-menu'><ul>" + |
| 852 | "<li class='new-folder'><a href='javascript:;'><span class='folder-icon-create_new_folder'></span> New Folder</a></li>" + |
| 853 | "<li class='rename-folder'><a href='javascript:;'><span class='folder-icon-border_color'><span class='path1'></span><span class='path2'></span></span> Rename</a></li>" + |
| 854 | "<li class='mark-folder'><a href='javascript:;'><span class='folder-icon-star_rate'></span>" + ((isHigh) ? " Remove Star" : "Add a Star") + "</a></li>" + |
| 855 | "<li class='remove-folder'><a href='javascript:;'><span class='folder-icon-delete'></span> Delete</a></li>" + |
| 856 | "</ul></div>"; |
| 857 | jQuery(this).closest("h3.title").after(menuHtml); |
| 858 | jQuery(this).parents("li.route").addClass("active-menu"); |
| 859 | }); |
| 860 | }); |
| 861 | //check_for_sub_menu(); |
| 862 | //jQuery(".has-sub-tree:first").addClass("active"); |
| 863 | jQuery(".nav-icon").livequery(function(){ |
| 864 | jQuery(this).click(function(){ |
| 865 | folderID = jQuery(this).closest("li.route").data("folder-id"); |
| 866 | if(jQuery("#wcp_folder_"+folderID).hasClass("active")) { |
| 867 | folderStatus = 0; |
| 868 | } else { |
| 869 | folderStatus = 1; |
| 870 | } |
| 871 | jQuery(".form-loader-count").css("width","100%"); |
| 872 | nonce = jQuery.trim(jQuery("#wcp_folder_"+folderID).data("nonce")); |
| 873 | checkForExpandCollapse(); |
| 874 | jQuery.ajax({ |
| 875 | url: wcp_settings.ajax_url, |
| 876 | data: "is_active=" + folderStatus + "&action=save_wcp_folder_state&term_id=" + folderID+"&nonce="+nonce, |
| 877 | method: 'post', |
| 878 | success: function (res) { |
| 879 | jQuery(".form-loader-count").css("width","0"); |
| 880 | res = jQuery.parseJSON(res); |
| 881 | if(res.status == "0") { |
| 882 | Swal.fire( |
| 883 | '', |
| 884 | res.message, |
| 885 | 'error' |
| 886 | ); |
| 887 | } else { |
| 888 | if(jQuery("#wcp_folder_"+folderID).hasClass("active")) { |
| 889 | jQuery("#wcp_folder_"+folderID).removeClass("active"); |
| 890 | jQuery("#wcp_folder_"+folderID).find("ul.ui-sortable:first-child > li").slideUp(); |
| 891 | folderStatus = 0; |
| 892 | } else { |
| 893 | jQuery("#wcp_folder_"+folderID).addClass("active"); |
| 894 | jQuery("#wcp_folder_"+folderID).find("ul.ui-sortable:first-child > li").slideDown(); |
| 895 | folderStatus = 1; |
| 896 | } |
| 897 | add_menu_to_list(); |
| 898 | } |
| 899 | } |
| 900 | }); |
| 901 | }); |
| 902 | }); |
| 903 | jQuery("#custom-menu .ui-icon, #custom-menu h3").livequery(function(){ |
| 904 | jQuery(this).click(function(){ |
| 905 | jQuery("#custom-menu .active-item").removeClass("active-item"); |
| 906 | jQuery(this).closest(".route").addClass("active-item"); |
| 907 | add_menu_to_list(); |
| 908 | }); |
| 909 | }); |
| 910 | jQuery(".remove-folder").livequery(function(){ |
| 911 | jQuery(this).click(function() { |
| 912 | folderID = jQuery(this).closest("li.route").data("folder-id"); |
| 913 | fileFolderID = folderID; |
| 914 | jQuery(".dynamic-menu").remove(); |
| 915 | jQuery(".active-menu").removeClass("active-menu"); |
| 916 | nonce = jQuery.trim(jQuery("#wcp_folder_"+fileFolderID).data("delete")); |
| 917 | Swal.fire({ |
| 918 | url: wcp_settings.ajax_url, |
| 919 | title: 'Are you sure you want to delete the selected folder?', |
| 920 | text: 'Items in the folder will not be deleted.', |
| 921 | type: 'warning', |
| 922 | showCancelButton: true, |
| 923 | confirmButtonText: 'Yes, delete it!', |
| 924 | cancelButtonText: 'No, keep it', |
| 925 | }).then((result) => { |
| 926 | if (result.value) { |
| 927 | Swal({ |
| 928 | title: 'Please wait..', |
| 929 | imageUrl: wcp_settings.ajax_image, |
| 930 | imageAlt: 'The uploaded picture', |
| 931 | showConfirmButton: false |
| 932 | }); |
| 933 | jQuery.ajax({ |
| 934 | url: wcp_settings.ajax_url, |
| 935 | data: "type=" + wcp_settings.post_type + "&action=wcp_remove_folder&term_id=" + folderID+"&nonce="+nonce, |
| 936 | method: 'post', |
| 937 | success: function (res) { |
| 938 | res = jQuery.parseJSON(res); |
| 939 | if (res.status == '1') { |
| 940 | Swal.fire( |
| 941 | 'Deleted!', |
| 942 | 'Your folder has been deleted.', |
| 943 | 'success' |
| 944 | ); |
| 945 | jQuery("#wcp_folder_"+fileFolderID).remove(); |
| 946 | jQuery("#folder_"+fileFolderID).remove(); |
| 947 | isKeyActive = parseInt(res.is_key_active); |
| 948 | totalFolders = parseInt(res.folders); |
| 949 | jQuery("#current-folder").text(totalFolders); |
| 950 | if(totalFolders > folderLimitation) { |
| 951 | folderLimitation = totalFolders; |
| 952 | } |
| 953 | jQuery("#total-folder").text(folderLimitation); |
| 954 | add_menu_to_list(); |
| 955 | } else { |
| 956 | Swal.fire( |
| 957 | '', |
| 958 | res.message, |
| 959 | 'error' |
| 960 | ); |
| 961 | } |
| 962 | } |
| 963 | }); |
| 964 | } |
| 965 | }); |
| 966 | }); |
| 967 | }); |
| 968 | jQuery(".wcp-parent .fa-caret-right").livequery(function(){ |
| 969 | jQuery(this).click(function() { |
| 970 | autoStatus = 1; |
| 971 | if (jQuery(this).closest(".wcp-parent").hasClass("active")) { |
| 972 | jQuery(this).closest(".wcp-parent").removeClass("active"); |
| 973 | jQuery("#custom-menu").removeClass("active"); |
| 974 | autoStatus = 0; |
| 975 | } else { |
| 976 | jQuery(this).closest(".wcp-parent").addClass("active"); |
| 977 | jQuery("#custom-menu").addClass("active"); |
| 978 | } |
| 979 | jQuery(".form-loader-count").css("width","100%"); |
| 980 | add_menu_to_list(); |
| 981 | jQuery.ajax({ |
| 982 | url: wcp_settings.ajax_url, |
| 983 | data: "type=" + wcp_settings.post_type + "&action=wcp_save_parent_data&is_active=" + autoStatus+"&nonce="+wcp_settings.nonce, |
| 984 | method: 'post', |
| 985 | success: function (res) { |
| 986 | jQuery(".form-loader-count").css("width","0%"); |
| 987 | res = jQuery.parseJSON(res); |
| 988 | if (res.status == '1') { |
| 989 | Swal.fire( |
| 990 | '', |
| 991 | res.message, |
| 992 | 'error' |
| 993 | ); |
| 994 | } |
| 995 | } |
| 996 | }); |
| 997 | }); |
| 998 | }); |
| 999 | |
| 1000 | checkForExpandCollapse(); |
| 1001 | }) |
| 1002 | |
| 1003 | function checkForExpandCollapse() { |
| 1004 | add_menu_to_list(); |
| 1005 | currentStatus = true; |
| 1006 | if((jQuery("#custom-menu .has-sub-tree").length == jQuery("#custom-menu .has-sub-tree.active").length) && jQuery("#custom-menu .has-sub-tree").length) { |
| 1007 | jQuery("#expand-collapse-list").addClass("all-open"); |
| 1008 | } else { |
| 1009 | jQuery("#expand-collapse-list").removeClass("all-open"); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | function check_for_sub_menu() { |
| 1014 | jQuery("#custom-menu li.route").removeClass("has-sub-tree"); |
| 1015 | jQuery("#custom-menu li.route").each(function(){ |
| 1016 | if(jQuery(this).find("ul.ui-sortable li").length) { |
| 1017 | jQuery(this).addClass("has-sub-tree"); |
| 1018 | if(jQuery(this).find("ul.ui-sortable:first").is(":hidden")) { |
| 1019 | jQuery(this).removeClass("is-hidden"); |
| 1020 | } else { |
| 1021 | jQuery(this).addClass("is-hidden") |
| 1022 | } |
| 1023 | } else { |
| 1024 | jQuery(this).removeClass("active"); |
| 1025 | } |
| 1026 | }); |
| 1027 | } |
| 1028 | |
| 1029 | //recursively calculate the Width all titles |
| 1030 | function calcWidth(obj){ |
| 1031 | var titles = |
| 1032 | jQuery(obj).siblings('.space').children('.route').children('.title'); |
| 1033 | jQuery(titles).each(function(index, element){ |
| 1034 | var pTitleWidth = parseInt(jQuery(obj).css('width')); |
| 1035 | var leftOffset = parseInt(jQuery(obj).siblings('.space').css('margin-left')); |
| 1036 | var newWidth = pTitleWidth - leftOffset; |
| 1037 | if (jQuery(obj).attr('id') == 'title_0'){ |
| 1038 | newWidth = newWidth - 10; |
| 1039 | } |
| 1040 | jQuery(element).css({ |
| 1041 | 'width': newWidth |
| 1042 | }); |
| 1043 | calcWidth(element); |
| 1044 | }); |
| 1045 | |
| 1046 | } |
| 1047 | |
| 1048 | |
| 1049 | /* code for sticky menu for media screen*/ |
| 1050 | |
| 1051 | if(wcp_settings.post_type == "attachment") { |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | jQuery(window).load(function() { |
| 1056 | jQuery("button.button.media-button.select-mode-toggle-button").after("<button class='button organize-button'>Organize</button>"); |
| 1057 | if(jQuery(".wcp-custom-form").length) { |
| 1058 | if (wp.Uploader !== undefined) { |
| 1059 | wp.Uploader.queue.on('reset', function () { |
| 1060 | resetMediaData(1); |
| 1061 | }); |
| 1062 | } |
| 1063 | jQuery(document).ajaxComplete(function(ev, jqXHR, settings) { |
| 1064 | actionName = settings.data; |
| 1065 | if(actionName.indexOf("action=delete-post&id=") == 0) { |
| 1066 | resetMediaData(0); |
| 1067 | } |
| 1068 | }); |
| 1069 | } |
| 1070 | }); |
| 1071 | |
| 1072 | function resetMediaData(loadData) { |
| 1073 | jQuery.ajax({ |
| 1074 | url: wcp_settings.ajax_url, |
| 1075 | data: "type=" + wcp_settings.post_type + "&action=wcp_get_default_list", |
| 1076 | method: 'post', |
| 1077 | success: function (res) { |
| 1078 | res = jQuery.parseJSON(res); |
| 1079 | jQuery("#custom-menu > ul#space_0").html(res.data); |
| 1080 | jQuery(".header-posts .total-count").text(res.total_items); |
| 1081 | jQuery(".un-categorised-items .total-count").text(res.empty_items); |
| 1082 | selectedVal = jQuery("#media-attachment-taxonomy-filter").val(); |
| 1083 | if(selectedVal != "all" && loadData == 1) { |
| 1084 | var wp1 = parent.wp; |
| 1085 | wp1.media.frame.setState('insert'); |
| 1086 | if (wp1.media.frame.content.get() !== null) { |
| 1087 | wp1.media.frame.content.get().collection.props.set({ignore: (+new Date())}); |
| 1088 | wp1.media.frame.content.get().options.selection.reset(); |
| 1089 | } else { |
| 1090 | wp1.media.frame.library.props.set({ignore: (+new Date())}); |
| 1091 | } |
| 1092 | } |
| 1093 | if(res.taxonomies.length) { |
| 1094 | var selectedDD = jQuery("#media-attachment-taxonomy-filter"); |
| 1095 | selectedDD.html("<option value='all'>All Folders</option><option value='unassigned'>(Unassigned)</option>"); |
| 1096 | for(i=0; i<res.taxonomies.length; i++) { |
| 1097 | selectedDD.append("<option value='"+i+"'>"+res.taxonomies[i].name+" ("+res.taxonomies[i].count+")</option>"); |
| 1098 | } |
| 1099 | selectedDD.val(selectedVal); |
| 1100 | } |
| 1101 | } |
| 1102 | }); |
| 1103 | } |
| 1104 | |
| 1105 | function setMediaBoxWidth() { |
| 1106 | jQuery(".media-frame-content .media-toolbar").width(jQuery(".media-frame-content").width() - 20); |
| 1107 | } |
| 1108 | |
| 1109 | setMediaBoxWidth(); |
| 1110 | |
| 1111 | jQuery(window).resize(function(){ |
| 1112 | setMediaBoxWidth(); |
| 1113 | }); |
| 1114 | |
| 1115 | jQuery(document).on("click", ".button.organize-button", function(){ |
| 1116 | jQuery("button.button.media-button.select-mode-toggle-button").trigger("click"); |
| 1117 | }); |
| 1118 | |
| 1119 | function setStickyHeaderForMedia() { |
| 1120 | if(!jQuery(".media-position").length) { |
| 1121 | jQuery(".media-frame-content .media-toolbar").before("<div class='media-position'></div>") |
| 1122 | } |
| 1123 | |
| 1124 | if(jQuery(".media-position").length) { |
| 1125 | setMediaBoxWidth(); |
| 1126 | |
| 1127 | thisPosition = jQuery(".media-position").offset().top - jQuery(window).scrollTop(); |
| 1128 | if(thisPosition <= 32) { |
| 1129 | jQuery(".media-frame-content .media-toolbar").addClass("sticky-media"); |
| 1130 | jQuery(".media-position").height(jQuery(".media-frame-content .media-toolbar").outerHeight()); |
| 1131 | } else { |
| 1132 | jQuery(".media-frame-content .media-toolbar").removeClass("sticky-media"); |
| 1133 | jQuery(".media-position").height(1); |
| 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | jQuery(window).scroll(function(){ |
| 1139 | setStickyHeaderForMedia() |
| 1140 | }); |
| 1141 | } else { |
| 1142 | function setStickyHeaderForMedia() {} |
| 1143 | } |