File Manager
Viewing File: admin.js
jQuery(document).ready(function($){
// Toggle Dropdown on Click
$(document).on('click', '.documentor-dropdown-trigger', function(e){
e.stopPropagation();
var $wrapper = $(this).closest('.documentor-multiselect-wrapper');
var $options = $wrapper.find('.documentor-dropdown-options');
// Close all other open dropdowns first
$('.documentor-dropdown-options').not($options).hide();
$options.toggle();
});
// Close Dropdown when clicking outside
$(document).on('click', function(e){
if(!$(e.target).closest('.documentor-multiselect-wrapper').length){
$('.documentor-dropdown-options').hide();
}
});
// Update Trigger Text when checkboxes change
$(document).on('change', '.documentor-dropdown-options input[type="checkbox"]', function(){
var $wrapper = $(this).closest('.documentor-multiselect-wrapper');
var $triggerText = $wrapper.find('.selected-text');
var checkedCount = $wrapper.find('input[type="checkbox"]:checked').length;
if(checkedCount === 0){
$triggerText.text('Select Document Hubs');
} else{
$triggerText.text(checkedCount + ' Selected');
}
});
var injectActions = ['documentor_create_doc', 'documentor_clone_doc'];
// Intercepts AJAX request to silently inject the active Hub ID from the UI into the payload.
$.ajaxPrefilter(function(options, originalOptions, jqXHR){
if(options.data && typeof options.data === 'string'){
// Check if the current action matches anything in our injectActions array
var needsHubId = injectActions.some(function(action){
return options.data.includes('action=' + action);
});
if(needsHubId){
// Scan the current page to find the actively selected Hub tab
var activeHubId = $('.hub-filter-btn a.active').attr('data-hub-id');
// Only send hub_id for real hub tabs; "default" intentionally creates unassigned docs.
if(activeHubId && activeHubId !== 'all' && activeHubId !== 'default'){
options.data += '&hub_id=' + encodeURIComponent(activeHubId);
}
}
}
});
});