JAVASCRIPT   28

default

Guest on 6th August 2022 01:09:47 AM

  1. window.page = 1;
  2. var ajax = true;
  3. var dragFiles;
  4. var isUploading;
  5. var filesSelected;
  6. var keyFileSelected;
  7. var all_files_selected = false;
  8. var params = [];
  9. var no_selected_files = [];
  10. var wdb_all_files_filtered = [];
  11. /* keeping last page of image add action to avoid duplication during the scroll */
  12. var ajax_request_count = 0;
  13.  
  14. jQuery(function() {
  15.         var page = 1;
  16.   function checking_the_need_of_images(_that) {
  17.     var explorer = jQuery("#explorer_body");
  18.     var page_per = explorer.data('page_per');
  19.     var files_count = explorer.data('files_count');
  20.     var items_count = jQuery("#explorer_body .explorer_item").length;
  21.     var scroll_position = _that.scrollTop() + _that.innerHeight();
  22.     var scroll_Height = _that[0].scrollHeight - 300;
  23.     /*
  24.       We get the number of "storage_images", if it is greater than the number of images displayed,
  25.       we run ajax redirection again until the appropriate number of images is selected
  26.       (the number of images selected in the displayed images equals the number of "storage_images")
  27.     */
  28.     var selected_images_caunt = jQuery('.explorer_item.explorer_item_select').length;
  29.     var storage_images_count = 0;
  30.     if ( localStorage.getItem('bwg_selected_images') ) {
  31.       var storage_images = localStorage.getItem('bwg_selected_images').split(',');
  32.       storage_images_count = storage_images.length;
  33.     }
  34.     if ( ( selected_images_caunt < storage_images_count ) || ( scroll_position >= scroll_Height && items_count == (page_per * page) ) ) {
  35.       _that.off('scroll');
  36.       var orderby = jQuery("input[name='sort_by']").val();
  37.       var order = jQuery("input[name='sort_order']").val();
  38.  
  39.       params['is_search'] = false;
  40.       params['element'] = explorer;
  41.       params['search'] = jQuery('#search_by_name .search_by_name').val().toLowerCase();
  42.       params['page'] = page;
  43.       params['orderby'] = orderby;
  44.       params['order'] = order;
  45.       if ( (page_per * page) < files_count && ajax_request_count !== params['page'] ) {
  46.         ajax_print_images( params ).then(function() {
  47.           page++;
  48.           items_count = jQuery("#explorer_body .explorer_item").length;
  49.           scroll_position = _that.scrollTop() + _that.innerHeight();
  50.           scroll_Height = _that[0].scrollHeight - 200;
  51.  
  52.           if ( ( selected_images_caunt < storage_images_count ) || ( scroll_position >= scroll_Height && items_count == (page_per * page) ) ) {
  53.             checking_the_need_of_images(_that)
  54.           }
  55.           else {
  56.             jQuery("#explorer_body_container").scroll(function () {
  57.               checking_the_need_of_images(_that)
  58.             });
  59.           }
  60.         });
  61.       }
  62.     }
  63.   }
  64.   checking_the_need_of_images(jQuery("#explorer_body_container"));
  65.         jQuery("#explorer_body_container").scroll(function () {
  66.     checking_the_need_of_images(jQuery(this));
  67.         });
  68.  
  69.         filesSelected = [];
  70.         dragFiles = [];
  71.  
  72.         jQuery("#wrapper").css("top", jQuery("#file_manager_message").css("height"));
  73.         jQuery(window).resize(function () {
  74.                 jQuery("#container").css("top", jQuery("#file_manager_message").css("height"));
  75.         });
  76.  
  77.         isUploading = false;
  78.         jQuery("#uploader").css("display", "none");
  79.         jQuery("#uploader_progress_bar").css("display", "none");
  80.         jQuery("#importer").css("display", "none");
  81.  
  82.         //decrease explorer header width by scroller width
  83.         jQuery(".scrollbar_filler").css("width", getScrollBarWidth() + "px");
  84.         jQuery(document).keydown(function(e) {
  85.                 onKeyDown(e);
  86.         });
  87.  
  88.         jQuery("#search_by_name .search_by_name").on("input", function() { // keyup
  89.                 page = 0;
  90.                 var search_by_name = jQuery(this).val().toLowerCase();
  91.                 var orderby = jQuery("input[name='sort_by']").val();
  92.                 var order = jQuery("input[name='sort_order']").val();
  93.                 var element = jQuery("#explorer_body");
  94.     var page_per = element.data('page_per');
  95.     var files_count = element.data('files_count');
  96.                 element.html('');
  97.                 jQuery('html, body').animate({scrollTop:0},0);
  98.                 params['is_search'] = true;
  99.                 params['element'] = element;
  100.                 params['search'] = search_by_name;
  101.                 params['page'] = page;
  102.                 params['orderby'] = orderby;
  103.                 params['order'] = order;
  104.     if ( (page_per * page) < files_count ) {
  105.       ajax_print_images(params);
  106.     }
  107.         });
  108. });
  109.  
  110. function getClipboardFiles() {
  111.   return jQuery("form[name=adminForm]").find("input[name=clipboard_file]").val();
  112. }
  113.  
  114. function submit(task, sortBy, sortOrder, itemsView, destDir, fileNewName, newDirName, clipboardTask, clipboardFiles, clipboardSrc, clipboardDest) {
  115.   jQuery('#loading_div', window.parent.document).show();
  116.   var names_array = [];
  117.   if ( all_files_selected === true ) {
  118.     for (i in wdb_all_files_filtered) {
  119.       var index = no_selected_files.indexOf(wdb_all_files_filtered[i]["name"]);
  120.       if (index < 0) {
  121.         var all_names = wdb_all_files_filtered[i]["name"];
  122.         names_array.push(all_names);
  123.       }
  124.     }
  125.     fileNames = names_array.join("**#**");
  126.   }
  127.   else {
  128.     fileNames = filesSelected.join("**#**");
  129.   }
  130.   switch ( task ) {
  131.     case "parsing_items":
  132.       destDir = dir;
  133.       break;
  134.     case "rename_item":
  135.       destDir = dir;
  136.       newDirName = "";
  137.       clipboardTask = ""
  138.       clipboardDest = "";
  139.       break;
  140.     case "remove_items":
  141.       destDir = dir;
  142.       fileNewName = "";
  143.       newDirName = "";
  144.       clipboardTask = ""
  145.       clipboardDest = "";
  146.       break;
  147.     case "make_dir":
  148.       destDir = dir;
  149.       fileNewName = "";
  150.       clipboardTask = ""
  151.       clipboardDest = "";
  152.       break;
  153.     case "paste_items":
  154.       destDir = dir;
  155.       fileNewName = "";
  156.       newDirName = "";
  157.       break;
  158.     case "import_items":
  159.       destDir = dir;
  160.       fileNewName = "";
  161.       newDirName = "";
  162.       break;
  163.     default:
  164.       task = "";
  165.       break;
  166.   }
  167.  
  168.   jQuery("form[name=adminForm]").find("input[name=task]").val(task);
  169.  
  170.   if (sortBy != null) {
  171.     jQuery("form[name=adminForm]").find("input[name=sort_by]").val(sortBy);
  172.   }
  173.   if (sortOrder != null) {
  174.     jQuery("form[name=adminForm]").find("input[name=sort_order]").val(sortOrder);
  175.   }
  176.   if (itemsView != null) {
  177.     jQuery("form[name=adminForm]").find("input[name=items_view]").val(itemsView);
  178.   }
  179.   if (destDir != null) {
  180.     jQuery("form[name=adminForm]").find("input[name=dir]").val(destDir);
  181.   }
  182.   if (fileNames != null) {
  183.     jQuery("form[name=adminForm]").find("input[name=file_names]").val(fileNames);
  184.   }
  185.   if (fileNewName != null) {
  186.     jQuery("form[name=adminForm]").find("input[name=file_new_name]").val(fileNewName);
  187.   }
  188.   if (newDirName != null) {
  189.     jQuery("form[name=adminForm]").find("input[name=new_dir_name]").val(newDirName);
  190.   }
  191.   if (clipboardTask != null) {
  192.     jQuery("form[name=adminForm]").find("input[name=clipboard_task]").val(clipboardTask);
  193.   }
  194.   if (clipboardFiles != null) {
  195.     jQuery("form[name=adminForm]").find("input[name=clipboard_files]").val(clipboardFiles);
  196.   }
  197.   if (clipboardSrc != null) {
  198.     jQuery("form[name=adminForm]").find("input[name=clipboard_src]").val(clipboardSrc);
  199.   }
  200.   if (clipboardDest != null) {
  201.     jQuery("form[name=adminForm]").find("input[name=clipboard_dest]").val(clipboardDest);
  202.   }
  203.   jQuery("form[name=adminForm]").submit();
  204. }
  205.  
  206. function updateFileNames() {
  207.   var result = "";
  208.   if (filesSelected.length > 0) {
  209.     var fileNames = [];
  210.     for (var i = 0; i < filesSelected.length; i++) {
  211.       fileNames[i] = "'" + filesSelected[i] + "'";
  212.     }
  213.     result = fileNames.join(" ");
  214.   }
  215.   jQuery("#file_names_span span").html(result);
  216. }
  217.  
  218. function submitFiles() {
  219.   if (filesSelected.length == 0) {
  220.     return;
  221.   }
  222.  
  223.   var filesValid = [];
  224.   if (all_files_selected === true) {
  225.     for (i in wdb_all_files_filtered) {
  226.       var fileData = [];
  227.       if (wdb_all_files_filtered[i]["is_dir"] === '0') {
  228.         var index = no_selected_files.indexOf(wdb_all_files_filtered[i]["name"]);
  229.         if ( index < 0 ) {
  230.           fileData['index'] = i;
  231.           fileData['name'] = wdb_all_files_filtered[i]["name"];
  232.           fileData['filename'] = wdb_all_files_filtered[i]["filename"];;
  233.           fileData['alt'] = wdb_all_files_filtered[i]["alt"];;
  234.           fileData['url'] = dir + "/" + wdb_all_files_filtered[i]["name"];
  235.           fileData['reliative_url'] = dirUrl + "/" + wdb_all_files_filtered[i]["name"];
  236.           fileData['thumb_url'] = dir + "/thumb/" + wdb_all_files_filtered[i]["name"];
  237.           fileData['thumb'] = wdb_all_files_filtered[i]["thumb"];
  238.           fileData['size'] = wdb_all_files_filtered[i]["size"];
  239.           fileData['filetype'] = wdb_all_files_filtered[i]["type"];
  240.           fileData['date_modified'] = wdb_all_files_filtered[i]["date_modified"];
  241.           fileData['resolution'] = wdb_all_files_filtered[i]["resolution"];
  242.           fileData['resolution_thumb'] = wdb_all_files_filtered[i]["resolution_thumb"];
  243.           fileData['aperture'] = wdb_all_files_filtered[i]["aperture"];
  244.           fileData['credit'] = wdb_all_files_filtered[i]["credit"];
  245.           fileData['camera'] =wdb_all_files_filtered[i]["camera"];
  246.           fileData['caption'] = wdb_all_files_filtered[i]["caption"];
  247.           fileData['iso'] = wdb_all_files_filtered[i]["iso"];
  248.           fileData['orientation'] = wdb_all_files_filtered[i]["orientation"];
  249.           fileData['copyright'] = wdb_all_files_filtered[i]["copyright"];
  250.           fileData['tags'] = wdb_all_files_filtered[i]["tags"];
  251.           filesValid.push(fileData);
  252.         }
  253.       } else {
  254.         submit("", null, null, null, dir + DS + jQuery(file_object).attr("name"), null, null, null, null, null, null);
  255.         return
  256.       }
  257.     }
  258.   }
  259.   else {
  260.     for (var i = 0; i < filesSelected.length; i++) {
  261.       var file_object = jQuery('.explorer_item[name="' + filesSelected[i] + '"]');
  262.       if ( typeof jQuery(file_object).attr('name') != 'undefined' && typeof jQuery(file_object).attr('isDir') != 'undefined' ) {
  263.         if ( jQuery(file_object).attr('isDir') == 'false' ) {
  264.           var fileData = [];
  265.             fileData['name'] = filesSelected[i];
  266.             fileData['filename'] = jQuery(file_object).attr("filename");
  267.             fileData['alt'] = jQuery(file_object).attr("alt");
  268.             fileData['url'] = dir + "/" + filesSelected[i];
  269.             fileData['reliative_url'] = dirUrl + "/" + filesSelected[i];
  270.             fileData['thumb_url'] = dir + "/thumb/" + filesSelected[i];
  271.             fileData['thumb'] = jQuery(file_object).attr("filethumb");
  272.             fileData['size'] = jQuery(file_object).attr("filesize");
  273.             fileData['filetype'] = jQuery(file_object).attr("filetype");
  274.             fileData['date_modified'] = jQuery(file_object).attr("date_modified");
  275.             fileData['resolution'] = jQuery(file_object).attr("fileresolution");
  276.             fileData['resolution_thumb'] = jQuery(file_object).attr("fileresolution_thumb");
  277.             fileData['aperture'] = jQuery(file_object).attr("fileAperture");
  278.             fileData['credit'] = jQuery(file_object).attr("fileCredit");
  279.             fileData['camera'] = jQuery(file_object).attr("fileCamera");
  280.             fileData['caption'] = jQuery(file_object).attr("fileCaption");
  281.             fileData['iso'] = jQuery(file_object).attr("fileIso");
  282.             fileData['orientation'] = jQuery(file_object).attr("fileOrientation");
  283.             fileData['copyright'] = jQuery(file_object).attr("fileCopyright");
  284.             fileData['tags'] = jQuery(file_object).attr("fileTags");
  285.           filesValid.push(fileData);
  286.         }
  287.         else {
  288.           submit('', null, null, null, dir + DS + jQuery(file_object).attr('name'), null, null, null, null, null, null);
  289.           return;
  290.         }
  291.       }
  292.     }
  293.   }
  294.   window.parent[callback](filesValid);
  295.   window.parent.tb_remove();
  296. }
  297.  
  298. function getScrollBarWidth() {
  299.   var inner = document.createElement("p");
  300.   inner.style.width = "100%";
  301.   inner.style.height = "200px";
  302.  
  303.   var outer = document.createElement("div");
  304.   outer.style.position = "absolute";
  305.   outer.style.top = "0px";
  306.   outer.style.left = "0px";
  307.   outer.style.visibility = "hidden";
  308.   outer.style.width = "200px";
  309.   outer.style.height = "150px";
  310.   outer.style.overflow = "hidden";
  311.   outer.appendChild(inner);
  312.  
  313.   document.body.appendChild(outer);
  314.   var w1 = inner.offsetWidth;
  315.   outer.style.overflow = "scroll";
  316.   var w2 = inner.offsetWidth;
  317.   if (w1 == w2) {
  318.     w2 = outer.clientWidth;
  319.   }
  320.   document.body.removeChild(outer);
  321.  
  322.   return (w1 - w2);
  323. }
  324.  
  325. function getFileName(file) {
  326.   var dotIndex = file.lastIndexOf('.');
  327.   return file.substring(0, dotIndex < 0 ? file.length : dotIndex);
  328. }
  329.  
  330. function getFileExtension(file) {
  331.   return file.substring(file.lastIndexOf('.') + 1);
  332. }
  333.  
  334. //ctrls bar handlers
  335. function onBtnUpClick(event, obj) {
  336.   var destDir = dir.substring(0, dir.lastIndexOf(DS));
  337.   submit("", null, null, null, destDir, null, null, null, null, null, null);
  338. }
  339.  
  340. function onBtnMakeDirClick(event, obj) {
  341.   var newDirName = prompt(messageEnterDirName);
  342.   if ((newDirName) && (newDirName != "")) {
  343.     submit("make_dir", null, null, null, null, null, newDirName.replace(/ /g, "_"), null, null, null, null);
  344.   }
  345. }
  346.  
  347. function onBtnRenameItemClick(event, obj) {
  348.         if (filesSelected.length != 0) {
  349.                 var oldName = getFileName(filesSelected[0]);
  350.                 var newName = prompt(messageEnterNewName, oldName);
  351.                 if ((newName != null) && (newName != "")) {
  352.                         newName = newName.replace(/"/g, "").replace(/ /g, "_").replace(/%/g, "");
  353.                         submit("rename_item", null, null, null, null, newName, null, null, null, null, null);
  354.                 }
  355.         }
  356. }
  357.  
  358. function onBtnCopyClick(event, obj) {
  359.         if (filesSelected.length != 0) {
  360.                 var names_list =  filesSelected.join("**#**");
  361.                 var names_array = [];
  362.                 if (all_files_selected === true) {
  363.                         for (i in wdb_all_files_filtered) {
  364.                                 var index = no_selected_files.indexOf(wdb_all_files_filtered[i]["name"]);
  365.                                 if (index < 0) {
  366.                                   var all_names = wdb_all_files_filtered[i]["name"];
  367.                                   names_array.push(all_names);
  368.                                 }
  369.                         }
  370.                         names_list =  names_array.join("**#**");
  371.                 }
  372.  
  373.                 submit("", null, null, null, null, null, null, "copy", names_list, dir, null);
  374.         }
  375. }
  376.  
  377. function onBtnCutClick(event, obj) {
  378.         if (filesSelected.length != 0) {
  379.                 var names_list =  filesSelected.join("**#**");
  380.                 var names_array = [];
  381.                 if (all_files_selected === true) {
  382.                         for (var i in wdb_all_files_filtered) {
  383.                                 var index = no_selected_files.indexOf(wdb_all_files_filtered[i]["name"]);
  384.                                 if (index < 0) {
  385.                                         var all_names = wdb_all_files_filtered[i]["name"];
  386.                                         names_array.push(all_names);
  387.                                 }
  388.                         }
  389.                         names_list = names_array.join("**#**");
  390.                 }
  391.                 submit("", null, null, null, null, null, null, "cut", names_list, dir, null);
  392.         }
  393. }
  394.  
  395. function onBtnPasteClick(event, obj) {
  396.         if (getClipboardFiles() != "") {
  397.                 submit("paste_items", null, null, null, null, null, null, null, null, null, dir);
  398.         }
  399. }
  400.  
  401. function onBtnRemoveItemsClick(event, obj) {
  402.         if ((filesSelected.length != 0) && (confirm(warningRemoveItems) == true)) {
  403.                 submit("remove_items", null, null, null, null, null, null, null, null, null, null);
  404.         }
  405. }
  406.  
  407. function onBtnParsingItemsClick(event, obj) {
  408.         submit("parsing_items", null, null, null, null, null, null, null, null, null, null);
  409. }
  410.  
  411. function onBtnShowUploaderClick(event, obj) {
  412.         jQuery(document).trigger("onUploadFilesPressed");
  413.         jQuery("#uploader").fadeIn();
  414. }
  415.  
  416. function onBtnViewThumbsClick(event, obj) {
  417.         submit("", null, null, "thumbs", null, null, null, null, null, null, null);
  418. }
  419.  
  420. function onBtnViewListClick(event, obj) {
  421.         submit("", null, null, "list", null, null, null, null, null, null, null);
  422. }
  423.  
  424. function onBtnBackClick(event, obj) {
  425.         if ((isUploading == false) || (confirm(warningCancelUploads) == true)) {
  426.                 submit("", null, null, null, null, null, null, null, null, null, null);
  427.         }
  428. }
  429.  
  430. function onPathComponentClick(event, obj, key) {
  431.         var path = '';
  432.         var pathArr = [];
  433.         jQuery("#path .path_dir").each( function( i,v ) {
  434.                 path += ( i == 0 ) ? '' : '/' + jQuery(v).text().trim();
  435.                 pathArr[i] = path;
  436.         });
  437.         var path = ( pathArr[key] ) ? pathArr[key] : '';
  438.         submit('display', null, null, null, path, null, null, null, null, null, null);
  439. }
  440.  
  441. function onBtnShowImportClick(event, obj) {
  442.         jQuery("#importer").fadeIn();
  443. }
  444.  
  445. function onNameHeaderClick(event, obj) {
  446.         var newSortOrder = ((sortBy == "name") && (sortOrder == "asc")) ? "desc" : "asc";
  447.         submit("", "name", newSortOrder, null, null, null, null, null, null, null, null);
  448. }
  449.  
  450. function onSizeHeaderClick(event, obj) {
  451.         var newSortOrder = ((sortBy == "size") && (sortOrder == "asc")) ? "desc" : "asc";
  452.         submit("", "size", newSortOrder, null, null, null, null, null, null, null, null);
  453. }
  454.  
  455. function onDateModifiedHeaderClick(event, obj) {
  456.         var newSortOrder = ((sortBy == "date_modified") && (sortOrder == "asc")) ? "desc" : "asc";
  457.         submit("", "date_modified", newSortOrder, null, null, null, null, null, null, null, null);
  458. }
  459.  
  460. //file handlers
  461. function onKeyDown(e) {
  462.         var e = e || window.event;
  463.         var chCode1 = e.which || e.paramlist_keyCode;
  464.         if ((e.ctrlKey || e.metaKey) && chCode1 == 65) {
  465.     onBtnSelectAllClick(dir + DS);
  466.                 e.preventDefault();
  467.         }
  468. }
  469.  
  470. function onFileMOver(event, obj) {
  471.         jQuery(obj).addClass("explorer_item_hover");
  472. }
  473.  
  474. function onFileMOut(event, obj) {
  475.         jQuery(obj).removeClass("explorer_item_hover");
  476. }
  477.  
  478. function onFileClick(event, obj) {
  479.   var isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
  480.   jQuery(".explorer_item").removeClass("explorer_item_select");
  481.   var objName = jQuery(obj).attr("name");
  482.   if (event.ctrlKey == true || event.metaKey == true || isMobile) {
  483.     if (all_files_selected === true) {
  484.       if (filesSelected.indexOf(objName) == -1) {
  485.         var index = no_selected_files.indexOf(objName);
  486.         if (index >= 0) {
  487.           no_selected_files.splice( index, 1 );
  488.         }
  489.       }
  490.       else {
  491.         no_selected_files.push(objName);
  492.       }
  493.     }
  494.     if (filesSelected.indexOf(objName) == -1) {
  495.       filesSelected.push(objName);
  496.       keyFileSelected = obj;
  497.     }
  498.     else {
  499.       filesSelected.splice(filesSelected.indexOf(objName), 1);
  500.       jQuery(obj).removeClass("explorer_item_select");
  501.       jQuery(obj).removeClass("explorer_item_hover");
  502.     }
  503.   }
  504.   else if (event.shiftKey == true) {
  505.     filesSelected = [];
  506.     var explorerItems = jQuery(".explorer_item");
  507.     var curFileIndex = explorerItems.index(jQuery(obj));
  508.     var keyFileIndex = explorerItems.index(keyFileSelected);
  509.     var startIndex = Math.min(keyFileIndex, curFileIndex);
  510.     var endIndex = startIndex + Math.abs(curFileIndex - keyFileIndex);
  511.     for (var i = startIndex; i < endIndex + 1; i++) {
  512.       filesSelected.push(jQuery(explorerItems[i]).attr("name"));
  513.     }
  514.   }
  515.   else {
  516.     filesSelected = [jQuery(obj).attr("name")];
  517.     keyFileSelected = obj;
  518.   }
  519.  
  520.   for (var i = 0; i < filesSelected.length; i++) {
  521.     jQuery('.explorer_item[name="' + filesSelected[i] + '"]').addClass("explorer_item_select");
  522.   }
  523.   updateFileNames();
  524. }
  525.  
  526. function onFileDblClick(event, obj) {
  527.   if (jQuery(obj).attr("isDir") == "true") {
  528.     submit("", null, null, null, dir + DS + jQuery(obj).attr("name"), null, null, null, null, null, null);
  529.   }
  530.   else {
  531.     filesSelected = [];
  532.     filesSelected.push(jQuery(obj).attr("name"));
  533.     submitFiles();
  534.   }
  535. }
  536. /*TODO function not used on view! (only file)*/
  537. function onFileDragStart(event, obj) {
  538.   var objName = jQuery(obj).attr("name");
  539.   if (filesSelected.indexOf(objName) < 0) {
  540.     jQuery(".explorer_item").removeClass("explorer_item_select");
  541.     if (event.ctrlKey == true || event.metaKey == true) {
  542.       if (filesSelected.indexOf(objName) == -1) {
  543.         filesSelected.push(objName);
  544.         keyFileSelected = obj;
  545.       }
  546.     }
  547.     else if (event.shiftKey == true) {
  548.       filesSelected = [];
  549.       var explorerItems = jQuery(".explorer_item");
  550.       var curFileIndex = explorerItems.index(jQuery(obj));
  551.       var keyFileIndex = explorerItems.index(keyFileSelected);
  552.       var startIndex = Math.min(keyFileIndex, curFileIndex);
  553.       var endIndex = startIndex + Math.abs(curFileIndex - keyFileIndex);
  554.       for (var i = startIndex; i < endIndex + 1; i++) {
  555.         filesSelected.push(jQuery(explorerItems[i]).attr("name"));
  556.       }
  557.     }
  558.     else {
  559.       filesSelected = [jQuery(obj).attr("name")];
  560.       keyFileSelected = obj;
  561.     }
  562.  
  563.     for (var i = 0; i < filesSelected.length; i++) {
  564.       jQuery('.explorer_item[name="' + filesSelected[i] + '"]').addClass("explorer_item_select");
  565.     }
  566.  
  567.     updateFileNames();
  568.   }
  569.   dragFiles = filesSelected;
  570. }
  571. /*TODO function not used on view! (only folder)*/
  572. function onFileDragOver(event, obj) {
  573.   event.preventDefault();
  574. }
  575. /*TODO function not used on view! (only folder)*/
  576. function onFileDrop(event, obj) {
  577.   var destDirName = jQuery(obj).attr("name");
  578.   if ((dragFiles.length == 0) || (dragFiles.indexOf(destDirName) >= 0)) {
  579.     return false;
  580.   }
  581.   var clipboardTask = (event.ctrlKey == true || event.metaKey == true) ? "copy" : "cut";
  582.   var clipboardDest = dir + DS + destDirName;
  583.   submit("paste_items", null, null, null, null, null, null, clipboardTask, dragFiles.join("**#**"), dir, clipboardDest);
  584.   event.preventDefault();
  585. }
  586.  
  587. function onBtnOpenClick(event, obj) {
  588.   if ( localStorage.getItem('bwg_selected_images') ) {
  589.     localStorage.removeItem('bwg_selected_images');
  590.   }
  591.   jQuery('#add_selectid_img').css('pointer-events', 'none');
  592.   jQuery('#cancel_add_img').css('pointer-events', 'none');
  593.   jQuery('#select_all_images').css('pointer-events', 'none');
  594.   if (jQuery('.explorer_item[name="' + filesSelected[0] + '"]').attr("isDir") == 'true') {
  595.     filesSelected.length = 1;
  596.     submit("", null, null, null, dir + DS + filesSelected[0], null, null, null, null, null, null);
  597.   }
  598.   else {
  599.     submitFiles();
  600.   }
  601.   window.parent.bwg_remove_loading_block();
  602. }
  603.  
  604. function onBtnCancelClick(event, obj) {
  605.   window.parent.tb_remove();
  606. }
  607.  
  608. function onBtnSelectAllClick( dir ) {
  609.         jQuery(".explorer_item").removeClass("explorer_item_select");
  610.         jQuery(".explorer_item:visible").addClass("explorer_item_select");
  611.         var search = jQuery('#search_by_name .search_by_name').val();
  612.         var orderby = jQuery("input[name='sort_by']").val();
  613.         var order = jQuery("input[name='sort_order']").val();
  614.         jQuery.ajax({
  615.                 type: "POST",
  616.                 dataType: "json",
  617.                 url: ajax_get_all_select_url,
  618.                 data: {
  619.                         dir,
  620.                         search,
  621.                         order,
  622.                         orderby
  623.                 },
  624.                 success: function (res) {
  625.                         files = res.data;
  626.                         filesSelected = [];
  627.                         jQuery.each(files, function(i, v) {
  628.                                 var objName = v.name;
  629.                                 if (filesSelected.indexOf(objName) == -1) {
  630.                                         filesSelected.push(objName);
  631.                                         keyFileSelected = this;
  632.                                 }
  633.                         });
  634.                         all_files_selected = true;
  635.                         wdb_all_files_filtered = files;
  636.                 },
  637.                 beforeSend: function() {
  638.                 },
  639.                 complete:function() {
  640.                 }
  641.         });
  642. }
  643.  
  644. function ajax_print_images( params ) {
  645.   var element = params['element'];
  646.   var is_search = params['is_search'];
  647.   var paged = params['page'];
  648.   ajax_request_count = paged;
  649.   var search = params['search'];
  650.   var orderby = params['orderby'];
  651.   var order = params['order'];
  652.   var page_per = element.data('page_per');
  653.   var found_wrap = jQuery('#explorer_body_container .fm-no-found-wrap');
  654.   var new_promise = new Promise(function ( resolve, reject ) {
  655.       jQuery.ajax({
  656.         type: "POST",
  657.         dataType: "json",
  658.         url: ajax_pagination_url,
  659.         data: {
  660.           dir,
  661.           paged,
  662.           search,
  663.           order,
  664.           orderby
  665.         },
  666.         success: function ( res ) {
  667.           if ( is_search ) {
  668.             jQuery('#loading_div', window.parent.document).hide();
  669.             element.html('');
  670.           }
  671.           if ( res.html ) {
  672.             element.append(res.html);
  673.             jQuery('#explorer_body .explorer_item').each(function ( i, that ) {
  674.               var img = jQuery(that).find('img');
  675.                   img.attr('scr', jQuery(that).attr('filethumb'));
  676.             });
  677.             var remove_local_storage = false;
  678.             if ( localStorage.getItem('bwg_selected_images') ) {
  679.               var bwg_selected_images   = localStorage.getItem('bwg_selected_images').split(',');
  680.               var selected_images_caunt = jQuery('.explorer_item.explorer_item_select').length;
  681.               if ( page_per <= bwg_selected_images.length && selected_images_caunt <= bwg_selected_images.length ) {
  682.                 var needed_choose_images_count = bwg_selected_images.length - selected_images_caunt;
  683.                 filesSelected = bwg_selected_images;
  684.                 jQuery('.explorer_item:not(.explorer_item_select)').each(function ( i, val ) {
  685.                   var index = (i + 1);
  686.                   if ( index <= needed_choose_images_count ) {
  687.                     if ( bwg_selected_images.includes(jQuery(this).attr('name')) > 0 ) {
  688.                       jQuery(this).addClass('explorer_item_select');
  689.                     }
  690.                   }
  691.                   if ( index == needed_choose_images_count ) {
  692.                     remove_local_storage = true;
  693.                   }
  694.                 });
  695.                 if ( remove_local_storage ) {
  696.                   localStorage.removeItem('bwg_selected_images');
  697.                 }
  698.               }
  699.               if ( remove_local_storage ) {
  700.                 localStorage.removeItem('bwg_selected_images');
  701.               }
  702.             }
  703.             found_wrap.hide();
  704.           }
  705.           else if ( search && res.html == '' ) {
  706.             found_wrap.show();
  707.           }
  708.           resolve()
  709.         },
  710.         beforeSend: function () {
  711.           if ( is_search ) {
  712.             jQuery('#loading_div', window.parent.document).show();
  713.             element.html('');
  714.           }
  715.         },
  716.         complete: function () {}
  717.       });
  718.     });
  719.   return new_promise;
  720. }

Raw Paste


Login or Register to edit or fork this paste. It's free.