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