PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.9.6
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.9.6
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / assets / js / folders.js
folders / assets / js Last commit date
custom.js 4 years ago folders.js 2 years ago folders.min.js 2 years ago jquery.overlayscrollbars.min.js 3 years ago jquery.star-rating-svg.min.js 2 years ago jquery.ui.touch-punch.min.js 4 years ago jstree.js 4 years ago jstree.min.js 4 years ago lottie-player.js 4 years ago lottie-player.json 4 years ago media.js 4 years ago new-media.js 4 years ago page-post-media.js 3 years ago page-post-media.min.js 2 years ago replace-file-name.js 3 years ago replace-media.js 2 years ago select2.min.js 4 years ago simpledropit.min.js 3 years ago slick.min.js 3 years ago spectrum.min.js 4 years ago
folders.js
3330 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 creatingParentMenu = 0;
23 var folderOrder = 0;
24 var isMultipleRemove = false;
25 var folderIDs = "";
26 var folderPropertyArray = [];
27 var folderCurrentURL = wcp_settings.current_url;
28 var foldersArray = [];
29 var hasStars;
30 var hasChildren;
31 var listFolderString = "<li class='grid-view' data-id='__folder_id__' id='folder___folder_id__'>" +
32 "<div class='folder-item is-folder' data-id='__folder_id__'>" +
33 "<a title='__folder_name__' id='folder_view___folder_id__'" +
34 "class='folder-view __append_class__ has-new-folder'" +
35 "data-id='__folder_id__'>" +
36 "<span class='folder item-name'><span id='wcp_folder_text___folder_id__'" +
37 "class='folder-title'>__folder_name__</span></span>" +
38 "</a>" +
39 "</div>" +
40 "</li>";
41 var contextOffsetX = null;
42 var contextOffsetY = null;
43 var currentPage = 1;
44 $(document).ready(function(){
45
46 $(document).on("click", ".subsubsub a", function(e){
47 if($("#js-tree-menu .jstree-anchor.jstree-clicked").length) {
48 var CurrentNode = $("#js-tree-menu .jstree-anchor.jstree-clicked").closest(".jstree-node").attr("id");
49 var folderSlug = getSettingForPost(CurrentNode, 'slug');
50 if(folderSlug != "") {
51 e.preventDefault();
52 var thisURL = $(this).attr("href");
53 thisURL = thisURL + "&" + wcp_settings.custom_type + "=" + folderSlug;
54 window.location = thisURL;
55 }
56 } else if($("#dynamic-tree-folders").length && $("#dynamic-tree-folders .jstree-anchor.jstree-clicked").length) {
57 var CurrentNode = $("#dynamic-tree-folders .jstree-anchor.jstree-clicked").closest(".jstree-node").attr("id");
58 if(CurrentNode != "") {
59 e.preventDefault();
60 var thisURL = $(this).attr("href");
61 thisURL = thisURL + "&ajax_action=premio_dynamic_folders&dynamic_folder=" + CurrentNode + "_anchor";
62 window.location = thisURL;
63 }
64 }
65 });
66
67 /* check for jetpack */
68 if($("body").hasClass("jetpack-connected") && !$("body").hasClass("mobile")) {
69 if(!$("body").hasClass("folded")) {
70 if($("#adminmenuwrap").length) {
71 var yLength = parseInt($("#adminmenuwrap").width());
72 if($("html").prop("dir") == "rtl") {
73 $(".wcp-content").css("right", yLength);
74 } else {
75 $(".wcp-content").css("left", yLength);
76 }
77 }
78 }
79 }
80
81 $(document).on("click", "#collapse-button", function(){
82 setTimeout(function(){
83 if($("body").hasClass("jetpack-connected") && !$("body").hasClass("mobile")) {
84 if(!$("body").hasClass("folded")) {
85 if($("#adminmenuwrap").length) {
86 var yLength = parseInt($("#adminmenuwrap").width());
87 if($("html").prop("dir") == "rtl") {
88 $(".wcp-content").css("right", yLength);
89 } else {
90 $(".wcp-content").css("left", yLength);
91 }
92 }
93 }
94 }
95 }, 50);
96 });
97
98
99 foldersArray = wcp_settings.taxonomies;
100
101 isKeyActive = parseInt(wcp_settings.is_key_active);
102 n_o_file = parseInt(wcp_settings.folders);
103 activeRecordID = parseInt(wcp_settings.selected_taxonomy);
104 hasStars = parseInt(wcp_settings.hasStars);
105 hasChildren = parseInt(wcp_settings.hasChildren);
106 currentPage = parseInt(wcp_settings.currentPage);
107 console.log(activeRecordID);
108
109 folderPropertyArray = wcp_settings.folder_settings;
110
111 $(document).on("click", ".folder-settings-btn > a", function(e){
112 e.stopPropagation();
113 $(".folder-settings-btn").toggleClass('active');
114 });
115 $(document).on("click", "body,html", function(){
116 $(".folder-settings-btn").removeClass('active');
117 });
118 $(document).on("click", ".folder-setting-menu", function(e){
119 e.stopPropagation();
120 });
121
122 initJSTree();
123
124 setCustomScrollForFolder();
125
126
127 $(document).ajaxComplete(function (ev, jqXHR, settings) {
128 var actionName = settings.data;
129 if(typeof actionName != "undefined") {
130 if(actionName.length && actionName.indexOf("action=inline-save") != -1) {
131 resetMediaAndPosts();
132 triggerInlineUpdate();
133 }
134 }
135 });
136
137 var resizeDirection = (wcp_settings.isRTL == "1" || wcp_settings.isRTL == 1)?"w":"e";
138 $(".wcp-content").resizable( {
139 resizeHeight: false,
140 handles: resizeDirection,
141 minWidth: 100,
142 maxWidth: 500,
143 resize: function( e, ui ) {
144 var menuWidth = ui.size.width;
145 if(menuWidth <= 275) {
146 $(".plugin-button").addClass("d-block");
147 } else {
148 $(".plugin-button").removeClass("d-block");
149 }
150 if(menuWidth <= 245) {
151 menuWidth = 245;
152 }
153 if(wcp_settings.isRTL == "1") {
154 $("#wpcontent").css("padding-right", (menuWidth + 20) + "px");
155 $("#wpcontent").css("padding-left", "0px");
156 } else {
157 $("#wpcontent").css("padding-left", (menuWidth + 20) + "px");
158 }
159 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px - "+menuWidth+"px)");
160 newWidth = menuWidth - 40;
161 cssString = "";
162 classString = "";
163 for(i=0; i<=15; i++) {
164 classString += " .space > .jstree-node >";
165 currentWidth = newWidth - (13+(20*i));
166 cssString += "#js-tree-menu > "+classString+" .title { width: "+currentWidth+"px !important; } ";
167 cssString += "#js-tree-menu > "+classString+" .dynamic-menu { left: "+(currentWidth - 190)+"px !important; } ";
168 setStickyHeaderForMedia();
169 }
170 $("#wcp-custom-style").html("<style>"+cssString+"</style>");
171 if(ui.size.width <= 185) {
172 folderStatus = "hide";
173 $(".wcp-hide-show-buttons .toggle-buttons.show-folders").addClass("active");
174 $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").removeClass("active");
175 $("#wcp-content").addClass("hide-folders-area");
176 if(wcp_settings.isRTL == "1") {
177 $("#wpcontent").css("padding-right", "20px");
178 $("#wpcontent").css("padding-left", "0px");
179 } else {
180 $("#wpcontent").css("padding-left", "20px");
181 }
182 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px)");
183 } else {
184 if($("#wcp-content").hasClass("hide-folders-area")) {
185 folderStatus = "show";
186 $(".wcp-hide-show-buttons .toggle-buttons.show-folders").removeClass("active");
187 $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").addClass("active");
188 $("#wcp-content").addClass("no-transition");
189 $("#wcp-content").removeClass("hide-folders-area");
190 if(wcp_settings.isRTL == "1") {
191 $("#wpcontent").css("padding-right", (parseInt(wcp_settings.folder_width) + 20) + "px");
192 $("#wpcontent").css("padding-left", "0px");
193 } else {
194 $("#wpcontent").css("padding-left", (parseInt(wcp_settings.folder_width) + 20) + "px");
195 }
196 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px - "+menuWidth+"px)");
197 setTimeout(function(){
198 $("#wcp-content").removeClass("no-transition");
199 }, 250);
200 }
201 }
202 },
203 stop: function( e, ui ) {
204 var menuWidth = ui.size.width;
205 if(ui.size.width <= 275) {
206 $(".plugin-button").addClass("d-block");
207 } else {
208 $(".plugin-button").removeClass("d-block");
209 }
210 if(menuWidth <= 245) {
211 menuWidth = 245;
212 }
213 if(ui.size.width <= 185) {
214 folderStatus = "hide";
215 $(".wcp-hide-show-buttons .toggle-buttons.show-folders").addClass("active");
216 $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").removeClass("active");
217 $("#wcp-content").addClass("hide-folders-area");
218 if(wcp_settings.isRTL == "1") {
219 $("#wpcontent").css("padding-right", "20px");
220 $("#wpcontent").css("padding-left", "0px");
221 } else {
222 $("#wpcontent").css("padding-left", "20px");
223 }
224 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px)");
225 $.ajax({
226 url: wcp_settings.ajax_url,
227 data: "type=" + wcp_settings.post_type + "&action=wcp_change_folder_display_status&status=" + folderStatus +"&nonce="+nonce,
228 method: 'post',
229 success: function (res) {
230 setStickyHeaderForMedia();
231 }
232 });
233 } else {
234 if($("#wcp-content").hasClass("hide-folders-area")) {
235 folderStatus = "show";
236 $(".wcp-hide-show-buttons .toggle-buttons.show-folders").removeClass("active");
237 $(".wcp-hide-show-buttons .toggle-buttons.hide-folders").addClass("active");
238 $("#wcp-content").addClass("no-transition");
239 $("#wcp-content").removeClass("hide-folders-area");
240 if(wcp_settings.isRTL == "1") {
241 $("#wpcontent").css("padding-right", (parseInt(wcp_settings.folder_width) + 20) + "px");
242 $("#wpcontent").css("padding-left", "0px");
243 } else {
244 $("#wpcontent").css("padding-left", (parseInt(wcp_settings.folder_width) + 20) + "px");
245 }
246 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px - "+menuWidth+"px)");
247 setTimeout(function(){
248 $("#wcp-content").removeClass("no-transition");
249 }, 250);
250 }
251 }
252 nonce = wcp_settings.nonce;
253 wcp_settings.folder_width = ui.size.width;
254 $.ajax({
255 url: wcp_settings.ajax_url,
256 data: "type=" + wcp_settings.post_type + "&action=wcp_change_post_width&width=" + menuWidth+"&nonce="+nonce,
257 method: 'post',
258 success: function (res) {
259 setStickyHeaderForMedia();
260 }
261 });
262 if(ui.size.width <= 245) {
263 $(".wcp-content").width(245);
264 wcp_settings.folder_width = 245;
265 }
266 }
267 });
268
269 $(document).on("contextmenu", "#js-tree-menu .jstree-anchor", function(e){
270 contextOffsetX = e.pageX;
271 contextOffsetY = e.pageY;
272 $(this).find("span.folder-inline-edit").trigger("click");
273 return false;
274 });
275
276 $(document).on("click", "#js-tree-menu .folder-actions span.folder-inline-edit", function(e){
277 e.stopImmediatePropagation()
278 e.stopPropagation();
279 if(wcp_settings.can_manage_folder == 0) {
280 return;
281 }
282 isHigh = $(this).closest("li.jstree-node").hasClass("is-high");
283 isSticky = $(this).closest("li.jstree-node").hasClass("is-sticky");
284 isStickyClass = (isSticky)?true:false;
285 $(".dynamic-menu").remove();
286 $(".active-menu").removeClass("active-menu");
287 menuHtml = "<div class='dynamic-menu' data-id='"+$(this).closest("li").prop("id")+"'><ul>";
288 menuHtml += "<li class='new-main-folder'><a href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span>"+wcp_settings.lang.NEW_FOLDER+"</a></li>";
289 if(hasChildren) {
290 menuHtml += "<li class='new-folder'><a href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span>"+wcp_settings.lang.NEW_FOLDER+"</a></li>";
291 } else {
292 menuHtml += "<li class='new-folder-pro'><a target='_blank' href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span>"+wcp_settings.lang.PRO.NEW_SUB_FOLDER+"</a></li>";
293 }
294 menuHtml += "<li class='rename-folder'><a href='javascript:;'><span class=''><i class='pfolder-edit'></i></span>"+wcp_settings.lang.RENAME+"</a></li>" +
295 "<li class='default-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-active-icon'></i></span>"+wcp_settings.lang.PRO.OPEN_THIS_FOLDER+"</a></li>" +
296 "<li class='sticky-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class='sticky-pin'><i class='pfolder-pin'></i></span>"+wcp_settings.lang.PRO.STICKY_FOLDER+"</a></li>";
297 if(hasStars) {
298 menuHtml += "<li class='mark-folder'><a href='javascript:;'><span class=''><i class='pfolder-star'></i></span>" + ((isHigh) ? wcp_settings.lang.REMOVE_STAR : wcp_settings.lang.ADD_STAR) + "</a></li>";
299 } else {
300 menuHtml += "<li class='mark-folder-pro'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-star'></i></span>" + ((isHigh) ? wcp_settings.lang.PRO.REMOVE_STAR : wcp_settings.lang.PRO.ADD_STAR) + "</a></li>";
301 }
302 menuHtml += "<li class='lock-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class='dashicons dashicons-lock'></span>"+wcp_settings.lang.PRO.LOCK_FOLDER+"</a></li>" +
303 "<li class='duplicate-folder-pro'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-clone'></i></span>"+wcp_settings.lang.PRO.DUPLICATE_FOLDER+"</a></li>";
304
305 hasPosts = parseInt($(this).closest("a.jstree-anchor").find(".premio-folder-count").text());
306 if (wcp_settings.post_type == "attachment" && hasPosts) {
307 menuHtml += "<li target='_blank' class='download-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-zip-file'></i></span>"+wcp_settings.lang.PRO.DOWNLOAD_ZIP+"</a></li>";
308 }
309 menuHtml += "<li class='remove-folder'><a href='javascript:;'><span class=''><i class='pfolder-remove'></i></span>"+wcp_settings.lang.DELETE+"</a></li>" +
310 "</ul></div>";
311 $("body").append(menuHtml);
312 var yPosition;
313 if(e.pageX == undefined || e.pageY == undefined) {
314 $(".dynamic-menu").css("left", (contextOffsetX));
315 $(".dynamic-menu").css("top", (contextOffsetY - 10));
316 yPosition = contextOffsetY;
317 } else {
318 $(".dynamic-menu").css("left", (e.pageX));
319 $(".dynamic-menu").css("top", (e.pageY));
320 yPosition = e.pageY;
321 }
322
323 $(this).parents("li.jstree-node").addClass("active-menu");
324 // if(($(this).offset().top + $(".dynamic-menu").height()) > ($(window).height() - 20)) {
325 // $(".dynamic-menu").addClass("bottom-fix");
326 //
327 // if($(".dynamic-menu.bottom-fix").offset().top < $("#custom-scroll-menu").offset().top) {
328 // $(".dynamic-menu").removeClass("bottom-fix");
329 // }
330 // }
331
332 if((yPosition + $(".dynamic-menu").height()) > $(window).height()) {
333 $(".dynamic-menu").css("margin-top", $(window).height() - (yPosition + $(".dynamic-menu").height()));
334 }
335 });
336
337 $(document).on("click", ".sticky-folders .sticky-fldr > a", function(e) {
338 e.stopPropagation();
339 var folder_ID = $(this).closest("li").data("folder-id");
340 if($(".jstree-node[id='"+folder_ID+"']").length) {
341 $(".jstree-clicked").removeClass("jstree-clicked");
342 $(".active-item").removeClass("active-item");
343 $("#js-tree-menu").jstree('select_node', activeRecordID);
344 $(".jstree-node[id='"+folder_ID+"'] > a.jstree-anchor").trigger("click");
345 $(".jstree-node[id='"+folder_ID+"'] > a.jstree-anchor").addClass("jstree-clicked");
346 $(".sticky-folders .sticky-folder-"+folder_ID+" a").addClass("active-item");
347 }
348 });
349
350 $(document).on("contextmenu", ".sticky-folders li .sticky-fldr > a", function(e){
351 $(this).find("span.update-inline-record").trigger("click");
352 return false;
353 });
354
355 $(document).on("click", ".tree-structure a", function(e) {
356 e.stopPropagation();
357 var folder_ID = $(this).data("id");
358 if($(".jstree-node[id='"+folder_ID+"']").length) {
359 $(".jstree-clicked").removeClass("jstree-clicked");
360 $(".active-item").removeClass("active-item");
361 $("#js-tree-menu").jstree('select_node', activeRecordID);
362 $(".jstree-node[id='"+folder_ID+"'] > a.jstree-anchor").trigger("click");
363 $(".jstree-node[id='"+folder_ID+"'] > a.jstree-anchor").addClass("jstree-clicked");
364 $(".sticky-folders .sticky-folder-"+folder_ID+" a").addClass("active-item");
365 }
366 });
367
368 $(document).on("click", ".update-inline-record", function(e){
369 e.stopImmediatePropagation()
370 e.stopPropagation();
371 if(wcp_settings.can_manage_folder == 0) {
372 return;
373 }
374 isHigh = $(this).closest("li.sticky-fldr").hasClass("is-high");
375 isSticky = $(this).closest("li.sticky-fldr").hasClass("is-sticky");
376 isStickyClass = (isSticky)?true:false;
377 $(".dynamic-menu").remove();
378 $(".active-menu").removeClass("active-menu");
379 menuHtml = "<div class='dynamic-menu' data-id='"+$(this).closest("li").data("folder-id")+"'><ul>";
380 menuHtml += "<li class='new-main-folder'><a href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span>"+wcp_settings.lang.NEW_FOLDER+"</a></li>";
381 if(hasChildren) {
382 menuHtml += "<li class='new-folder'><a href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span>"+wcp_settings.lang.NEW_FOLDER+"</a></li>";
383 } else {
384 menuHtml += "<li class='new-folder-pro'><a target='_blank' href='javascript:;'><span class=''><i class='pfolder-add-folder'></i></span>"+wcp_settings.lang.PRO.NEW_SUB_FOLDER+"</a></li>";
385 }
386 menuHtml += "<li class='rename-folder'><a href='javascript:;'><span class=''><i class='pfolder-edit'></i></span>Rename</a></li>" +
387 "<li class='default-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-active-icon'></i></span>"+wcp_settings.lang.PRO.OPEN_THIS_FOLDER+"</a></li>" +
388 "<li class='sticky-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class='sticky-pin'><i class='pfolder-pin'></i></span>"+wcp_settings.lang.PRO.STICKY_FOLDER+"</a></li>";
389 if(hasStars) {
390 menuHtml += "<li class='mark-folder'><a href='javascript:;'><span class=''><i class='pfolder-star'></i></span>" + ((isHigh) ? wcp_settings.lang.ADD_STAR : wcp_settings.lang.REMOVE_STAR) + "</a></li>";
391 } else {
392 menuHtml += "<li class='mark-folder-pro'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-star'></i></span>" + ((isHigh) ? wcp_settings.lang.PRO.ADD_STAR : wcp_settings.lang.PRO.REMOVE_STAR) + "</a></li>";
393 }
394 menuHtml += "<li class='lock-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class='dashicons dashicons-lock'></span>"+wcp_settings.lang.PRO.LOCK_FOLDER+"</a></li>" +
395 "<li class='duplicate-folder-pro'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-clone'></i></span>"+wcp_settings.lang.PRO.DUPLICATE_FOLDER+"</a></li>";
396
397 hasPosts = parseInt($(this).closest("li.jstree-node").find("h3.title:first > .total-count").text());
398 if (wcp_settings.post_type == "attachment" && hasPosts) {
399 menuHtml += "<li class='download-folder'><a target='_blank' href='"+wcp_settings.upgrade_url+"'><span class=''><i class='pfolder-zip-file'></i></span>"+wcp_settings.lang.PRO.DOWNLOAD_ZIP+"</a></li>";
400 }
401 menuHtml += "<li class='remove-folder'><a href='javascript:;'><span class=''><i class='pfolder-remove'></i></span> "+wcp_settings.lang.DELETE+"</a></li>" +
402 "</ul></div>";
403 $("body").append(menuHtml);
404
405 var yPosition;
406 if(e.pageX == undefined || e.pageY == undefined) {
407 $(".dynamic-menu").css("left", (contextOffsetX));
408 $(".dynamic-menu").css("top", (contextOffsetY - 10));
409 yPosition = contextOffsetY;
410 } else {
411 $(".dynamic-menu").css("left", (e.pageX));
412 $(".dynamic-menu").css("top", (e.pageY));
413 yPosition = e.pageY;
414 }
415
416 if((yPosition + $(".dynamic-menu").height()) > $(window).height()) {
417 $(".dynamic-menu").css("margin-top", $(window).height() - (yPosition + $(".dynamic-menu").height()));
418 }
419 });
420
421 $(document).on("click", ".dynamic-menu", function(e){
422 e.stopImmediatePropagation()
423 e.stopPropagation();
424 });
425
426 $(document).on("click", ".new-folder-pro", function(e){
427 e.preventDefault();
428 $(".dynamic-menu").remove();
429 $("#sub-folder-popup").show();
430 });
431
432 $(document).on("click", ".close-popup-button a:not(.hide-upgrade-modal)", function(){
433 $(".folder-popup-form").hide();
434 if($(".jstree-node[id='"+fileFolderID+"']").length) {
435 $(".jstree-node[id='"+fileFolderID+"'] > a.jstree-anchor").trigger("focus");
436 }
437 if($(this).hasClass("upgrade-model-button")) {
438 $("#upgrade-modal-popup").remove();
439 }
440 });
441
442 $(document).on("click", ".close-popup-button a.hide-upgrade-modal", function(){
443 if($(".rating-modal-steps#step-4").hasClass("active")) {
444 set_review_reminder(-1);
445 $(".rating-modal-popup").remove();
446 } else if($(".rating-modal-steps#step-3").hasClass("active")) {
447 set_review_reminder(14);
448 } else {
449 $(".rating-modal-steps").removeClass("active");
450 $(".rating-modal-steps#step-3").addClass("active");
451 }
452 });
453
454 $(document).on("click", "body, html", function(){
455 $(".dynamic-menu").remove();
456 });
457
458 $(document).on("click", ".wcp-hide-show-buttons .toggle-buttons", function(){
459 var folderStatus = "show";
460 if($(this).hasClass("hide-folders")) {
461 folderStatus = "hide";
462 }
463 $(".wcp-hide-show-buttons .toggle-buttons").toggleClass("active");
464 nonce = wcp_settings.nonce;
465 if(folderStatus == "show") {
466 $("#wcp-content").addClass("no-transition");
467 $("#wcp-content").removeClass("hide-folders-area");
468 if(wcp_settings.isRTL == "1") {
469 $("#wpcontent").css("padding-right", (parseInt(wcp_settings.folder_width) + 20) + "px");
470 $("#wpcontent").css("padding-left", "0px");
471 } else {
472 $("#wpcontent").css("padding-left", (parseInt(wcp_settings.folder_width) + 20) + "px");
473 }
474 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px - "+parseInt(wcp_settings.folder_width)+"px)");
475 setTimeout(function(){
476 $("#wcp-content").removeClass("no-transition");
477 }, 250);
478 } else {
479 $("#wcp-content").addClass("hide-folders-area");
480 if(wcp_settings.isRTL == "1") {
481 $("#wpcontent").css("padding-right", "20px");
482 $("#wpcontent").css("padding-left", "0px");
483 } else {
484 $("#wpcontent").css("padding-left", "20px");
485 }
486 $("body.wp-admin #e-admin-top-bar-root.e-admin-top-bar--active").css("width", "calc(100% - 160px)");
487 }
488
489 $.ajax({
490 url: wcp_settings.ajax_url,
491 data: "type=" + wcp_settings.post_type + "&action=wcp_change_folder_display_status&status=" + folderStatus +"&nonce="+nonce,
492 method: 'post',
493 success: function (res) {
494 setStickyHeaderForMedia();
495 }
496 });
497 });
498
499 /* grag and drop */
500 setDragAndDropElements();
501
502 $( document ).ajaxComplete(function( event, xhr, settings ) {
503 if(settings.data != undefined && settings.data != "" && settings.data.indexOf("action=query-attachments") != -1) {
504 setDragAndDropElements();
505 }
506 });
507
508 $(document).on("click", ".undo-button, .undo-folder-action:not(.disabled)", function(){
509 $("#do-undo").removeClass("active");
510 if(wcp_settings.useFolderUndo == "yes") {
511 $.ajax({
512 url: wcp_settings.ajax_url,
513 type: 'post',
514 data: {
515 post_type: wcp_settings.post_type,
516 nonce: wcp_settings.nonce,
517 action: 'wcp_undo_folder_changes'
518 },
519 success: function(res){
520 $("#undo-done").addClass("active");
521 setTimeout(function(){
522 $("#undo-done").removeClass("active");
523 }, 2500);
524 if($("#media-attachment-taxonomy-filter").length) {
525 var wp1 = parent.wp;
526 if(wp1.media != undefined) {
527 wp1.media.frame.setState('insert');
528 if (wp1.media.frame.content.get() !== null && typeof(wp1.media.frame.content.get().collection) != "undefined") {
529 wp1.media.frame.content.get().collection.props.set({ignore: (+new Date())});
530 wp1.media.frame.content.get().options.selection.reset();
531 } else {
532 wp1.media.frame.library.props.set({ignore: (+new Date())});
533 }
534 }
535 }
536 resetMediaAndPosts();
537 }
538 })
539 }
540 });
541
542 $(document).on("click", ".close-undo-box", function(e){
543 e.preventDefault();
544 $("#do-undo").removeClass("active");
545 });
546 });
547
548 function checkForUndoFunctionality() {
549 if(wcp_settings.useFolderUndo == "yes") {
550 $("#do-undo").addClass("active");
551 $('.undo-folder-action').removeClass("disabled");
552 setTimeout(function(){
553 $("#do-undo").removeClass("active");
554 $('.undo-folder-action').addClass("disabled");
555 }, parseInt(wcp_settings.defaultTimeout));
556 }
557 }
558
559 function checkForCopyPaste() {
560 $(".cut-folder-action, .copy-folder-action, .paste-folder-action, .delete-folder-action").addClass("disabled");
561 if($("#js-tree-menu .jstree-anchor.jstree-clicked").length) {
562 $(".delete-folder-action").removeClass("disabled");
563 }
564
565 if($("#menu-checkbox").is(":checked")) {
566 if($("#js-tree-menu input.checkbox:checked").length > 0) {
567 $(".delete-folder-action").removeClass("disabled");
568 }
569 }
570 }
571
572 function setDragAndDropElements() {
573
574 checkForCopyPaste();
575
576 $(".wcp-move-file:not(.ui-draggable)").draggable({
577 revert: "invalid",
578 containment: "document",
579 helper: "clone",
580 cursor: "move",
581 start: function( event, ui){
582 $(this).closest("td").addClass("wcp-draggable");
583 $("body").addClass("no-hover-css");
584 },
585 stop: function( event, ui ) {
586 $(this).closest("td").removeClass("wcp-draggable");
587 $("body").removeClass("no-hover-css");
588 }
589 });
590
591 $(".wcp-move-multiple:not(.ui-draggable)").draggable({
592 revert: "invalid",
593 containment: "document",
594 helper: function (event, ui) {
595 $(".selected-items").remove();
596 selectedItems = $("#the-list th input:checked").length;
597 if(selectedItems > 0) {
598 selectedItems = (selectedItems == 0 || selectedItems == 1) ? (wcp_settings.lang.ONE_ITEM) : (selectedItems + " " + wcp_settings.lang.ITEMS);
599 return $("<div class='selected-items'><span class='total-post-count'>" + selectedItems + " "+wcp_settings.lang.SELECTED+"</span></div>");
600 } else {
601 return $("<div class='selected-items'><span class='total-post-count'>"+wcp_settings.lang.SELECT_ITEMS+"</span></div>");
602 }
603 },
604 start: function( event, ui){
605 $("body").addClass("no-hover-css");
606 },
607 cursor: "move",
608 cursorAt: {
609 left: 0,
610 top: 0
611 },
612 stop: function( event, ui ) {
613 $(".selected-items").remove();
614 $("body").removeClass("no-hover-css");
615 }
616 });
617
618 $(".jstree-anchor:not(.ui-droppable)").droppable({
619 accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment",
620 hoverClass: 'wcp-drop-hover',
621 classes: {
622 "ui-droppable-active": "ui-state-highlight"
623 },
624 drop: function( event, ui ) {
625 folderID = $(this).closest("li.jstree-node").attr('id');
626 if ( ui.draggable.hasClass( 'wcp-move-multiple')) {
627 if($(".wp-list-table input:checked").length) {
628 chkStr = "";
629 $(".wp-list-table input:checked").each(function(){
630 chkStr += $(this).val()+",";
631 });
632 nonce = getSettingForPost(folderID, 'nonce');
633 $.ajax({
634 url: wcp_settings.ajax_url,
635 data: {
636 post_ids: chkStr,
637 type: wcp_settings.post_type,
638 action: "wcp_change_multiple_post_folder",
639 folder_id: folderID,
640 nonce: nonce,
641 status: wcp_settings.taxonomy_status,
642 taxonomy: activeRecordID,
643 post_status: wcp_settings.post_status
644 },
645 method: 'post',
646 success: function (res) {
647 res = $.parseJSON(res);
648 if(res.status == "1") {
649 resetMediaAndPosts();
650 checkForUndoFunctionality();
651 $("#upgrade-modal-popup").show();
652 } else {
653 $(".folder-popup-form").hide();
654 $(".folder-popup-form").removeClass("disabled");
655 $("#error-folder-popup-message").html(res.message);
656 $("#error-folder-popup").show()
657 }
658 }
659 });
660 }
661 } else if( ui.draggable.hasClass( 'wcp-move-file' ) ){
662 postID = ui.draggable[0].attributes['data-id'].nodeValue;
663 nonce = getSettingForPost(folderID, 'nonce');
664 chkStr = postID+",";
665 $(".wp-list-table input:checked").each(function(){
666 if($(this).val() != postID) {
667 chkStr += $(this).val() + ",";
668 }
669 });
670 $.ajax({
671 url: wcp_settings.ajax_url,
672 method: 'post',
673 data: {
674 post_ids: chkStr,
675 type: wcp_settings.post_type,
676 action: "wcp_change_multiple_post_folder",
677 folder_id: folderID,
678 nonce: nonce,
679 status: wcp_settings.taxonomy_status,
680 taxonomy: activeRecordID,
681 post_status: wcp_settings.post_status
682 },
683 success: function (res) {
684 res = $.parseJSON(res);
685 if(res.status == "1") {
686 // window.location.reload();
687 resetMediaAndPosts();
688 checkForUndoFunctionality();
689 $("#upgrade-modal-popup").show();
690 } else {
691 $(".folder-popup-form").hide();
692 $(".folder-popup-form").removeClass("disabled");
693 $("#error-folder-popup-message").html(res.message);
694 $("#error-folder-popup").show()
695 }
696 }
697 });
698 } else if (ui.draggable.hasClass('attachment')) {
699 chkStr = ui.draggable[0].attributes['data-id'].nodeValue;
700 nonce = getSettingForPost(folderID, 'nonce');
701 if ($(".attachments-browser li.attachment.selected").length > 1) {
702 chkStr = "";
703 $(".attachments-browser li.attachment.selected").each(function(){
704 chkStr += $(this).data("id") + ",";
705 });
706 }
707 folderIDs = chkStr;
708 $.ajax({
709 url: wcp_settings.ajax_url,
710 data: {
711 post_ids: chkStr,
712 type: wcp_settings.post_type,
713 action: "wcp_change_multiple_post_folder",
714 folder_id: folderID,
715 nonce: nonce,
716 status: wcp_settings.taxonomy_status,
717 taxonomy: activeRecordID,
718 post_status: wcp_settings.post_status
719 },
720 method: 'post',
721 success: function (res) {
722 // window.location.reload();
723 $("#upgrade-modal-popup").show();
724 resetMediaAndPosts();
725 checkForUndoFunctionality();
726 }
727 });
728 }
729 }
730 });
731
732 $(".un-categorised-items:not(.ui-droppable)").droppable({
733 accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment",
734 hoverClass: 'wcp-hover-list',
735 classes: {
736 "ui-droppable-active": "ui-state-highlight"
737 },
738 drop: function (event, ui) {
739 folderID = -1;
740 nonce = wcp_settings.nonce;
741 if(ui.draggable.hasClass('wcp-move-multiple')) {
742 if($(".wp-list-table input:checked").length) {
743 chkStr = "";
744 $(".wp-list-table input:checked").each(function(){
745 chkStr += $(this).val() + ",";
746 });
747 checkForOtherFolders(chkStr);
748 }
749 } else if(ui.draggable.hasClass('wcp-move-file')) {
750 postID = ui.draggable[0].attributes['data-id'].nodeValue;
751 chkStr = postID+",";
752 $(".wp-list-table input:checked").each(function(){
753 if(postID != $(this).val()) {
754 chkStr += $(this).val() + ",";
755 }
756 });
757 checkForOtherFolders(chkStr);
758 } else if(ui.draggable.hasClass('attachment')) {
759 chkStr = ui.draggable[0].attributes['data-id'].nodeValue;
760 if($(".attachments-browser li.attachment.selected").length > 1) {
761 chkStr = "";
762 $(".attachments-browser li.attachment.selected").each(function(){
763 chkStr += $(this).data("id") + ",";
764 });
765 }
766 folderIDs = chkStr;
767 checkForOtherFolders(chkStr);
768 }
769 }
770 });
771
772 $(".attachments-browser li.attachment:not(.ui-draggable)").draggable({
773 revert: "invalid",
774 containment: "document",
775 helper: function (event, ui) {
776 $(".selected-items").remove();
777 selectedItems = $(".attachments-browser li.attachment.selected").length;
778 selectedItems = (selectedItems == 0 || selectedItems == 1) ? "1 Item" : selectedItems + " Items";
779 return $("<div class='selected-items'><span class='total-post-count'>" + selectedItems + " Selected</span></div>");
780 },
781 start: function( event, ui){
782 $("body").addClass("no-hover-css");
783 },
784 cursor: "move",
785 cursorAt: {
786 left: 0,
787 top: 0
788 },
789 stop: function( event, ui ) {
790 $(".selected-items").remove();
791 $("body").removeClass("no-hover-css");
792 }
793 });
794
795 $(".tree-structure .folder-item:not(.ui-droppable)").droppable({
796 accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment",
797 hoverClass: 'wcp-drop-hover-list',
798 classes: {
799 "ui-droppable-active": "ui-state-highlight"
800 },
801 drop: function( event, ui ) {
802 $("body").removeClass("no-hover-css");
803 folderID = $(this).data('id');
804 if( ui.draggable.hasClass( 'wcp-move-multiple' ) ) {
805 nonce = getSettingForPost(folderID, 'nonce');
806 if($(".wp-list-table input:checked").length) {
807 chkStr = "";
808 $(".wp-list-table input:checked").each(function(){
809 chkStr += $(this).val()+",";
810 });
811 $.ajax({
812 url: wcp_settings.ajax_url,
813 method: 'post',
814 data: {
815 post_ids: chkStr,
816 type: wcp_settings.post_type,
817 action: "wcp_change_multiple_post_folder",
818 folder_id: folderID,
819 nonce: nonce,
820 status: wcp_settings.taxonomy_status,
821 taxonomy: activeRecordID,
822 post_status: wcp_settings.post_status
823 },
824 success: function (res) {
825 // window.location.reload();
826 resetMediaAndPosts();
827 ajaxAnimation();
828 checkForUndoFunctionality();
829 }
830 });
831 }
832 } else if( ui.draggable.hasClass( 'wcp-move-file' ) ) {
833 postID = ui.draggable[0].attributes['data-id'].nodeValue;
834 nonce = getSettingForPost(folderID, 'nonce');
835 chkStr = postID+",";
836 $(".wp-list-table input:checked").each(function(){
837 if($(this).val() != postID) {
838 chkStr += $(this).val() + ",";
839 }
840 });
841 $.ajax({
842 url: wcp_settings.ajax_url,
843 method: 'post',
844 data: {
845 post_ids: chkStr,
846 type: wcp_settings.post_type,
847 action: "wcp_change_multiple_post_folder",
848 folder_id: folderID,
849 nonce: nonce,
850 status: wcp_settings.taxonomy_status,
851 taxonomy: activeRecordID,
852 post_status: wcp_settings.post_status
853 },
854 success: function (res) {
855 // window.location.reload();
856 resetMediaAndPosts();
857 ajaxAnimation();
858 checkForUndoFunctionality();
859 }
860 });
861 } else if( ui.draggable.hasClass( 'attachment' ) ){
862 chkStr = ui.draggable[0].attributes['data-id'].nodeValue;
863 nonce = getSettingForPost(folderID, 'nonce');
864 if($(".attachments-browser li.attachment.selected").length > 1) {
865 chkStr = "";
866 $(".attachments-browser li.attachment.selected").each(function(){
867 chkStr += $(this).data("id")+",";
868 });
869 }
870 $.ajax({
871 url: wcp_settings.ajax_url,
872 method: 'post',
873 data: {
874 post_ids: chkStr,
875 type: wcp_settings.post_type,
876 action: "wcp_change_multiple_post_folder",
877 folder_id: folderID,
878 nonce: nonce,
879 status: wcp_settings.taxonomy_status,
880 taxonomy: activeRecordID,
881 post_status: wcp_settings.post_status
882 },
883 success: function (res) {
884 // window.location.reload();
885 resetMediaAndPosts();
886 ajaxAnimation();
887 checkForUndoFunctionality();
888 }
889 });
890 }
891 }
892 });
893
894 $(".sticky-folders li a:not(.ui-droppable)").droppable({
895 accept: ".wcp-move-file, .wcp-move-multiple, .attachments-browser li.attachment",
896 hoverClass: 'wcp-drop-hover',
897 classes: {
898 "ui-droppable-active": "ui-state-highlight"
899 },
900 drop: function( event, ui ) {
901 folderID = $(this).closest("li").data('folder-id');
902 if ( ui.draggable.hasClass( 'wcp-move-multiple' ) ) {
903 if($(".wp-list-table input:checked").length) {
904 chkStr = "";
905 $(".wp-list-table input:checked").each(function(){
906 chkStr += $(this).val()+",";
907 });
908 nonce = getSettingForPost(folderID, 'nonce');
909 $.ajax({
910 url: wcp_settings.ajax_url,
911 method: 'post',
912 data: {
913 post_ids: chkStr,
914 type: wcp_settings.post_type,
915 action: "wcp_change_multiple_post_folder",
916 folder_id: folderID,
917 nonce: nonce,
918 status: wcp_settings.taxonomy_status,
919 taxonomy: activeRecordID,
920 post_status: wcp_settings.post_status
921 },
922 success: function (res) {
923 res = $.parseJSON(res);
924 if(res.status == "1") {
925 resetMediaAndPosts();
926 ajaxAnimation();
927 checkForUndoFunctionality();
928 } else {
929 $(".folder-popup-form").hide();
930 $(".folder-popup-form").removeClass("disabled");
931 $("#error-folder-popup-message").html(res.message);
932 $("#error-folder-popup").show()
933 }
934 }
935 });
936 }
937 } else if( ui.draggable.hasClass( 'wcp-move-file' ) ){
938 postID = ui.draggable[0].attributes['data-id'].nodeValue;
939 nonce = getSettingForPost(folderID, 'nonce');
940 chkStr = postID+",";
941 $(".wp-list-table input:checked").each(function(){
942 if($(this).val() != postID) {
943 chkStr += $(this).val() + ",";
944 }
945 });
946 $.ajax({
947 url: wcp_settings.ajax_url,
948 method: 'post',
949 data: {
950 post_ids: chkStr,
951 type: wcp_settings.post_type,
952 action: "wcp_change_multiple_post_folder",
953 folder_id: folderID,
954 nonce: nonce,
955 status: wcp_settings.taxonomy_status,
956 taxonomy: activeRecordID,
957 post_status: wcp_settings.post_status
958 },
959 success: function (res) {
960 res = $.parseJSON(res);
961 if(res.status == "1") {
962 // window.location.reload();
963 resetMediaAndPosts();
964 ajaxAnimation();
965 checkForUndoFunctionality();
966 } else {
967 $(".folder-popup-form").hide();
968 $(".folder-popup-form").removeClass("disabled");
969 $("#error-folder-popup-message").html(res.message);
970 $("#error-folder-popup").show()
971 }
972 }
973 });
974 } else if(ui.draggable.hasClass('attachment')) {
975 chkStr = ui.draggable[0].attributes['data-id'].nodeValue;
976 nonce = getSettingForPost(folderID, 'nonce');
977 if($(".attachments-browser li.attachment.selected").length > 1) {
978 chkStr = "";
979 $(".attachments-browser li.attachment.selected").each(function () {
980 chkStr += $(this).data("id") + ",";
981 });
982 }
983 folderIDs = chkStr;
984 $.ajax({
985 url: wcp_settings.ajax_url,
986 data: {
987 post_ids: chkStr,
988 type: wcp_settings.post_type,
989 action: "wcp_change_multiple_post_folder",
990 folder_id: folderID,
991 nonce: nonce,
992 status: wcp_settings.taxonomy_status,
993 taxonomy: activeRecordID,
994 post_status: wcp_settings.post_status
995 },
996 method: 'post',
997 success: function (res) {
998 // window.location.reload();
999 resetMediaAndPosts();
1000 ajaxAnimation();
1001 checkForUndoFunctionality();
1002 }
1003 });
1004 }
1005 }
1006 });
1007
1008 setFolderCountAndDD();
1009 }
1010
1011 function setFolderCount() {
1012 $("#js-tree-menu .jstree-node").each(function(){
1013 var folderCount = ($(this).data("count") && $(this).data("count") != "")?$(this).data("count"):0;
1014 $(".jstree-node[id='" + $(this).attr("id") + "'] > a span.premio-folder-count").text(folderCount);
1015 });
1016 $("span.premio-folder-count").each(function(){
1017 if($(this).text() == "") {
1018 $(this).text(0);
1019 }
1020 });
1021
1022 if(activeRecordID != "" && activeRecordID != 0) {
1023 if($(".jstree-node[id='"+activeRecordID+"']").length) {
1024 $("#js-tree-menu").jstree('select_node', activeRecordID);
1025 if($(".sticky-folders .sticky-folder-"+activeRecordID+" a").length) {
1026 $(".sticky-folders .sticky-folder-" + activeRecordID + " a").addClass("active-item");
1027 }
1028 }
1029 }
1030 $(".ajax-preloader").hide();
1031 $(".js-tree-data").show();
1032 setCustomScrollForFolder();
1033 make_sticky_folder_menu();
1034 if($(".sticky-folders ul > li").length > 0) {
1035 $(".sticky-folders").addClass("active");
1036 }
1037 add_active_item_to_list();
1038 }
1039
1040 function getSettingForPost(postId, filedName) {
1041 if(folderPropertyArray.length > 0) {
1042 for(i=0; i<folderPropertyArray.length; i++) {
1043 if(parseInt(folderPropertyArray[i]['folder_id']) == parseInt(postId)) {
1044 return folderPropertyArray[i][filedName];
1045 }
1046 }
1047 }
1048 return "";
1049 }
1050
1051 function getIndexForPostSetting(postId) {
1052 if(folderPropertyArray.length > 0) {
1053 for(i=0; i<folderPropertyArray.length; i++) {
1054 if(parseInt(folderPropertyArray[i]['folder_id']) == parseInt(postId)) {
1055 return i;
1056 }
1057 }
1058 }
1059 return null;
1060 }
1061
1062 function resetMediaAndPosts() {
1063 if($(".media-toolbar").hasClass("media-toolbar-mode-select")) {
1064 if($("ul.attachments li.selected").length) {
1065 $("ul.attachments li.selected").trigger("click");
1066 $(".select-mode-toggle-button").trigger("click");
1067 }
1068 }
1069 if(folderIDs != "" && ($("#js-tree-menu a.jstree-clicked").length > 0 || activeRecordID == "-1")) {
1070 if($("#media-attachment-taxonomy-filter").length) {
1071 folderIDs = folderIDs.split(",");
1072 for (var i = 0; i < folderIDs.length; i++) {
1073 if(folderIDs[i] != "") {
1074 $(".attachments-browser li[data-id='"+folderIDs[i]+"']").remove();
1075 }
1076 }
1077 }
1078 folderIDs = "";
1079 }
1080 if($("#media-attachment-taxonomy-filter").length) {
1081 resetMediaData(0);
1082 } else {
1083 $.ajax({
1084 url: wcp_settings.ajax_url,
1085 data: {
1086 type: wcp_settings.post_type,
1087 action: "get_folders_default_list",
1088 post_status: wcp_settings.post_status
1089 },
1090 method: 'post',
1091 success: function (res) {
1092 res = $.parseJSON(res);
1093 // $("#js-tree-menu > ul#space_0").html(res.data);
1094 $(".header-posts .total-count").text(res.total_items);
1095 $(".un-categorised-items .total-count").text(res.empty_items);
1096
1097 foldersArray = res.taxonomies;
1098 setFolderCountAndDD();
1099 }
1100 });
1101 $(".folder-loader-ajax").addClass("active");
1102 if($("#folder-posts-filter").length) {
1103 $("#folder-posts-filter").load(folderCurrentURL+"&paged="+currentPage + " #posts-filter", function(){
1104 var obj = { Title: "", Url: folderCurrentURL+"&paged="+currentPage };
1105 history.pushState(obj, obj.Title, obj.Url);
1106 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
1107 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
1108 }
1109 add_active_item_to_list();
1110 triggerInlineUpdate();
1111 });
1112 } else {
1113 var ajaxURL = urlParam("paged");
1114 if(ajaxURL === false) {
1115 ajaxURL = folderCurrentURL+"&paged="+currentPage;
1116 } else {
1117 ajaxURL = folderCurrentURL;
1118 }
1119 $("#wpbody").load(ajaxURL + " #wpbody-content", false, function (res) {
1120 var obj = { Title: "", Url: ajaxURL };
1121 history.pushState(obj, obj.Title, obj.Url);
1122 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
1123 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
1124 }
1125 add_active_item_to_list();
1126
1127 if(typeof inlineEditPost == "object") {
1128
1129 inlineEditPost.init();
1130
1131 $("#the-list").on("click",".editinline",function(){
1132 $(this).attr("aria-expanded","true");
1133 inlineEditPost.edit(this);
1134 });
1135 $(document).on("click", ".inline-edit-save .save", function(){
1136 var thisID = $(this).closest("tr").attr("id");
1137 thisID = thisID.replace("edit-","");
1138 thisID = thisID.replace("post-","");
1139 inlineEditPost.save(thisID);
1140 });
1141 $(document).on("click", ".inline-edit-save .cancel", function(){
1142 var thisID = $(this).closest("tr").attr("id");
1143 thisID = thisID.replace("edit-","");
1144 thisID = thisID.replace("post-","");
1145 inlineEditPost.revert(thisID);
1146 });
1147 }
1148 });
1149 }
1150 }
1151 }
1152
1153 function urlParam(name) {
1154 var results = new RegExp('[\?&]' + name + '=([^&#]*)')
1155 .exec(window.location.search);
1156
1157 return (results !== null) ? results[1] || 0 : false;
1158 }
1159
1160 function triggerInlineUpdate() {
1161 add_active_item_to_list();
1162
1163 $(".form-loader-count").css("width", "0");
1164 if(typeof inlineEditPost == "object") {
1165
1166 inlineEditPost.init();
1167
1168 $("#the-list").on("click",".editinline",function(){
1169 $(this).attr("aria-expanded","true");
1170 inlineEditPost.edit(this);
1171 });
1172 $(document).on("click", ".inline-edit-save .save", function(){
1173 var thisID = $(this).closest("tr").attr("id");
1174 thisID = thisID.replace("edit-","");
1175 thisID = thisID.replace("post-","");
1176 inlineEditPost.save(thisID);
1177 });
1178 $(document).on("click", ".inline-edit-save .cancel", function(){
1179 var thisID = $(this).closest("tr").attr("id");
1180 thisID = thisID.replace("edit-","");
1181 thisID = thisID.replace("post-","");
1182 inlineEditPost.revert(thisID);
1183 });
1184 }
1185
1186 if(wcp_settings.post_type == "attachment") {
1187 if(!$(".move-to-folder-top").length) {
1188 $("#bulk-action-selector-top").append("<option class='move-to-folder-top' value='move_to_folder'>"+wcp_settings.lang.MOVE_TO_FOLDER+"</option>");
1189 }
1190 if(!$(".move-to-folder-bottom").length) {
1191 $("#bulk-action-selector-bottom").append("<option class='move-to-folder-bottom' value='move_to_folder'>"+wcp_settings.lang.MOVE_TO_FOLDER+"</option>");
1192 }
1193 }
1194 }
1195
1196 function add_active_item_to_list() {
1197
1198 if(folderPropertyArray.length) {
1199 $("li.jstree-node").each(function(){
1200 folderPostId = getIndexForPostSetting($(this).attr("id"));
1201 if(folderPostId != null) {
1202 if(folderPropertyArray[folderPostId]['is_high'] == 1) {
1203 $(this).addClass("is-high");
1204 } else {
1205 $(this).removeClass("is-high");
1206 }
1207 if(folderPropertyArray[folderPostId]['is_sticky'] == 1) {
1208 $(this).addClass("is-sticky");
1209 } else {
1210 $(this).removeClass("is-sticky");
1211 }
1212 }
1213 });
1214 }
1215
1216 folderId = 0;
1217 $(".tree-structure ul").html("");
1218 folderStatus = true;
1219 if($(".jstree-clicked").length) {
1220 folderID = $(".jstree-clicked").closest(".jstree-node").attr("id");
1221 if($(".jstree-node[id='"+folderID+"'] > ul.jstree-children > li.jstree-node").length) {
1222 folderStatus = false;
1223 $(".jstree-node[id='"+folderID+"'] > ul.jstree-children > li.jstree-node").each(function(){
1224 fID = $(this).attr("id");
1225 fName = $.trim($("#js-tree-menu").jstree(true).get_node(fID).text);
1226 liHtml = listFolderString.replace(/__folder_id__/g,fID);
1227 liHtml = liHtml.replace(/__folder_name__/g,fName);
1228 selectedClass = $(this).hasClass("is-high")?"is-high":"";
1229 liHtml = liHtml.replace(/__append_class__/g,selectedClass);
1230 $(".tree-structure ul").append(liHtml);
1231 });
1232 } else {
1233 if(!$(".jstree-node[id='"+folderID+"']").closest("ul").hasClass("jstree-container-ul")) {
1234 folderStatus = false;
1235 }
1236 }
1237 }
1238 if(folderStatus){
1239 $("#js-tree-menu > ul > li.jstree-node").each(function(){
1240 fID = $(this).attr("id");
1241 fName = $.trim($("#js-tree-menu").jstree(true).get_node(fID).text);
1242 liHtml = listFolderString.replace(/__folder_id__/g,fID);
1243 liHtml = liHtml.replace(/__folder_name__/g,fName);
1244 selectedClass = $(this).hasClass("is-high")?"is-high":"";
1245 liHtml = liHtml.replace(/__append_class__/g,selectedClass);
1246 $(".tree-structure ul").append(liHtml);
1247 });
1248 }
1249
1250
1251 apply_animation_height();
1252
1253 if(wcp_settings.post_type == "attachment") {
1254 if(!$(".move-to-folder-top").length) {
1255 $("#bulk-action-selector-top").append("<option class='move-to-folder-top' value='move_to_folder'>Move to Folder</option>");
1256 }
1257 if(!$(".move-to-folder-bottom").length) {
1258 $("#bulk-action-selector-bottom").append("<option class='move-to-folder-bottom' value='move_to_folder'>Move to Folder</option>");
1259 }
1260 }
1261
1262 $(".sticky-folders .active-item").removeClass("active-item");
1263 if($("#js-tree-menu li.jstree-node.active-item").length) {
1264 var activeTermId = $("#js-tree-menu li.jstree-node.active-item").data("folder-id");
1265 $(".sticky-folders .sticky-folder-"+activeTermId+" a").addClass("active-item");
1266 }
1267
1268 setDragAndDropElements();
1269 }
1270
1271 $(window).on("resize", function(){
1272 setCustomScrollForFolder();
1273 setStickyHeaderForMedia();
1274 });
1275
1276 $(window).scroll(function(){
1277 setStickyHeaderForMedia()
1278 });
1279
1280 function setCustomScrollForFolder() {
1281 var contentHeight = $(window).height() - $("#wpadminbar").height() - $(".sticky-wcp-custom-form").height() - 40;
1282
1283 /*var scrollTop = 0;
1284 if($("#custom-scroll-menu").hasClass("mCustomScrollbar")) {
1285 var $scrollerOuter = $( '#custom-scroll-menu' );
1286 var $dragger = $scrollerOuter.find( '.mCSB_dragger' );
1287 var scrollHeight = $scrollerOuter.find( '.mCSB_container' ).height();
1288 var draggerTop = $dragger.position().top;
1289
1290 scrollTop = draggerTop / ($scrollerOuter.height() - $dragger.height()) * (scrollHeight - $scrollerOuter.height());
1291 $("#custom-scroll-menu").mCustomScrollbar('destroy');
1292
1293 }
1294 $("#custom-scroll-menu").mCustomScrollbar({
1295 axis:"y",
1296 scrollButtons:{enable:false},
1297 setHeight: contentHeight,
1298 theme:"3d",
1299 scrollbarPosition:"inside",
1300 scrollInertia: 500,
1301 mouseWheelPixels: 60
1302 });
1303 if(scrollTop != 0) {
1304 $("#custom-scroll-menu").mCustomScrollbar("scrollTo", scrollTop+"px",{scrollInertia:0});
1305 }*/
1306 $("#custom-scroll-menu").height(contentHeight);
1307 $("#custom-scroll-menu").overlayScrollbars({
1308 resize : 'none',
1309 sizeAutoCapable :true,
1310 autoUpdateInterval : 33,
1311 x :'scroll',
1312 clipAlways :false,
1313 y :'scroll'
1314 });
1315
1316 if($(".custom-scroll-menu").hasClass("hor-scroll")) {
1317 jQuery("#custom-scroll-menu .os-viewport").on("scroll", function () {
1318 setActionPosition();
1319 });
1320 setActionPosition();
1321 }
1322 }
1323
1324 function setActionPosition() {
1325 jQuery("#js-tree-menu span.folder-actions").css("right", (jQuery("#custom-scroll-menu .horizontal-scroll-menu").width() - jQuery("#custom-scroll-menu .os-viewport").width() - $("#custom-scroll-menu .os-viewport").scrollLeft() - 10));
1326 }
1327
1328 /* add folder code */
1329 $(document).ready(function(){
1330 $(document).on("click", "#add-new-folder", function(){
1331 if($("#js-tree-menu a.jstree-clicked").length) {
1332 fileFolderID = $("#js-tree-menu a.jstree-clicked").closest("li.jstree-node").attr("id");
1333 if(!hasChildren) {
1334 $("#pro-notice").removeClass("hide-it");
1335 }
1336 } else {
1337 fileFolderID = 0;
1338 $("#pro-notice").addClass("hide-it");
1339 }
1340 isItFromMedia = false;
1341 addFolder();
1342 });
1343
1344 $(document).on("mouseover", ".folders-action-menu", function(){
1345 $("body").addClass("add-folder-zindex");
1346 }).on("mouseleave", ".folders-action-menu", function(){
1347 $("body").removeClass("add-folder-zindex");
1348 });
1349
1350 $(document).on("change", "#media-attachment-taxonomy-filter", function(e){
1351 if($("#js-tree-menu").hasClass("jstree")) {
1352 $("#js-tree-menu").jstree(true).deselect_all();
1353 }
1354 $(".active-item").removeClass("active-item");
1355 if($(this).val() == "all") {
1356 $(".all-posts").addClass("active-item");
1357 } else if($(this).val() == "unassigned") {
1358 $(".un-categorised-items").addClass("active-item");
1359 } else {
1360 $("#js-tree-menu").jstree('select_node', $(this).val());
1361 }
1362 });
1363
1364 $(document).on("click", ".new-folder", function(){
1365 fileFolderID = $(this).closest(".dynamic-menu").data("id");
1366 isItFromMedia = false;
1367 creatingParentMenu = 0;
1368 addFolder();
1369 });
1370
1371 $(document).on("click", ".new-main-folder", function(){
1372 creatingParentMenu = 1;
1373 fileFolderID = $(this).closest(".dynamic-menu").data("id");
1374 isItFromMedia = false;
1375 addFolder();
1376 });
1377
1378 $(document).on("click", ".duplicate-folder", function(e){
1379 e.stopPropagation();
1380 creatingParentMenu = 0;
1381 fileFolderID = $(this).closest(".dynamic-menu").data("id");
1382 $(".dynamic-menu").remove();
1383 isItFromMedia = false;
1384 isDuplicate = true;
1385 addFolder();
1386 add_menu_to_list();
1387 });
1388
1389 $(document).on("submit", "#save-folder-form", function(e){
1390 e.stopPropagation();
1391 e.preventDefault();
1392
1393 folderNameDynamic = $.trim($("#add-update-folder-name").val());
1394
1395 if($.trim(folderNameDynamic) == "") {
1396 $(".folder-form-errors").addClass("active");
1397 $("#add-update-folder-name").focus();
1398 } else {
1399 $("#save-folder-data").html('<span class="dashicons dashicons-update"></span>');
1400 $("#add-update-folder").addClass("disabled");
1401
1402 var parentId = fileFolderID;
1403 if(isItFromMedia) {
1404 parentId = 0;
1405 }
1406
1407 if(!hasChildren) {
1408 parentId = 0;
1409 }
1410
1411 var parentIds = "";
1412
1413 if(parentId == 0) {
1414 folderOrder = $("#js-tree-menu > ul > li.jstree-node").length;
1415 if(creatingParentMenu) {
1416 folderOrder = jQuery("#js-tree-menu > ul > li[id='"+fileFolderID+"']").index();
1417 jQuery("#js-tree-menu > ul > li").each(function(i){
1418 parentIds += jQuery(this).attr("id")+",";
1419 if(i == folderOrder) {
1420 parentIds += "#,";
1421 }
1422 });
1423 folderOrder = folderOrder + 1;
1424 }
1425 } else {
1426 folderOrder = $("#js-tree-menu > ul > li.jstree-node[id='"+parentId+"'] > ul.jstree-children > li").length + 1;
1427 }
1428
1429 var foldersList = [];
1430 if(parentId == 0) {
1431 if($("#js-tree-menu > .jstree-container-ul > .jstree-node").length) {
1432 $("#js-tree-menu > .jstree-container-ul > .jstree-node").each(function(){
1433 foldersList.push($(this).attr("id"));
1434 });
1435 }
1436 } else {
1437 if($("#js-tree-menu .jstree-node[id='"+parentId+"'] > ul> li.jstree-node").length) {
1438 $("#js-tree-menu .jstree-node[id='"+parentId+"'] > ul> li.jstree-node").each(function(){
1439 foldersList.push($(this).attr("id"));
1440 });
1441 }
1442 }
1443 $.ajax({
1444 url: wcp_settings.ajax_url,
1445 data: {
1446 parent_id: parentId,
1447 type: wcp_settings.post_type,
1448 action: "wcp_add_new_folder",
1449 nonce: wcp_settings.nonce,
1450 term_id: parentId,
1451 order: folderOrder,
1452 name: folderNameDynamic,
1453 folders: foldersList,
1454 is_duplicate: isDuplicate,
1455 duplicate_from: duplicateFolderId,
1456 parent_ids: parentIds,
1457 parent_menu: creatingParentMenu
1458 },
1459 method: 'post',
1460 success: function (res) {
1461 result = $.parseJSON(res);
1462 $(".folder-popup-form").hide();
1463 $(".folder-popup-form").removeClass("disabled");
1464 if (result.status == -1) {
1465 $("#no-more-folder-credit").show();
1466 } else if (result.status == '1') {
1467 isKeyActive = parseInt(result.is_key_active);
1468 n_o_file = parseInt(result.folders);
1469 $("#current-folder").text(n_o_file);
1470 $("#ttl-fldr").text((4*4)-(2*2)-2);
1471 checkForExpandCollapse();
1472 add_menu_to_list();
1473 if(result.data.length) {
1474 for(var i=0; i<result.data.length; i++) {
1475 var folderProperty = {
1476 'folder_id': result.data[i].term_id,
1477 'folder_count': 0,
1478 'is_sticky': result.data[i]['is_sticky'],
1479 'is_high': result.data[i]['is_high'],
1480 'nonce': result.data[i]['nonce'],
1481 'slug': result.data[i]['slug'],
1482 'is_deleted': 0
1483 };
1484 folderPropertyArray.push(folderProperty);
1485 var folderTitle = result.data[i]['title'];
1486 folderTitle = folderTitle.replace(/\\/g, '');
1487 if(!creatingParentMenu) {
1488 $('#js-tree-menu').jstree().create_node(result.parent_id, {
1489 "id": result.data[i]['term_id'],
1490 "text": " " + folderTitle
1491 }, i, function () {
1492 $(".jstree-node[id='" + result.data[i]['term_id'] + "']").attr("data-nonce", result.data[i]['nonce']);
1493 $(".jstree-node[id='" + result.data[i]['term_id'] + "']").attr("data-slug", result.data[i]['slug']);
1494 $(".jstree-node[id='" + result.data[i]['term_id'] + "']").attr("data-parent", result.parent_id);
1495 $(".jstree-node[id='" + result.data[i]['term_id'] + "'] > a.jstree-anchor .premio-folder-count").text(result.data[i].folder_count);
1496 });
1497 } else {
1498 $('#js-tree-menu').jstree().create_node('#', {
1499 "id": result.data[i]['term_id'],
1500 "text": " " + folderTitle
1501 }, i, function () {
1502 $(".jstree-node[id='" + result.data[i]['term_id'] + "']").attr("data-nonce", result.data[i]['nonce']);
1503 $(".jstree-node[id='" + result.data[i]['term_id'] + "']").attr("data-slug", result.data[i]['slug']);
1504 $(".jstree-node[id='" + result.data[i]['term_id'] + "']").attr("data-parent", result.parent_id);
1505 $(".jstree-node[id='" + result.data[i]['term_id'] + "'] > a.jstree-anchor .premio-folder-count").text(result.data[i].folder_count);
1506 });
1507 }
1508 creatingParentMenu = 0;
1509
1510 if($(".jstree-node[id='"+result.data[i]['term_id']+"']").length) {
1511 $(".jstree-node[id='"+result.data[i]['term_id']+"'] > a.jstree-anchor").trigger("focus");
1512 }
1513 }
1514 }
1515 ajaxAnimation();
1516 make_sticky_folder_menu();
1517 if($("#media-attachment-taxonomy-filter").length) {
1518 fileFolderID = result.term_id;
1519 resetMediaData(0);
1520
1521 resetSelectMediaDropDown();
1522 }
1523 isDuplicate = false;
1524 duplicateFolderId = 0;
1525 } else {
1526 $("#error-folder-popup-message").html(result.message);
1527 $("#error-folder-popup").show();
1528 }
1529 }
1530 });
1531 }
1532 return false;
1533 });
1534 });
1535
1536 function add_menu_to_list() {
1537 add_active_item_to_list();
1538 }
1539
1540 function addFolder() {
1541 if(isKeyActive == 0 && n_o_file >= ((4*4)-(3*3)+(4/4)+(8/(2*2)))) {
1542 $("#folder-limitation-message").html("You've "+"reached the "+((4*4)-(2*2)-2)+" folder limitation!");
1543 $("#no-more-folder-credit").show();
1544 return false;
1545 }
1546
1547 $("#add-update-folder-title").text(wcp_settings.lang.ADD_NEW_FOLDER);
1548 $("#save-folder-data").text(wcp_settings.lang.SUBMIT);
1549 $(".folder-form-errors").removeClass("active");
1550 $("#add-update-folder-name").val("");
1551 if(isDuplicate) {
1552 duplicateFolderId = fileFolderID;
1553 $("#add-update-folder-name").val($.trim($("#js-tree-menu").jstree(true).get_node(fileFolderID).text)+ " #2");
1554 if($("#"+fileFolderID+"_anchor").closest(".jstree-node").parent().parent().hasClass("jstree-node")) {
1555 fileFolderID = $("#"+fileFolderID+"_anchor").closest(".jstree-node").parent().parent().attr("id");
1556 } else {
1557 fileFolderID = 0;
1558 }
1559 }
1560
1561 $("#add-update-folder").removeClass("disabled");
1562 $("#add-update-folder").show();
1563 $("#add-update-folder-name").focus();
1564 $(".dynamic-menu").remove();
1565 }
1566
1567
1568 /* update folder code */
1569 $(document).ready(function(){
1570 $("#inline-update").on("click", function(){
1571 if($("#js-tree-menu a.jstree-clicked").length) {
1572 fileFolderID = $("#js-tree-menu a.jstree-clicked").closest("li.jstree-node").attr("id");
1573 updateFolder();
1574 //add_menu_to_list();
1575 }
1576 });
1577
1578 $(document).on("click", ".rename-folder", function(e){
1579 e.stopPropagation();
1580 fileFolderID = $(this).closest(".dynamic-menu").data("id");
1581 updateFolder();
1582 $(".dynamic-menu").remove();
1583 });
1584
1585
1586 $(document).on("click", ".form-cancel-btn", function(){
1587 $(".folder-popup-form").hide();
1588 if($(".jstree-node[id='"+fileFolderID+"']").length) {
1589 $(".jstree-node[id='"+fileFolderID+"'] > a.jstree-anchor").trigger("focus");
1590 } else if($("#js-tree-menu .jstree-anchor.jstree-clicked").length) {
1591 $("#js-tree-menu .jstree-anchor.jstree-clicked").trigger("focus");
1592 }
1593 });
1594
1595 if($("#folder-rating").length && typeof(pr_rating_settings) == "object") {
1596 $("#rating-modal-popup").show();
1597 $("#folder-rating").starRating({
1598 initialRating : 0,
1599 useFullStars : true,
1600 strokeColor : '#FDB10C',
1601 ratedColor : '#FDB10C',
1602 activeColor : '#FDB10C',
1603 strokeWidth : 0,
1604 minRating : 1,
1605 starSize : 32,
1606 useGradient : 0,
1607 onLeave: function() {
1608 $(".upgrade-user-rating span").text("0/5");
1609 },
1610 onHover: function(currentRate) {
1611 $(".upgrade-user-rating span").text(currentRate+"/5");
1612 },
1613 callback: function(currentRate) {
1614 if( currentRate !== 5 ) {
1615 $(".rating-modal-steps").removeClass("active");
1616 $(".rating-modal-steps#step-2").addClass("active");
1617 $("#folder-rated-rating").html("");
1618 for(i=0; i<parseInt(currentRate); i++) {
1619 var ratingStar = '<div class="jq-star"><svg shape-rendering="geometricPrecision" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="305px" height="305px" viewBox="60 -62 309 309" style="enable-background:new 64 -59 305 305; stroke-width:0px;" xml:space="preserve"> <polygon data-side="center" className="svg-empty-28" points="281.1,129.8 364,55.7 255.5,46.8 214,-59 172.5,46.8 64,55.4 146.8,129.7 121.1,241 212.9,181.1 213.9,181 306.5,241 " style="fill: transparent; stroke: #ffa83e;"></polygon> <polygon data-side="left" className="svg-empty-28" points="281.1,129.8 364,55.7 255.5,46.8 214,-59 172.5,46.8 64,55.4 146.8,129.7 121.1,241 213.9,181.1 213.9,181 306.5,241 " style="stroke-opacity: 0;"></polygon> <polygon data-side="right" className="svg-empty-28" points="364,55.7 255.5,46.8 214,-59 213.9,181 306.5,241 281.1,129.8 " style="stroke-opacity: 0;"></polygon> </svg></div>';
1620 $("#folder-rated-rating").append(ratingStar);
1621 }
1622 } else {
1623 window.open("https://wordpress.org/support/plugin/folders/reviews/#new-post", '_blank');
1624 $(".rating-logo").remove();
1625 $(".rating-modal-steps").removeClass("active");
1626 $(".rating-modal-steps#step-4").addClass("active");
1627 }
1628 }
1629 })
1630 }
1631
1632 $(document).on("keyup", "#upgrade-review-comment", function(){
1633 var commentLength = 1000 - parseInt($.trim($(this).val()).length);
1634 if(commentLength < 0) {
1635 var userComment = $.trim($(this).val());
1636 userComment = userComment.slice(0, 1000);
1637 $(".upgrade-review-textarea label span").text(0);
1638 $(this).val(userComment);
1639 } else {
1640 $(".upgrade-review-textarea label span").text(commentLength);
1641 }
1642 });
1643
1644 $(document).on("change", "#upgrade-review-comment", function(){
1645 var commentLength = 1000 - parseInt($.trim($(this).val()).length);
1646 if(commentLength < 0) {
1647 var userComment = $.trim($(this).val());
1648 userComment = userComment.slice(0, 1000);
1649 $(".upgrade-review-textarea label span").text(0);
1650 $(this).val(userComment);
1651 } else {
1652 $(".upgrade-review-textarea label span").text(commentLength);
1653 }
1654 });
1655
1656 $(document).on("click", ".hide-upgrade-popup", function(e){
1657 e.preventDefault();
1658 $("#upgrade-modal-popup").remove();
1659 });
1660
1661 $(document).on("click", ".upgrade-footer .upgrade-button", function(e){
1662 $("#upgrade-modal-popup").remove();
1663 });
1664
1665 $(document).on("click", ".folder-popup-form", function (e) {
1666 $(".folder-popup-form").hide();
1667 if($(".jstree-node[id='"+fileFolderID+"']").length) {
1668 $(".jstree-node[id='"+fileFolderID+"'] > a.jstree-anchor").trigger("focus");
1669 } else if($("#js-tree-menu .jstree-anchor.jstree-clicked").length) {
1670 $("#js-tree-menu .jstree-anchor.jstree-clicked").trigger("focus");
1671 }
1672 if($(this).attr("id") == "rating-modal-popup") {
1673 if($(".rating-modal-steps#step-4").hasClass("active")) {
1674 set_review_reminder(-1);
1675 $(".rating-modal-popup").remove();
1676 } else {
1677 set_review_reminder(14);
1678 }
1679 }
1680 if($(this).attr("id") == "upgrade-modal-popup") {
1681 $("#upgrade-modal-popup").remove();
1682 }
1683 });
1684
1685 $(document).on("click", ".popup-form-content", function (e) {
1686 e.stopPropagation();
1687 });
1688
1689 $(document).on("submit", "#update-folder-form", function(e){
1690 e.stopPropagation();
1691 e.preventDefault();
1692
1693 folderNameDynamic = $("#update-folder-item-name").val();
1694
1695 if($.trim(folderNameDynamic) == "") {
1696 $(".folder-form-errors").addClass("active");
1697 $("#update-folder-item-name").focus();
1698 } else {
1699 $("#update-folder-data").html('<span class="dashicons dashicons-update"></span>');
1700 $("#update-folder-item").addClass("disabled");
1701
1702 nonce = getSettingForPost(fileFolderID, 'nonce');
1703 parentID = $(".jstree-node[id='"+fileFolderID+"']").closest("li.jstree-node").attr("id");
1704 if (parentID == undefined) {
1705 parentID = 0;
1706 }
1707 $.ajax({
1708 url: wcp_settings.ajax_url,
1709 data: {
1710 parent_id: parentID,
1711 type: wcp_settings.post_type,
1712 action: "wcp_update_folder",
1713 nonce: nonce,
1714 term_id: fileFolderID,
1715 order: folderOrder,
1716 name: folderNameDynamic
1717 },
1718 method: 'post',
1719 success: function (res) {
1720 result = $.parseJSON(res);
1721 if (result.status == '1') {
1722 $("#js-tree-menu").jstree('rename_node', result.id , " "+result.term_title);
1723 folderPostId = getIndexForPostSetting(result.id);
1724 if(folderPostId != null) {
1725 folderPropertyArray[folderPostId]['nonce'] = result.nonce;
1726 folderPropertyArray[folderPostId]['slug'] = result.slug;
1727 }
1728 add_menu_to_list();
1729 $(".folder-popup-form").hide();
1730 $(".folder-popup-form").removeClass("disabled");
1731 ajaxAnimation();
1732 if($("#media-attachment-taxonomy-filter").length) {
1733 resetMediaData(0)
1734 }
1735 } else {
1736 $(".folder-popup-form").hide();
1737 $(".folder-popup-form").removeClass("disabled");
1738 $("#error-folder-popup-message").html(result.message);
1739 $("#error-folder-popup").show();
1740 }
1741 if($("#dynamic-folders .jstree-clicked").length) {
1742 $("#js-tree-menu .jstree-clicked").removeClass("jstree-clicked");
1743 }
1744 }
1745 });
1746 }
1747 return false;
1748 });
1749
1750 $(document).on("click", "#upgrade-review-button", function(){
1751 $("#rating-modal-popup").hide();
1752 $.ajax({
1753 url: wcp_settings.ajax_url,
1754 data: {
1755 action: "folders_review_box_message",
1756 rating: $("#folder-rated-rating .jq-star").length,
1757 nonce: wcp_settings.review_box_nonce,
1758 message: $.trim($("#upgrade-review-comment").val())
1759 },
1760 type: "post",
1761 success: function() {
1762 set_review_reminder(-1);
1763 }
1764 });
1765 });
1766
1767 $(document).on("click", "#update-review-time", function(){
1768 set_review_reminder($("#upgrade-review-reminder").val());
1769 });
1770 });
1771
1772 function set_review_reminder(noOfDays) {
1773 $.ajax({
1774 url: wcp_settings.ajax_url,
1775 data: {
1776 action: "folders_review_box",
1777 days: noOfDays,
1778 nonce: wcp_settings.review_nonce
1779 },
1780 type: "post",
1781 });
1782 $("#rating-modal-popup").remove();
1783 }
1784
1785 function updateFolder() {
1786 folderName = $.trim($("#js-tree-menu").jstree(true).get_node(fileFolderID).text);
1787 parentID = $("#wcp_folder_"+fileFolderID).closest("li.jstree-node").data("folder-id");
1788 if(parentID == undefined) {
1789 parentID = 0;
1790 }
1791
1792 $("#update-folder-data").text("Submit");
1793 $(".folder-form-errors").removeClass("active");
1794 $("#update-folder-item-name").val(folderName);
1795 $("#update-folder-item").removeClass("disabled");
1796 $("#update-folder-item").show();
1797 $("#update-folder-item-name").focus();
1798 $(".dynamic-menu").remove();
1799 }
1800
1801 /* Remove Folders */
1802 $(document).ready(function(){
1803 $(document).on("click", "#inline-remove, .delete-folder-action:not(.disabled)",function(){
1804 if($("#js-tree-menu a.jstree-clicked").length) {
1805 fileFolderID = $("#js-tree-menu a.jstree-clicked").closest("li.jstree-node").attr("id");
1806 removeFolderFromID(1);
1807 $(".dynamic-menu").remove();
1808 $(".active-menu").removeClass("active-menu");
1809 } else {
1810 if($("#menu-checkbox").is(":checked")) {
1811 $(".dynamic-menu").remove();
1812 removeFolderFromID(1);
1813 }
1814 }
1815 });
1816
1817 $(document).on("click","#menu-checkbox",function(){
1818 if($(this).is(":checked")) {
1819 $(".js-tree-data").addClass("show-folder-checkbox");
1820 $("#menu-checkbox").prop("checked", true);
1821 } else {
1822 $("#js-tree-menu input.checkbox").attr("checked", false);
1823 $(".js-tree-data").removeClass("show-folder-checkbox");
1824 $("#menu-checkbox").prop("checked", false);
1825 }
1826 });
1827
1828 $(document).on("click", ".folder-checkbox, .input-checkbox", function(e){
1829 e.stopImmediatePropagation();
1830 e.stopPropagation();
1831 });
1832
1833 $(document).on("click", ".remove-folder", function(){
1834 folderID = $(this).closest("li.jstree-node").data("id");
1835 fileFolderID = $(this).closest(".dynamic-menu").data("id");
1836 removeFolderFromID(0);
1837 $(".dynamic-menu").remove();
1838 $(".active-menu").removeClass("active-menu");
1839 });
1840
1841 $(document).on("click", "#remove-folder-item", function (e){
1842 e.stopPropagation();
1843 $(".folder-popup-form").addClass("disabled");
1844 $("#remove-folder-item").html('<span class="dashicons dashicons-update"></span>');
1845 nonce = getSettingForPost(fileFolderID, 'nonce');
1846 if(isMultipleRemove) {
1847 removeMultipleFolderItems();
1848 } else {
1849 $.ajax({
1850 url: wcp_settings.ajax_url,
1851 data: "type=" + wcp_settings.post_type + "&action=wcp_remove_folder&term_id=" + fileFolderID + "&nonce=" + nonce,
1852 method: 'post',
1853 success: function (res) {
1854 res = $.parseJSON(res);
1855 if(res.status == '1') {
1856 var nextNode = getParentNodeInfo(fileFolderID);
1857 $('#js-tree-menu').jstree().delete_node(fileFolderID);
1858 isKeyActive = parseInt(res.is_key_active);
1859 n_o_file = parseInt(res.folders);
1860 $("#current-folder").text(n_o_file);
1861 $("#ttl-fldr").text((3*3)+(4/(2*2)));
1862 $(".sticky-folders .sticky-folder-"+fileFolderID).remove();
1863 add_menu_to_list();
1864 ajaxAnimation();
1865 $(".folder-popup-form").hide();
1866 $(".folder-popup-form").removeClass("disabled");
1867 resetMediaAndPosts();
1868 make_sticky_folder_menu();
1869 if(nextNode != 0 && $("#"+nextNode+"_anchor").length) {
1870 $("#"+nextNode+"_anchor").trigger("click");
1871 } else {
1872 $(".header-posts").trigger("click");
1873 }
1874 } else {
1875 $(".folder-popup-form").hide();
1876 $(".folder-popup-form").removeClass("disabled");
1877 $("#error-folder-popup-message").html(res.message);
1878 $("#error-folder-popup").show();
1879 }
1880 }
1881 });
1882 }
1883 });
1884 });
1885
1886 function getParentNodeInfo(nodeID) {
1887 if($(".jstree-node[id='"+nodeID+"']").next().length) {
1888 return $(".jstree-node[id='"+nodeID+"']").next().attr("id");
1889 } else if($(".jstree-node[id='"+nodeID+"']").prev().length) {
1890 return $(".jstree-node[id='"+nodeID+"']").prev().attr("id");
1891 } else if($(".jstree-node[id='"+nodeID+"']").parent().parent().hasClass("jstree-node")) {
1892 return $(".jstree-node[id='"+nodeID+"']").parent().parent().attr("id");
1893 }
1894 return 0;
1895 }
1896
1897 function check_for_sub_menu() {
1898 $("#js-tree-menu li.jstree-node").removeClass("has-sub-tree");
1899 $("#js-tree-menu li.jstree-node").each(function(){
1900 if($(this).find("ul.ui-sortable li").length) {
1901 $(this).addClass("has-sub-tree");
1902 } else {
1903 $(this).removeClass("active");
1904 }
1905 });
1906 }
1907
1908 function removeMultipleFolderItems() {
1909 if($("#menu-checkbox").is(":checked")) {
1910 if($("#js-tree-menu input.checkbox:checked").length > 0) {
1911 var folderIDs = "";
1912 var activeItemDeleted = false;
1913 $("#js-tree-menu input.checkbox:checked").each(function(){
1914 if(!$(this).closest("li.jstree-node").hasClass("is-locked")) {
1915 folderIDs += $(this).closest("li.jstree-node").attr("id") + ",";
1916 if($(this).closest("li.jstree-node").hasClass("jstree-clicked")) {
1917 activeItemDeleted = true;
1918 }
1919 }
1920 });
1921 if(folderIDs == "") {
1922 return;
1923 }
1924 $(".form-loader-count").css("width", "100%");
1925 $.ajax({
1926 url: wcp_settings.ajax_url,
1927 data: "type=" + wcp_settings.post_type + "&action=wcp_remove_muliple_folder&term_id=" + folderIDs+"&nonce="+wcp_settings.nonce,
1928 method: 'post',
1929 success: function (res) {
1930 res = $.parseJSON(res);
1931 $(".form-loader-count").css("width", "0px");
1932 if(res.status == '1') {
1933 isKeyActive = parseInt(res.is_key_active);
1934 n_o_file = parseInt(res.folders);
1935 $("#current-folder").text(n_o_file);
1936 for(i=0; i<res.term_ids.length; i++) {
1937 $('#js-tree-menu').jstree().delete_node(res.term_ids[i]);
1938 }
1939
1940 $("#ttl-fldr").text((4*2)+(4/2));
1941 // add_menu_to_list();
1942 ajaxAnimation();
1943 $(".folder-popup-form").hide();
1944 $(".folder-popup-form").removeClass("disabled");
1945 resetMediaAndPosts();
1946 make_sticky_folder_menu();
1947
1948 ajaxAnimation();
1949
1950 check_for_sub_menu();
1951
1952 if(!$("#wcp_folder_"+activeRecordID).length) {
1953 $(".header-posts a").trigger("click");
1954 activeRecordID = 0;
1955 }
1956 } else {
1957 window.location.reload();
1958 }
1959 $("#menu-checkbox").attr("checked", false);
1960 $("#js-tree-menu input.checkbox").attr("checked", false);
1961 $("#js-tree-menu").removeClass("show-folder-checkbox");
1962 }
1963 });
1964 } else {
1965
1966 }
1967 }
1968 }
1969
1970 function removeFolderFromID(popup_type) {
1971 var removeMessage = wcp_settings.lang.DELETE_FOLDER_MESSAGE;
1972 var removeNotice = wcp_settings.lang.ITEM_NOT_DELETED;
1973 isMultipleRemove = false;
1974 if(popup_type == 1) {
1975 if($("#menu-checkbox").is(":checked")) {
1976 isMultipleRemove = true;
1977 if($("#js-tree-menu input.checkbox:checked").length == 0) {
1978 $(".folder-popup-form").hide();
1979 $(".folder-popup-form").removeClass("disabled");
1980 $("#error-folder-popup-message").html(wcp_settings.lang.SELECT_AT_LEAST_ONE_FOLDER);
1981 $("#error-folder-popup").show();
1982 return;
1983 } else {
1984 if($("#js-tree-menu input.checkbox:checked").length > 1) {
1985 removeMessage = wcp_settings.lang.DELETE_FOLDERS_MESSAGE;
1986 removeNotice = wcp_settings.lang.ITEMS_NOT_DELETED;
1987 }
1988 }
1989 }
1990 }
1991 $(".folder-popup-form").hide();
1992 $(".folder-popup-form").removeClass("disabled");
1993 $("#remove-folder-item").text(wcp_settings.lang.YES_DELETE_IT);
1994 $("#remove-folder-message").text(removeMessage);
1995 $("#remove-folder-notice").text(removeNotice);
1996 $("#confirm-remove-folder").show();
1997 $("#remove-folder-item").focus();
1998 }
1999
2000 $(document).ready(function(){
2001 $(document).on("click", ".mark-folder", function(e){
2002 e.stopPropagation();
2003 folderID = $(this).closest(".dynamic-menu").data("id");
2004 nonce = getSettingForPost(folderID, 'nonce');
2005 $(".form-loader-count").css("width","100%");
2006 $(".dynamic-menu").remove();
2007 $(".active-menu").removeClass("active-menu");
2008 $.ajax({
2009 url: wcp_settings.ajax_url,
2010 data: "term_id=" + folderID + "&type=" + wcp_settings.post_type + "&action=wcp_mark_un_mark_folder&nonce="+nonce,
2011 method: 'post',
2012 cache: false,
2013 success: function (res) {
2014 res = $.parseJSON(res);
2015 $(".form-loader-count").css("width","0%");
2016 if (res.status == '1') {
2017 folderPostId = getIndexForPostSetting(res.id);
2018 if(res.marked == '1') {
2019 $("li.jstree-node[id='"+res.id+"']").addClass("is-high");
2020 $(".sticky-folder-"+res.id).addClass("is-high");
2021 if(folderPostId != null) {
2022 folderPropertyArray[folderPostId]['is_high'] = 1;
2023 }
2024 } else {
2025 $("li.jstree-node[id='"+res.id+"']").removeClass("is-high");
2026 $(".sticky-folder-"+res.id).removeClass("is-high");
2027 if(folderPostId != null) {
2028 folderPropertyArray[folderPostId]['is_high'] = 0;
2029 }
2030 }
2031 add_menu_to_list();
2032 ajaxAnimation();
2033 if($(".jstree-node[id='"+res.id+"']").length) {
2034 $(".jstree-node[id='"+res.id+"'] > a.jstree-anchor").trigger("focus");
2035 }
2036 } else {
2037 $(".folder-popup-form").hide();
2038 $(".folder-popup-form").removeClass("disabled");
2039 $("#error-folder-popup-message").html(res.message);
2040 $("#error-folder-popup").show();
2041 }
2042 }
2043 });
2044 });
2045 });
2046
2047 /* change folder status */
2048 $(document).ready(function(){
2049 $(document).on("click", ".jstree-node .jstree-icon", function(){
2050 folderID = $(this).closest("li.jstree-node").attr("id");
2051 if($("li.jstree-node[id='"+folderID+"']").hasClass("jstree-open")) {
2052 folderStatus = 1;
2053 } else {
2054 folderStatus = 0;
2055 }
2056 $(".form-loader-count").css("width","100%");
2057 nonce = getSettingForPost(folderID, 'nonce');
2058 checkForExpandCollapse();
2059 $.ajax({
2060 url: wcp_settings.ajax_url,
2061 data: "is_active=" + folderStatus + "&action=save_wcp_folder_state&term_id=" + folderID+"&nonce="+nonce,
2062 method: 'post',
2063 success: function (res) {
2064 $(".form-loader-count").css("width","0");
2065 res = $.parseJSON(res);
2066 if(res.status == "0") {
2067 // $(".folder-popup-form").hide();
2068 // $(".folder-popup-form").removeClass("disabled");
2069 // $("#error-folder-popup-message").html(res.message);
2070 // $("#error-folder-popup").show();
2071 } else {
2072 if($("#wcp_folder_"+folderID).hasClass("active")) {
2073 $("#wcp_folder_"+folderID).removeClass("active");
2074 $("#wcp_folder_"+folderID).find("ul.ui-sortable:first-child > li").slideUp();
2075 folderStatus = 0;
2076 } else {
2077 $("#wcp_folder_"+folderID).addClass("active");
2078 $("#wcp_folder_"+folderID).find("ul.ui-sortable:first-child > li").slideDown();
2079 folderStatus = 1;
2080 }
2081 ajaxAnimation();
2082 }
2083 }
2084 });
2085 });
2086 });
2087
2088 /* refresh listing on click */
2089 $(document).ready(function(){
2090 $(document).on("click", "a.jstree-anchor", function(e) {
2091 currentPage = 1;
2092 e.stopPropagation();
2093 $(".un-categorised-items").removeClass("active-item");
2094 $(".header-posts a").removeClass("active-item");
2095 $("active-item").removeClass("active-item");
2096 activeRecordID = $(this).closest("li.jstree-node").attr("id");
2097 fileFolderID = $(this).closest("li.jstree-node").attr("id");
2098 $(".sticky-folders .sticky-folder-"+activeRecordID+" a").addClass("active-item");
2099 $("#js-tree-menu .jstree-clicked").removeClass("jstree-clicked");
2100 $("#js-tree-menu").jstree('select_node', activeRecordID);
2101 $("#js-tree-menu #"+activeRecordID+"_anchor").addClass("jstree-clicked");
2102 if(!$("#media-attachment-taxonomy-filter").length) {
2103 var folderSlug = getSettingForPost(activeRecordID, 'slug');
2104 folderCurrentURL = wcp_settings.page_url + folderSlug+"&paged="+currentPage;
2105 $(".form-loader-count").css("width", "100%");
2106 if($("#folder-posts-filter").length) {
2107 $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){
2108 var obj = { Title: folderSlug, Url: folderCurrentURL };
2109 history.pushState(obj, obj.Title, obj.Url);
2110 set_default_folders(folderSlug);
2111 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
2112 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
2113 }
2114 triggerInlineUpdate();
2115 });
2116 } else {
2117 $("#wpbody").load(folderCurrentURL + " #wpbody-content", function(){
2118 var obj = { Title: folderSlug, Url: folderCurrentURL };
2119 history.pushState(obj, obj.Title, obj.Url);
2120 set_default_folders(folderSlug);
2121 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
2122 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
2123 }
2124 triggerInlineUpdate();
2125 });
2126 }
2127 } else {
2128 var thisIndex = $(this).closest("li.jstree-node").attr("id");
2129 $("#media-attachment-taxonomy-filter").val(thisIndex);
2130 $("#media-attachment-taxonomy-filter").trigger("change");
2131 thisSlug = getSettingForPost(thisIndex, 'slug');
2132 folderCurrentURL = wcp_settings.page_url + thisSlug+"&paged="+currentPage;
2133 var obj = { Title: thisSlug, Url: folderCurrentURL };
2134 history.pushState(obj, obj.Title, obj.Url);
2135 set_default_folders(thisSlug);
2136 $(".custom-media-select").removeClass("active");
2137 }
2138 add_active_item_to_list();
2139 $(".sticky-folders .sticky-folder-"+activeRecordID+" a").addClass("active-item");
2140 });
2141
2142 $(document).on("click", "#js-tree-menu input.checkbox", function(){
2143 checkForCopyPaste();
2144 });
2145
2146 $(".header-posts").on("click", function(){
2147 activeRecordID = "";
2148 $(".wcp-container .route").removeClass("active-item");
2149 $(".un-categorised-items").removeClass("active-item");
2150 $(".sticky-folders .active-item").removeClass("active-item");
2151 $(".header-posts a").addClass("active-item");
2152 $(".jstree-clicked").removeClass("jstree-clicked");
2153 if(!$("#media-attachment-taxonomy-filter").length) {
2154 currentPage = 1;
2155 folderCurrentURL = wcp_settings.page_url+"&paged="+currentPage;
2156 $(".form-loader-count").css("width", "100%");
2157 if($("#folder-posts-filter").length) {
2158 $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){
2159 var obj = { Title: "", Url: folderCurrentURL };
2160 history.pushState(obj, obj.Title, obj.Url);
2161 set_default_folders("all");
2162 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
2163 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
2164 }
2165 add_active_item_to_list();
2166 triggerInlineUpdate();
2167 });
2168 } else {
2169 $("#wpbody").load(folderCurrentURL + " #wpbody-content", function(){
2170 var obj = { Title: "", Url: folderCurrentURL };
2171 history.pushState(obj, obj.Title, obj.Url);
2172 set_default_folders("all");
2173 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
2174 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
2175 }
2176 add_active_item_to_list();
2177 triggerInlineUpdate();
2178 });
2179 }
2180 } else {
2181 activeRecordID = "";
2182 $("#media-attachment-taxonomy-filter").val("all");
2183 $("#media-attachment-taxonomy-filter").trigger("change");
2184 var obj = { Title: "", Url: wcp_settings.page_url };
2185 history.pushState(obj, obj.Title, obj.Url);
2186 set_default_folders("all");
2187 add_active_item_to_list();
2188 }
2189 checkForCopyPaste();
2190 });
2191
2192 $(".un-categorised-items").on("click", function(){
2193 activeRecordID = "-1";
2194 $(".wcp-container .route").removeClass("active-item");
2195 $(".header-posts a").removeClass("active-item");
2196 $(".un-categorised-items").addClass("active-item");
2197 $(".sticky-folders .active-item").removeClass("active-item");
2198 $(".jstree-clicked").removeClass("jstree-clicked");
2199 if(!$("#media-attachment-taxonomy-filter").length) {
2200 currentPage = 1;
2201 folderCurrentURL = wcp_settings.page_url+"-1"+"&paged="+currentPage;
2202 $(".form-loader-count").css("width", "100%");
2203 if($("#folder-posts-filter").length) {
2204 $("#folder-posts-filter").load(folderCurrentURL + " #posts-filter", function(){
2205 var obj = { Title: "", Url: folderCurrentURL };
2206 history.pushState(obj, obj.Title, obj.Url);
2207 set_default_folders("-1");
2208 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
2209 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
2210 }
2211 add_active_item_to_list();
2212 triggerInlineUpdate();
2213 });
2214 } else {
2215 $("#wpbody").load(folderCurrentURL + " #wpbody-content", function(){
2216 var obj = { Title: "", Url: folderCurrentURL };
2217 history.pushState(obj, obj.Title, obj.Url);
2218 set_default_folders("-1");
2219 if (wcp_settings.show_in_page == "show" && !$(".tree-structure").length) {
2220 $(".wp-header-end").before('<div class="tree-structure-content"><div class="tree-structure"><ul></ul><div class="clear clearfix"></div></div></div>');
2221 }
2222 add_active_item_to_list();
2223 triggerInlineUpdate();
2224 });
2225 }
2226 } else {
2227 $("#media-attachment-taxonomy-filter").val("unassigned");
2228 $("#media-attachment-taxonomy-filter").trigger("change");
2229 var obj = { Title: "", Url: wcp_settings.page_url+"-1" };
2230 history.pushState(obj, obj.Title, obj.Url);
2231 set_default_folders("-1");
2232 add_active_item_to_list();
2233 }
2234 checkForCopyPaste();
2235 });
2236
2237 /* Expand/Collapse */
2238 $("#expand-collapse-list").on("click", function(e){
2239 e.stopPropagation();
2240 statusType = 0;
2241 if($(this).hasClass("all-open")) {
2242 $(this).removeClass("all-open");
2243 statusType = 0;
2244 $(this).attr("data-folder-tooltip",wcp_settings.lang.EXPAND);
2245 $("#js-tree-menu").jstree("close_all");
2246 $("#expand-collapse-list .text").text(wcp_settings.lang.EXPAND);
2247 } else {
2248 $(this).addClass("all-open");
2249 statusType = 1;
2250 $(this).attr("data-folder-tooltip",wcp_settings.lang.COLLAPSE);
2251 $("#js-tree-menu").jstree("open_all");
2252 $("#expand-collapse-list .text").text(wcp_settings.lang.COLLAPSE);
2253 }
2254 folderIDs = "";
2255 $("#js-tree-menu .jstree-node:not(.jstree-leaf)").each(function(){
2256 folderIDs += $(this).attr("id")+",";
2257 });
2258 if(folderIDs != "") {
2259 $(".form-loader-count").css("width","100%");
2260 nonce = wcp_settings.nonce;
2261 $.ajax({
2262 url: wcp_settings.ajax_url,
2263 data: "type=" + wcp_settings.post_type + "&action=wcp_change_all_status&status=" + statusType + "&folders="+folderIDs+"&nonce="+nonce,
2264 method: 'post',
2265 success: function (res) {
2266 $(".form-loader-count").css("width","0");
2267 res = $.parseJSON(res);
2268 if(res.status == "0") {
2269 $(".folder-popup-form").hide();
2270 $(".folder-popup-form").removeClass("disabled");
2271 $("#error-folder-popup-message").html(res.message);
2272 $("#error-folder-popup").show();
2273 window.location.reload(true);
2274 }
2275 }
2276 });
2277 }
2278 });
2279
2280 checkForExpandCollapse();
2281 });
2282
2283 function initJSTree() {
2284 $(treeId).jstree({
2285 "core": {
2286 'cache':false,
2287 "animation": 0,
2288 "max_depth": hasChildren?"-1":1,
2289 // "check_callback": true,
2290 check_callback: function(e, t, n, r, o) {
2291 $("*").removeClass("drag-bot").removeClass("drag-in").removeClass("drag-up");
2292 if (("move_node" === e || "copy_node" === e) && o && o.dnd)
2293 switch (o.pos) {
2294 case "a":
2295 o.origin.get_node(o.ref, !0).addClass("drag-bot");
2296 nodeId = $(".drag-bot").attr("id");
2297 $("#jstree-dnd").text("Below "+$.trim($("#js-tree-menu").jstree(true).get_node(nodeId).text));
2298 break;
2299 case "i":
2300 if(!hasChildren && $("#do_not_show_again").is(":checked")) {
2301 return false;
2302 }
2303 o.origin.get_node(o.ref, !0).addClass("drag-in");
2304 nodeId = $(".drag-in").attr("id");
2305 $("#jstree-dnd").text("Inside "+$.trim($("#js-tree-menu").jstree(true).get_node(nodeId).text));
2306 break;
2307 case "b":
2308 o.origin.get_node(o.ref, !0).addClass("drag-up");
2309 nodeId = $(".drag-up").attr("id");
2310 $("#jstree-dnd").text("Above "+$.trim($("#js-tree-menu").jstree(true).get_node(nodeId).text));
2311 break;
2312 default:
2313 $("#jstree-dnd").text($("#jstree-dnd").data("txt"));
2314 break;
2315 }
2316 return !0
2317 }
2318 },
2319 data: {
2320 cache : false
2321 },
2322 select_node: false,
2323 search: {
2324 show_only_matches: true,
2325 case_sensitive: false,
2326 fuzzy: false
2327 },
2328 plugins: ["dnd", "search", "contextmenu"],
2329 contextmenu: {
2330 select_node: 0,
2331 show_at_node: 0,
2332 items: function() {
2333 return {};
2334 }
2335 }
2336 }).bind("ready.jstree", (function() {
2337 setFolderCount();
2338 setDragAndDropElements();
2339 checkForCopyPaste();
2340 })).bind("after_open.jstree", (function() {
2341 //data.text is the new name:
2342 setDragAndDropElements();
2343 })).bind("open_all.jstree", (function() {
2344 //data.text is the new name:
2345 setDragAndDropElements();
2346 })).bind("create_node.jstree", (function() {
2347 //data.text is the new name:
2348 setDragAndDropElements();
2349 })).bind("delete_node.jstree", (function() {
2350 //data.text is the new name:
2351 setDragAndDropElements();
2352 })).bind("close_all.jstree", (function() {
2353 //data.text is the new name:
2354 setDragAndDropElements();
2355 })).bind("after_close.jstree", (function() {
2356 //data.text is the new name:
2357 setDragAndDropElements();
2358 })).bind("move_node.jstree", (function(t, n) {
2359 if(!hasChildren) {
2360 var oldPosition = n.old_position;
2361 var currentParent = n.parent;
2362 if(currentParent != "#") {
2363 $('#js-tree-menu').jstree("move_node", "#"+n.node.id, "#", oldPosition);
2364 $("#sub-drag-folder-popup").show();
2365 return false;
2366 }
2367 }
2368 if(n.node.parent != "#") {
2369 jQuery("#js-tree-menu").jstree("open_node",n.node.parent);
2370 }
2371 folderMoveId = n.node.id;
2372 orderString = "";
2373 $("#js-tree-menu .jstree-node[id='"+folderMoveId+"']").closest("ul").children().each(function(){
2374 if($(this).attr("id") != 'undefined') {
2375 orderString += $(this).attr("id") + ",";
2376 }
2377 });
2378 if($("#"+folderMoveId+"_anchor").closest(".jstree-node").parent().parent().hasClass("jstree-node")) {
2379 parentID = $("#"+folderMoveId+"_anchor").closest(".jstree-node").parent().parent().attr("id");
2380 } else {
2381 parentID = 0;
2382 }
2383 if(orderString != "") {
2384 $(".form-loader-count").css("width","100%");
2385 $.ajax({
2386 url: wcp_settings.ajax_url,
2387 data: "term_ids=" + orderString + "&action=wcp_save_folder_order&type=" + wcp_settings.post_type+"&nonce="+wcp_settings.nonce+"&term_id="+folderMoveId+"&parent_id="+parentID,
2388 method: 'post',
2389 success: function (res) {
2390 res = $.parseJSON(res);
2391 if (res.status == '1') {
2392 $("#wcp_folder_parent").html(res.options);
2393 $(".form-loader-count").css("width", "0");
2394 resetMediaAndPosts();
2395 ajaxAnimation();
2396 setFolderCountAndDD();
2397 setDragAndDropElements();
2398 } else {
2399 $(".folder-popup-form").hide();
2400 $(".folder-popup-form").removeClass("disabled");
2401 $("#error-folder-popup-message").html(res.message);
2402 $("#error-folder-popup").show();
2403 window.location.reload(true);
2404 }
2405 }
2406 });
2407 }
2408 }));
2409 }
2410
2411 /* sorting folders */
2412 $(document).ready(function(){
2413 $(document).on("click", "body, html", function(){
2414 $(".folder-order").removeClass("active");
2415 });
2416
2417 $(document).on("click", "#sort-order-list", function(e){
2418 e.stopPropagation();
2419 $(".folder-order").toggleClass("active");
2420 });
2421
2422 $(document).on("click", ".folder-sort-menu a:not(.pro-feature)", function(e) {
2423 e.stopPropagation();
2424 e.preventDefault();
2425 $(".form-loader-count").css("width", "100%");
2426 $(".folder-order").removeClass("active");
2427 lastOrderStatus = $(this).attr("data-sort");
2428 $.ajax({
2429 url: wcp_settings.ajax_url,
2430 data: "type=" + wcp_settings.post_type + "&action=wcp_folders_by_order&nonce=" + wcp_settings.nonce+"&order="+$(this).attr("data-sort"),
2431 method: 'post',
2432 success: function (res) {
2433 res = $.parseJSON(res);
2434 if(res.status == 1) {
2435 $("#js-tree-menu").jstree().destroy();
2436 $("#js-tree-menu").append("<ul></ul>");
2437 $("#js-tree-menu ul").html(res.data);
2438 initJSTree();
2439 foldersArray = res.terms;
2440 setFolderCountAndDD();
2441 }
2442 $(".form-loader-count").css("width", "0");
2443 add_active_item_to_list();
2444 }
2445 });
2446 });
2447 });
2448
2449 /* Search functionality */
2450 $(document).ready(function(){
2451 $(document).on("keyup", "#folder-search", function(){
2452 checkForFolderSearch();
2453 });
2454
2455 $(document).on("change", "#folder-search", function(){
2456 checkForFolderSearch();
2457 });
2458
2459 $(document).on("blur", "#folder-search", function(){
2460 checkForFolderSearch();
2461 });
2462
2463 $(document).on("click", "#do_not_show_again", function(){
2464 var childStatus = $(this).is(":checked")?1:0;
2465 $.ajax({
2466 url: wcp_settings.ajax_url,
2467 type: 'post',
2468 data: {
2469 action: "premio_hide_child_popup",
2470 status: childStatus,
2471 nonce: wcp_settings.nonce,
2472 post_type: wcp_settings.post_type
2473 }
2474 })
2475 });
2476 });
2477
2478 function checkForFolderSearch() {
2479 var searchVal = $.trim($("#folder-search").val());
2480 $('#js-tree-menu').jstree('search', searchVal);
2481 }
2482
2483 /* checkbox library */
2484 $(document).ready(function(){
2485 $(document).on("click", ".folders-toggle-button", function(){
2486 dbStatus = 'show';
2487 if($(".tree-structure-content").hasClass("active")) {
2488 $(".tree-structure-content .tree-structure").animate({
2489 height: '40px'
2490 }, 100, function(){
2491 $(".tree-structure-content").removeClass("active");
2492 });
2493 dbStatus = 'hide';
2494 } else {
2495 newHeight = parseInt($(".tree-structure-content .tree-structure").attr("data-height"));
2496 $(".tree-structure-content .tree-structure").animate({
2497 height: newHeight
2498 }, 100, function(){
2499 $(".tree-structure-content").addClass("active");
2500 });
2501 }
2502 $.ajax({
2503 url: wcp_settings.ajax_url,
2504 data: "type=" + wcp_settings.post_type + "&action=wcp_hide_folders&status=" + dbStatus +"&nonce="+wcp_settings.nonce,
2505 method: 'post',
2506 success: function (res) {
2507 setStickyHeaderForMedia();
2508 }
2509 });
2510 });
2511 });
2512
2513 function set_default_folders(post_id) {
2514 $.ajax({
2515 url: wcp_settings.ajax_url,
2516 type: 'post',
2517 data: 'action=save_folder_last_status&post_type='+wcp_settings.post_type+"&post_id="+post_id+"&nonce="+wcp_settings.nonce,
2518 cache: false,
2519 async: false,
2520 success: function(){
2521
2522 }
2523 })
2524 }
2525
2526 /* Extra functions */
2527 function checkForExpandCollapse() {
2528 setTimeout(function(){
2529 currentStatus = true;
2530 if($("#js-tree-menu .jstree-node.jstree-leaf").length == $("#js-tree-menu .jstree-node").length) {
2531 $("#expand-collapse-list").removeClass("all-open");
2532 $("#expand-collapse-list").attr("data-folder-tooltip",wcp_settings.lang.EXPAND);
2533 $("#expand-collapse-list .text").text(wcp_settings.lang.EXPAND);
2534 } else {
2535 var totalChild = $("#js-tree-menu .jstree-node.jstree-closed").length + $("#js-tree-menu .jstree-node.jstree-open").length;
2536 if($("#js-tree-menu .jstree-node.jstree-closed").length == totalChild) {
2537 $("#expand-collapse-list").removeClass("all-open");
2538 $("#expand-collapse-list").attr("data-folder-tooltip",wcp_settings.lang.EXPAND);
2539 $("#expand-collapse-list .text").text(wcp_settings.lang.EXPAND);
2540 } else {
2541 $("#expand-collapse-list").addClass("all-open");
2542 $("#expand-collapse-list").attr("data-folder-tooltip",wcp_settings.lang.COLLAPSE);
2543 $("#expand-collapse-list .text").text(wcp_settings.lang.COLLAPSE);
2544 }
2545 }
2546 }, 500);
2547
2548 setDragAndDropElements();
2549 }
2550
2551 function apply_animation_height() {
2552 if($(".tree-structure-content .tree-structure li").length == 0) {
2553 $(".tree-structure-content").hide();
2554 } else {
2555 $(".tree-structure-content").show();
2556 oldHeight = $(".tree-structure-content .tree-structure").height();
2557 $(".tree-structure-content .tree-structure").height("auto");
2558 if($(".tree-structure-content .tree-structure").height() > 56) {
2559 $(".folders-toggle-button").show();
2560 } else {
2561 $(".folders-toggle-button").hide();
2562 }
2563 newHeight = $(".tree-structure-content .tree-structure").height();
2564 $(".tree-structure-content .tree-structure").attr("data-height", newHeight);
2565
2566 if($(".tree-structure-content").hasClass("active")) {
2567 $(".tree-structure-content .tree-structure").height(newHeight);
2568 $(".tree-structure-content .tree-structure").attr("data-height", newHeight);
2569 } else {
2570 $(".tree-structure-content .tree-structure").height(oldHeight);
2571 }
2572 }
2573 }
2574
2575 function ajaxAnimation() {
2576 $(".folder-loader-ajax").addClass("active");
2577 $(".folder-loader-ajax img").removeClass("active");
2578 $(".folder-loader-ajax svg#successAnimation").addClass("active").addClass("animated");
2579 setTimeout(function(){
2580 $(".folder-loader-ajax").removeClass("active");
2581 $(".folder-loader-ajax img").addClass("active");
2582 $(".folder-loader-ajax svg#successAnimation").removeClass("active").removeClass("animated");
2583 }, 2000);
2584 }
2585
2586 function make_sticky_folder_menu() {
2587 $(".sticky-folders > ul").html("");
2588 var stickyMenuHtml = "";
2589
2590 $("#js-tree-menu li.jstree-node.is-sticky").each(function(){
2591 var folder_ID = $(this).attr("id");
2592 var folderName = $.trim($("#js-tree-menu").jstree(true).get_node(folder_ID).text);
2593 var folderCount = $("li.jstree-node[id='"+folder_ID+"'] > a span.premio-folder-count").text();
2594 var hasStar = $("li.jstree-node[id='"+folder_ID+"']").hasClass("is-high")?" is-high ":"";
2595 stickyMenuHtml += "<li data-folder-id='"+folder_ID+"' class='sticky-fldr "+hasStar+" sticky-folder-"+folder_ID+"'>" +
2596 "<a href='javascript:;'>" +
2597 "<span class='folder-title'>"+folderName+"</span>" +
2598 "<span class='folder-actions'>" +
2599 "<span class='update-inline-record'><i class='pfolder-edit-folder'></i></span>" +
2600 "<span class='star-icon'><i class='pfolder-star'></i></span>" +
2601 "<span class='premio-folder-count'>"+folderCount+"</span>" +
2602 "</span>"+
2603 "</a>" +
2604 "</li>";
2605 });
2606 $(".sticky-folders > ul").html(stickyMenuHtml);
2607 if($(".jstree-anchor.jstree-clicked").length) {
2608 var activeTermId = $(".jstree-anchor.jstree-clicked").closest("li.jstree-node").attr("id");
2609 $(".sticky-folders .sticky-folder-"+activeTermId+" a").addClass("active-item");
2610 }
2611
2612 if($(".sticky-folders > ul > li").length > 0) {
2613 $(".sticky-folders").addClass("active");
2614 } else {
2615 $(".sticky-folders").removeClass("active");
2616 }
2617
2618 setDragAndDropElements();
2619 }
2620
2621 function setFolderCountAndDD() {
2622 if($("#media-attachment-taxonomy-filter").length) {
2623 $("#media-attachment-taxonomy-filter").each(function(){
2624 wcp_settings.terms = foldersArray;
2625 var selectedDD = $(this);
2626 currentDDVal = $(this).val();
2627 selectedDD.html("<option value='all'>All Folders</option><option value='unassigned'>(Unassigned)</option>");
2628 lastFolderData = foldersArray;
2629 for (var i = 0; i < foldersArray.length; i++) {
2630 selectedDD.append("<option value='" + foldersArray[i].term_id + "'>" + foldersArray[i].name + " (" + foldersArray[i].trash_count + ")</option>");
2631 }
2632 selectedDD.val(currentDDVal).trigger("change");
2633 });
2634 if($("select.folder_for_media").length) {
2635 var selectedVal = $("select.folder_for_media").val();
2636 $("select.folder_for_media option:not(:first-child):not(:last-child)").remove();
2637 for (var i = 0; i < foldersArray.length; i++) {
2638 $("select.folder_for_media option:last-child").before("<option value='" + foldersArray[i].term_id + "'>" + foldersArray[i].name +"</option>");
2639 }
2640 if(selectedVal != "") {
2641 $(".folder_for_media").val(selectedVal);
2642 }
2643 }
2644 }
2645 $(".folder-count").text("");
2646 for (i = 0; i < foldersArray.length; i++) {
2647 if(foldersArray[i].trash_count == "") {
2648 foldersArray[i].trash_count = 0;
2649 }
2650 $(".jstree-node[id='" + foldersArray[i].term_id + "'] > a.jstree-anchor span.premio-folder-count").text(foldersArray[i].trash_count);
2651 $(".sticky-folder-"+foldersArray[i].term_id+" .premio-folder-count").text(foldersArray[i].trash_count);
2652 }
2653 $("span.premio-folder-count").each(function(){
2654 if($(this).text() == "") {
2655 $(this).text(0);
2656 }
2657 });
2658
2659 if($(".media-select-folder").length) {
2660 $(".media-select-folder").html("<option value=''>Select Folder</option><option value='-1'>(Unassigned)</option>");
2661 for (i = 0; i < foldersArray.length; i++) {
2662 $(".media-select-folder").append("<option value='" + foldersArray[i].term_id + "'>" + foldersArray[i].name + " (" + foldersArray[i].trash_count + ")</option>");
2663 }
2664 $(".media-select-folder").val("");
2665 }
2666
2667 if(activeRecordID != "") {
2668 $("#wcp_folder_"+activeRecordID).addClass("active-item");
2669 }
2670
2671 if(isItFromMedia) {
2672 $("#title_"+fileFolderID).trigger("click");
2673 isItFromMedia = false;
2674 }
2675
2676 uploadFolderID = 0;
2677 }
2678
2679 $(document).ready(function(){
2680
2681 $(document).on("click", "#remove-from-all-folders:not(.disabled), #remove-from-current-folder:not(.disabled)", function(){
2682 $("#remove-from-all-folders, #remove-from-current-folder").addClass("disabled");
2683 var removeFrom = 'all';
2684 if($(this).hasClass("remove-from-current-folder")) {
2685 removeFrom = 'current';
2686 }
2687 $("#confirm-your-change").hide();
2688 $.ajax({
2689 url: wcp_settings.ajax_url,
2690 data: {
2691 post_id: $("#unassigned_folders").val(),
2692 action: 'wcp_remove_post_folder',
2693 active_folder: activeRecordID,
2694 type: wcp_settings.post_type,
2695 folder_id: -1,
2696 nonce: wcp_settings.nonce,
2697 status: wcp_settings.taxonomy_status,
2698 taxonomy: activeRecordID,
2699 remove_from: removeFrom
2700 },
2701 method: 'post',
2702 success: function (res) {
2703 $("#remove-from-all-folders, #remove-from-current-folder").removeClass("disabled");
2704 ajaxAnimation();
2705 resetMediaAndPosts();
2706 checkForUndoFunctionality();
2707 }
2708 });
2709 });
2710
2711 $(document).on("click", ".thumbnail-hover-box a", function(e){
2712 e.stopPropagation();
2713 e.stopImmediatePropagation();
2714 e.preventDefault();
2715 window.open($(this).prop("href"), "_blank");
2716 wp.media.frame.close();
2717 return false;
2718 });
2719
2720 /* select dropdown */
2721 $(document).on("click", "#doaction", function(e){
2722 if($("#bulk-action-selector-top").val() == "move_to_folder") {
2723 show_folder_popup();
2724 return false;
2725 } else if($("#bulk-action-selector-top").val() == "edit") {
2726 if(typeof inlineEditPost == "object") {
2727 inlineEditPost.setBulk();
2728 return false;
2729 }
2730 }
2731 });
2732 $(document).on("click", "#doaction2", function(e){
2733 if($("#bulk-action-selector-bottom").val() == "move_to_folder") {
2734 show_folder_popup();
2735 return false;
2736 } else if($("#bulk-action-selector-bottom").val() == "edit") {
2737 if(typeof inlineEditPost == "object") {
2738 inlineEditPost.setBulk();
2739 return false;
2740 }
2741 }
2742 });
2743
2744
2745 $(document).on("submit", "#bulk-folder-form", function(e) {
2746 e.stopPropagation();
2747 e.preventDefault();
2748
2749 if($("#bulk-select").val() != "") {
2750 chkStr = "";
2751 $(".wp-list-table input:checked").each(function () {
2752 chkStr += $(this).val() + ",";
2753 });
2754 if($("#bulk-select").val() != "") {
2755 if($("#bulk-select").val() == "-1") {
2756 $.ajax({
2757 url: wcp_settings.ajax_url,
2758 data: "post_id=" + chkStr + "&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,
2759 method: 'post',
2760 success: function (res) {
2761 $("#bulk-move-folder").hide();
2762 resetMediaAndPosts();
2763 ajaxAnimation();
2764 }
2765 });
2766 } else {
2767 nonce = getSettingForPost($("#bulk-select").val(), 'nonce');
2768 $.ajax({
2769 url: wcp_settings.ajax_url,
2770 data: {
2771 post_ids: chkStr,
2772 type: wcp_settings.post_type,
2773 action: "wcp_change_multiple_post_folder",
2774 folder_id: $("#bulk-select").val(),
2775 nonce: nonce,
2776 status: wcp_settings.taxonomy_status,
2777 taxonomy: activeRecordID,
2778 post_status: wcp_settings.post_status
2779 },
2780 method: 'post',
2781 success: function (res) {
2782 res = $.parseJSON(res);
2783 $("#bulk-move-folder").hide();
2784 if (res.status == "1") {
2785 resetMediaAndPosts();
2786 ajaxAnimation();
2787 } else {
2788 $(".folder-popup-form").hide();
2789 $(".folder-popup-form").removeClass("disabled");
2790 $("#error-folder-popup-message").html(res.message);
2791 $("#error-folder-popup").show()
2792 }
2793 }
2794 });
2795 }
2796 }
2797 }
2798 });
2799 });
2800
2801 function show_folder_popup() {
2802 $("#bulk-action-selector-top, #bulk-action-selector-bottom").val("-1");
2803 if($(".wp-list-table tbody input[type='checkbox']:checked").length == 0) {
2804 alert(wcp_settings.lang.SELECT_ITEMS_TO_MOVE);
2805 } else {
2806 $("#bulk-move-folder").show();
2807 $("#bulk-select").html("<option value=''>"+wcp_settings.lang.LOADING_FILES+"</option>");
2808 $(".move-to-folder").attr("disabled", true);
2809 $("#move-to-folder").prop("disabled", true);
2810 $.ajax({
2811 url: wcp_settings.ajax_url,
2812 data: "type=" + wcp_settings.post_type + "&action=wcp_get_default_list&active_id=" + activeRecordID,
2813 method: 'post',
2814 success: function (res) {
2815 res = $.parseJSON(res);
2816 $("#bulk-select").html("<option value=''>"+wcp_settings.lang.SELECT_FOLDER+"</option><option value='-1'>"+wcp_settings.lang.UNASSIGNED+"</option>");
2817 $(".move-to-folder").prop("disabled", false);
2818 $("#move-to-folder").prop("disabled", false);
2819 if(res.status == 1) {
2820 var taxonomies = res.taxonomies;
2821 for(i=0;i<taxonomies.length;i++) {
2822 $("#bulk-select").append("<option value='"+taxonomies[i].term_id+"'>"+taxonomies[i].name+"</option>");
2823 }
2824 }
2825 }
2826 });
2827 }
2828 }
2829
2830 function checkForOtherFolders(folderIDs) {
2831 var folderID = -1;
2832 if(activeRecordID == "" || activeRecordID == 0) {
2833 nonce = wcp_settings.nonce;
2834 $.ajax({
2835 url: wcp_settings.ajax_url,
2836 data: "post_id=" + folderIDs + "&type=" + wcp_settings.post_type + "&action=wcp_remove_post_folder&folder_id=" + folderID + "&nonce=" + nonce + "&status=" + wcp_settings.taxonomy_status + "&taxonomy=" + activeRecordID,
2837 method: 'post',
2838 success: function (res) {
2839 // window.location.reload();
2840 resetMediaAndPosts();
2841 checkForUndoFunctionality();
2842 }
2843 });
2844 } else {
2845 $.ajax({
2846 url: wcp_settings.ajax_url,
2847 data: {
2848 post_id: folderIDs,
2849 action: 'premio_check_for_other_folders',
2850 active_folder: activeRecordID,
2851 type: wcp_settings.post_type,
2852 folder_id: folderID,
2853 nonce: wcp_settings.nonce,
2854 status: wcp_settings.taxonomy_status,
2855 taxonomy: activeRecordID
2856 },
2857 method: 'post',
2858 success: function (res) {
2859 res = $.parseJSON(res);
2860 if(res.status == -1) {
2861 $("#unassigned_folders").val(res.data.post_id);
2862 $("#confirm-your-change").show();
2863 } else {
2864 resetMediaAndPosts();
2865 checkForUndoFunctionality();
2866 }
2867 }
2868 });
2869 }
2870 }
2871
2872 if(wcp_settings.post_type == "attachment") {
2873
2874 $(document).ready(function(){
2875 if(wcp_settings.show_in_page == "show") {
2876 $(".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>');
2877 }
2878
2879 add_menu_to_list();
2880
2881 apply_animation_height();
2882 });
2883
2884
2885
2886 var resetMediaFlag = null;
2887
2888 function resetMediaData(loadData) {
2889 resetMediaFlag = $.ajax({
2890 url: wcp_settings.ajax_url,
2891 data: "type=" + wcp_settings.post_type + "&action=wcp_get_default_list&active_id="+activeRecordID,
2892 method: 'post',
2893 beforeSend: function() {
2894 if(resetMediaFlag != null) {
2895 resetMediaFlag.abort();
2896 }
2897 },
2898 success: function (res) {
2899 res = $.parseJSON(res);
2900 // $("#js-tree-menu > ul#space_0").html(res.data);
2901 $(".header-posts .total-count").text(res.total_items);
2902 $(".un-categorised-items .total-count").text(res.empty_items);
2903 selectedVal = $("#media-attachment-taxonomy-filter").val();
2904 if(selectedVal != "all" && loadData == 1) {
2905 var wp1 = parent.wp;
2906 if(wp1.media != undefined) {
2907 wp1.media.frame.setState('insert');
2908 if(wp1.media.frame.content.get() !== null && typeof(wp1.media.frame.content.get().collection) != "undefined") {
2909 wp1.media.frame.content.get().collection.props.set({ignore: (+new Date())});
2910 wp1.media.frame.content.get().options.selection.reset();
2911 } else {
2912 wp1.media.frame.library.props.set({ignore: (+new Date())});
2913 }
2914 }
2915 }
2916 foldersArray = res.taxonomies;
2917 setFolderCountAndDD();
2918
2919 if(activeRecordID != "") {
2920 $("#wcp_folder_"+activeRecordID).addClass("active-item");
2921 }
2922
2923 if(isItFromMedia) {
2924 $("#title_"+fileFolderID).trigger("click");
2925 isItFromMedia = false;
2926 }
2927 }
2928 });
2929 }
2930
2931 function setMediaBoxWidth() {
2932 $(".media-frame-content .media-toolbar").width($(".media-frame-content").width() - 20);
2933 }
2934
2935 setMediaBoxWidth();
2936
2937 $(window).resize(function(){
2938 setMediaBoxWidth();
2939 });
2940
2941 $(document).on("click", ".button.organize-button", function(){
2942 if(!$(".media-frame").hasClass("mode-select")) {
2943 setCookie("media-select-mode", "on", 7);
2944 } else {
2945 eraseCookie("media-select-mode");
2946 }
2947 $("button.button.media-button.select-mode-toggle-button").trigger("click");
2948 if($(".media-frame").hasClass("mode-select")) {
2949 $(".media-info-message").addClass("active");
2950 $(".select-all-item-btn").addClass("active");
2951 } else {
2952 $(".media-info-message, .custom-media-select").removeClass("active");
2953 $(".select-all-item-btn").removeClass("active");
2954 }
2955 });
2956
2957 $(document).on("click", ".select-mode-toggle-button", function(){
2958 setTimeout(function() {
2959 if(!$(".media-frame").hasClass("mode-select")) {
2960 setCookie("media-select-mode", "off", -1);
2961 }
2962 if($(".media-frame").hasClass("mode-select")) {
2963 $(".media-info-message").addClass("active");
2964 $(".select-all-item-btn").addClass("active");
2965 } else {
2966 $(".media-info-message, .custom-media-select").removeClass("active");
2967 $(".select-all-item-btn").removeClass("active");
2968 }
2969 }, 10);
2970 });
2971
2972 $(document).on("click", ".select-all-item-btn", function(){
2973 $("ul.attachments li:not(.selected)").trigger("click");
2974 });
2975
2976 $(document).on("change", ".folder_for_media", function(){
2977 if($(this).val() == "add-folder") {
2978 fileFolderID = 0;
2979 isItFromMedia = true;
2980 addFolder();
2981 // $(".add-new-folder").trigger("click");
2982 //$(this).val("-1");
2983 }
2984 });
2985
2986 function setCookie(name,value,days) {
2987 var expires = "";
2988 if(days) {
2989 var date = new Date();
2990 date.setTime(date.getTime() + (days*24*60*60*1000));
2991 expires = "; expires=" + date.toUTCString();
2992 }
2993 document.cookie = name + "=" + (value || "") + expires + "; path=/";
2994 }
2995
2996 function getCookie(name) {
2997 var nameEQ = name + "=";
2998 var ca = document.cookie.split(';');
2999 for(var i=0;i < ca.length;i++) {
3000 var c = ca[i];
3001 while (c.charAt(0)==' ') c = c.substring(1,c.length);
3002 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
3003 }
3004 return null;
3005 }
3006
3007 function eraseCookie(name) {
3008 document.cookie = name+'=; Max-Age=-99999999;';
3009 }
3010
3011 function setStickyHeaderForMedia() {
3012 if(!$(".media-position").length) {
3013 $(".media-frame-content .media-toolbar").before("<div class='media-position'></div>")
3014 }
3015
3016 if($(".media-position").length) {
3017 setMediaBoxWidth();
3018
3019 thisPosition = $(".media-position").offset().top - $(window).scrollTop();
3020 if(thisPosition <= 32) {
3021 $(".media-frame-content .media-toolbar").addClass("sticky-media");
3022 $(".media-position").height($(".media-frame-content .media-toolbar").outerHeight());
3023 } else {
3024 $(".media-frame-content .media-toolbar").removeClass("sticky-media");
3025 $(".media-position").height(1);
3026 }
3027 }
3028 }
3029
3030 $(window).scroll(function(){
3031 setStickyHeaderForMedia()
3032 });
3033 } else {
3034 function setStickyHeaderForMedia() {}
3035 }
3036
3037 var checkForMediaScreen;
3038
3039 function setMediaButtons() {
3040 if($("button.button.media-button.select-mode-toggle-button").length) {
3041 clearInterval(checkForMediaScreen);
3042 $("button.button.media-button.select-mode-toggle-button").after("<button class='button organize-button'>"+wcp_settings.lang.BULK_ORGANIZE+"</button>");
3043 $(".media-toolbar-secondary").append("<span class='media-info-message'>"+wcp_settings.lang.DRAG_AND_DROP+"</span>");
3044 $(".delete-selected-button").before("<button type='button' class='button button-primary select-all-item-btn'>"+wcp_settings.lang.SELECT_ALL+"</button>");
3045 $(".media-toolbar-secondary").after("<div class='custom-media-select'>"+wcp_settings.lang.MOVE_SELECTED_FILES+" <select class='media-select-folder'></select></div>");
3046 $(".media-toolbar").append("<div style='clear:both;'></div><div class='media-folder-loader'><span>"+wcp_settings.lang.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>");
3047 if($(".wcp-custom-form").length) {
3048 if(wp.Uploader !== undefined) {
3049 wp.Uploader.queue.on('reset', function () {
3050 resetMediaData(1);
3051 });
3052 }
3053 $(document).ajaxComplete(function (ev, jqXHR, settings) {
3054 actionName = settings.data;
3055 if(typeof actionName != "undefined") {
3056 if(actionName.length && actionName.indexOf("action=delete-post&id=") == 0) {
3057 resetMediaData(0);
3058 }
3059 }
3060 });
3061 }
3062 setTimeout(function () {
3063 docReferrar = document.referrer;
3064 if(docReferrar.indexOf("wp-admin/upload.php") != -1) {
3065 mediaMode = getCookie("media-select-mode");
3066 if(mediaMode == "on") {
3067 $("button.button.media-button.select-mode-toggle-button").trigger("click");
3068 //$(".attachments-browser li.attachment").draggable("enable");
3069
3070 if($(".media-frame").hasClass("mode-select")) {
3071 $(".media-info-message").addClass("active");
3072 } else {
3073 $(".media-info-message, .custom-media-select").removeClass("active");
3074 }
3075 }
3076 } else {
3077 eraseCookie("media-select-mode");
3078 }
3079 resetMediaData(1);
3080 }, 1000);
3081 }
3082 }
3083
3084 $(document).ready(function(){
3085 if(wcp_settings.post_type == "attachment") {
3086 if($("#tmpl-media-frame").length) {
3087 checkForMediaScreen = setInterval(function(){
3088 setMediaButtons();
3089 }, 1000);
3090 }
3091 }
3092
3093 $(document).on("click", ".attachments-browser ul.attachments .thumbnail", function () {
3094 if(wcp_settings.post_type == "attachment") {
3095 if($(".media-toolbar").hasClass("media-toolbar-mode-select")) {
3096 if($("ul.attachments li.selected").length == 0) {
3097 $(".custom-media-select").removeClass("active");
3098 } else {
3099 $(".custom-media-select").addClass("active");
3100 }
3101 }
3102 }
3103 });
3104
3105 $(document).on("change", ".media-select-folder", function () {
3106 if(wcp_settings.post_type == "attachment") {
3107 if($(this).val() != "") {
3108 var checkStr = "";
3109 $(".attachments-browser li.attachment.selected").each(function () {
3110 checkStr += $(this).attr("data-id") + ",";
3111 });
3112 if ($(this).val() == "-1") {
3113 $.ajax({
3114 url: wcp_settings.ajax_url,
3115 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,
3116 method: 'post',
3117 success: function (res) {
3118 if (fileFolderID != 0 && fileFolderID != $(".media-select-folder").val()) {
3119 $("ul.attachments li.selected").remove();
3120 }
3121 resetMediaAndPosts();
3122 ajaxAnimation();
3123 }
3124 });
3125 } else {
3126 nonce = getSettingForPost($(this).val(), 'nonce');
3127 $.ajax({
3128 url: wcp_settings.ajax_url,
3129 data: {
3130 post_ids: chkStr,
3131 type: wcp_settings.post_type,
3132 action: "wcp_change_multiple_post_folder",
3133 folder_id: $(this).val(),
3134 nonce: nonce,
3135 status: wcp_settings.taxonomy_status,
3136 taxonomy: activeRecordID,
3137 post_status: wcp_settings.post_status
3138 },
3139 method: 'post',
3140 success: function (res) {
3141 res = $.parseJSON(res);
3142 $("#bulk-move-folder").hide();
3143 if (res.status == "1") {
3144 if (fileFolderID != 0 && fileFolderID != $(".media-select-folder").val()) {
3145 $("ul.attachments li.selected").remove();
3146 }
3147 resetMediaAndPosts();
3148 ajaxAnimation();
3149 } else {
3150 $(".folder-popup-form").hide();
3151 $(".folder-popup-form").removeClass("disabled");
3152 $("#error-folder-popup-message").html(res.message);
3153 $("#error-folder-popup").show()
3154 }
3155 }
3156 });
3157 }
3158 }
3159 }
3160 });
3161 });
3162
3163 $(document).ready(function(){
3164 if(wcp_settings.use_shortcuts == "yes") {
3165 $(document).on("click", ".view-shortcodes", function (e) {
3166 e.preventDefault();
3167 $("#keyboard-shortcut").show();
3168 });
3169
3170 $(document).keydown(function (e) {
3171 var isCtrlPressed = (e.ctrlKey || e.metaKey) ? true : false;
3172
3173 // Shift + N : New Folder
3174 if(!($("input").is(":focus") || $("textarea").is(":focus"))) {
3175 if (e.shiftKey && (e.keyCode == 78 || e.which == 78)) {
3176 e.preventDefault();
3177 $("#add-new-folder").trigger("click");
3178 }
3179 }
3180 // F2 Rename Folder
3181 if(e.keyCode == 113 || e.which == 113) {
3182 if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3183 fileFolderID = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3184 updateFolder();
3185 $(".dynamic-menu").remove();
3186 }
3187 }
3188
3189 // Ctrl+C/CMD+C: Copy Folder
3190 if(isCtrlPressed && (e.keyCode == 67 || e.which == 67)) {
3191 /*if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3192 isFolderCopy = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3193 CPCAction = "copy";
3194 $(".folders-undo-notification").removeClass("active");
3195 $("#copy-message").addClass("active");
3196 setTimeout(function () {
3197 $("#copy-message").removeClass("active");
3198 }, 5000);
3199 checkForCopyPaste();
3200 }*/
3201 }
3202
3203 // Ctrl+X/CMD+X: Cut Folder
3204 if(isCtrlPressed && (e.keyCode == 88 || e.which == 88)) {
3205 /*if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3206 e.preventDefault();
3207 isFolderCopy = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3208 CPCAction = "cut";
3209 $(".folders-undo-notification").removeClass("active");
3210 $("#cut-message").addClass("active");
3211 setTimeout(function () {
3212 $("#cut-message").removeClass("active");
3213 }, 5000);
3214 checkForCopyPaste();
3215 }*/
3216 }
3217
3218 // Ctrl+V: Paste Folder
3219 if(isCtrlPressed && (e.keyCode == 86 || e.which == 86)) {
3220 /*if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3221 e.preventDefault();
3222 activeRecordID = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3223 if(activeRecordID == "" || isNaN(activeRecordID)) {
3224 activeRecordID = 0;
3225 }
3226 if(isFolderCopy != 0 && isFolderCopy != "" && isFolderCopy != activeRecordID) {
3227 if(CPCAction == "cut") {
3228 lastParentID = $("#" + isFolderCopy).data("parent");
3229 lastCopiedFolder = isFolderCopy;
3230 lastFolderOrder = $("#" + isFolderCopy).index() + 1;
3231 if(activeRecordID != "" && activeRecordID != 0) {
3232 $('#js-tree-menu').jstree("move_node", "#" + isFolderCopy, "#" + activeRecordID, 0);
3233 } else {
3234 $('#js-tree-menu').jstree("move_node", "#" + isFolderCopy, "#", $("#js-tree-menu > ul > li.jstree-node").length);
3235 }
3236 $(".folders-undo-notification").removeClass("active");
3237 $("#paste-message").addClass("active");
3238 setTimeout(function () {
3239 $("#paste-message").removeClass("active");
3240 }, 5000);
3241 } else {
3242 if(activeRecordID == "" || isNaN(activeRecordID)) {
3243 activeRecordID = 0;
3244 }
3245 copyFolders(isFolderCopy, activeRecordID);
3246 }
3247 checkForCopyPaste();
3248 CPCAction = "";
3249 isFolderCopy = 0;
3250 }
3251 }*/
3252 }
3253
3254 if(isCtrlPressed && (e.keyCode == 75 || e.which == 75)) {
3255 $("#keyboard-shortcut").show();
3256 }
3257
3258 // delete action
3259 if((e.keyCode == 46 || e.which == 46) || (e.keyCode == 8 || e.which == 8)) {
3260 if ($("#menu-checkbox").is(":checked") && $("#js-tree-menu input.checkbox:checked").length > 0) {
3261 $(".delete-folder-action").trigger("click");
3262 } else if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3263 if(!$("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").hasClass("is-locked")) {
3264 fileFolderID = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3265 removeFolderFromID(0);
3266 $(".dynamic-menu").remove();
3267 $(".active-menu").removeClass("active-menu");
3268 }
3269 }
3270 }
3271
3272 // ctrl + down
3273 if(isCtrlPressed && (e.keyCode == 40 || e.which == 40)) {
3274 if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3275 fileFolderID = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3276 var lastParent = parseInt($("#"+fileFolderID).data("parent"));
3277 var folderOrder = parseInt($("#"+fileFolderID).index())+1;
3278 var dataChild = parseInt($("#"+fileFolderID).data("child"));
3279 if(isNaN(lastParent)) {
3280 lastParent = ($("li#" + fileFolderID).parents("li.jstree-node").length)?$("li#" + fileFolderID).parents("li.jstree-node").data("folder"):0;
3281 dataChild = ($("li#" + fileFolderID).parents("li.jstree-node").length)?$("li#" + fileFolderID).parents("li.jstree-node").children():($("#js-tree-menu > ul > li").length);
3282 }
3283 if(lastParent == 0) {
3284 lastParent = "";
3285 }
3286 if(dataChild == folderOrder) {
3287 $('#js-tree-menu').jstree("move_node", "#"+fileFolderID, "#"+lastParent, 0);
3288 } else {
3289 $('#js-tree-menu').jstree("move_node", "#"+fileFolderID, "#"+lastParent, folderOrder+1);
3290 }
3291 }
3292 }
3293
3294 // ctrl + down
3295 if(isCtrlPressed && (e.keyCode == 38 || e.which == 38)) {
3296 if($("#js-tree-menu .jstree-anchor").is(":focus")) {
3297 fileFolderID = $("#js-tree-menu .jstree-anchor:focus").closest("li.jstree-node").attr("id");
3298 var lastParent = parseInt($("#" + fileFolderID).data("parent"));
3299 var folderOrder = parseInt($("#" + fileFolderID).index()) - 1;
3300 var dataChild = parseInt($("#" + fileFolderID).data("child"));
3301 if(isNaN(lastParent)) {
3302 folderOrder = parseInt($("#" + fileFolderID).index()) - 1;
3303 lastParent = ($("li#" + fileFolderID).parents("li.jstree-node").length)?$("li#" + fileFolderID).parents("li.jstree-node").data("folder"):0;
3304 dataChild = ($("li#" + fileFolderID).parents("li.jstree-node").length)?$("li#" + fileFolderID).parents("li.jstree-node").children():($("#js-tree-menu > ul > li").length);
3305 }
3306 if (lastParent == 0) {
3307 lastParent = "";
3308 }
3309 if (folderOrder == -1) {
3310 $('#js-tree-menu').jstree("move_node", "#" + fileFolderID, "#" + lastParent, dataChild);
3311 } else {
3312 $('#js-tree-menu').jstree("move_node", "#" + fileFolderID, "#" + lastParent, folderOrder);
3313 }
3314 }
3315 }
3316
3317 // esc key
3318 if(e.keyCode == 27 || e.which == 27) {
3319 $(".folder-popup-form:not(#rating-modal-popup)").hide();
3320 if($(".jstree-node[id='"+fileFolderID+"']").length) {
3321 $(".jstree-node[id='"+fileFolderID+"'] > a.jstree-anchor").trigger("focus");
3322 } else if($("#js-tree-menu .jstree-anchor.jstree-clicked").length) {
3323 $("#js-tree-menu .jstree-anchor.jstree-clicked").trigger("focus");
3324 }
3325 }
3326 });
3327 }
3328 });
3329 }));
3330