simplyview 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/simply.app.js +1120 -0
- package/dist/simply.app.js.map +7 -0
- package/dist/simply.app.min.js +2 -0
- package/dist/simply.app.min.js.map +7 -0
- package/dist/simply.everything.js +1583 -2025
- package/dist/simply.everything.js.map +7 -0
- package/dist/simply.everything.min.js +2 -0
- package/dist/simply.everything.min.js.map +7 -0
- package/package.json +8 -3
- package/src/action.mjs +12 -0
- package/src/activate.mjs +63 -0
- package/src/app.mjs +40 -0
- package/src/bind.mjs +572 -0
- package/src/command.mjs +125 -0
- package/src/everything.mjs +27 -0
- package/src/include.mjs +191 -0
- package/src/key.mjs +55 -0
- package/src/model.mjs +151 -0
- package/src/route.mjs +222 -0
- package/src/state.mjs +536 -0
- package/js/.eslintrc.json +0 -29
- package/js/simply.action.js +0 -115
- package/js/simply.activate.js +0 -79
- package/js/simply.api.js +0 -228
- package/js/simply.app.js +0 -63
- package/js/simply.collect.js +0 -72
- package/js/simply.command.js +0 -196
- package/js/simply.include.js +0 -226
- package/js/simply.keyboard.js +0 -62
- package/js/simply.modules.js +0 -22
- package/js/simply.observe.js +0 -349
- package/js/simply.path.js +0 -48
- package/js/simply.render.js +0 -125
- package/js/simply.resize.js +0 -80
- package/js/simply.route.js +0 -234
- package/js/simply.view.js +0 -35
- package/js/simply.viewmodel.js +0 -189
- /package/{js/simply.include.next.js → src/include.next.js} +0 -0
package/js/simply.activate.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var listeners = {};
|
|
5
|
-
|
|
6
|
-
var activate = {
|
|
7
|
-
addListener: function(name, callback) {
|
|
8
|
-
if (!listeners[name]) {
|
|
9
|
-
listeners[name] = [];
|
|
10
|
-
}
|
|
11
|
-
listeners[name].push(callback);
|
|
12
|
-
initialCall(name);
|
|
13
|
-
},
|
|
14
|
-
removeListener: function(name, callback) {
|
|
15
|
-
if (!listeners[name]) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
listeners[name] = listeners[name].filter(function(listener) {
|
|
19
|
-
return listener!=callback;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
var initialCall = function(name) {
|
|
25
|
-
var nodes = document.querySelectorAll('[data-simply-activate="'+name+'"]');
|
|
26
|
-
if (nodes) {
|
|
27
|
-
[].forEach.call(nodes, function(node) {
|
|
28
|
-
callListeners(node);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
var callListeners = function(node) {
|
|
34
|
-
if (node && node.dataset.simplyActivate
|
|
35
|
-
&& listeners[node.dataset.simplyActivate]
|
|
36
|
-
) {
|
|
37
|
-
listeners[node.dataset.simplyActivate].forEach(function(callback) {
|
|
38
|
-
callback.call(node);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var handleChanges = function(changes) {
|
|
44
|
-
var activateNodes = [];
|
|
45
|
-
for (var change of changes) {
|
|
46
|
-
if (change.type=='childList') {
|
|
47
|
-
[].forEach.call(change.addedNodes, function(node) {
|
|
48
|
-
if (node.querySelectorAll) {
|
|
49
|
-
var toActivate = [].slice.call(node.querySelectorAll('[data-simply-activate]'));
|
|
50
|
-
if (node.matches('[data-simply-activate]')) {
|
|
51
|
-
toActivate.push(node);
|
|
52
|
-
}
|
|
53
|
-
activateNodes = activateNodes.concat(toActivate);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (activateNodes.length) {
|
|
59
|
-
activateNodes.forEach(function(node) {
|
|
60
|
-
callListeners(node);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
var observer = new MutationObserver(handleChanges);
|
|
66
|
-
observer.observe(document, {
|
|
67
|
-
subtree: true,
|
|
68
|
-
childList: true
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
72
|
-
module.exports = activate;
|
|
73
|
-
} else {
|
|
74
|
-
if (!global.simply) {
|
|
75
|
-
global.simply = {};
|
|
76
|
-
}
|
|
77
|
-
global.simply.activate = activate;
|
|
78
|
-
}
|
|
79
|
-
})(this);
|
package/js/simply.api.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var api = {
|
|
5
|
-
/**
|
|
6
|
-
* Returns a Proxy object that translates property access to a URL in the api
|
|
7
|
-
* and method calls to a fetch on that URL.
|
|
8
|
-
* @param options: a list of options for fetch(),
|
|
9
|
-
* see the 'init' parameter at https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#parameters
|
|
10
|
-
* additionally:
|
|
11
|
-
* - baseURL: (required) the endpoint of the API
|
|
12
|
-
* - path: the current path in the API, is appended to the baseURL
|
|
13
|
-
* - verbs: list of http verbs to allow as methods, default ['get','post']
|
|
14
|
-
* - handlers.fetch: alternative fetch method
|
|
15
|
-
* - handlers.result: alternative getResult method
|
|
16
|
-
* - handlers.error: alternative error method
|
|
17
|
-
* - user (and password): if set, a basic authentication header will be added
|
|
18
|
-
* - paramsFormat: either 'formData', 'json' or 'search'. Default is search.
|
|
19
|
-
* - responseFormat: test, formData, blob, json, arrayBuffer or unbuffered. Default is json.
|
|
20
|
-
* @return Proxy
|
|
21
|
-
*/
|
|
22
|
-
proxy: function(options) {
|
|
23
|
-
var cache = () => {};
|
|
24
|
-
cache.$options = Object.assign({}, options);
|
|
25
|
-
return new Proxy( cache, getApiHandler(cache.$options) );
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Fetches the options.baseURL using the fetch api and returns a promise
|
|
30
|
-
* Extra options in addition to those of global.fetch():
|
|
31
|
-
* - user (and password): if set, a basic authentication header will be added
|
|
32
|
-
* - paramsFormat: either 'formData', 'json' or 'search'
|
|
33
|
-
* By default params, if set, will be added to the baseURL as searchParams
|
|
34
|
-
* @param method one of the http verbs, e.g. get, post, etc.
|
|
35
|
-
* @param options the options for fetch(), with some additions
|
|
36
|
-
* @param params the parameters to send with the request, as javascript/json data
|
|
37
|
-
* @return Promise
|
|
38
|
-
*/
|
|
39
|
-
fetch: function(method, params, options) {
|
|
40
|
-
if (!options.url) {
|
|
41
|
-
if (!options.baseURL) {
|
|
42
|
-
throw new Error('No url or baseURL in options object');
|
|
43
|
-
}
|
|
44
|
-
while (options.baseURL[options.baseURL.length-1]=='/') {
|
|
45
|
-
options.baseURL = options.baseURL.substr(0, options.baseURL.length-1);
|
|
46
|
-
}
|
|
47
|
-
var url = new URL(options.baseURL+options.path);
|
|
48
|
-
} else {
|
|
49
|
-
var url = options.url;
|
|
50
|
-
}
|
|
51
|
-
var fetchOptions = Object.assign({}, options);
|
|
52
|
-
if (!fetchOptions.headers) {
|
|
53
|
-
fetchOptions.headers = {};
|
|
54
|
-
}
|
|
55
|
-
if (params) {
|
|
56
|
-
if (method=='GET') {
|
|
57
|
-
var paramsFormat = 'search';
|
|
58
|
-
} else {
|
|
59
|
-
var paramsFormat = options.paramsFormat;
|
|
60
|
-
}
|
|
61
|
-
switch(paramsFormat) {
|
|
62
|
-
case 'formData':
|
|
63
|
-
var formData = new FormData();
|
|
64
|
-
for (const name in params) {
|
|
65
|
-
formData.append(name, params[name]);
|
|
66
|
-
}
|
|
67
|
-
if (!fetchOptions.headers['Content-Type']) {
|
|
68
|
-
fetchOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
case 'json':
|
|
72
|
-
var formData = JSON.stringify(params);
|
|
73
|
-
if (!fetchOptions.headers['Content-Type']) {
|
|
74
|
-
fetchOptions.headers['Content-Type'] = 'application/json';
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
case 'search':
|
|
78
|
-
var searchParams = url.searchParams; //new URLSearchParams(url.search.slice(1));
|
|
79
|
-
for (const name in params) {
|
|
80
|
-
searchParams.set(name, params[name]);
|
|
81
|
-
}
|
|
82
|
-
url.search = searchParams.toString();
|
|
83
|
-
break;
|
|
84
|
-
default:
|
|
85
|
-
throw Error('Unknown options.paramsFormat '+options.paramsFormat+'. Select one of formData, json or search.');
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (formData) {
|
|
90
|
-
fetchOptions.body = formData
|
|
91
|
-
}
|
|
92
|
-
if (options.user) {
|
|
93
|
-
fetchOptions.headers['Authorization'] = 'Basic '+btoa(options.user+':'+options.password);
|
|
94
|
-
}
|
|
95
|
-
fetchOptions.method = method.toUpperCase();
|
|
96
|
-
var fetchURL = url.toString()
|
|
97
|
-
return fetch(fetchURL, fetchOptions);
|
|
98
|
-
},
|
|
99
|
-
/**
|
|
100
|
-
* Creates a function to call one or more graphql queries
|
|
101
|
-
*/
|
|
102
|
-
graphqlQuery: function(url, query, options) {
|
|
103
|
-
options = Object.assign({ paramsFormat: 'json', url: url, responseFormat: 'json' }, options);
|
|
104
|
-
return function(params, operationName) {
|
|
105
|
-
let postParams = {
|
|
106
|
-
query: query
|
|
107
|
-
};
|
|
108
|
-
if (operationName) {
|
|
109
|
-
postParams.operationName = operationName;
|
|
110
|
-
}
|
|
111
|
-
postParams.variables = params || {};
|
|
112
|
-
return simply.api.fetch('POST', postParams, options )
|
|
113
|
-
.then(function(response) {
|
|
114
|
-
return simply.api.getResult(response, options);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* Handles the response and returns a Promise with the response data as specified
|
|
120
|
-
* @param response Response
|
|
121
|
-
* @param options
|
|
122
|
-
* - responseFormat: one of 'text', 'formData', 'blob', 'arrayBuffer', 'unbuffered' or 'json'.
|
|
123
|
-
* The default is json.
|
|
124
|
-
*/
|
|
125
|
-
getResult: function(response, options) {
|
|
126
|
-
if (response.ok) {
|
|
127
|
-
switch(options.responseFormat) {
|
|
128
|
-
case 'text':
|
|
129
|
-
return response.text();
|
|
130
|
-
break;
|
|
131
|
-
case 'formData':
|
|
132
|
-
return response.formData();
|
|
133
|
-
break;
|
|
134
|
-
case 'blob':
|
|
135
|
-
return response.blob();
|
|
136
|
-
break;
|
|
137
|
-
case 'arrayBuffer':
|
|
138
|
-
return response.arrayBuffer();
|
|
139
|
-
break;
|
|
140
|
-
case 'unbuffered':
|
|
141
|
-
return response.body;
|
|
142
|
-
break;
|
|
143
|
-
case 'json':
|
|
144
|
-
default:
|
|
145
|
-
return response.json();
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
throw {
|
|
150
|
-
status: response.status,
|
|
151
|
-
message: response.statusText,
|
|
152
|
-
response: response
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
logError: function(error, options) {
|
|
157
|
-
console.error(error.status, error.message);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
var defaultOptions = {
|
|
162
|
-
path: '',
|
|
163
|
-
responseFormat: 'json',
|
|
164
|
-
paramsFormat: 'search',
|
|
165
|
-
verbs: ['get','post'],
|
|
166
|
-
handlers: {
|
|
167
|
-
fetch: api.fetch,
|
|
168
|
-
result: api.getResult,
|
|
169
|
-
error: api.logError
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
function cd(path, name) {
|
|
174
|
-
name = name.replace(/\//g,'');
|
|
175
|
-
if (!path.length || path[path.length-1]!=='/') {
|
|
176
|
-
path+='/';
|
|
177
|
-
}
|
|
178
|
-
return path+encodeURIComponent(name);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function fetchChain(prop, params) {
|
|
182
|
-
var options = this;
|
|
183
|
-
return this.handlers.fetch
|
|
184
|
-
.call(this, prop, params, options)
|
|
185
|
-
.then(function(res) {
|
|
186
|
-
return options.handlers.result.call(options, res, options);
|
|
187
|
-
})
|
|
188
|
-
.catch(function(error) {
|
|
189
|
-
return options.handlers.error.call(options, error, options);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function getApiHandler(options) {
|
|
194
|
-
options.handlers = Object.assign({}, defaultOptions.handlers, options.handlers);
|
|
195
|
-
options = Object.assign({}, defaultOptions, options);
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
get: function(cache, prop) {
|
|
199
|
-
if (!cache[prop]) {
|
|
200
|
-
if (options.verbs.indexOf(prop)!=-1) {
|
|
201
|
-
cache[prop] = function(params) {
|
|
202
|
-
return fetchChain.call(options, prop, params);
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
cache[prop] = api.proxy(Object.assign({}, options, {
|
|
206
|
-
path: cd(options.path, prop)
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return cache[prop];
|
|
211
|
-
},
|
|
212
|
-
apply: function(cache, thisArg, params) {
|
|
213
|
-
return fetchChain.call(options, 'get', params[0] ? params[0] : null)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
220
|
-
module.exports = api;
|
|
221
|
-
} else {
|
|
222
|
-
if (!global.simply) {
|
|
223
|
-
global.simply = {};
|
|
224
|
-
}
|
|
225
|
-
global.simply.api = api;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
})(this);
|
package/js/simply.app.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var app = function(options) {
|
|
5
|
-
if (!options) {
|
|
6
|
-
options = {};
|
|
7
|
-
}
|
|
8
|
-
if (!options.container) {
|
|
9
|
-
console.warn('No simply.app application container element specified, using document.body.');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function simplyApp(options) {
|
|
13
|
-
if (!options) {
|
|
14
|
-
options = {};
|
|
15
|
-
}
|
|
16
|
-
if ( options.routes ) {
|
|
17
|
-
simply.route.load(options.routes);
|
|
18
|
-
if (options.routeEvents) {
|
|
19
|
-
Object.keys(options.routeEvents).forEach(function(action) {
|
|
20
|
-
Object.keys(options.routeEvents[action]).forEach(function(route) {
|
|
21
|
-
options.routeEvents[action][route].forEach(function(callback) {
|
|
22
|
-
simply.route.addListener(action, route, callback);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
simply.route.handleEvents();
|
|
28
|
-
global.setTimeout(function() {
|
|
29
|
-
simply.route.match(global.location.pathname+global.location.hash);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
this.container = options.container || document.body;
|
|
33
|
-
this.keyboard = simply.keyboard ? simply.keyboard(this, options.keyboard || {}) : false;
|
|
34
|
-
this.actions = simply.action ? simply.action(this, options.actions) : false;
|
|
35
|
-
this.commands = simply.command ? simply.command(this, options.commands) : false;
|
|
36
|
-
this.resize = simply.resize ? simply.resize(this, options.resize) : false;
|
|
37
|
-
this.view = simply.view ? simply.view(this, options.view) : false;
|
|
38
|
-
if (!(global.editor && global.editor.field) && simply.bind) {
|
|
39
|
-
// skip simplyview databinding if SimplyEdit is loaded
|
|
40
|
-
options.bind = simply.render(options.bind || {});
|
|
41
|
-
options.bind.model = this.view;
|
|
42
|
-
options.bind.container = this.container;
|
|
43
|
-
this.bind = options.bindings = simply.bind(options.bind);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
simplyApp.prototype.get = function(id) {
|
|
48
|
-
return this.container.querySelector('[data-simply-id='+id+']') || document.getElementById(id);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return new simplyApp(options);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
55
|
-
module.exports = app;
|
|
56
|
-
} else {
|
|
57
|
-
if (!global.simply) {
|
|
58
|
-
global.simply = {};
|
|
59
|
-
}
|
|
60
|
-
global.simply.app = app;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
})(this);
|
package/js/simply.collect.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var knownCollections = {};
|
|
5
|
-
|
|
6
|
-
var collect = {
|
|
7
|
-
addListener: function(name, callback) {
|
|
8
|
-
if (!knownCollections[name]) {
|
|
9
|
-
knownCollections[name] = [];
|
|
10
|
-
}
|
|
11
|
-
if (knownCollections[name].indexOf(callback) == -1) {
|
|
12
|
-
knownCollections[name].push(callback);
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
removeListener: function(name, callback) {
|
|
16
|
-
if (knownCollections[name]) {
|
|
17
|
-
var index = knownCollections[name].indexOf(callback);
|
|
18
|
-
if (index>=0) {
|
|
19
|
-
knownCollections[name].splice(index, 1);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
update: function(element, value) {
|
|
24
|
-
element.value = value;
|
|
25
|
-
element.dispatchEvent(new Event('change', {
|
|
26
|
-
bubbles: true,
|
|
27
|
-
cancelable: true
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function findCollection(el) {
|
|
33
|
-
while (el && !el.dataset.simplyCollection) {
|
|
34
|
-
el = el.parentElement;
|
|
35
|
-
}
|
|
36
|
-
return el;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
global.addEventListener('change', function(evt) {
|
|
40
|
-
var root = null;
|
|
41
|
-
var name = '';
|
|
42
|
-
if (evt.target.dataset.simplyElement) {
|
|
43
|
-
root = findCollection(evt.target);
|
|
44
|
-
if (root && root.dataset) {
|
|
45
|
-
name = root.dataset.simplyCollection;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (name && knownCollections[name]) {
|
|
49
|
-
var inputs = root.querySelectorAll('[data-simply-element]');
|
|
50
|
-
var elements = [].reduce.call(inputs, function(elements, input) {
|
|
51
|
-
elements[input.dataset.simplyElement] = input;
|
|
52
|
-
return elements;
|
|
53
|
-
}, {});
|
|
54
|
-
for (var i=knownCollections[name].length-1; i>=0; i--) {
|
|
55
|
-
var result = knownCollections[name][i].call(evt.target.form, elements);
|
|
56
|
-
if (result === false) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, true);
|
|
62
|
-
|
|
63
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
64
|
-
module.exports = collect;
|
|
65
|
-
} else {
|
|
66
|
-
if (!global.simply) {
|
|
67
|
-
global.simply = {};
|
|
68
|
-
}
|
|
69
|
-
global.simply.collect = collect;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
})(this);
|
package/js/simply.command.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var defaultCommands = {
|
|
5
|
-
'simply-hide': function(el, value) {
|
|
6
|
-
var target = this.app.get(value);
|
|
7
|
-
if (target) {
|
|
8
|
-
this.action('simply-hide',target);
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
'simply-show': function(el, value) {
|
|
12
|
-
var target = this.app.get(value);
|
|
13
|
-
if (target) {
|
|
14
|
-
this.action('simply-show',target);
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
'simply-select': function(el, value) {
|
|
18
|
-
var group = el.dataset.simplyGroup;
|
|
19
|
-
var target = this.app.get(value);
|
|
20
|
-
var targetGroup = (target ? target.dataset.simplyGroup : null);
|
|
21
|
-
this.action('simply-select', el, group, target, targetGroup);
|
|
22
|
-
},
|
|
23
|
-
'simply-toggle-select': function(el, value) {
|
|
24
|
-
var group = el.dataset.simplyGroup;
|
|
25
|
-
var target = this.app.get(value);
|
|
26
|
-
var targetGroup = (target ? target.dataset.simplyTarget : null);
|
|
27
|
-
this.action('simply-toggle-select',el,group,target,targetGroup);
|
|
28
|
-
},
|
|
29
|
-
'simply-toggle-class': function(el, value) {
|
|
30
|
-
var target = this.app.get(el.dataset.simplyTarget);
|
|
31
|
-
this.action('simply-toggle-class',el,value,target);
|
|
32
|
-
},
|
|
33
|
-
'simply-deselect': function(el, value) {
|
|
34
|
-
var target = this.app.get(value);
|
|
35
|
-
this.action('simply-deselect',el,target);
|
|
36
|
-
},
|
|
37
|
-
'simply-fullscreen': function(el, value) {
|
|
38
|
-
var target = this.app.get(value);
|
|
39
|
-
this.action('simply-fullscreen',target);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var handlers = [
|
|
45
|
-
{
|
|
46
|
-
match: 'input,select,textarea',
|
|
47
|
-
get: function(el) {
|
|
48
|
-
if (el.tagName==='SELECT' && el.multiple) {
|
|
49
|
-
var values = [], opt;
|
|
50
|
-
for (var i=0,l=el.options.length;i<l;i++) {
|
|
51
|
-
var opt = el.options[i];
|
|
52
|
-
if (opt.selected) {
|
|
53
|
-
values.push(opt.value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return values;
|
|
57
|
-
}
|
|
58
|
-
return el.dataset.simplyValue || el.value;
|
|
59
|
-
},
|
|
60
|
-
check: function(el, evt) {
|
|
61
|
-
return evt.type=='change' || (el.dataset.simplyImmediate && evt.type=='input');
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
match: 'a,button',
|
|
66
|
-
get: function(el) {
|
|
67
|
-
return el.dataset.simplyValue || el.href || el.value;
|
|
68
|
-
},
|
|
69
|
-
check: function(el,evt) {
|
|
70
|
-
return evt.type=='click' && evt.ctrlKey==false && evt.button==0;
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
match: 'form',
|
|
75
|
-
get: function(el) {
|
|
76
|
-
var data = {};
|
|
77
|
-
[].forEach.call(el.elements, function(el) {
|
|
78
|
-
if (el.tagName=='INPUT' && (el.type=='checkbox' || el.type=='radio')) {
|
|
79
|
-
if (!el.checked) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (data[el.name] && !Array.isArray(data[el.name])) {
|
|
84
|
-
data[el.name] = [data[el.name]];
|
|
85
|
-
}
|
|
86
|
-
if (Array.isArray(data[el.name])) {
|
|
87
|
-
data[el.name].push(el.value);
|
|
88
|
-
} else {
|
|
89
|
-
data[el.name] = el.value;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return data;//new FormData(el);
|
|
93
|
-
},
|
|
94
|
-
check: function(el,evt) {
|
|
95
|
-
return evt.type=='submit';
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
var fallbackHandler = {
|
|
101
|
-
get: function(el) {
|
|
102
|
-
return el.dataset.simplyValue;
|
|
103
|
-
},
|
|
104
|
-
check: function(el, evt) {
|
|
105
|
-
return evt.type=='click' && evt.ctrlKey==false && evt.button==0;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
function getCommand(evt) {
|
|
110
|
-
var el = evt.target.closest('[data-simply-command]');
|
|
111
|
-
if (el) {
|
|
112
|
-
var matched = false;
|
|
113
|
-
for (var i=handlers.length-1; i>=0; i--) {
|
|
114
|
-
if (el.matches(handlers[i].match)) {
|
|
115
|
-
matched = true;
|
|
116
|
-
if (handlers[i].check(el, evt)) {
|
|
117
|
-
return {
|
|
118
|
-
name: el.dataset.simplyCommand,
|
|
119
|
-
source: el,
|
|
120
|
-
value: handlers[i].get(el)
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (!matched && fallbackHandler.check(el,evt)) {
|
|
126
|
-
return {
|
|
127
|
-
name: el.dataset.simplyCommand,
|
|
128
|
-
source: el,
|
|
129
|
-
value: fallbackHandler.get(el)
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
var command = function(app, inCommands) {
|
|
137
|
-
|
|
138
|
-
var commands = Object.create(defaultCommands);
|
|
139
|
-
for (var i in inCommands) {
|
|
140
|
-
commands[i] = inCommands[i];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
commands.app = app;
|
|
144
|
-
|
|
145
|
-
commands.action = function(name) {
|
|
146
|
-
var params = Array.prototype.slice.call(arguments);
|
|
147
|
-
params.shift();
|
|
148
|
-
return app.actions[name].apply(app.actions,params);
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
commands.call = function(name) {
|
|
152
|
-
var params = Array.prototype.slice.call(arguments);
|
|
153
|
-
params.shift();
|
|
154
|
-
return this[name].apply(this,params);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
commands.appendHandler = function(handler) {
|
|
158
|
-
handlers.push(handler);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
commands.prependHandler = function(handler) {
|
|
162
|
-
handlers.unshift(handler);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
var commandHandler = function(evt) {
|
|
166
|
-
var command = getCommand(evt);
|
|
167
|
-
if ( command ) {
|
|
168
|
-
if (!commands[command.name]) {
|
|
169
|
-
console.error('simply.command: undefined command '+command.name, command.source);
|
|
170
|
-
} else {
|
|
171
|
-
commands.call(command.name, command.source, command.value);
|
|
172
|
-
evt.preventDefault();
|
|
173
|
-
evt.stopPropagation();
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
app.container.addEventListener('click', commandHandler);
|
|
180
|
-
app.container.addEventListener('submit', commandHandler);
|
|
181
|
-
app.container.addEventListener('change', commandHandler);
|
|
182
|
-
app.container.addEventListener('input', commandHandler);
|
|
183
|
-
|
|
184
|
-
return commands;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
188
|
-
module.exports = command;
|
|
189
|
-
} else {
|
|
190
|
-
if (!global.simply) {
|
|
191
|
-
global.simply = {};
|
|
192
|
-
}
|
|
193
|
-
global.simply.command = command;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
})(this);
|