j-Templates
- multiple templates
- drag & drop
- custom scrollbars
- context menu
Configuration:
template {String}a path to the watching a template namescrollbar {Boolean}uses a custom scrollbar (default:true)scrolltop {Boolean}scrolls to top if the source is changed (default:true)visibleY {Boolean}shows scrollbar Y (default:true)margin {Number}a vertical margin (default:0)parent {String}jQuery selector to parent container due toscrollbar(default:auto)contextmenu {String}a path to the methodfunction(e)if the user triggers context-menuemptyif {String}a condition for showing of empty content (default:!value || !value.length)drop {String}a path to the methodfunction(e, target, selel)- the method is evaluated if the user drops some files, then
selelis undefined - or the user drags & drops element with the
draggableattribute (selelargument) into thetargetargument (target must containdroppableclass)
- the method is evaluated if the user drops some files, then
Templates must be defined in <script type="text/html" data-name="NAME_OF_TEMPLATE">Tangular template</script> element. This component supports one special template called empty that will be visible if the emptyif option will be valid.
Use it with <ui-component name="templates">. 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>
<span data-name="list" onclick="changetemplate(this)" style="text-decoration:underline;cursor:pointer;margin-right:5px">List</span>
<span data-name="icons" onclick="changetemplate(this)" style="text-decoration:underline;cursor:pointer">Icons</span>
</div>
<br />
<div style="width:500px;height:300px;border:1px solid #E0E0E0">
<ui-component name="templates" path="myfiles" config="template:mytemplate;drop:template_drop">
<script type="text/html" data-name="list">
<div class="list padding">
{{ foreach m in value }}
<div draggable="true"{{ if m.isfolder }} class="droppable"{{ fi }}>{{ m.name }}</div>
{{ end }}
</div>
</script>
<script type="text/html" data-name="icons">
<div class="icons padding">
{{ foreach m in value }}
<span draggable="true" class="mr5 {{ if m.isfolder }} droppable{{ fi }}"><i class="{{ m.icon }} mr5"></i>{{ m.name }}</span>
{{ end }}
</div>
</script>
</ui-component>
</div>
<br />
<div><b>Without multiple templates:</b></div>
<div style="width:500px;height:300px;border:1px solid #E0E0E0;margin-top:10px">
<ui-component name="templates" path="myfiles">
<script type="text/html">
<div class="list padding">
{{ foreach m in value }}
<div draggable="true"{{ if m.isfolder }} class="droppable"{{ fi }}>{{ m.name }}</div>
{{ end }}
</div>
</script>
</ui-component>
</div>
<script>
var myfiles = [{ icon: 'ti ti-folder', name: 'temp', isfolder: true }, { icon: 'ti ti-file', name: 'logo.png' }, { icon: 'ti ti-file', name: 'logo.svg' }];
var mytemplate = 'list';
function changetemplate(el) {
SET('mytemplate', el.getAttribute('data-name'));
}
function template_drop(e, target, item) {
console.log(e, target, item);
// @target {jQuery element}
if (item) {
// @item {jQuery element}
} else {
var files = e.target.files || e.originalEvent.dataTransfer.files;
}
}
</script>