j-Folder
The component can render a content like file browser. path must be in the form e.g. Directory/Directory/File. Learn from example.
Configuration:
up {String}a label for Up button (default:..)delimiter {String}a delimiter for the path (default:/)root {String}a label for first item in breadcrumb (default:Root)scrollbar {Boolean}enables custom scrollbar (default:true)scrollbarY {Boolean}shows Y scrollbar always (default:false)delimiter {String}a delimiter for path (default:/)options {String}a path to methodfunction(item, el)(user must click on the right button)click {String}a path to variable or methodfunction(item)(user must click on the item)checked {String}a path to variable or methodfunction(checked_items, component)(user must check the checkbox)browse {String}IMPORTANT: a path to methodfunction(path, next(ARRAY), [item])which must return a content for the componentparent {String}optional, a container with fixed height, can bewindow. Default value:component.element()margin {Number}optional, a top/bottom margin together (default:0)drop {String}optional, a path to method which will be executed if a file will be drag&droppedkey {String}optional, a key name for creating of path (default:name)raw {Boolean}optional, disables HTML encodingname(default:false)- NEW:
contextmenu {String}optional, a path to methodfunction(item, el, e)(when a user displays the context menu)
function fn_browser(path, next, item) {
// @path {String} paths divided according to the "config.delimiter"
// @next {Function(Array)} importat: this function expects array with items
// @item {Object} can be null
var arr = [];
// Object for array:
// obj.name {String} a label/name
// obj.checkbox {Boolean} enables checkbox (default: false)
// obj.checked {Boolean} item will be checked
// obj.icon {String} a icon for item
// obj.type {Number} determines a type of item (1: directory, other: file)
// obj.classname {String} adds a CSS class onto "label" element
// Good to know:
// Only directories can be drilled
// Example:
arr.push({ name: 'Node.js', checkbox: true, type: 1, icon: 'folder' });
arr.push({ name: 'Client-Side', checkbox: true, type: 1, icon: 'folder' });
next(arr);
// next(array, noscroll);
}Use it with <ui-component name="folder">. When the component is not loaded yet, jComponent downloads it on first use from the address in DEF.fallback (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.
<div class="container">
<br />
<ui-component name="folder" path="currentpath" config="browse:fn_browse;checked:fn_checked;click:fn_click" style="height:500px"></ui-component>
<br />
</div>
<script>
var currentpath = 'Frameworks/Node.js';
function fn_browse(path, next, item) {
var arr = [];
switch (path) {
case 'Frameworks':
arr.push({ name: 'Node.js', checkbox: true, type: 1, icon: 'folder' });
arr.push({ name: 'Client-Side', checkbox: true, type: 1, icon: 'folder' });
break;
case 'Frameworks/Node.js':
arr.push({ name: 'Total.js', checkbox: true, checked: true, icon: 'file' });
arr.push({ name: 'Express.js', checkbox: true, icon: 'file' });
arr.push({ name: 'Koa.js', checkbox: true, icon: 'file' });
arr.push({ name: 'Meteor.js', checkbox: true, icon: 'file' });
break;
case 'Frameworks/Client-Side':
arr.push({ name: 'React', checkbox: true, icon: 'file' });
arr.push({ name: 'Vue', checkbox: true, icon: 'file' });
arr.push({ name: 'jComponent', checkbox: true, checked: true, icon: 'file' });
arr.push({ name: 'Angular.js', checkbox: true, icon: 'file' });
arr.push({ name: 'jQuery', checkbox: true, icon: 'file' });
break;
default:
arr.push({ name: 'Frameworks', checkbox: true, type: 1, icon: 'folder' });
arr.push({ name: 'Item 1', checkbox: true, icon: 'file' });
arr.push({ name: 'Item 2', checkbox: true, icon: 'file' });
arr.push({ name: 'Item 3', checkbox: true, icon: 'file' });
break;
}
next(arr);
}
function fn_click(item) {
console.log('click', item);
}
function fn_checked(arr) {
console.log('checked', arr);
}
</script>