uid . '" class="av-folderlist level-0' . '">';
$subdir = $this->showdir($dir, $folderOnly, $showRoot, $level + 1, $ef);
$name = substr(strrchr($dir, '/'), 1);
$html .= '
' . ($subdir ? '' : '') . '' . $name . '' . $subdir . '';
$html .= '';
} else {
$list = scandir($dir);
if (is_array($list)) {
$list = array_diff($list, array('.', '..'));
if ($list) {
$folders = array();
$files = array();
foreach ($list as $name) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $name)) {
$folders[] = $name;
} else {
$files[] = $name;
}
}
if (!($folderOnly && !$folders) || !(!$folders || !$files)) {
$html .= '';
}
sort($folders);
sort($files);
foreach ($folders as $name) {
$fpath = $dir.'/'.$name;
$subdir = $this->showdir($fpath, $folderOnly, $showRoot, $level + 1, $ef);
$fpath = str_replace('\\', '/', str_replace($ef, '', $fpath));
$html .= '- ' . ($subdir ? '' : '') . '' . $name . '' . $subdir . '
';
}
if (!$folderOnly)
foreach ($files as $name) {
$fpath = $dir.'/'.$name;
$fpath = str_replace('\\', '/', str_replace($ef, '', $fpath));
$ext = substr(strrchr($name, '.'), 1);
$html .= '- ' . $name . '
';
}
if (!($folderOnly && !$folders) || !(!$folders || !$files)) {
$html .= '
';
}
unset($folders, $files, $fpath, $ext);
}
}
}
return $html;
}
protected function getInput()
{
// include css
$path = str_replace('\\', '/', str_replace(JPATH_ROOT.'/', '', __DIR__));
JHtml::_('stylesheet', $path.'/fileselect.css');
// get attributes
$folder = $this->getAttribute('folder');
$folder = ($folder && file_exists(realpath(JPATH_ROOT.'/'.$folder)) ? $folder : 'images');
$folderOnly = $this->getAttribute('folderonly');
$folderOnly = ($folderOnly && (strtolower($folderOnly) === 'true' || strtolower($folderOnly) === 'folderonly') ? true : false);
$showRoot = $this->getAttribute('showroot');
$showRoot = ($showRoot && (strtolower($showRoot) === 'true' || strtolower($showRoot) === 'showroot') ? true : false);
$color = $this->getAttribute('color');
// get uniq id
$this->uid = uniqid('avfl');
// make html
$html = '';
// input
$html .= '
';
$script = "
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('" . $this->uid . "btn').addEventListener('click', function(e) {
document.getElementById('" . $this->uid . "modal').classList.toggle('open');
});
document.querySelectorAll('#" . $this->uid . " .av-folderlist-tree').forEach(function(el) {
el.addEventListener('click', function(e) {
e.target.parentNode.classList.toggle('open');
});
});
document.querySelectorAll('#" . $this->uid . " .av-folderlist-label').forEach(function(el) {
el.addEventListener('click', function(e) {
var
target = e.target;
list = e.target.closest('.av-folderlist');
list.querySelectorAll('.av-folderlist-label').forEach(function(elm) {
elm.classList.remove('selected');
});
document.getElementById('" . $this->id . "').value = target.getAttribute('path');
target.classList.add('selected');
if (!target.parentNode.classList.contains('open')) {
target.parentNode.classList.add('open');
}
});
});
});
";
JFactory::getDocument()->addScriptDeclaration($script);
$html .= '
';
return $html;
}
}