custom.js
5 years ago
folders.js
5 years ago
folders.min.js
5 years ago
jstree.js
5 years ago
jstree.min.js
5 years ago
livequery.min.js
6 years ago
media.js
5 years ago
new-media.js
5 years ago
page-post-media.js
5 years ago
page-post-media.min.js
5 years ago
select2.min.js
6 years ago
spectrum.min.js
6 years ago
folders.js
2280 lines
| 1 | (function (factory) { |
| 2 | "use strict"; |
| 3 | if (typeof define === 'function' && define.amd) { |
| 4 | define(['jquery'], factory); |
| 5 | } |
| 6 | else if(typeof module !== 'undefined' && module.exports) { |
| 7 | module.exports = factory(require('jquery')); |
| 8 | } |
| 9 | else { |
| 10 | factory(jQuery); |
| 11 | } |
| 12 | }(function ($, undefined) { |
| 13 | var treeId = "#js-tree-menu"; |
| 14 | var nonce; |
| 15 | var activeRecordID = ""; |
| 16 | var isItFromMedia = false; |
| 17 | var isDuplicate = false; |
| 18 | var isKeyActive; |
| 19 | var n_o_file; |
| 20 | var duplicateFolderId = 0; |
| 21 | var fileFolderID = 0; |
| 22 | var folderOrder = 0; |
| 23 | var isMultipleRemove = false; |
| 24 | var folderIDs = ""; |
| 25 | var folderPropertyArray = []; |
| 26 | var folderCurrentURL = wcp_settings.page_url; |
| 27 | var foldersArray = []; |
| 28 | var listFolderString = "<li class='grid-view' data-id='__folder_id__' id='folder___folder_id__'>" + |
| 29 | "<div class='folder-item is-folder' data-id='__folder_id__'>" + |
| 30 | "<a title='__folder_name__' id='folder_view___folder_id__'" + |
| 31 | "class='folder-view __append_class__ has-new-folder'" + |
| 32 | "data-id='__folder_id__'>" + |
| 33 | "<span class='folder item-name'><span id='wcp_folder_text___folder_id__'" + |
| 34 | "class='folder-title'>__folder_name__</span></span>" + |
| 35 | "</a>" + |
| 36 | "</div>" + |
| 37 | "</li>"; |
| 38 | $(document).ready(function(){ |
| 39 | |
| 40 | foldersArray = wcp_settings.taxonomies; |
| 41 | |
| 42 | isKeyActive = parseInt(wcp_settings.is_key_active); |
| 43 | n_o_file = parseInt(wcp_settings.folders); |
| 44 | activeRecordID = parseInt(wcp_settings.selected_taxonomy); |
| 45 | |
| 46 | folderPropertyArray = wcp_settings.folder_settings; |
| 47 | |
| 48 | initJSTree(); |
| 49 | |
| 50 | setCustomScrollForFolder(); |
| 51 | |
| 52 | var resizeDirection = (wcp_settings.isRTL == "1" || wcp_settings.isRTL == 1)?"w":"e"; |
| 53 | $(".wcp-content").resizable( { |
| 54 | resizeHeight: false, |
| 55 | handles: resizeDirection, |
| 56 | minWidth: 100, |
| 57 | maxWidth: 500, |
| 58 | resize: function( e, ui ) { |
| 59 | var menuWidth = ui.size.width; |
| 60 | if(menuWidth <= 275) { |
| 61 | $(".plugin-button").addClass("d-block"); |
| 62 | } else { |
| 63 | $(".plugin-button").removeClass("d-block"); |
| 64 | } |
| 65 | if(menuWidth <= 225) { |
| 66 | menuWidth = 225; |
| 67 | } |
| 68 | if(wcp_settings.isRTL == "1") { |
| 69 | $("#wpcontent").css("padding-right", (menuWidth + 20) + "px"); |
| 70 | $("#wpcontent").css("padding-left", "0px"); |
| 71 | } else { |
| 72 | $("#wpcontent").css("padding-left", (menuWidth + 20) + "px"); |
| 73 | } |
| 74 | newWidth = menuWidth - 40; |
| 75 | cssString = ""; |
| 76 | classString = ""; |
| 77 | for(i=0; i<=15; i++) { |
| 78 | classString += " .space > .jstree-node >"; |
| 79 | currentWidth = newWidth - (13+(20*i)); |
| 80 | cssString += "#js-tree-menu > "+classString+" .title { width: "+currentWidth+"px !important; } "; |
| 81 | cssString += "#js-tree-menu > "+classString+" .dynamic-menu { left: "+(currentWidth - 190)+"px !important; } "; |
| 82 | setStickyHeaderForMedia(); |
| 83 | } |
| 84 | $("#wcp-custom-style").html("<style>"+cssString+"</style>"); |
| 85 | if(ui.size.width <= 185) { |
| 86 | folderStatus = "hide"; |
| 87 | $(".wcp-hide-show-buttons .toggle-buttons.show-folders").addClass("active"); |
| 88 | $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").removeClass("active"); |
| 89 | $("#wcp-content").addClass("hide-folders-area"); |
| 90 | if(wcp_settings.isRTL == "1") { |
| 91 | $("#wpcontent").css("padding-right", "20px"); |
| 92 | $("#wpcontent").css("padding-left", "0px"); |
| 93 | } else { |
| 94 | $("#wpcontent").css("padding-left", "20px"); |
| 95 | } |
| 96 | } else { |
| 97 | if($("#wcp-content").hasClass("hide-folders-area")) { |
| 98 | folderStatus = "show"; |
| 99 | $(".wcp-hide-show-buttons .toggle-buttons.show-folders").removeClass("active"); |
| 100 | $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").addClass("active"); |
| 101 | $("#wcp-content").addClass("no-transition"); |
| 102 | $("#wcp-content").removeClass("hide-folders-area"); |
| 103 | if (wcp_settings.isRTL == "1") { |
| 104 | $("#wpcontent").css("padding-right", (parseInt(wcp_settings.folder_width) + 20) + "px"); |
| 105 | $("#wpcontent").css("padding-left", "0px"); |
| 106 | } else { |
| 107 | $("#wpcontent").css("padding-left", (parseInt(wcp_settings.folder_width) + 20) + "px"); |
| 108 | } |
| 109 | setTimeout(function(){ |
| 110 | $("#wcp-content").removeClass("no-transition"); |
| 111 | }, 250); |
| 112 | } |
| 113 | } |
| 114 | }, |
| 115 | stop: function( e, ui ) { |
| 116 | var menuWidth = ui.size.width; |
| 117 | if(ui.size.width <= 275) { |
| 118 | $(".plugin-button").addClass("d-block"); |
| 119 | } else { |
| 120 | $(".plugin-button").removeClass("d-block"); |
| 121 | } |
| 122 | if(menuWidth <= 225) { |
| 123 | menuWidth = 225; |
| 124 | } |
| 125 | if(ui.size.width <= 185) { |
| 126 | folderStatus = "hide"; |
| 127 | $(".wcp-hide-show-buttons .toggle-buttons.show-folders").addClass("active"); |
| 128 | $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").removeClass("active"); |
| 129 | $("#wcp-content").addClass("hide-folders-area"); |
| 130 | if(wcp_settings.isRTL == "1") { |
| 131 | $("#wpcontent").css("padding-right", "20px"); |
| 132 | $("#wpcontent").css("padding-left", "0px"); |
| 133 | } else { |
| 134 | $("#wpcontent").css("padding-left", "20px"); |
| 135 | } |
| 136 | |
| 137 | $.ajax({ |
| 138 | url: wcp_settings.ajax_url, |
| 139 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_folder_display_status&status=" + folderStatus +"&nonce="+nonce, |
| 140 | method: 'post', |
| 141 | success: function (res) { |
| 142 | setStickyHeaderForMedia(); |
| 143 | } |
| 144 | }); |
| 145 | } else { |
| 146 | if($("#wcp-content").hasClass("hide-folders-area")) { |
| 147 | folderStatus = "show"; |
| 148 | $(".wcp-hide-show-buttons .toggle-buttons.show-folders").removeClass("active"); |
| 149 | $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").addClass("active"); |
| 150 | $("#wcp-content").addClass("no-transition"); |
| 151 | $("#wcp-content").removeClass("hide-folders-area"); |
| 152 | if (wcp_settings.isRTL == "1") { |
| 153 | $("#wpcontent").css("padding-right", (parseInt(wcp_settings.folder_width) + 20) + "px"); |
| 154 | $("#wpcontent").css("padding-left", "0px"); |
| 155 | } else { |
| 156 | $("#wpcontent").css("padding-left", (parseInt(wcp_settings.folder_width) + 20) + "px"); |
| 157 | } |
| 158 | setTimeout(function(){ |
| 159 | $("#wcp-content").removeClass("no-transition"); |
| 160 | }, 250); |
| 161 | } |
| 162 | } |
| 163 | nonce = wcp_settings.nonce; |
| 164 | wcp_settings.folder_width = ui.size.width; |
| 165 | $.ajax({ |
| 166 | url: wcp_settings.ajax_url, |
| 167 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_post_width&width=" + menuWidth+"&nonce="+nonce, |
| 168 | method: 'post', |
| 169 | success: function (res) { |
| 170 | setStickyHeaderForMedia(); |
| 171 | } |
| 172 | }); |
| 173 | if(ui.size.width <= 225) { |
| 174 | $(".wcp-content").width(225); |
| 175 | wcp_settings.folder_width = 225; |
| 176 | } |
| 177 | } |
| 178 | }); |
| 179 | |
| 180 | $(document).on("contextmenu", ".jstree-anchor", function(e){ |
| 181 | $(this).find("span.folder-inline-edit").trigger("click"); |
| 182 | return false; |
| 183 | }); |
| 184 | |
| 185 | $(document).on("click", ".folder-actions span.folder-inline-edit", function(e){ |
| 186 | e.stopImmediatePropagation() |
| 187 | e.stopPropagation(); |
| 188 | if(wcp_settings.can_manage_folder == 0) { |
| 189 | return; |
| 190 | } |
| 191 | isHigh = $(this).closest("li.jstree-node").hasClass("is-high"); |
| 192 | isSticky = $(this).closest("li.jstree-node").hasClass("is-sticky"); |
| 193 | isStickyClass = (isSticky)?true:false; |
| 194 | $(".dynamic-menu").remove(); |
| 195 | $(".active-menu").removeClass("active-menu"); |
| 196 | menuHtml = "<div class='dynamic-menu'><ul>" + |
| 197 | "<li class='new-folder'><a href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span> New Folder</a></li>" + |
| 198 | "<li class='rename-folder'><a href='javascript:;'><span class=''><i class='pfolder-edit'></i></span> Rename</a></li>" + |
| 199 | "<li class='sticky-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class='sticky-pin'><i class='pfolder-pin'></i></span> Sticky Folder (Pro)</a></li>" + |
| 200 | "<li class='mark-folder'><a href='javascript:;'><span class=''><i class='pfolder-star'></i></span>" + ((isHigh) ? " Remove Star" : "Add a Star") + "</a></li>"+ |
| 201 | "<li class='duplicate-folder'><a href='javascript:;'><span class=''><i class='pfolder-clone'></i></span> Duplicate folder</a></li>"; |
| 202 | |
| 203 | hasPosts = parseInt($(this).closest("a.jstree-anchor").find(".premio-folder-count").text()); |
| 204 | if (wcp_settings.post_type == "attachment" && hasPosts) { |
| 205 | menuHtml += "<li target='_blank' class='download-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-zip-file'></i></span> Download Zip (Pro)</a></li>"; |
| 206 | } |
| 207 | menuHtml += "<li class='remove-folder'><a href='javascript:;'><span class=''><i class='pfolder-remove'></i></span> Delete</a></li>" + |
| 208 | "</ul></div>"; |
| 209 | $(this).closest("a.jstree-anchor").after(menuHtml); |
| 210 | $(this).parents("li.jstree-node").addClass("active-menu"); |
| 211 | if(($(this).offset().top + $(".dynamic-menu").height()) > ($(window).height() - 20)) { |
| 212 | $(".dynamic-menu").addClass("bottom-fix"); |
| 213 | |
| 214 | if($(".dynamic-menu.bottom-fix").offset().top < $("#custom-scroll-menu").offset().top) { |
| 215 | $(".dynamic-menu").removeClass("bottom-fix"); |
| 216 | } |
| 217 | } |
| 218 | }); |
| 219 | |
| 220 | $(document).on("click", ".sticky-folders .sticky-fldr > a", function(e) { |
| 221 | e.stopPropagation(); |
| 222 | var folder_ID = $(this).closest("li").data("folder-id"); |
| 223 | if($(".jstree-node[id='"+folder_ID+"']").length) { |
| 224 | $(".jstree-clicked").removeClass("jstree-clicked"); |
| 225 | $(".active-item").removeClass("active-item"); |
| 226 | $("#js-tree-menu").jstree('select_node', activeRecordID); |
| 227 | $(".jstree-node[id='"+folder_ID+"'] > a.jstree-anchor").trigger("click"); |
| 228 | $(".jstree-node[id='"+folder_ID+"'] > a.jstree-anchor").addClass("jstree-clicked"); |
| 229 | $(".sticky-folders .sticky-folder-"+folder_ID+" a").addClass("active-item"); |
| 230 | } |
| 231 | }); |
| 232 | |
| 233 | $(document).on("contextmenu", ".sticky-folders li .sticky-fldr > a", function(e){ |
| 234 | $(this).find("span.update-inline-record").trigger("click"); |
| 235 | return false; |
| 236 | }); |
| 237 | |
| 238 | $(document).on("click", ".update-inline-record", function(e){ |
| 239 | e.stopImmediatePropagation() |
| 240 | e.stopPropagation(); |
| 241 | if(wcp_settings.can_manage_folder == 0) { |
| 242 | return; |
| 243 | } |
| 244 | isHigh = $(this).closest("li.sticky-fldr").hasClass("is-high"); |
| 245 | isSticky = $(this).closest("li.sticky-fldr").hasClass("is-sticky"); |
| 246 | isStickyClass = (isSticky)?true:false; |
| 247 | $(".dynamic-menu").remove(); |
| 248 | $(".active-menu").removeClass("active-menu"); |
| 249 | menuHtml = "<div class='dynamic-menu'><ul>" + |
| 250 | "<li class='new-folder'><a href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span> New Folder</a></li>" + |
| 251 | "<li class='rename-folder'><a href='javascript:;'><span class=''><i class='pfolder-edit'></i></span> Rename</a></li>" + |
| 252 | "<li class='sticky-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class='sticky-pin'><i class='pfolder-pin'></i></span>Sticky Folder (Pro)</a></li>" + |
| 253 | "<li class='mark-folder'><a href='javascript:;'><span class=''><i class='pfolder-star'></i></span>" + ((isHigh) ? " Remove Star" : "Add a Star") + "</a></li>"+ |
| 254 | "<li class='duplicate-folder'><a href='javascript:;'><span class=''><i class='pfolder-clone'></i></span> Duplicate folder</a></li>"; |
| 255 | |
| 256 | hasPosts = parseInt($(this).closest("li.jstree-node").find("h3.title:first > .total-count").text()); |
| 257 | if (wcp_settings.post_type == "attachment" && hasPosts) { |
| 258 | menuHtml += "<li class='download-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-zip-file'></i></span> Download Zip (Pro)</a></li>"; |
| 259 | } |
| 260 | menuHtml += "<li class='remove-folder'><a href='javascript:;'><span class=''><i class='pfolder-remove'></i></span> Delete</a></li>" + |
| 261 | "</ul></div>"; |
| 262 | $(this).closest("li").append(menuHtml); |
| 263 | if(($(this).offset().top + $(".dynamic-menu").height()) > ($(window).height() - 20)) { |
| 264 | $(".dynamic-menu").addClass("bottom-fix"); |
| 265 | |
| 266 | if($(".dynamic-menu.bottom-fix").offset().top < $("#custom-scroll-menu").offset().top) { |
| 267 | $(".dynamic-menu").removeClass("bottom-fix"); |
| 268 | } |
| 269 | } |
| 270 | }); |
| 271 | |
| 272 | $(document).on("click", ".dynamic-menu", function(e){ |
| 273 | e.stopImmediatePropagation() |
| 274 | e.stopPropagation(); |
| 275 | }); |
| 276 | |
| 277 | $(document).on("click", "body, html", function(){ |
| 278 | $(".dynamic-menu").remove(); |
| 279 | }); |
| 280 | |
| 281 | $(".wcp-hide-show-buttons .toggle-buttons").click(function(){ |
| 282 | var folderStatus = "show"; |
| 283 | if($(this).hasClass("hide-folders")) { |
| 284 | folderStatus = "hide"; |
| 285 | } |
| 286 | $(".wcp-hide-show-buttons .toggle-buttons").toggleClass("active"); |
| 287 | nonce = wcp_settings.nonce; |
| 288 | if(folderStatus == "show") { |
| 289 | $("#wcp-content").addClass("no-transition"); |
| 290 | $("#wcp-content").removeClass("hide-folders-area"); |
| 291 | if(wcp_settings.isRTL == "1") { |
| 292 | $("#wpcontent").css("padding-right", (parseInt(wcp_settings.folder_width) + 20) + "px"); |
| 293 | $("#wpcontent").css("padding-left", "0px"); |
| 294 | } else { |
| 295 | $("#wpcontent").css("padding-left", (parseInt(wcp_settings.folder_width) + 20) + "px"); |
| 296 | } |
| 297 | setTimeout(function(){ |
| 298 | $("#wcp-content").removeClass("no-transition"); |
| 299 | }, 250); |
| 300 | } else { |
| 301 | $("#wcp-content").addClass("hide-folders-area"); |
| 302 | if(wcp_settings.isRTL == "1") { |
| 303 | $("#wpcontent").css("padding-right", "20px"); |
| 304 | $("#wpcontent").css("padding-left", "0px"); |
| 305 | } else { |
| 306 | $("#wpcontent").css("padding-left", "20px"); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | $.ajax({ |
| 311 | url: wcp_settings.ajax_url, |
| 312 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_folder_display_status&status=" + folderStatus +"&nonce="+nonce, |
| 313 | method: 'post', |
| 314 | success: function (res) { |
| 315 | setStickyHeaderForMedia(); |
| 316 | } |
| 317 | }); |
| 318 | }); |
| 319 | |
| 320 | /* grag and drop */ |
| 321 | $(".jstree-anchor").livequery(function(){ |
| 322 | $(this).droppable({ |
| 323 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 324 | hoverClass: 'wcp-drop-hover', |
| 325 | classes: { |
| 326 | "ui-droppable-active": "ui-state-highlight" |
| 327 | }, |
| 328 | drop: function( event, ui ) { |
| 329 | folderID = $(this).closest("li.jstree-node").attr('id'); |
| 330 | if ( ui.draggable.hasClass( 'wcp-move-multiple')) { |
| 331 | if($(".wp-list-table input:checked").length) { |
| 332 | chkStr = ""; |
| 333 | $(".wp-list-table input:checked").each(function(){ |
| 334 | chkStr += $(this).val()+","; |
| 335 | }); |
| 336 | nonce = getSettingForPost(folderID, 'nonce'); |
| 337 | $.ajax({ |
| 338 | url: wcp_settings.ajax_url, |
| 339 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID+"&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 340 | method: 'post', |
| 341 | success: function (res) { |
| 342 | res = $.parseJSON(res); |
| 343 | if(res.status == "1") { |
| 344 | resetMediaAndPosts(); |
| 345 | } else { |
| 346 | $(".folder-popup-form").hide(); |
| 347 | $(".folder-popup-form").removeClass("disabled"); |
| 348 | $("#error-folder-popup-message").html(res.message); |
| 349 | $("#error-folder-popup").show() |
| 350 | } |
| 351 | } |
| 352 | }); |
| 353 | } |
| 354 | } else if( ui.draggable.hasClass( 'wcp-move-file' ) ){ |
| 355 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 356 | nonce = getSettingForPost(folderID, 'nonce'); |
| 357 | chkStr = postID+","; |
| 358 | $(".wp-list-table input:checked").each(function(){ |
| 359 | if($(this).val() != postID) { |
| 360 | chkStr += $(this).val() + ","; |
| 361 | } |
| 362 | }); |
| 363 | $.ajax({ |
| 364 | url: wcp_settings.ajax_url, |
| 365 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID+"&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 366 | method: 'post', |
| 367 | success: function (res) { |
| 368 | res = $.parseJSON(res); |
| 369 | if(res.status == "1") { |
| 370 | // window.location.reload(); |
| 371 | resetMediaAndPosts(); |
| 372 | } else { |
| 373 | $(".folder-popup-form").hide(); |
| 374 | $(".folder-popup-form").removeClass("disabled"); |
| 375 | $("#error-folder-popup-message").html(res.message); |
| 376 | $("#error-folder-popup").show() |
| 377 | } |
| 378 | } |
| 379 | }); |
| 380 | } else if (ui.draggable.hasClass('attachment')) { |
| 381 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 382 | nonce = getSettingForPost(folderID, 'nonce'); |
| 383 | if ($(".attachments-browser li.attachment.selected").length > 1) { |
| 384 | chkStr = ""; |
| 385 | $(".attachments-browser li.attachment.selected").each(function(){ |
| 386 | chkStr += $(this).data("id") + ","; |
| 387 | }); |
| 388 | } |
| 389 | folderIDs = chkStr; |
| 390 | $.ajax({ |
| 391 | url: wcp_settings.ajax_url, |
| 392 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 393 | method: 'post', |
| 394 | success: function (res) { |
| 395 | // window.location.reload(); |
| 396 | resetMediaAndPosts(); |
| 397 | } |
| 398 | }); |
| 399 | } |
| 400 | } |
| 401 | }); |
| 402 | }); |
| 403 | |
| 404 | $(".un-categorised-items").livequery(function(){ |
| 405 | $(this).droppable({ |
| 406 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 407 | hoverClass: 'wcp-hover-list', |
| 408 | classes: { |
| 409 | "ui-droppable-active": "ui-state-highlight" |
| 410 | }, |
| 411 | drop: function (event, ui) { |
| 412 | folderID = -1; |
| 413 | nonce = wcp_settings.nonce; |
| 414 | if (ui.draggable.hasClass('wcp-move-multiple')) { |
| 415 | if ($(".wp-list-table input:checked").length) { |
| 416 | chkStr = ""; |
| 417 | $(".wp-list-table input:checked").each(function(){ |
| 418 | chkStr += $(this).val() + ","; |
| 419 | }); |
| 420 | $.ajax({ |
| 421 | url: wcp_settings.ajax_url, |
| 422 | data: "post_id=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 423 | method: 'post', |
| 424 | success: function (res) { |
| 425 | //window.location.reload(); |
| 426 | resetMediaAndPosts(); |
| 427 | } |
| 428 | }); |
| 429 | } |
| 430 | } else if (ui.draggable.hasClass('wcp-move-file')) { |
| 431 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 432 | chkStr = postID+","; |
| 433 | $(".wp-list-table input:checked").each(function(){ |
| 434 | if(postID != $(this).val()) { |
| 435 | chkStr += $(this).val() + ","; |
| 436 | } |
| 437 | }); |
| 438 | $.ajax({ |
| 439 | url: wcp_settings.ajax_url, |
| 440 | data: "post_id=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 441 | method: 'post', |
| 442 | success: function (res) { |
| 443 | //window.location.reload(); |
| 444 | resetMediaAndPosts(); |
| 445 | } |
| 446 | }); |
| 447 | } else if (ui.draggable.hasClass('attachment')) { |
| 448 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 449 | if ($(".attachments-browser li.attachment.selected").length > 1) { |
| 450 | chkStr = ""; |
| 451 | $(".attachments-browser li.attachment.selected").each(function(){ |
| 452 | chkStr += $(this).data("id") + ","; |
| 453 | }); |
| 454 | } |
| 455 | folderIDs = chkStr; |
| 456 | $.ajax({ |
| 457 | url: wcp_settings.ajax_url, |
| 458 | data: "post_id=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 459 | method: 'post', |
| 460 | success: function (res) { |
| 461 | // window.location.reload(); |
| 462 | resetMediaAndPosts(); |
| 463 | } |
| 464 | }); |
| 465 | } |
| 466 | } |
| 467 | }); |
| 468 | }); |
| 469 | |
| 470 | $(".attachments-browser li.attachment").livequery(function(){ |
| 471 | $(this).draggable({ |
| 472 | revert: "invalid", |
| 473 | containment: "document", |
| 474 | helper: function (event, ui) { |
| 475 | $(".selected-items").remove(); |
| 476 | selectedItems = $(".attachments-browser li.attachment.selected").length; |
| 477 | selectedItems = (selectedItems == 0 || selectedItems == 1) ? "1 Item" : selectedItems + " Items"; |
| 478 | return $("<div class='selected-items'><span class='total-post-count'>" + selectedItems + " Selected</span></div>"); |
| 479 | }, |
| 480 | start: function( event, ui){ |
| 481 | $("body").addClass("no-hover-css"); |
| 482 | }, |
| 483 | cursor: "move", |
| 484 | cursorAt: { |
| 485 | left: 0, |
| 486 | top: 0 |
| 487 | }, |
| 488 | stop: function( event, ui ) { |
| 489 | $(".selected-items").remove(); |
| 490 | $("body").removeClass("no-hover-css"); |
| 491 | } |
| 492 | }); |
| 493 | }); |
| 494 | |
| 495 | $(".tree-structure .folder-item").livequery(function(){ |
| 496 | $(this).droppable({ |
| 497 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 498 | hoverClass: 'wcp-drop-hover-list', |
| 499 | classes: { |
| 500 | "ui-droppable-active": "ui-state-highlight" |
| 501 | }, |
| 502 | drop: function( event, ui ) { |
| 503 | $("body").removeClass("no-hover-css"); |
| 504 | folderID = $(this).data('id'); |
| 505 | if ( ui.draggable.hasClass( 'wcp-move-multiple' ) ) { |
| 506 | nonce = getSettingForPost(folderID, 'nonce'); |
| 507 | if($(".wp-list-table input:checked").length) { |
| 508 | chkStr = ""; |
| 509 | $(".wp-list-table input:checked").each(function(){ |
| 510 | chkStr += $(this).val()+","; |
| 511 | }); |
| 512 | $.ajax({ |
| 513 | url: wcp_settings.ajax_url, |
| 514 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 515 | method: 'post', |
| 516 | success: function (res) { |
| 517 | // window.location.reload(); |
| 518 | resetMediaAndPosts(); |
| 519 | ajaxAnimation(); |
| 520 | } |
| 521 | }); |
| 522 | } |
| 523 | } else if ( ui.draggable.hasClass( 'wcp-move-file' ) ) { |
| 524 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 525 | nonce = getSettingForPost(folderID, 'nonce'); |
| 526 | chkStr = postID+","; |
| 527 | $(".wp-list-table input:checked").each(function(){ |
| 528 | if($(this).val() != postID) { |
| 529 | chkStr += $(this).val() + ","; |
| 530 | } |
| 531 | }); |
| 532 | $.ajax({ |
| 533 | url: wcp_settings.ajax_url, |
| 534 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 535 | method: 'post', |
| 536 | success: function (res) { |
| 537 | // window.location.reload(); |
| 538 | resetMediaAndPosts(); |
| 539 | ajaxAnimation(); |
| 540 | } |
| 541 | }); |
| 542 | } else if( ui.draggable.hasClass( 'attachment' ) ){ |
| 543 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 544 | nonce = getSettingForPost(folderID, 'nonce'); |
| 545 | if($(".attachments-browser li.attachment.selected").length > 1) { |
| 546 | chkStr = ""; |
| 547 | $(".attachments-browser li.attachment.selected").each(function(){ |
| 548 | chkStr += $(this).data("id")+","; |
| 549 | }); |
| 550 | } |
| 551 | $.ajax({ |
| 552 | url: wcp_settings.ajax_url, |
| 553 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 554 | method: 'post', |
| 555 | success: function (res) { |
| 556 | // window.location.reload(); |
| 557 | resetMediaAndPosts(); |
| 558 | ajaxAnimation(); |
| 559 | } |
| 560 | }); |
| 561 | } |
| 562 | } |
| 563 | }); |
| 564 | }); |
| 565 | |
| 566 | $(".sticky-folders li a").livequery(function(){ |
| 567 | $(this).droppable({ |
| 568 | accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment", |
| 569 | hoverClass: 'wcp-drop-hover', |
| 570 | classes: { |
| 571 | "ui-droppable-active": "ui-state-highlight" |
| 572 | }, |
| 573 | drop: function( event, ui ) { |
| 574 | folderID = $(this).closest("li").data('folder-id'); |
| 575 | if ( ui.draggable.hasClass( 'wcp-move-multiple' ) ) { |
| 576 | if($(".wp-list-table input:checked").length) { |
| 577 | chkStr = ""; |
| 578 | $(".wp-list-table input:checked").each(function(){ |
| 579 | chkStr += $(this).val()+","; |
| 580 | }); |
| 581 | nonce = getSettingForPost(folderID, 'nonce'); |
| 582 | $.ajax({ |
| 583 | url: wcp_settings.ajax_url, |
| 584 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID+"&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 585 | method: 'post', |
| 586 | success: function (res) { |
| 587 | res = $.parseJSON(res); |
| 588 | if(res.status == "1") { |
| 589 | resetMediaAndPosts(); |
| 590 | ajaxAnimation(); |
| 591 | } else { |
| 592 | $(".folder-popup-form").hide(); |
| 593 | $(".folder-popup-form").removeClass("disabled"); |
| 594 | $("#error-folder-popup-message").html(res.message); |
| 595 | $("#error-folder-popup").show() |
| 596 | } |
| 597 | } |
| 598 | }); |
| 599 | } |
| 600 | } else if( ui.draggable.hasClass( 'wcp-move-file' ) ){ |
| 601 | postID = ui.draggable[0].attributes['data-id'].nodeValue; |
| 602 | nonce = getSettingForPost(folderID, 'nonce'); |
| 603 | chkStr = postID+","; |
| 604 | $(".wp-list-table input:checked").each(function(){ |
| 605 | if($(this).val() != postID) { |
| 606 | chkStr += $(this).val() + ","; |
| 607 | } |
| 608 | }); |
| 609 | $.ajax({ |
| 610 | url: wcp_settings.ajax_url, |
| 611 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID+"&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 612 | method: 'post', |
| 613 | success: function (res) { |
| 614 | res = $.parseJSON(res); |
| 615 | if(res.status == "1") { |
| 616 | // window.location.reload(); |
| 617 | resetMediaAndPosts(); |
| 618 | ajaxAnimation(); |
| 619 | } else { |
| 620 | $(".folder-popup-form").hide(); |
| 621 | $(".folder-popup-form").removeClass("disabled"); |
| 622 | $("#error-folder-popup-message").html(res.message); |
| 623 | $("#error-folder-popup").show() |
| 624 | } |
| 625 | } |
| 626 | }); |
| 627 | } else if (ui.draggable.hasClass('attachment')) { |
| 628 | chkStr = ui.draggable[0].attributes['data-id'].nodeValue; |
| 629 | nonce = getSettingForPost(folderID, 'nonce'); |
| 630 | if ($(".attachments-browser li.attachment.selected").length > 1) { |
| 631 | chkStr = ""; |
| 632 | $(".attachments-browser li.attachment.selected").each(function () { |
| 633 | chkStr += $(this).data("id") + ","; |
| 634 | }); |
| 635 | } |
| 636 | folderIDs = chkStr; |
| 637 | $.ajax({ |
| 638 | url: wcp_settings.ajax_url, |
| 639 | data: "post_ids=" + chkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + folderID + "&nonce="+nonce+"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 640 | method: 'post', |
| 641 | success: function (res) { |
| 642 | // window.location.reload(); |
| 643 | resetMediaAndPosts(); |
| 644 | ajaxAnimation(); |
| 645 | } |
| 646 | }); |
| 647 | } |
| 648 | } |
| 649 | }); |
| 650 | }); |
| 651 | }); |
| 652 | |
| 653 | function setFolderCount() { |
| 654 | $("#js-tree-menu .jstree-node").each(function(){ |
| 655 | var folderCount = parseInt($(this).data("count")); |
| 656 | if(folderCount > 0) { |
| 657 | $(".jstree-node[id='" + $(this).attr("id") + "'] > a span.premio-folder-count").text(folderCount); |
| 658 | } |
| 659 | }); |
| 660 | |
| 661 | if(activeRecordID != "" && activeRecordID != 0) { |
| 662 | if($(".jstree-node[id='"+activeRecordID+"']").length) { |
| 663 | $("#js-tree-menu").jstree('select_node', activeRecordID); |
| 664 | if($(".sticky-folders .sticky-folder-"+activeRecordID+" a").length) { |
| 665 | $(".sticky-folders .sticky-folder-" + activeRecordID + " a").addClass("active-item"); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | $(".ajax-preloader").hide(); |
| 670 | $(".js-tree-data").show(); |
| 671 | setCustomScrollForFolder(); |
| 672 | make_sticky_folder_menu(); |
| 673 | if($(".sticky-folders ul > li").length > 0) { |
| 674 | $(".sticky-folders").addClass("active"); |
| 675 | } |
| 676 | add_active_item_to_list(); |
| 677 | } |
| 678 | |
| 679 | function getSettingForPost(postId, filedName) { |
| 680 | if(folderPropertyArray.length > 0) { |
| 681 | for(i=0; i<folderPropertyArray.length; i++) { |
| 682 | if(parseInt(folderPropertyArray[i]['folder_id']) == parseInt(postId)) { |
| 683 | return folderPropertyArray[i][filedName]; |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | return ""; |
| 688 | } |
| 689 | |
| 690 | function getIndexForPostSetting(postId) { |
| 691 | if(folderPropertyArray.length > 0) { |
| 692 | for(i=0; i<folderPropertyArray.length; i++) { |
| 693 | if(parseInt(folderPropertyArray[i]['folder_id']) == parseInt(postId)) { |
| 694 | return i; |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | return null; |
| 699 | } |
| 700 | |
| 701 | function resetMediaAndPosts() { |
| 702 | if($(".media-toolbar").hasClass("media-toolbar-mode-select")) { |
| 703 | if($("ul.attachments li.selected").length) { |
| 704 | $("ul.attachments li.selected").trigger("click"); |
| 705 | $(".select-mode-toggle-button").trigger("click"); |
| 706 | } |
| 707 | } |
| 708 | if(folderIDs != "" && ($("#js-tree-menu a.jstree-clicked").length > 0 || activeRecordID == "-1")) { |
| 709 | if($("#media-attachment-taxonomy-filter").length) { |
| 710 | folderIDs = folderIDs.split(","); |
| 711 | for (var i = 0; i < folderIDs.length; i++) { |
| 712 | if(folderIDs[i] != "") { |
| 713 | $(".attachments-browser li[data-id='"+folderIDs[i]+"']").remove(); |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | folderIDs = ""; |
| 718 | } |
| 719 | if($("#media-attachment-taxonomy-filter").length) { |
| 720 | resetMediaData(0); |
| 721 | } else { |
| 722 | $.ajax({ |
| 723 | url: wcp_settings.ajax_url, |
| 724 | data: "type=" + wcp_settings.post_type + "&action=get_folders_default_list", |
| 725 | method: 'post', |
| 726 | success: function (res) { |
| 727 | res = $.parseJSON(res); |
| 728 | // $("#js-tree-menu > ul#space_0").html(res.data); |
| 729 | $(".header-posts .total-count").text(res.total_items); |
| 730 | $(".un-categorised-items .total-count").text(res.empty_items); |
| 731 | |
| 732 | foldersArray = res.taxonomies; |
| 733 | setFolderCountAndDD(); |
| 734 | } |
| 735 | }); |
| 736 | $(".folder-loader-ajax").addClass("active"); |
| 737 | if($("#folder-posts-filter").length) { |
| 738 | $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){ |
| 739 | var obj = { Title: "", Url: folderCurrentURL }; |
| 740 | history.pushState(obj, obj.Title, obj.Url); |
| 741 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 742 | $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>'); |
| 743 | } |
| 744 | add_active_item_to_list(); |
| 745 | triggerInlineUpdate(); |
| 746 | }); |
| 747 | } else { |
| 748 | $("#wpbody").load(folderCurrentURL + " #wpbody-content", false, function (res) { |
| 749 | var obj = { Title: "", Url: folderCurrentURL }; |
| 750 | history.pushState(obj, obj.Title, obj.Url); |
| 751 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 752 | $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>'); |
| 753 | } |
| 754 | add_active_item_to_list(); |
| 755 | }); |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | function triggerInlineUpdate() { |
| 761 | add_active_item_to_list(); |
| 762 | |
| 763 | $(".form-loader-count").css("width", "0"); |
| 764 | if(typeof inlineEditPost == "object") { |
| 765 | |
| 766 | inlineEditPost.init(); |
| 767 | |
| 768 | $("#the-list").on("click",".editinline",function(){ |
| 769 | $(this).attr("aria-expanded","true"); |
| 770 | inlineEditPost.edit(this); |
| 771 | }); |
| 772 | $(document).on("click", ".inline-edit-save .save", function(){ |
| 773 | var thisID = $(this).closest("tr").attr("id"); |
| 774 | thisID = thisID.replace("edit-",""); |
| 775 | thisID = thisID.replace("post-",""); |
| 776 | inlineEditPost.save(thisID); |
| 777 | }); |
| 778 | $(document).on("click", ".inline-edit-save .cancel", function(){ |
| 779 | var thisID = $(this).closest("tr").attr("id"); |
| 780 | thisID = thisID.replace("edit-",""); |
| 781 | thisID = thisID.replace("post-",""); |
| 782 | inlineEditPost.revert(thisID); |
| 783 | }); |
| 784 | } |
| 785 | |
| 786 | if(wcp_settings.post_type == "attachment") { |
| 787 | if(!$(".move-to-folder-top").length) { |
| 788 | $("#bulk-action-selector-top").append("<option class='move-to-folder-top' value='move_to_folder'>Move to Folder</option>"); |
| 789 | } |
| 790 | if(!$(".move-to-folder-bottom").length) { |
| 791 | $("#bulk-action-selector-bottom").append("<option class='move-to-folder-bottom' value='move_to_folder'>Move to Folder</option>"); |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | function add_active_item_to_list() { |
| 797 | |
| 798 | if(folderPropertyArray.length) { |
| 799 | $("li.jstree-node").each(function(){ |
| 800 | folderPostId = getIndexForPostSetting($(this).attr("id")); |
| 801 | if(folderPostId != null) { |
| 802 | if(folderPropertyArray[folderPostId]['is_high'] == 1) { |
| 803 | $(this).addClass("is-high"); |
| 804 | } else { |
| 805 | $(this).removeClass("is-high"); |
| 806 | } |
| 807 | if(folderPropertyArray[folderPostId]['is_sticky'] == 1) { |
| 808 | $(this).addClass("is-sticky"); |
| 809 | } else { |
| 810 | $(this).removeClass("is-sticky"); |
| 811 | } |
| 812 | } |
| 813 | }); |
| 814 | } |
| 815 | |
| 816 | folderId = 0; |
| 817 | $(".tree-structure ul").html(""); |
| 818 | folderStatus = true; |
| 819 | if($(".jstree-clicked").length) { |
| 820 | folderID = $(".jstree-clicked").closest(".jstree-node").attr("id"); |
| 821 | if($(".jstree-node[id='"+folderID+"'] > ul.jstree-children > li.jstree-node").length) { |
| 822 | folderStatus = false; |
| 823 | $(".jstree-node[id='"+folderID+"'] > ul.jstree-children > li.jstree-node").each(function(){ |
| 824 | fID = $(this).attr("id"); |
| 825 | fName = $.trim($("#js-tree-menu").jstree(true).get_node(fID).text); |
| 826 | liHtml = listFolderString.replace(/__folder_id__/g,fID); |
| 827 | liHtml = liHtml.replace(/__folder_name__/g,fName); |
| 828 | selectedClass = $(this).hasClass("is-high")?"is-high":""; |
| 829 | liHtml = liHtml.replace(/__append_class__/g,selectedClass); |
| 830 | $(".tree-structure ul").append(liHtml); |
| 831 | }); |
| 832 | } else { |
| 833 | if(!$(".jstree-node[id='"+folderID+"']").closest("ul").hasClass("jstree-container-ul")) { |
| 834 | folderStatus = false; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | if(folderStatus){ |
| 839 | $("#js-tree-menu > ul > li.jstree-node").each(function(){ |
| 840 | fID = $(this).attr("id"); |
| 841 | fName = $.trim($("#js-tree-menu").jstree(true).get_node(fID).text); |
| 842 | liHtml = listFolderString.replace(/__folder_id__/g,fID); |
| 843 | liHtml = liHtml.replace(/__folder_name__/g,fName); |
| 844 | selectedClass = $(this).hasClass("is-high")?"is-high":""; |
| 845 | liHtml = liHtml.replace(/__append_class__/g,selectedClass); |
| 846 | $(".tree-structure ul").append(liHtml); |
| 847 | }); |
| 848 | } |
| 849 | |
| 850 | |
| 851 | apply_animation_height(); |
| 852 | |
| 853 | if(wcp_settings.post_type == "attachment") { |
| 854 | if(!$(".move-to-folder-top").length) { |
| 855 | $("#bulk-action-selector-top").append("<option class='move-to-folder-top' value='move_to_folder'>Move to Folder</option>"); |
| 856 | } |
| 857 | if(!$(".move-to-folder-bottom").length) { |
| 858 | $("#bulk-action-selector-bottom").append("<option class='move-to-folder-bottom' value='move_to_folder'>Move to Folder</option>"); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | $(".sticky-folders .active-item").removeClass("active-item"); |
| 863 | if($("#js-tree-menu li.jstree-node.active-item").length) { |
| 864 | var activeTermId = $("#js-tree-menu li.jstree-node.active-item").data("folder-id"); |
| 865 | $(".sticky-folders .sticky-folder-"+activeTermId+" a").addClass("active-item"); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | $(window).on("resize", function(){ |
| 870 | setCustomScrollForFolder(); |
| 871 | setStickyHeaderForMedia(); |
| 872 | }); |
| 873 | |
| 874 | $(window).scroll(function(){ |
| 875 | setStickyHeaderForMedia() |
| 876 | }); |
| 877 | |
| 878 | function setCustomScrollForFolder() { |
| 879 | /*contentHeight = $(window).height() - $("#wpadminbar").height() - $(".sticky-wcp-custom-form").height() - 30; |
| 880 | var scrollTop = 0; |
| 881 | if($("#custom-scroll-menu").hasClass("mCustomScrollbar")) { |
| 882 | var $scrollerOuter = $( '#custom-scroll-menu' ); |
| 883 | var $dragger = $scrollerOuter.find( '.mCSB_dragger' ); |
| 884 | var scrollHeight = $scrollerOuter.find( '.mCSB_container' ).height(); |
| 885 | var draggerTop = $dragger.position().top; |
| 886 | |
| 887 | scrollTop = draggerTop / ($scrollerOuter.height() - $dragger.height()) * (scrollHeight - $scrollerOuter.height()); |
| 888 | $("#custom-scroll-menu").mCustomScrollbar('destroy'); |
| 889 | |
| 890 | } |
| 891 | $("#custom-scroll-menu").mCustomScrollbar({ |
| 892 | axis:"y", |
| 893 | scrollButtons:{enable:false}, |
| 894 | setHeight: contentHeight, |
| 895 | theme:"3d", |
| 896 | scrollbarPosition:"inside", |
| 897 | }); |
| 898 | if(scrollTop != 0) { |
| 899 | $("#custom-scroll-menu").mCustomScrollbar("scrollTo", scrollTop+"px",{scrollInertia:0}); |
| 900 | }*/ |
| 901 | } |
| 902 | |
| 903 | /* add folder code */ |
| 904 | $(document).ready(function(){ |
| 905 | $("#add-new-folder").livequery(function(){ |
| 906 | $(this).click(function() { |
| 907 | if($("#js-tree-menu a.jstree-clicked").length) { |
| 908 | fileFolderID = $("#js-tree-menu a.jstree-clicked").closest("li.jstree-node").attr("id"); |
| 909 | } else { |
| 910 | fileFolderID = 0; |
| 911 | } |
| 912 | isItFromMedia = false; |
| 913 | addFolder(); |
| 914 | }); |
| 915 | }); |
| 916 | |
| 917 | $(".new-folder").livequery(function(){ |
| 918 | $(this).click(function() { |
| 919 | if($(this).closest("li.jstree-node").length) { |
| 920 | fileFolderID = $(this).closest("li.jstree-node").attr("id"); |
| 921 | } else { |
| 922 | fileFolderID = $(this).closest("li.sticky-fldr").data("folder-id"); |
| 923 | } |
| 924 | isItFromMedia = false; |
| 925 | addFolder(); |
| 926 | }); |
| 927 | }); |
| 928 | |
| 929 | $(".duplicate-folder").livequery(function(){ |
| 930 | $(this).click(function(e) { |
| 931 | e.stopPropagation(); |
| 932 | if($(this).closest("li.jstree-node").length) { |
| 933 | fileFolderID = $(this).closest("li.jstree-node").attr("id"); |
| 934 | } else { |
| 935 | fileFolderID = $(this).closest("li.sticky-fldr").data("folder-id"); |
| 936 | } |
| 937 | $(".dynamic-menu").remove(); |
| 938 | isItFromMedia = false; |
| 939 | isDuplicate = true; |
| 940 | addFolder(); |
| 941 | add_menu_to_list(); |
| 942 | }); |
| 943 | }); |
| 944 | |
| 945 | $(document).on("submit", "#save-folder-form", function(e){ |
| 946 | e.stopPropagation(); |
| 947 | e.preventDefault(); |
| 948 | |
| 949 | folderNameDynamic = $.trim($("#add-update-folder-name").val()); |
| 950 | |
| 951 | if($.trim(folderNameDynamic) == "") { |
| 952 | $(".folder-form-errors").addClass("active"); |
| 953 | $("#add-update-folder-name").focus(); |
| 954 | } else { |
| 955 | $("#save-folder-data").html('<span class="dashicons dashicons-update"></span>'); |
| 956 | $("#add-update-folder").addClass("disabled"); |
| 957 | |
| 958 | var parentId = fileFolderID; |
| 959 | if(isItFromMedia) { |
| 960 | parentId = 0; |
| 961 | } |
| 962 | |
| 963 | if(parentId == 0) { |
| 964 | folderOrder = $("#js-tree-menu > ul > li.jstree-node").length; |
| 965 | } else { |
| 966 | folderOrder = $("#js-tree-menu > ul > li.jstree-node[id='"+parentId+"'] > ul.jstree-children > li").length + 1; |
| 967 | } |
| 968 | |
| 969 | $.ajax({ |
| 970 | url: wcp_settings.ajax_url, |
| 971 | data: { |
| 972 | parent_id: parentId, |
| 973 | type: wcp_settings.post_type, |
| 974 | action: "wcp_add_new_folder", |
| 975 | nonce: wcp_settings.nonce, |
| 976 | term_id: parentId, |
| 977 | order: folderOrder, |
| 978 | name: folderNameDynamic, |
| 979 | is_duplicate: isDuplicate, |
| 980 | duplicate_from: duplicateFolderId |
| 981 | }, |
| 982 | method: 'post', |
| 983 | success: function (res) { |
| 984 | result = $.parseJSON(res); |
| 985 | if (result.status == '1') { |
| 986 | isKeyActive = parseInt(result.is_key_active); |
| 987 | n_o_file = parseInt(result.folders); |
| 988 | $("#current-folder").text(n_o_file); |
| 989 | $("#ttl-fldr").text((4*4)-(2*2)-2); |
| 990 | checkForExpandCollapse(); |
| 991 | add_menu_to_list(); |
| 992 | $(".folder-popup-form").hide(); |
| 993 | $(".folder-popup-form").removeClass("disabled"); |
| 994 | var folderProperty = { |
| 995 | 'folder_id': result.term_id, |
| 996 | 'folder_count': 0, |
| 997 | 'is_sticky': 0, |
| 998 | 'is_high': 0, |
| 999 | 'nonce': result.nonce, |
| 1000 | 'slug': result.slug, |
| 1001 | 'is_deleted': 0 |
| 1002 | }; |
| 1003 | folderPropertyArray.push(folderProperty); |
| 1004 | ajaxAnimation(); |
| 1005 | make_sticky_folder_menu(); |
| 1006 | $('#js-tree-menu').jstree().create_node(result.parent_id, { "id" : result.term_id, "text" : " "+result.title }, "last", function(){ |
| 1007 | $(".jstree-node[id='"+result.term_id+"']").attr("data-nonce", result.nonce); |
| 1008 | $(".jstree-node[id='"+result.term_id+"']").attr("data-slug", result.slug); |
| 1009 | }); |
| 1010 | if($("#media-attachment-taxonomy-filter").length) { |
| 1011 | fileFolderID = result.term_id; |
| 1012 | resetMediaData(0); |
| 1013 | } |
| 1014 | } else { |
| 1015 | $(".folder-popup-form").hide(); |
| 1016 | $(".folder-popup-form").removeClass("disabled"); |
| 1017 | $("#error-folder-popup-message").html(result.message); |
| 1018 | $("#error-folder-popup").show(); |
| 1019 | } |
| 1020 | } |
| 1021 | }); |
| 1022 | } |
| 1023 | return false; |
| 1024 | }); |
| 1025 | }); |
| 1026 | |
| 1027 | function add_menu_to_list() { |
| 1028 | add_active_item_to_list(); |
| 1029 | } |
| 1030 | |
| 1031 | function addFolder() { |
| 1032 | if(isKeyActive == 0 && n_o_file >= ((4*4)-(3*3)+(4/4)+(8/(2*2)))) { |
| 1033 | $("#folder-limitation-message").html("You've "+"reached the "+((4*4)-(2*2)-2)+" folder limitation!"); |
| 1034 | $("#no-more-folder-credit").show(); |
| 1035 | return false; |
| 1036 | } |
| 1037 | |
| 1038 | $("#add-update-folder-title").text("Add new folder"); |
| 1039 | $("#save-folder-data").text("Submit"); |
| 1040 | $(".folder-form-errors").removeClass("active"); |
| 1041 | $("#add-update-folder-name").val(""); |
| 1042 | if(isDuplicate) { |
| 1043 | duplicateFolderId = fileFolderID; |
| 1044 | $("#add-update-folder-name").val($.trim($("#js-tree-menu").jstree(true).get_node(fileFolderID).text)+ " #2"); |
| 1045 | if($("#"+fileFolderID+"_anchor").closest(".jstree-node").parent().parent().hasClass("jstree-node")) { |
| 1046 | fileFolderID = $("#"+fileFolderID+"_anchor").closest(".jstree-node").parent().parent().attr("id"); |
| 1047 | } else { |
| 1048 | fileFolderID = 0; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | $("#add-update-folder").removeClass("disabled"); |
| 1053 | $("#add-update-folder").show(); |
| 1054 | $("#add-update-folder-name").focus(); |
| 1055 | $(".dynamic-menu").remove(); |
| 1056 | } |
| 1057 | |
| 1058 | /* update folder code */ |
| 1059 | $(document).ready(function(){ |
| 1060 | $("#inline-update").click(function(){ |
| 1061 | if($("#js-tree-menu a.jstree-clicked").length) { |
| 1062 | fileFolderID = $("#js-tree-menu a.jstree-clicked").closest("li.jstree-node").attr("id"); |
| 1063 | updateFolder(); |
| 1064 | //add_menu_to_list(); |
| 1065 | } |
| 1066 | }); |
| 1067 | |
| 1068 | $(".rename-folder").livequery(function(){ |
| 1069 | $(this).click(function(e){ |
| 1070 | e.stopPropagation(); |
| 1071 | if($(this).closest("li.jstree-node").length) { |
| 1072 | fileFolderID = $(this).closest("li.jstree-node").attr("id"); |
| 1073 | } else { |
| 1074 | fileFolderID = $(this).closest("li.sticky-fldr").data("folder-id"); |
| 1075 | } |
| 1076 | updateFolder(); |
| 1077 | $(".dynamic-menu").remove(); |
| 1078 | }); |
| 1079 | }); |
| 1080 | |
| 1081 | $(document).on("click", ".form-cancel-btn", function(){ |
| 1082 | $(".folder-popup-form").hide(); |
| 1083 | }); |
| 1084 | |
| 1085 | $(document).on("click", ".folder-popup-form", function (e) { |
| 1086 | $(".folder-popup-form").hide(); |
| 1087 | }); |
| 1088 | |
| 1089 | $(document).on("click", ".popup-form-content", function (e) { |
| 1090 | e.stopPropagation(); |
| 1091 | }); |
| 1092 | |
| 1093 | $(document).on("submit", "#update-folder-form", function(e){ |
| 1094 | e.stopPropagation(); |
| 1095 | e.preventDefault(); |
| 1096 | |
| 1097 | folderNameDynamic = $("#update-folder-item-name").val(); |
| 1098 | |
| 1099 | if($.trim(folderNameDynamic) == "") { |
| 1100 | $(".folder-form-errors").addClass("active"); |
| 1101 | $("#update-folder-item-name").focus(); |
| 1102 | } else { |
| 1103 | $("#update-folder-data").html('<span class="dashicons dashicons-update"></span>'); |
| 1104 | $("#update-folder-item").addClass("disabled"); |
| 1105 | |
| 1106 | nonce = getSettingForPost(fileFolderID, 'nonce'); |
| 1107 | parentID = $(".jstree-node[id='"+fileFolderID+"']").closest("li.jstree-node").attr("id"); |
| 1108 | if (parentID == undefined) { |
| 1109 | parentID = 0; |
| 1110 | } |
| 1111 | $.ajax({ |
| 1112 | url: wcp_settings.ajax_url, |
| 1113 | data: { |
| 1114 | parent_id: parentID, |
| 1115 | type: wcp_settings.post_type, |
| 1116 | action: "wcp_update_folder", |
| 1117 | nonce: nonce, |
| 1118 | term_id: fileFolderID, |
| 1119 | order: folderOrder, |
| 1120 | name: folderNameDynamic |
| 1121 | }, |
| 1122 | method: 'post', |
| 1123 | success: function (res) { |
| 1124 | result = $.parseJSON(res); |
| 1125 | if (result.status == '1') { |
| 1126 | $("#js-tree-menu").jstree('rename_node', result.id , " "+result.term_title); |
| 1127 | folderPostId = getIndexForPostSetting(result.id); |
| 1128 | if(folderPostId != null) { |
| 1129 | folderPropertyArray[folderPostId]['nonce'] = result.nonce; |
| 1130 | folderPropertyArray[folderPostId]['slug'] = result.slug; |
| 1131 | } |
| 1132 | add_menu_to_list(); |
| 1133 | $(".folder-popup-form").hide(); |
| 1134 | $(".folder-popup-form").removeClass("disabled"); |
| 1135 | ajaxAnimation(); |
| 1136 | if($("#media-attachment-taxonomy-filter").length) { |
| 1137 | resetMediaData(0) |
| 1138 | } |
| 1139 | } else { |
| 1140 | $(".folder-popup-form").hide(); |
| 1141 | $(".folder-popup-form").removeClass("disabled"); |
| 1142 | $("#error-folder-popup-message").html(result.message); |
| 1143 | $("#error-folder-popup").show(); |
| 1144 | } |
| 1145 | } |
| 1146 | }); |
| 1147 | } |
| 1148 | return false; |
| 1149 | }); |
| 1150 | }); |
| 1151 | |
| 1152 | function updateFolder() { |
| 1153 | folderName = $.trim($("#js-tree-menu").jstree(true).get_node(fileFolderID).text); |
| 1154 | parentID = $("#wcp_folder_"+fileFolderID).closest("li.jstree-node").data("folder-id"); |
| 1155 | if(parentID == undefined) { |
| 1156 | parentID = 0; |
| 1157 | } |
| 1158 | |
| 1159 | $("#update-folder-data").text("Submit"); |
| 1160 | $(".folder-form-errors").removeClass("active"); |
| 1161 | $("#update-folder-item-name").val(folderName); |
| 1162 | $("#update-folder-item").removeClass("disabled"); |
| 1163 | $("#update-folder-item").show(); |
| 1164 | $("#update-folder-item-name").focus(); |
| 1165 | $(".dynamic-menu").remove(); |
| 1166 | } |
| 1167 | |
| 1168 | /* Remove Folders */ |
| 1169 | $(document).ready(function(){ |
| 1170 | $("#inline-remove").click(function(){ |
| 1171 | if($("#js-tree-menu a.jstree-clicked").length) { |
| 1172 | fileFolderID = $("#js-tree-menu a.jstree-clicked").closest("li.jstree-node").attr("id"); |
| 1173 | removeFolderFromID(1); |
| 1174 | $(".dynamic-menu").remove(); |
| 1175 | $(".active-menu").removeClass("active-menu"); |
| 1176 | } else { |
| 1177 | if($("#folder-hide-show-checkbox").is(":checked")) { |
| 1178 | $(".dynamic-menu").remove(); |
| 1179 | removeFolderFromID(1); |
| 1180 | } |
| 1181 | } |
| 1182 | }); |
| 1183 | |
| 1184 | $(document).on("click","#folder-hide-show-checkbox",function(){ |
| 1185 | if($(this).is(":checked")) { |
| 1186 | $("#js-tree-menu").addClass("show-folder-checkbox"); |
| 1187 | } else { |
| 1188 | $("#js-tree-menu input.checkbox").attr("checked", false); |
| 1189 | $("#js-tree-menu").removeClass("show-folder-checkbox"); |
| 1190 | } |
| 1191 | }); |
| 1192 | |
| 1193 | $(document).on("click", ".folder-checkbox, .input-checkbox", function(e){ |
| 1194 | e.stopImmediatePropagation(); |
| 1195 | e.stopPropagation(); |
| 1196 | }); |
| 1197 | |
| 1198 | $(".remove-folder").livequery(function(){ |
| 1199 | $(this).click(function() { |
| 1200 | folderID = $(this).closest("li.jstree-node").data("id"); |
| 1201 | if($(this).closest("li.jstree-node").length) { |
| 1202 | fileFolderID = $(this).closest("li.jstree-node").attr("id"); |
| 1203 | } else { |
| 1204 | fileFolderID = $(this).closest("li.sticky-fldr").data("folder-id"); |
| 1205 | } |
| 1206 | removeFolderFromID(0); |
| 1207 | $(".dynamic-menu").remove(); |
| 1208 | $(".active-menu").removeClass("active-menu"); |
| 1209 | }); |
| 1210 | }); |
| 1211 | |
| 1212 | $(document).on("click", "#remove-folder-item", function (e){ |
| 1213 | e.stopPropagation(); |
| 1214 | $(".folder-popup-form").addClass("disabled"); |
| 1215 | $("#remove-folder-item").html('<span class="dashicons dashicons-update"></span>'); |
| 1216 | nonce = getSettingForPost(fileFolderID, 'nonce'); |
| 1217 | if(isMultipleRemove) { |
| 1218 | removeMultipleFolderItems(); |
| 1219 | } else { |
| 1220 | $.ajax({ |
| 1221 | url: wcp_settings.ajax_url, |
| 1222 | data: "type=" + wcp_settings.post_type + "&action=wcp_remove_folder&term_id=" + fileFolderID + "&nonce=" + nonce, |
| 1223 | method: 'post', |
| 1224 | success: function (res) { |
| 1225 | res = $.parseJSON(res); |
| 1226 | if (res.status == '1') { |
| 1227 | $('#js-tree-menu').jstree().delete_node(fileFolderID); |
| 1228 | isKeyActive = parseInt(res.is_key_active); |
| 1229 | n_o_file = parseInt(res.folders); |
| 1230 | $("#current-folder").text(n_o_file); |
| 1231 | $("#ttl-fldr").text((3*3)+(4/(2*2))); |
| 1232 | $(".sticky-folders .sticky-folder-"+fileFolderID).remove(); |
| 1233 | add_menu_to_list(); |
| 1234 | ajaxAnimation(); |
| 1235 | $(".folder-popup-form").hide(); |
| 1236 | $(".folder-popup-form").removeClass("disabled"); |
| 1237 | resetMediaAndPosts(); |
| 1238 | make_sticky_folder_menu(); |
| 1239 | if (activeRecordID == fileFolderID) { |
| 1240 | $(".header-posts").trigger("click"); |
| 1241 | } |
| 1242 | } else { |
| 1243 | $(".folder-popup-form").hide(); |
| 1244 | $(".folder-popup-form").removeClass("disabled"); |
| 1245 | $("#error-folder-popup-message").html(res.message); |
| 1246 | $("#error-folder-popup").show(); |
| 1247 | } |
| 1248 | } |
| 1249 | }); |
| 1250 | } |
| 1251 | }); |
| 1252 | }); |
| 1253 | |
| 1254 | function check_for_sub_menu() { |
| 1255 | $("#js-tree-menu li.jstree-node").removeClass("has-sub-tree"); |
| 1256 | $("#js-tree-menu li.jstree-node").each(function(){ |
| 1257 | if($(this).find("ul.ui-sortable li").length) { |
| 1258 | $(this).addClass("has-sub-tree"); |
| 1259 | } else { |
| 1260 | $(this).removeClass("active"); |
| 1261 | } |
| 1262 | }); |
| 1263 | } |
| 1264 | |
| 1265 | function removeMultipleFolderItems() { |
| 1266 | if($("#folder-hide-show-checkbox").is(":checked")) { |
| 1267 | if($("#js-tree-menu input.checkbox:checked").length > 0) { |
| 1268 | var folderIDs = ""; |
| 1269 | var activeItemDeleted = false; |
| 1270 | $("#js-tree-menu input.checkbox:checked").each(function(){ |
| 1271 | folderIDs += $(this).closest("li.jstree-node").attr("id")+","; |
| 1272 | if($(this).closest("li.jstree-node").hasClass("jstree-clicked")) { |
| 1273 | activeItemDeleted = true; |
| 1274 | } |
| 1275 | }); |
| 1276 | $(".form-loader-count").css("width", "100%"); |
| 1277 | $.ajax({ |
| 1278 | url: wcp_settings.ajax_url, |
| 1279 | data: "type=" + wcp_settings.post_type + "&action=wcp_remove_muliple_folder&term_id=" + folderIDs+"&nonce="+wcp_settings.nonce, |
| 1280 | method: 'post', |
| 1281 | success: function (res) { |
| 1282 | res = $.parseJSON(res); |
| 1283 | $(".form-loader-count").css("width", "0px"); |
| 1284 | if (res.status == '1') { |
| 1285 | isKeyActive = parseInt(res.is_key_active); |
| 1286 | n_o_file = parseInt(res.folders); |
| 1287 | $("#current-folder").text(n_o_file); |
| 1288 | for(i=0; i<res.term_ids.length; i++) { |
| 1289 | $('#js-tree-menu').jstree().delete_node(res.term_ids[i]); |
| 1290 | } |
| 1291 | |
| 1292 | $("#ttl-fldr").text((4*2)+(4/2)); |
| 1293 | // add_menu_to_list(); |
| 1294 | ajaxAnimation(); |
| 1295 | $(".folder-popup-form").hide(); |
| 1296 | $(".folder-popup-form").removeClass("disabled"); |
| 1297 | resetMediaAndPosts(); |
| 1298 | make_sticky_folder_menu(); |
| 1299 | |
| 1300 | ajaxAnimation(); |
| 1301 | |
| 1302 | check_for_sub_menu(); |
| 1303 | |
| 1304 | if(!$("#wcp_folder_"+activeRecordID).length) { |
| 1305 | $(".header-posts a").trigger("click"); |
| 1306 | activeRecordID = 0; |
| 1307 | } |
| 1308 | } else { |
| 1309 | window.location.reload(); |
| 1310 | } |
| 1311 | $("#folder-hide-show-checkbox").attr("checked", false); |
| 1312 | $("#js-tree-menu input.checkbox").attr("checked", false); |
| 1313 | $("#js-tree-menu").removeClass("show-folder-checkbox"); |
| 1314 | } |
| 1315 | }); |
| 1316 | } else { |
| 1317 | |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | function removeFolderFromID(popup_type) { |
| 1323 | var removeMessage = "Are you sure you want to delete the selected folder?"; |
| 1324 | var removeNotice = "Items in the folder will not be deleted."; |
| 1325 | isMultipleRemove = false; |
| 1326 | if(popup_type == 1) { |
| 1327 | if($("#folder-hide-show-checkbox").is(":checked")) { |
| 1328 | isMultipleRemove = true; |
| 1329 | if($("#js-tree-menu input.checkbox:checked").length == 0) { |
| 1330 | $(".folder-popup-form").hide(); |
| 1331 | $(".folder-popup-form").removeClass("disabled"); |
| 1332 | $("#error-folder-popup-message").html("Please select at least one folder to delete"); |
| 1333 | $("#error-folder-popup").show(); |
| 1334 | return; |
| 1335 | } else { |
| 1336 | if($("#js-tree-menu input.checkbox:checked").length > 1) { |
| 1337 | removeMessage = "Are you sure you want to delete the selected folders?"; |
| 1338 | removeNotice = "Items in the selected folders will not be deleted."; |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | $(".folder-popup-form").hide(); |
| 1344 | $(".folder-popup-form").removeClass("disabled"); |
| 1345 | $("#remove-folder-item").text("Yes, Delete it!"); |
| 1346 | $("#remove-folder-message").text(removeMessage); |
| 1347 | $("#remove-folder-notice").text(removeNotice); |
| 1348 | $("#confirm-remove-folder").show(); |
| 1349 | $("#remove-folder-item").focus(); |
| 1350 | } |
| 1351 | |
| 1352 | $(document).ready(function(){ |
| 1353 | $(".mark-folder").livequery(function(){ |
| 1354 | $(this).click(function(e){ |
| 1355 | e.stopPropagation(); |
| 1356 | if($(this).closest("li.jstree-node").length) { |
| 1357 | folderID = $(this).closest("li.jstree-node").attr("id"); |
| 1358 | } else { |
| 1359 | folderID = $(this).closest("li.sticky-fldr").data("folder-id"); |
| 1360 | } |
| 1361 | nonce = getSettingForPost(folderID, 'nonce'); |
| 1362 | $(".form-loader-count").css("width","100%"); |
| 1363 | $(".dynamic-menu").remove(); |
| 1364 | $(".active-menu").removeClass("active-menu"); |
| 1365 | $.ajax({ |
| 1366 | url: wcp_settings.ajax_url, |
| 1367 | data: "term_id=" + folderID + "&type=" + wcp_settings.post_type + "&action=wcp_mark_un_mark_folder&nonce="+nonce, |
| 1368 | method: 'post', |
| 1369 | cache: false, |
| 1370 | success: function (res) { |
| 1371 | res = $.parseJSON(res); |
| 1372 | $(".form-loader-count").css("width","0%"); |
| 1373 | if (res.status == '1') { |
| 1374 | folderPostId = getIndexForPostSetting(res.id); |
| 1375 | if(res.marked == '1') { |
| 1376 | $("li.jstree-node[id='"+res.id+"']").addClass("is-high"); |
| 1377 | $(".sticky-folder-"+res.id).addClass("is-high"); |
| 1378 | if(folderPostId != null) { |
| 1379 | folderPropertyArray[folderPostId]['is_high'] = 1; |
| 1380 | } |
| 1381 | } else { |
| 1382 | $("li.jstree-node[id='"+res.id+"']").removeClass("is-high"); |
| 1383 | $(".sticky-folder-"+res.id).removeClass("is-high"); |
| 1384 | if(folderPostId != null) { |
| 1385 | folderPropertyArray[folderPostId]['is_high'] = 0; |
| 1386 | } |
| 1387 | } |
| 1388 | add_menu_to_list(); |
| 1389 | ajaxAnimation(); |
| 1390 | } else { |
| 1391 | $(".folder-popup-form").hide(); |
| 1392 | $(".folder-popup-form").removeClass("disabled"); |
| 1393 | $("#error-folder-popup-message").html(res.message); |
| 1394 | $("#error-folder-popup").show(); |
| 1395 | } |
| 1396 | } |
| 1397 | }); |
| 1398 | }); |
| 1399 | }); |
| 1400 | }); |
| 1401 | |
| 1402 | /* change folder status */ |
| 1403 | $(document).ready(function(){ |
| 1404 | $(".jstree-node .jstree-icon").livequery(function(){ |
| 1405 | $(this).click(function(){ |
| 1406 | folderID = $(this).closest("li.jstree-node").attr("id"); |
| 1407 | if($("li.jstree-node[id='"+folderID+"']").hasClass("jstree-open")) { |
| 1408 | folderStatus = 0; |
| 1409 | } else { |
| 1410 | folderStatus = 1; |
| 1411 | } |
| 1412 | $(".form-loader-count").css("width","100%"); |
| 1413 | nonce = getSettingForPost(folderID, 'nonce'); |
| 1414 | checkForExpandCollapse(); |
| 1415 | $.ajax({ |
| 1416 | url: wcp_settings.ajax_url, |
| 1417 | data: "is_active=" + folderStatus + "&action=save_wcp_folder_state&term_id=" + folderID+"&nonce="+nonce, |
| 1418 | method: 'post', |
| 1419 | success: function (res) { |
| 1420 | $(".form-loader-count").css("width","0"); |
| 1421 | res = $.parseJSON(res); |
| 1422 | if(res.status == "0") { |
| 1423 | // $(".folder-popup-form").hide(); |
| 1424 | // $(".folder-popup-form").removeClass("disabled"); |
| 1425 | // $("#error-folder-popup-message").html(res.message); |
| 1426 | // $("#error-folder-popup").show(); |
| 1427 | } else { |
| 1428 | if($("#wcp_folder_"+folderID).hasClass("active")) { |
| 1429 | $("#wcp_folder_"+folderID).removeClass("active"); |
| 1430 | $("#wcp_folder_"+folderID).find("ul.ui-sortable:first-child > li").slideUp(); |
| 1431 | folderStatus = 0; |
| 1432 | } else { |
| 1433 | $("#wcp_folder_"+folderID).addClass("active"); |
| 1434 | $("#wcp_folder_"+folderID).find("ul.ui-sortable:first-child > li").slideDown(); |
| 1435 | folderStatus = 1; |
| 1436 | } |
| 1437 | ajaxAnimation(); |
| 1438 | } |
| 1439 | } |
| 1440 | }); |
| 1441 | }); |
| 1442 | }); |
| 1443 | }); |
| 1444 | |
| 1445 | /* refresh listing on click */ |
| 1446 | $(document).ready(function(){ |
| 1447 | $(document).on("click", "a.jstree-anchor", function(e) { |
| 1448 | e.stopPropagation(); |
| 1449 | $(".un-categorised-items").removeClass("active-item"); |
| 1450 | $(".header-posts a").removeClass("active-item"); |
| 1451 | $("active-item").removeClass("active-item"); |
| 1452 | activeRecordID = $(this).closest("li.jstree-node").attr("id"); |
| 1453 | fileFolderID = $(this).closest("li.jstree-node").attr("id"); |
| 1454 | $(".sticky-folders .sticky-folder-"+activeRecordID+" a").addClass("active-item"); |
| 1455 | if(!$("#media-attachment-taxonomy-filter").length) { |
| 1456 | var folderSlug = getSettingForPost(activeRecordID, 'slug'); |
| 1457 | folderCurrentURL = wcp_settings.page_url + folderSlug; |
| 1458 | $(".form-loader-count").css("width", "100%"); |
| 1459 | if($("#folder-posts-filter").length) { |
| 1460 | $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){ |
| 1461 | var obj = { Title: folderSlug, Url: folderCurrentURL }; |
| 1462 | history.pushState(obj, obj.Title, obj.Url); |
| 1463 | set_default_folders(folderSlug); |
| 1464 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 1465 | $(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 1466 | } |
| 1467 | triggerInlineUpdate(); |
| 1468 | }); |
| 1469 | } else { |
| 1470 | $("#wpbody").load(folderCurrentURL + " #wpbody-content", function(){ |
| 1471 | var obj = { Title: folderSlug, Url: folderCurrentURL }; |
| 1472 | history.pushState(obj, obj.Title, obj.Url); |
| 1473 | set_default_folders(folderSlug); |
| 1474 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 1475 | $(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 1476 | } |
| 1477 | triggerInlineUpdate(); |
| 1478 | }); |
| 1479 | } |
| 1480 | } else { |
| 1481 | var thisIndex = $(this).closest("li.jstree-node").attr("id"); |
| 1482 | $("#media-attachment-taxonomy-filter").val(thisIndex); |
| 1483 | $("#media-attachment-taxonomy-filter").trigger("change"); |
| 1484 | thisSlug = getSettingForPost(thisIndex, 'slug'); |
| 1485 | folderCurrentURL = wcp_settings.page_url + thisSlug; |
| 1486 | var obj = { Title: thisSlug, Url: folderCurrentURL }; |
| 1487 | history.pushState(obj, obj.Title, obj.Url); |
| 1488 | set_default_folders(thisSlug); |
| 1489 | $(".custom-media-select").removeClass("active"); |
| 1490 | } |
| 1491 | add_active_item_to_list(); |
| 1492 | $(".sticky-folders .sticky-folder-"+activeRecordID+" a").addClass("active-item"); |
| 1493 | }); |
| 1494 | |
| 1495 | $(".header-posts").click(function(){ |
| 1496 | activeRecordID = ""; |
| 1497 | $(".wcp-container .route").removeClass("active-item"); |
| 1498 | $(".un-categorised-items").removeClass("active-item"); |
| 1499 | $(".sticky-folders .active-item").removeClass("active-item"); |
| 1500 | $(".header-posts a").addClass("active-item"); |
| 1501 | $(".jstree-clicked").removeClass("jstree-clicked"); |
| 1502 | if(!$("#media-attachment-taxonomy-filter").length) { |
| 1503 | folderCurrentURL = wcp_settings.page_url; |
| 1504 | $(".form-loader-count").css("width", "100%"); |
| 1505 | if($("#folder-posts-filter").length) { |
| 1506 | $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){ |
| 1507 | var obj = { Title: "", Url: folderCurrentURL }; |
| 1508 | history.pushState(obj, obj.Title, obj.Url); |
| 1509 | set_default_folders("all"); |
| 1510 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 1511 | $(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 1512 | } |
| 1513 | add_active_item_to_list(); |
| 1514 | triggerInlineUpdate(); |
| 1515 | }); |
| 1516 | } else { |
| 1517 | $("#wpbody").load(folderCurrentURL + " #wpbody-content", function(){ |
| 1518 | var obj = { Title: "", Url: folderCurrentURL }; |
| 1519 | history.pushState(obj, obj.Title, obj.Url); |
| 1520 | set_default_folders("all"); |
| 1521 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 1522 | $(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 1523 | } |
| 1524 | add_active_item_to_list(); |
| 1525 | triggerInlineUpdate(); |
| 1526 | }); |
| 1527 | } |
| 1528 | } else { |
| 1529 | activeRecordID = ""; |
| 1530 | $("#media-attachment-taxonomy-filter").val("all"); |
| 1531 | $("#media-attachment-taxonomy-filter").trigger("change"); |
| 1532 | var obj = { Title: "", Url: wcp_settings.page_url }; |
| 1533 | history.pushState(obj, obj.Title, obj.Url); |
| 1534 | set_default_folders("all"); |
| 1535 | add_active_item_to_list(); |
| 1536 | } |
| 1537 | }); |
| 1538 | |
| 1539 | $(".un-categorised-items").click(function(){ |
| 1540 | activeRecordID = "-1"; |
| 1541 | $(".wcp-container .route").removeClass("active-item"); |
| 1542 | $(".header-posts a").removeClass("active-item"); |
| 1543 | $(".un-categorised-items").addClass("active-item"); |
| 1544 | $(".sticky-folders .active-item").removeClass("active-item"); |
| 1545 | $(".jstree-clicked").removeClass("jstree-clicked"); |
| 1546 | if(!$("#media-attachment-taxonomy-filter").length) { |
| 1547 | folderCurrentURL = wcp_settings.page_url+"-1"; |
| 1548 | $(".form-loader-count").css("width", "100%"); |
| 1549 | if($("#folder-posts-filter").length) { |
| 1550 | $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){ |
| 1551 | var obj = { Title: "", Url: folderCurrentURL }; |
| 1552 | history.pushState(obj, obj.Title, obj.Url); |
| 1553 | set_default_folders("-1"); |
| 1554 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 1555 | $(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 1556 | } |
| 1557 | add_active_item_to_list(); |
| 1558 | triggerInlineUpdate(); |
| 1559 | }); |
| 1560 | } else { |
| 1561 | $("#wpbody").load(folderCurrentURL + " #wpbody-content", function(){ |
| 1562 | var obj = { Title: "", Url: folderCurrentURL }; |
| 1563 | history.pushState(obj, obj.Title, obj.Url); |
| 1564 | set_default_folders("-1"); |
| 1565 | if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) { |
| 1566 | $(".wp-header-end").before('<div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div>'); |
| 1567 | } |
| 1568 | add_active_item_to_list(); |
| 1569 | triggerInlineUpdate(); |
| 1570 | }); |
| 1571 | } |
| 1572 | } else { |
| 1573 | $("#media-attachment-taxonomy-filter").val("unassigned"); |
| 1574 | $("#media-attachment-taxonomy-filter").trigger("change"); |
| 1575 | var obj = { Title: "", Url: wcp_settings.page_url+"-1" }; |
| 1576 | history.pushState(obj, obj.Title, obj.Url); |
| 1577 | set_default_folders("-1"); |
| 1578 | add_active_item_to_list(); |
| 1579 | } |
| 1580 | }); |
| 1581 | |
| 1582 | /* Expand/Collapse */ |
| 1583 | $("#expand-collapse-list").click(function(e){ |
| 1584 | e.stopPropagation(); |
| 1585 | statusType = 0; |
| 1586 | if($(this).hasClass("all-open")) { |
| 1587 | $(this).removeClass("all-open"); |
| 1588 | statusType = 0; |
| 1589 | $(this).attr("data-folder-tooltip","Expand"); |
| 1590 | $("#js-tree-menu").jstree("close_all"); |
| 1591 | } else { |
| 1592 | $(this).addClass("all-open"); |
| 1593 | statusType = 1; |
| 1594 | $(this).attr("data-folder-tooltip","Collapse"); |
| 1595 | $("#js-tree-menu").jstree("open_all"); |
| 1596 | } |
| 1597 | folderIDs = ""; |
| 1598 | $("#js-tree-menu .jstree-node:not(.jstree-leaf)").each(function(){ |
| 1599 | folderIDs += $(this).attr("id")+","; |
| 1600 | }); |
| 1601 | if(folderIDs != "") { |
| 1602 | $(".form-loader-count").css("width","100%"); |
| 1603 | nonce = wcp_settings.nonce; |
| 1604 | $.ajax({ |
| 1605 | url: wcp_settings.ajax_url, |
| 1606 | data: "type=" + wcp_settings.post_type + "&action=wcp_change_all_status&status=" + statusType + "&folders="+folderIDs+"&nonce="+nonce, |
| 1607 | method: 'post', |
| 1608 | success: function (res) { |
| 1609 | $(".form-loader-count").css("width","0"); |
| 1610 | res = $.parseJSON(res); |
| 1611 | if(res.status == "0") { |
| 1612 | $(".folder-popup-form").hide(); |
| 1613 | $(".folder-popup-form").removeClass("disabled"); |
| 1614 | $("#error-folder-popup-message").html(res.message); |
| 1615 | $("#error-folder-popup").show(); |
| 1616 | window.location.reload(true); |
| 1617 | } |
| 1618 | } |
| 1619 | }); |
| 1620 | } |
| 1621 | }); |
| 1622 | |
| 1623 | checkForExpandCollapse(); |
| 1624 | }); |
| 1625 | |
| 1626 | function initJSTree() { |
| 1627 | $(treeId).jstree({ |
| 1628 | "core": { |
| 1629 | 'cache':false, |
| 1630 | "animation": 0, |
| 1631 | // "check_callback": true, |
| 1632 | check_callback: function(e, t, n, r, o) { |
| 1633 | $("*").removeClass("drag-bot").removeClass("drag-in").removeClass("drag-up"); |
| 1634 | if (("move_node" === e || "copy_node" === e) && o && o.dnd) |
| 1635 | switch (o.pos) { |
| 1636 | case "a": |
| 1637 | o.origin.get_node(o.ref, !0).addClass("drag-bot"); |
| 1638 | nodeId = $(".drag-bot").attr("id"); |
| 1639 | $("#jstree-dnd").text("Below "+$.trim($("#js-tree-menu").jstree(true).get_node(nodeId).text)); |
| 1640 | break; |
| 1641 | case "i": |
| 1642 | o.origin.get_node(o.ref, !0).addClass("drag-in"); |
| 1643 | nodeId = $(".drag-in").attr("id"); |
| 1644 | $("#jstree-dnd").text("Inside "+$.trim($("#js-tree-menu").jstree(true).get_node(nodeId).text)); |
| 1645 | break; |
| 1646 | case "b": |
| 1647 | o.origin.get_node(o.ref, !0).addClass("drag-up"); |
| 1648 | nodeId = $(".drag-up").attr("id"); |
| 1649 | $("#jstree-dnd").text("Above "+$.trim($("#js-tree-menu").jstree(true).get_node(nodeId).text)); |
| 1650 | break; |
| 1651 | default: |
| 1652 | $("#jstree-dnd").text($("#jstree-dnd").data("txt")); |
| 1653 | break; |
| 1654 | } |
| 1655 | return !0 |
| 1656 | } |
| 1657 | }, |
| 1658 | data: { |
| 1659 | cache : false |
| 1660 | }, |
| 1661 | select_node: false, |
| 1662 | search: { |
| 1663 | show_only_matches: true, |
| 1664 | case_sensitive: false, |
| 1665 | fuzzy: false |
| 1666 | }, |
| 1667 | plugins: ["dnd", "search", "contextmenu"], |
| 1668 | contextmenu: { |
| 1669 | select_node: 0, |
| 1670 | show_at_node: 0, |
| 1671 | items: function() { |
| 1672 | return {}; |
| 1673 | } |
| 1674 | } |
| 1675 | }).bind("ready.jstree", (function() { |
| 1676 | setFolderCount(); |
| 1677 | })).bind("move_node.jstree", (function(t, n) { |
| 1678 | folderMoveId = n.node.id; |
| 1679 | orderString = ""; |
| 1680 | $(".jstree-node[id='"+folderMoveId+"']").closest("ul").children().each(function(){ |
| 1681 | if($(this).attr("id") != 'undefined') { |
| 1682 | orderString += $(this).attr("id") + ","; |
| 1683 | } |
| 1684 | }); |
| 1685 | if($("#"+folderMoveId+"_anchor").closest(".jstree-node").parent().parent().hasClass("jstree-node")) { |
| 1686 | parentID = $("#"+folderMoveId+"_anchor").closest(".jstree-node").parent().parent().attr("id"); |
| 1687 | } else { |
| 1688 | parentID = 0; |
| 1689 | } |
| 1690 | if(orderString != "") { |
| 1691 | $(".form-loader-count").css("width","100%"); |
| 1692 | $.ajax({ |
| 1693 | url: wcp_settings.ajax_url, |
| 1694 | data: "term_ids=" + orderString + "&action=wcp_save_folder_order&type=" + wcp_settings.post_type+"&nonce="+wcp_settings.nonce+"&term_id="+folderMoveId+"&parent_id="+parentID, |
| 1695 | method: 'post', |
| 1696 | success: function (res) { |
| 1697 | res = $.parseJSON(res); |
| 1698 | if (res.status == '1') { |
| 1699 | $("#wcp_folder_parent").html(res.options); |
| 1700 | $(".form-loader-count").css("width", "0"); |
| 1701 | resetMediaAndPosts(); |
| 1702 | ajaxAnimation(); |
| 1703 | setFolderCountAndDD(); |
| 1704 | } else { |
| 1705 | $(".folder-popup-form").hide(); |
| 1706 | $(".folder-popup-form").removeClass("disabled"); |
| 1707 | $("#error-folder-popup-message").html(res.message); |
| 1708 | $("#error-folder-popup").show(); |
| 1709 | window.location.reload(true); |
| 1710 | } |
| 1711 | } |
| 1712 | }); |
| 1713 | } |
| 1714 | })); |
| 1715 | } |
| 1716 | |
| 1717 | /* sorting folders */ |
| 1718 | $(document).ready(function(){ |
| 1719 | $(document).on("click", "body, html", function(){ |
| 1720 | $(".folder-order").removeClass("active"); |
| 1721 | }); |
| 1722 | |
| 1723 | $(document).on("click", "#sort-order-list", function(e){ |
| 1724 | e.stopPropagation(); |
| 1725 | $(".folder-order").toggleClass("active"); |
| 1726 | }); |
| 1727 | |
| 1728 | $(document).on("click", ".folder-sort-menu a", function(e) { |
| 1729 | e.stopPropagation(); |
| 1730 | e.preventDefault(); |
| 1731 | $(".form-loader-count").css("width", "100%"); |
| 1732 | $(".folder-order").removeClass("active"); |
| 1733 | lastOrderStatus = $(this).attr("data-sort"); |
| 1734 | $.ajax({ |
| 1735 | url: wcp_settings.ajax_url, |
| 1736 | data: "type=" + wcp_settings.post_type + "&action=wcp_folders_by_order&nonce=" + wcp_settings.nonce+"&order="+$(this).attr("data-sort"), |
| 1737 | method: 'post', |
| 1738 | success: function (res) { |
| 1739 | res = $.parseJSON(res); |
| 1740 | if(res.status == 1) { |
| 1741 | $("#js-tree-menu").jstree().destroy(); |
| 1742 | $("#js-tree-menu").append("<ul></ul>"); |
| 1743 | $("#js-tree-menu ul").html(res.data); |
| 1744 | initJSTree(); |
| 1745 | foldersArray = res.terms; |
| 1746 | setFolderCountAndDD(); |
| 1747 | } |
| 1748 | $(".form-loader-count").css("width", "0"); |
| 1749 | add_active_item_to_list(); |
| 1750 | } |
| 1751 | }); |
| 1752 | }); |
| 1753 | }); |
| 1754 | |
| 1755 | /* Search functionality */ |
| 1756 | $(document).ready(function(){ |
| 1757 | $(document).on("keyup", "#folder-search", function(){ |
| 1758 | checkForFolderSearch(); |
| 1759 | }); |
| 1760 | |
| 1761 | $(document).on("change", "#folder-search", function(){ |
| 1762 | checkForFolderSearch(); |
| 1763 | }); |
| 1764 | |
| 1765 | $(document).on("blur", "#folder-search", function(){ |
| 1766 | checkForFolderSearch(); |
| 1767 | }); |
| 1768 | }); |
| 1769 | |
| 1770 | function checkForFolderSearch() { |
| 1771 | var searchVal = $.trim($("#folder-search").val()); |
| 1772 | $('#js-tree-menu').jstree('search', searchVal); |
| 1773 | } |
| 1774 | |
| 1775 | /* checkbox library */ |
| 1776 | $(document).ready(function(){ |
| 1777 | $(".wcp-move-file").livequery(function(){ |
| 1778 | $(this).draggable({ |
| 1779 | revert: "invalid", |
| 1780 | containment: "document", |
| 1781 | helper: "clone", |
| 1782 | cursor: "move", |
| 1783 | start: function( event, ui){ |
| 1784 | $(this).closest("td").addClass("wcp-draggable"); |
| 1785 | $("body").addClass("no-hover-css"); |
| 1786 | }, |
| 1787 | stop: function( event, ui ) { |
| 1788 | $(this).closest("td").removeClass("wcp-draggable"); |
| 1789 | $("body").removeClass("no-hover-css"); |
| 1790 | } |
| 1791 | }); |
| 1792 | }); |
| 1793 | |
| 1794 | $(".wcp-move-multiple").livequery(function(){ |
| 1795 | $(this).draggable({ |
| 1796 | // /*cancel: "a.ui-icon",*/ |
| 1797 | // revert: "invalid", |
| 1798 | // containment: "document", |
| 1799 | // helper: "clone", |
| 1800 | // cursor: "move", |
| 1801 | // start: function( event, ui){ |
| 1802 | // $("body").addClass("no-hover-css"); |
| 1803 | // }, |
| 1804 | // stop: function( event, ui ) { |
| 1805 | // $("body").removeClass("no-hover-css"); |
| 1806 | // } |
| 1807 | revert: "invalid", |
| 1808 | containment: "document", |
| 1809 | helper: function (event, ui) { |
| 1810 | $(".selected-items").remove(); |
| 1811 | selectedItems = $("#the-list th input:checked").length; |
| 1812 | if(selectedItems > 0) { |
| 1813 | selectedItems = (selectedItems == 0 || selectedItems == 1) ? "1 Item" : selectedItems + " Items"; |
| 1814 | return $("<div class='selected-items'><span class='total-post-count'>" + selectedItems + " Selected</span></div>"); |
| 1815 | } else { |
| 1816 | return $("<div class='selected-items'><span class='total-post-count'>Select Items to move</span></div>"); |
| 1817 | } |
| 1818 | }, |
| 1819 | start: function( event, ui){ |
| 1820 | $("body").addClass("no-hover-css"); |
| 1821 | }, |
| 1822 | cursor: "move", |
| 1823 | cursorAt: { |
| 1824 | left: 0, |
| 1825 | top: 0 |
| 1826 | }, |
| 1827 | stop: function( event, ui ) { |
| 1828 | $(".selected-items").remove(); |
| 1829 | $("body").removeClass("no-hover-css"); |
| 1830 | } |
| 1831 | }); |
| 1832 | }); |
| 1833 | |
| 1834 | $(document).on("click", ".folders-toggle-button", function(){ |
| 1835 | dbStatus = 'show'; |
| 1836 | if($(".tree-structure-content").hasClass("active")) { |
| 1837 | $(".tree-structure-content .tree-structure").animate({ |
| 1838 | height: '40px' |
| 1839 | }, 100, function(){ |
| 1840 | $(".tree-structure-content").removeClass("active"); |
| 1841 | }); |
| 1842 | dbStatus = 'hide'; |
| 1843 | } else { |
| 1844 | newHeight = parseInt($(".tree-structure-content .tree-structure").attr("data-height")); |
| 1845 | $(".tree-structure-content .tree-structure").animate({ |
| 1846 | height: newHeight |
| 1847 | }, 100, function(){ |
| 1848 | $(".tree-structure-content").addClass("active"); |
| 1849 | }); |
| 1850 | } |
| 1851 | $.ajax({ |
| 1852 | url: wcp_settings.ajax_url, |
| 1853 | data: "type=" + wcp_settings.post_type + "&action=wcp_hide_folders&status=" + dbStatus +"&nonce="+wcp_settings.nonce, |
| 1854 | method: 'post', |
| 1855 | success: function (res) { |
| 1856 | setStickyHeaderForMedia(); |
| 1857 | } |
| 1858 | }); |
| 1859 | }); |
| 1860 | }); |
| 1861 | |
| 1862 | function set_default_folders(post_id) { |
| 1863 | $.ajax({ |
| 1864 | url: wcp_settings.ajax_url, |
| 1865 | type: 'post', |
| 1866 | data: 'action=save_folder_last_status&post_type='+wcp_settings.post_type+"&post_id="+post_id+"&nonce="+wcp_settings.nonce, |
| 1867 | cache: false, |
| 1868 | async: false, |
| 1869 | success: function(){ |
| 1870 | |
| 1871 | } |
| 1872 | }) |
| 1873 | } |
| 1874 | |
| 1875 | /* Extra functions */ |
| 1876 | function checkForExpandCollapse() { |
| 1877 | setTimeout(function(){ |
| 1878 | currentStatus = true; |
| 1879 | if($("#js-tree-menu .jstree-node.jstree-leaf").length == $("#js-tree-menu .jstree-node").length) { |
| 1880 | $("#expand-collapse-list").removeClass("all-open"); |
| 1881 | $("#expand-collapse-list").attr("data-folder-tooltip","Expand"); |
| 1882 | } else { |
| 1883 | var totalChild = $("#js-tree-menu .jstree-node.jstree-closed").length + $("#js-tree-menu .jstree-node.jstree-open").length; |
| 1884 | if($("#js-tree-menu .jstree-node.jstree-closed").length == totalChild) { |
| 1885 | $("#expand-collapse-list").removeClass("all-open"); |
| 1886 | $("#expand-collapse-list").attr("data-folder-tooltip","Expand"); |
| 1887 | } else { |
| 1888 | $("#expand-collapse-list").addClass("all-open"); |
| 1889 | $("#expand-collapse-list").attr("data-folder-tooltip","Collapse"); |
| 1890 | } |
| 1891 | } |
| 1892 | }, 500); |
| 1893 | } |
| 1894 | |
| 1895 | function apply_animation_height() { |
| 1896 | if($(".tree-structure-content .tree-structure li").length == 0) { |
| 1897 | $(".tree-structure-content").hide(); |
| 1898 | } else { |
| 1899 | $(".tree-structure-content").show(); |
| 1900 | oldHeight = $(".tree-structure-content .tree-structure").height(); |
| 1901 | $(".tree-structure-content .tree-structure").height("auto"); |
| 1902 | if($(".tree-structure-content .tree-structure").height() > 56) { |
| 1903 | $(".folders-toggle-button").show(); |
| 1904 | } else { |
| 1905 | $(".folders-toggle-button").hide(); |
| 1906 | } |
| 1907 | newHeight = $(".tree-structure-content .tree-structure").height(); |
| 1908 | $(".tree-structure-content .tree-structure").attr("data-height", newHeight); |
| 1909 | |
| 1910 | if($(".tree-structure-content").hasClass("active")) { |
| 1911 | $(".tree-structure-content .tree-structure").height(newHeight); |
| 1912 | $(".tree-structure-content .tree-structure").attr("data-height", newHeight); |
| 1913 | } else { |
| 1914 | $(".tree-structure-content .tree-structure").height(oldHeight); |
| 1915 | } |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | function ajaxAnimation() { |
| 1920 | $(".folder-loader-ajax").addClass("active"); |
| 1921 | $(".folder-loader-ajax img").removeClass("active"); |
| 1922 | $(".folder-loader-ajax svg#successAnimation").addClass("active").addClass("animated"); |
| 1923 | setTimeout(function(){ |
| 1924 | $(".folder-loader-ajax").removeClass("active"); |
| 1925 | $(".folder-loader-ajax img").addClass("active"); |
| 1926 | $(".folder-loader-ajax svg#successAnimation").removeClass("active").removeClass("animated"); |
| 1927 | }, 2000); |
| 1928 | } |
| 1929 | |
| 1930 | function make_sticky_folder_menu() { |
| 1931 | $(".sticky-folders > ul").html(""); |
| 1932 | var stickyMenuHtml = ""; |
| 1933 | |
| 1934 | $("#js-tree-menu li.jstree-node.is-sticky").each(function(){ |
| 1935 | var folder_ID = $(this).attr("id"); |
| 1936 | var folderName = $.trim($("#js-tree-menu").jstree(true).get_node(folder_ID).text); |
| 1937 | var folderCount = $("li.jstree-node[id='"+folder_ID+"'] > a span.premio-folder-count").text(); |
| 1938 | var hasStar = $("li.jstree-node[id='"+folder_ID+"']").hasClass("is-high")?" is-high ":""; |
| 1939 | stickyMenuHtml += "<li data-folder-id='"+folder_ID+"' class='sticky-fldr "+hasStar+" sticky-folder-"+folder_ID+"'>" + |
| 1940 | "<a href='javascript:;'>" + |
| 1941 | "<span class='folder-title'>"+folderName+"</span>" + |
| 1942 | "<span class='folder-actions'>" + |
| 1943 | "<span class='update-inline-record'><i class='pfolder-edit-folder'></i></span>" + |
| 1944 | "<span class='star-icon'><i class='pfolder-star'></i></span>" + |
| 1945 | "<span class='premio-folder-count'>"+folderCount+"</span>" + |
| 1946 | "</span>"+ |
| 1947 | "</a>" + |
| 1948 | "</li>"; |
| 1949 | }); |
| 1950 | $(".sticky-folders > ul").html(stickyMenuHtml); |
| 1951 | if($(".jstree-anchor.jstree-clicked").length) { |
| 1952 | var activeTermId = $(".jstree-anchor.jstree-clicked").closest("li.jstree-node").attr("id"); |
| 1953 | $(".sticky-folders .sticky-folder-"+activeTermId+" a").addClass("active-item"); |
| 1954 | } |
| 1955 | |
| 1956 | if($(".sticky-folders > ul > li").length > 0) { |
| 1957 | $(".sticky-folders").addClass("active"); |
| 1958 | } else { |
| 1959 | $(".sticky-folders").removeClass("active"); |
| 1960 | } |
| 1961 | |
| 1962 | setCustomScrollForFolder(); |
| 1963 | } |
| 1964 | |
| 1965 | function setFolderCountAndDD() { |
| 1966 | if($("#media-attachment-taxonomy-filter").length) { |
| 1967 | $("#media-attachment-taxonomy-filter").each(function(){ |
| 1968 | folders_media_options.terms = foldersArray; |
| 1969 | var selectedDD = $(this); |
| 1970 | currentDDVal = $(this).val(); |
| 1971 | selectedDD.html("<option value='all'>All Folders</option><option value='unassigned'>(Unassigned)</option>"); |
| 1972 | lastFolderData = foldersArray; |
| 1973 | for (var i = 0; i < foldersArray.length; i++) { |
| 1974 | selectedDD.append("<option value='" + foldersArray[i].term_id + "'>" + foldersArray[i].name + " (" + foldersArray[i].trash_count + ")</option>"); |
| 1975 | } |
| 1976 | selectedDD.val(currentDDVal).trigger("change"); |
| 1977 | }); |
| 1978 | if($("select.folder_for_media").length) { |
| 1979 | var selectedVal = $("select.folder_for_media").val(); |
| 1980 | $("select.folder_for_media option:not(:first-child):not(:last-child)").remove(); |
| 1981 | for (var i = 0; i < foldersArray.length; i++) { |
| 1982 | $("select.folder_for_media option:last-child").before("<option value='" + foldersArray[i].term_id + "'>" + foldersArray[i].name +"</option>"); |
| 1983 | } |
| 1984 | if(selectedVal != "") { |
| 1985 | $(".folder_for_media").val(selectedVal); |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | $("span.premio-folder-count").text(""); |
| 1990 | $(".folder-count").text(""); |
| 1991 | for (i = 0; i < foldersArray.length; i++) { |
| 1992 | if(parseInt(foldersArray[i].trash_count) != 0) { |
| 1993 | $(".jstree-node[id='" + foldersArray[i].term_id + "'] > a.jstree-anchor span.premio-folder-count").text(foldersArray[i].trash_count); |
| 1994 | $(".sticky-folder-"+foldersArray[i].term_id+" .premio-folder-count").text(foldersArray[i].trash_count); |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | if($(".media-select-folder").length) { |
| 1999 | $(".media-select-folder").html("<option value=''>Select Folder</option><option value='-1'>(Unassigned)</option>"); |
| 2000 | for (i = 0; i < foldersArray.length; i++) { |
| 2001 | $(".media-select-folder").append("<option value='" + foldersArray[i].term_id + "'>" + foldersArray[i].name + " (" + foldersArray[i].trash_count + ")</option>"); |
| 2002 | } |
| 2003 | $(".media-select-folder").val(""); |
| 2004 | } |
| 2005 | |
| 2006 | if(activeRecordID != "") { |
| 2007 | $("#wcp_folder_"+activeRecordID).addClass("active-item"); |
| 2008 | } |
| 2009 | |
| 2010 | if(isItFromMedia) { |
| 2011 | $("#title_"+fileFolderID).trigger("click"); |
| 2012 | isItFromMedia = false; |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | if(wcp_settings.post_type == "attachment") { |
| 2017 | |
| 2018 | $(document).ready(function(){ |
| 2019 | if(wcp_settings.show_in_page == "show") { |
| 2020 | $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div><div class="folders-toggle-button"><span></span></div></div>'); |
| 2021 | } |
| 2022 | |
| 2023 | add_menu_to_list(); |
| 2024 | |
| 2025 | apply_animation_height(); |
| 2026 | }); |
| 2027 | |
| 2028 | $(window).on('load', function(){ |
| 2029 | $("button.button.media-button.select-mode-toggle-button").after("<button class='button organize-button'>Bulk Organize</button>"); |
| 2030 | $(".media-toolbar-secondary").append("<span class='media-info-message'>Drag and drop your media files to the relevant folders</span>"); |
| 2031 | $(".delete-selected-button").before("<button type='button' class='button button-primary select-all-item-btn'>Select All</button>"); |
| 2032 | $(".media-toolbar-secondary").after("<div class='custom-media-select'>Move Selected files to: <select class='media-select-folder'></select></div>"); |
| 2033 | $(".media-toolbar").append("<div style='clear:both;'></div><div class='media-folder-loader'><span>Uploading files</span> <span id='current_upload_files'></span>/<span id='total_upload_files'></span><div class='folder-progress'><div class='folder-meter orange-bg'><span></span></div></div></div>"); |
| 2034 | if($(".wcp-custom-form").length) { |
| 2035 | if (wp.Uploader !== undefined) { |
| 2036 | wp.Uploader.queue.on('reset', function () { |
| 2037 | resetMediaData(1); |
| 2038 | }); |
| 2039 | } |
| 2040 | $(document).ajaxComplete(function(ev, jqXHR, settings) { |
| 2041 | actionName = settings.data; |
| 2042 | if (typeof actionName != "undefined") { |
| 2043 | if (actionName.length && actionName.indexOf("action=delete-post&id=") == 0) { |
| 2044 | resetMediaData(0); |
| 2045 | } |
| 2046 | } |
| 2047 | }); |
| 2048 | } |
| 2049 | setTimeout(function(){ |
| 2050 | docReferrar = document.referrer; |
| 2051 | if(docReferrar.indexOf("wp-admin/upload.php") != -1) { |
| 2052 | mediaMode = getCookie("media-select-mode"); |
| 2053 | if (mediaMode == "on") { |
| 2054 | $("button.button.media-button.select-mode-toggle-button").trigger("click"); |
| 2055 | //$(".attachments-browser li.attachment").draggable("enable"); |
| 2056 | |
| 2057 | if ($(".media-frame").hasClass("mode-select")) { |
| 2058 | $(".media-info-message").addClass("active"); |
| 2059 | } else { |
| 2060 | $(".media-info-message, .custom-media-select").removeClass("active"); |
| 2061 | } |
| 2062 | } |
| 2063 | } else { |
| 2064 | eraseCookie("media-select-mode"); |
| 2065 | } |
| 2066 | resetMediaData(1); |
| 2067 | }, 1000); |
| 2068 | |
| 2069 | $(document).on("click", ".attachments-browser ul.attachments .thumbnail", function(){ |
| 2070 | if($(".media-toolbar").hasClass("media-toolbar-mode-select")) { |
| 2071 | if($("ul.attachments li.selected").length == 0) { |
| 2072 | $(".custom-media-select").removeClass("active"); |
| 2073 | } else { |
| 2074 | $(".custom-media-select").addClass("active"); |
| 2075 | } |
| 2076 | } |
| 2077 | }); |
| 2078 | |
| 2079 | $(document).on("change", ".media-select-folder", function(){ |
| 2080 | if($(this).val() != "") { |
| 2081 | var checkStr = ""; |
| 2082 | $(".attachments-browser li.attachment.selected").each(function(){ |
| 2083 | checkStr += $(this).attr("data-id")+","; |
| 2084 | }); |
| 2085 | if($(this).val() == "-1") { |
| 2086 | $.ajax({ |
| 2087 | url: wcp_settings.ajax_url, |
| 2088 | data: "post_id=" + checkStr + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + $(this).val() + "&nonce=" + wcp_settings.nonce +"&status="+wcp_settings.taxonomy_status+"&taxonomy="+activeRecordID, |
| 2089 | method: 'post', |
| 2090 | success: function (res) { |
| 2091 | if(fileFolderID != 0 && fileFolderID != $(".media-select-folder").val()) { |
| 2092 | $("ul.attachments li.selected").remove(); |
| 2093 | } |
| 2094 | resetMediaAndPosts(); |
| 2095 | ajaxAnimation(); |
| 2096 | } |
| 2097 | }); |
| 2098 | } else { |
| 2099 | nonce = getSettingForPost($(this).val(), 'nonce'); |
| 2100 | $.ajax({ |
| 2101 | url: wcp_settings.ajax_url, |
| 2102 | data: "post_ids=" + checkStr + "&type=" + wcp_settings.post_type + "&action=wcp_change_multiple_post_folder&folder_id=" + $(this).val() + "&nonce=" + nonce + "&status=" + wcp_settings.taxonomy_status + "&taxonomy=" + activeRecordID, |
| 2103 | method: 'post', |
| 2104 | success: function (res) { |
| 2105 | res = $.parseJSON(res); |
| 2106 | $("#bulk-move-folder").hide(); |
| 2107 | if (res.status == "1") { |
| 2108 | if(fileFolderID != 0 && fileFolderID != $(".media-select-folder").val()) { |
| 2109 | $("ul.attachments li.selected").remove(); |
| 2110 | } |
| 2111 | resetMediaAndPosts(); |
| 2112 | ajaxAnimation(); |
| 2113 | } else { |
| 2114 | $(".folder-popup-form").hide(); |
| 2115 | $(".folder-popup-form").removeClass("disabled"); |
| 2116 | $("#error-folder-popup-message").html(res.message); |
| 2117 | $("#error-folder-popup").show() |
| 2118 | } |
| 2119 | } |
| 2120 | }); |
| 2121 | } |
| 2122 | } |
| 2123 | }); |
| 2124 | }); |
| 2125 | |
| 2126 | var resetMediaFlag = null; |
| 2127 | |
| 2128 | function resetMediaData(loadData) { |
| 2129 | resetMediaFlag = $.ajax({ |
| 2130 | url: wcp_settings.ajax_url, |
| 2131 | data: "type=" + wcp_settings.post_type + "&action=wcp_get_default_list&active_id="+activeRecordID, |
| 2132 | method: 'post', |
| 2133 | beforeSend: function() { |
| 2134 | if(resetMediaFlag != null) { |
| 2135 | resetMediaFlag.abort(); |
| 2136 | } |
| 2137 | }, |
| 2138 | success: function (res) { |
| 2139 | res = $.parseJSON(res); |
| 2140 | // $("#js-tree-menu > ul#space_0").html(res.data); |
| 2141 | $(".header-posts .total-count").text(res.total_items); |
| 2142 | $(".un-categorised-items .total-count").text(res.empty_items); |
| 2143 | selectedVal = $("#media-attachment-taxonomy-filter").val(); |
| 2144 | if(selectedVal != "all" && loadData == 1) { |
| 2145 | var wp1 = parent.wp; |
| 2146 | if(wp1.media != undefined) { |
| 2147 | wp1.media.frame.setState('insert'); |
| 2148 | if (wp1.media.frame.content.get() !== null) { |
| 2149 | wp1.media.frame.content.get().collection.props.set({ignore: (+new Date())}); |
| 2150 | wp1.media.frame.content.get().options.selection.reset(); |
| 2151 | } else { |
| 2152 | wp1.media.frame.library.props.set({ignore: (+new Date())}); |
| 2153 | } |
| 2154 | } |
| 2155 | } |
| 2156 | foldersArray = res.taxonomies; |
| 2157 | setFolderCountAndDD(); |
| 2158 | |
| 2159 | if(activeRecordID != "") { |
| 2160 | $("#wcp_folder_"+activeRecordID).addClass("active-item"); |
| 2161 | } |
| 2162 | |
| 2163 | if(isItFromMedia) { |
| 2164 | $("#title_"+fileFolderID).trigger("click"); |
| 2165 | isItFromMedia = false; |
| 2166 | } |
| 2167 | } |
| 2168 | }); |
| 2169 | } |
| 2170 | |
| 2171 | function setMediaBoxWidth() { |
| 2172 | $(".media-frame-content .media-toolbar").width($(".media-frame-content").width() - 20); |
| 2173 | } |
| 2174 | |
| 2175 | setMediaBoxWidth(); |
| 2176 | |
| 2177 | $(window).resize(function(){ |
| 2178 | setMediaBoxWidth(); |
| 2179 | }); |
| 2180 | |
| 2181 | $(document).ready(function(){ |
| 2182 | |
| 2183 | }); |
| 2184 | |
| 2185 | $(document).on("click", ".button.organize-button", function(){ |
| 2186 | if(!$(".media-frame").hasClass("mode-select")) { |
| 2187 | setCookie("media-select-mode", "on", 7); |
| 2188 | } else { |
| 2189 | eraseCookie("media-select-mode"); |
| 2190 | } |
| 2191 | $("button.button.media-button.select-mode-toggle-button").trigger("click"); |
| 2192 | if($(".media-frame").hasClass("mode-select")) { |
| 2193 | $(".media-info-message").addClass("active"); |
| 2194 | $(".select-all-item-btn").addClass("active"); |
| 2195 | } else { |
| 2196 | $(".media-info-message, .custom-media-select").removeClass("active"); |
| 2197 | $(".select-all-item-btn").removeClass("active"); |
| 2198 | } |
| 2199 | }); |
| 2200 | |
| 2201 | $(document).on("click", ".select-mode-toggle-button", function(){ |
| 2202 | setTimeout(function() { |
| 2203 | if(!$(".media-frame").hasClass("mode-select")) { |
| 2204 | setCookie("media-select-mode", "off", -1); |
| 2205 | } |
| 2206 | if($(".media-frame").hasClass("mode-select")) { |
| 2207 | $(".media-info-message").addClass("active"); |
| 2208 | $(".select-all-item-btn").addClass("active"); |
| 2209 | } else { |
| 2210 | $(".media-info-message, .custom-media-select").removeClass("active"); |
| 2211 | $(".select-all-item-btn").removeClass("active"); |
| 2212 | } |
| 2213 | }, 10); |
| 2214 | }); |
| 2215 | |
| 2216 | $(document).on("click", ".select-all-item-btn", function(){ |
| 2217 | $("ul.attachments li:not(.selected)").trigger("click"); |
| 2218 | }); |
| 2219 | |
| 2220 | $(document).on("change", ".folder_for_media", function(){ |
| 2221 | if($(this).val() == "add-folder") { |
| 2222 | fileFolderID = 0; |
| 2223 | isItFromMedia = true; |
| 2224 | addFolder(); |
| 2225 | // $(".add-new-folder").trigger("click"); |
| 2226 | //$(this).val("-1"); |
| 2227 | } |
| 2228 | }); |
| 2229 | |
| 2230 | function setCookie(name,value,days) { |
| 2231 | var expires = ""; |
| 2232 | if (days) { |
| 2233 | var date = new Date(); |
| 2234 | date.setTime(date.getTime() + (days*24*60*60*1000)); |
| 2235 | expires = "; expires=" + date.toUTCString(); |
| 2236 | } |
| 2237 | document.cookie = name + "=" + (value || "") + expires + "; path=/"; |
| 2238 | } |
| 2239 | |
| 2240 | function getCookie(name) { |
| 2241 | var nameEQ = name + "="; |
| 2242 | var ca = document.cookie.split(';'); |
| 2243 | for(var i=0;i < ca.length;i++) { |
| 2244 | var c = ca[i]; |
| 2245 | while (c.charAt(0)==' ') c = c.substring(1,c.length); |
| 2246 | if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); |
| 2247 | } |
| 2248 | return null; |
| 2249 | } |
| 2250 | |
| 2251 | function eraseCookie(name) { |
| 2252 | document.cookie = name+'=; Max-Age=-99999999;'; |
| 2253 | } |
| 2254 | |
| 2255 | function setStickyHeaderForMedia() { |
| 2256 | if(!$(".media-position").length) { |
| 2257 | $(".media-frame-content .media-toolbar").before("<div class='media-position'></div>") |
| 2258 | } |
| 2259 | |
| 2260 | if($(".media-position").length) { |
| 2261 | setMediaBoxWidth(); |
| 2262 | |
| 2263 | thisPosition = $(".media-position").offset().top - $(window).scrollTop(); |
| 2264 | if(thisPosition <= 32) { |
| 2265 | $(".media-frame-content .media-toolbar").addClass("sticky-media"); |
| 2266 | $(".media-position").height($(".media-frame-content .media-toolbar").outerHeight()); |
| 2267 | } else { |
| 2268 | $(".media-frame-content .media-toolbar").removeClass("sticky-media"); |
| 2269 | $(".media-position").height(1); |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | $(window).scroll(function(){ |
| 2275 | setStickyHeaderForMedia() |
| 2276 | }); |
| 2277 | } else { |
| 2278 | function setStickyHeaderForMedia() {} |
| 2279 | } |
| 2280 | })); |