-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic-example.js
48 lines (38 loc) · 1.34 KB
/
basic-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var basicExample = (function(w,d) {
var modelOutput, m;
m = murk({
dev: true,
id: 'basic'
}).registerFilter('reverseStr', function(val) {
return val.split('').reverse().join('');
}).registerFilter('highlightText', function() {
this.style.color = 'red';
}).linkProperty('linkedExample', ['firstExample', 'thirdExample'], function(model) {
return model.firstExample + ' ' + model.thirdExample;
});
function init() {
modelOutput = d.getElementById('basicModel');
m.on(['firstExample','secondExample','thirdExample','fourthExample'], function(key) {
var count = this.getAttribute('data-murk-count');
var el = d.getElementById(key + 'Count');
var input = d.getElementById(key);
if (!input.value) input.value = m.state.model[key];
if (count) {
m.set(key + 'Count', count);
el.style.display = 'inherit';
}
}).set({
firstExample: 'this is',
secondExample: 'data binding',
thirdExample: 'murked.',
});
example.updateModel(modelOutput,m.state.model,m.state.keys,m.state.totalCount);
$('[data-murk-example="basic"]').on('keyup blur', function() {
m.set(this.id, this.value);
example.updateModel(modelOutput,m.state.model,m.state.keys,m.state.totalCount);
});
return m;
}
$(d).ready(init);
return m;
})(window,document);