# j-Modificator

> Komponent ten może zmienić zachowanie elementu zgodnie z wstępnie zdefiniowanym schematem. Komponent może być zakrzywiony na elementie ciała (ponieważ jest to singleton) i jest optymalizowany dla wydajności.

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

Komponent ten może zmienić zachowanie elementu zgodnie z wstępnie zdefiniowanym schematem. Komponent może być zakrzywiony na elementu `body` (ponieważ jest singleton) i jest optymalizowany dla wydajności.

__Wspierane atrybuty__:

- `data-m="SOME.PATH"` - składnik będzie obserwować tę ścieżkę
- `data-m-schema="schema_name"` - modyfikator wykorzystuje ten zarejestrowany schemat
- `data-m-selector=".ui-textbox-label"` (opcjonalnie) element docelowy będzie elementem według selektora (default: `null`)
- __NEW UPDATE__: `data-m="SOME.PATH + schema_name"` Ten atrybut może zawierać `path` i `schema_name` razem

__Wspierane klasy__:

- `modify` umożliwia wydarzenie `click` dla tego elementu `e.type` będzie zawierać typ `click`

__Rejestracja schematu__:

- Możesz zdefiniować kilka schematów

```javascript
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
});
```

__celów__:

j-Modificator Wsparcie jComponent Wszelkie ścieżki, ale każdy z nich musi zawierać `?` Pytanie o g. `data-m="?.name"` Zastępuje się go ścieżką zakresu. _Important:__ jComponent Sklep musi zawierać kilka elementów j.

```html
<div data-scope="user">
	<div data---="textbox__?.name">Your name</div>
	<div data-m="?.name"></div>
</div>
```

Użyj go z `<ui-component name="modificator">`Gdy element nie jest jeszcze ładowany, jComponent Pobierz go po pierwszym użyciu z adresu `DEF.fallback` (Wydaje się Componentator Autor: Peter Širka Źródło: Componentator Zestaw składników, licencja MIT.

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