# j-Parts

> This content can handle multiple parts stored in the Array and focus on one specific part. It simulates something like browser tabs.

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

This content can handle multiple `parts` stored in the `Array` and focus on one specific part. It simulates something like browser tabs.


__Configuration__:

- `parent {String}` parent area due to part size (default: `auto`)
- `margin {Number}` vertical margin (default: `0`)
- `create {String}` a link to the `function(part)`, it's executed if the part is created (called once)
- `focus {String}` a link to the `function(part)`, it's executed if the part is focused
- `close {String}` a link to the `function(part)`, it's executed if the part is closed

__Good to know 1__:

- all `~PATH~` phrases will be replaced by `item.path` automatically
- all `~ID~` phrases will be replaced by `item.id` automatically

__Item specification__:

- `item.id {String}` very important, part identifier
- `item.blur {String/Function(el, item)}` optional, a link to the `function(element, item)` if the part is focused out
- `item.focus {String/Function(el, item)}` or `item.reload {String}` optional, a link to the `function(element, item)` if the part is focused
- `item.remove {String/Function(el, item)}` optional, a link to the `function(element, item)` if the part is removed
- `item.html {String}` a HTML content or use `item.url`
- `item.import {String}` URL address for the part content
- `item.path {String}` optional, it replaces all `~PATH~` phrases automatically
- `item.delay {Number}` a delay for removing of `invisible` class
- __NEW__ `item.attrd {Object}` adds `data-key` attributes into the item element

__Extendend by the component__:

- `item.focused {Boolean}` determines if the part is focused or not
- `item.element {jQuery}` part element

__Methods__:

- `component.close(id)` closes part
- `component.focus(id)` focuses part
- `component.rename(id, name, [icon])` renames part

Use it with `<ui-component name="parts">`. 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
<ui-component name="exec">

	<ui-bind path="myparts" config="template" class="block">
		<script type="text/html">
			{{ foreach m in value }}
			<button class="exec" data-exec="changepart" data-id="{{ m.id }}"><i class="ti ti-times exec mr5" data-prevent="true" data-exec="closepart"></i>{{ m.name }}</button>
			{{ end }}
		</script>
	</ui-bind>
	<br />

	<div style="width:600px;height:300px;border:1px solid #E0E0E0">
		<ui-component name="parts" path="myparts" config="parent:auto"></ui-component>
	</div>

</ui-component>

<script>
	var myparts = [];

	myparts.push({ id: '1', name: 'Part 1', html: '<div class="padding">Part 1</div>' });
	myparts.push({ id: '2', name: 'Part 2', html: '<div class="padding">Part 2</div>' });
	myparts.push({ id: '3', name: 'Part 3', html: '<div class="padding">Part 3</div>' });

	function changepart(el ,e) {
		var id = ATTRD(el);
		SETTER('parts/focus', id);
	}

	function closepart(el, e) {
		var id = ATTRD(el);
		SETTER('parts/close', id);
	}

</script>
```
