j-Modificator
This component can modify behaviour of element according to the preddefined schema. The component can be hooked on a body element (because it's singleton) and it's optimized for the performance.
Supported attributes:
data-m="SOME.PATH"- the component will watch this pathdata-m-schema="schema_name"- modificator uses this registered schemadata-m-selector=".ui-textbox-label"(optional) a target element will be an element according to the selector (default:null)- NEW UPDATE:
data-m="SOME.PATH + schema_name"this attribute can containpathandschema_nametogether
Supported classes:
modifyenablesclickevent for this elemente.typewill containclicktype
Registering schema:
- you can define multiple schemas
instance.register('schema_name', function(value, element, e) {
// value: according to the "data-m"
// element: jQuery element (target)
// e: contains additional data { type: 'init/click/bind' } and can be used as a repository
// here you can modify the element
});Scopes:
j-Modificator supports jComponent scopes but each path in the scope needs to contain ? question mark e.g. data-m="?.name" which is replaced with a scope path. Important: jComponent scope needs to contain some jComponents.
<div data-scope="user">
<div data---="textbox__?.name">Your name</div>
<div data-m="?.name"></div>
</div>Use it with <ui-component name="modificator">. 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.
<ui-component name="modificator">
<div><a href="javascript:void(0)" class="modify" data-m="obj.a" data-m-schema="link">Click 1</a> second: <a href="javascript:void(0)" class="modify" data-m="obj.a" data-m-schema="link">Click 2</a></div>
<br />
<div><button class="modify" data-m="obj.b" data-m-schema="button"><i></i><b>Submit</b></button></div>
</ui-component>
<script>
// v20 STYLE(), v19 CSS()
(W.STYLE?W.STYLE:W.CSS)('.sending{color:black;font-weight:bold;cursor:not-allowed}.done{color:green;font-weight:bold;}button .ti{margin-right:5px;}');
// Register modificator schemas
SETTER(true, 'modificator', 'register', 'link', function(value, element, e) {
switch (e.type) {
case 'init':
break;
case 'click':
element.aclass('sending').html('Sending...');
break;
default:
if (value != null)
element.rclass().aclass('done').html(value);
break;
}
});
SETTER(true, 'modificator', 'register', 'button', function(value, element, e) {
switch (e.type) {
case 'init':
e.icon = element.find('i');
e.html = element.html();
break;
case 'click':
e.icon.rclass().aclass('ti ti-spinner ti-refresh');
element.prop('disabled', true).find('b').html('Sending...');
break;
default:
e.icon.rclass();
element.prop('disabled', false);
element.find('b').html(e.html);
if (value != null)
e.icon.aclass('ti ' + (value ? 'ti-check-circle' : 'ti-times-circle'));
break;
}
});
var obj = {};
obj.a = null;
obj.b = null;
// Only for test
$(document).on('click', '.modify', function(e) {
var path = $(this).attr('data-m');
if (path === 'obj.a') {
SET(path, 'Success', 3000);
} else {
SET(path, true, 3000);
SET(path, null, 5000);
}
});
</script>