# 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.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 02b73fa6ac68bd8aae79cfb69761be8b8a87264b2371371601ca590cacf6c995
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

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 method `function(item, el)` (user must click on the right button)
- `click {String}` a path to variable or method `function(item)` (user must click on the item)
- `checked {String}` a path to variable or method `function(checked_items, component)` (user must check the checkbox)
- `browse {String}` __IMPORTANT__: a path to method `function(path, next(ARRAY), [item])` which must return a content for the component
- `parent {String}` optional, a container with fixed height, can be `window`. 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&dropped
- `key {String}` optional, a key name for creating of path (default: `name`)
- `raw {Boolean}` optional, disables HTML encoding `name` (default: `false`)
- __NEW__: `contextmenu {String}` optional, a path to method `function(item, el, e)` (when a user displays the context menu)

```js
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.

```html example.html
<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>
```
