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/js/simply.path.js DELETED
@@ -1,48 +0,0 @@
1
- (function(global) {
2
- 'us strict';
3
-
4
- var path = {
5
- get: function(model, path) {
6
- if (!path) {
7
- return model;
8
- }
9
- return path.split('.').reduce(function(acc, name) {
10
- return (acc && acc[name] ? acc[name] : null);
11
- }, model);
12
- },
13
- set: function(model, path, value) {
14
- var lastName = simply.path.pop(path);
15
- var parentPath = simply.path.parent(path);
16
- var parentOb = simply.path.get(model, parentPath);
17
- parentOb[lastName] = value;
18
- },
19
- pop: function(path) {
20
- return path.split('.').pop();
21
- },
22
- push: function(path, name) {
23
- return (path ? path + '.' : '') + name;
24
- },
25
- parent: function(path) {
26
- var p = path.split('.');
27
- p.pop();
28
- return p.join('.');
29
- },
30
- parents: function(path) {
31
- var result = [];
32
- path.split('.').reduce(function(acc, name) {
33
- acc.push( (acc.length ? acc[acc.length-1] + '.' : '') + name );
34
- return acc;
35
- },result);
36
- return result;
37
- }
38
- };
39
-
40
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
41
- module.exports = path;
42
- } else {
43
- if (!global.simply) {
44
- global.simply = {};
45
- }
46
- global.simply.path = path;
47
- }
48
- })(this);
@@ -1,125 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
-
4
- var render = function(options) {
5
- if (!options) {
6
- options = {};
7
- }
8
- options = Object.assign({
9
- attribute: 'data-simply-field',
10
- selector: '[data-simply-field]',
11
- twoway: true,
12
- model: {}
13
- }, options);
14
-
15
- options.fieldTypes = Object.assign({
16
- '*': {
17
- set: function(value) {
18
- this.innerHTML = value;
19
- },
20
- get: function() {
21
- return this.innerHTML;
22
- }
23
- },
24
- 'input,textarea,select': {
25
- init: function(binding) {
26
- this.addEventListener('input', function() {
27
- if (binding.observing) {
28
- this.dispatchEvent(new Event('simply.bind.update', {
29
- bubbles: true,
30
- cancelable: true
31
- }));
32
- }
33
- });
34
- },
35
- set: function(value) {
36
- this.value = value;
37
- },
38
- get: function() {
39
- return this.value;
40
- }
41
- },
42
- 'input[type=radio]': {
43
- init: function(binding) {
44
- this.addEventListener('change', function() {
45
- if (binding.observing) {
46
- this.dispatchEvent(new Event('simply.bind.update', {
47
- bubbles: true,
48
- cancelable: true
49
- }));
50
- }
51
- });
52
- },
53
- set: function(value) {
54
- this.checked = (value==this.value);
55
- },
56
- get: function() {
57
- var checked;
58
- if (this.form) {
59
- return this.form[this.name].value;
60
- } else if (checked=document.body.querySelector('input[name="'+this.name+'"][checked]')) {
61
- return checked.value;
62
- } else {
63
- return null;
64
- }
65
- }
66
- },
67
- 'input[type=checkbox]': {
68
- init: function(binding) {
69
- this.addEventListener('change', function() {
70
- if (binding.observing) {
71
- this.dispatchEvent(new Event('simply.bind.update', {
72
- bubbles: true,
73
- cancelable: true
74
- }));
75
- }
76
- });
77
- },
78
- set: function(value) {
79
- this.checked = (value.checked);
80
- this.value = value.value;
81
- },
82
- get: function() {
83
- return {
84
- checked: this.checked,
85
- value: this.value
86
- };
87
- }
88
- },
89
- 'select[multiple]': {
90
- init: function(binding) {
91
- this.addEventListener('change', function() {
92
- if (binding.observing) {
93
- this.dispatchEvent(new Event('simply.bind.update', {
94
- bubbles: true,
95
- cancelable: true
96
- }));
97
- }
98
- });
99
- },
100
- set: function(value) {
101
- for (var i=0,l=this.options.length;i<l;i++) {
102
- this.options[i].selected = (value.indexOf(this.options[i].value)>=0);
103
- }
104
- },
105
- get: function() {
106
- return this.value;
107
- }
108
- },
109
- // '[data-simply-content="template"]': {
110
- // allowNesting: true
111
- // },
112
- }, options.fieldTypes);
113
-
114
- return options;
115
- };
116
-
117
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
118
- module.exports = render;
119
- } else {
120
- if (!global.simply) {
121
- global.simply = {};
122
- }
123
- global.simply.render = render;
124
- }
125
- })(this);
@@ -1,80 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
-
4
- var resize = function(app, config) {
5
- if (!config) {
6
- config = {};
7
- }
8
- if (!config.sizes) {
9
- config.sizes = {
10
- 'simply-tiny' : 0,
11
- 'simply-xsmall' : 480,
12
- 'simply-small' : 768,
13
- 'simply-medium' : 992,
14
- 'simply-large' : 1200
15
- };
16
- }
17
-
18
- var lastSize = 0;
19
- function resizeSniffer() {
20
- var size = app.container.getBoundingClientRect().width;
21
- if ( lastSize==size ) {
22
- return;
23
- }
24
- lastSize = size;
25
- var sizes = Object.keys(config.sizes);
26
- var match = sizes.pop();
27
- while (match) {
28
- if ( size<config.sizes[match] ) {
29
- if ( app.container.classList.contains(match)) {
30
- app.container.classList.remove(match);
31
- }
32
- } else {
33
- if ( !app.container.classList.contains(match) ) {
34
- app.container.classList.add(match);
35
- match = sizes.pop(); // skip to next match to remove these
36
- }
37
- break;
38
- }
39
- match = sizes.pop();
40
- }
41
- while (match) {
42
- if ( app.container.classList.contains(match)) {
43
- app.container.classList.remove(match);
44
- }
45
- match = sizes.pop();
46
- }
47
- var toolbars = app.container.querySelectorAll('.simply-toolbar');
48
- [].forEach.call(toolbars, function(toolbar) {
49
- toolbar.style.transform = '';
50
- });
51
- }
52
-
53
- if ( global.attachEvent ) {
54
- app.container.attachEvent('onresize', resizeSniffer);
55
- } else {
56
- global.setInterval(resizeSniffer, 200);
57
- }
58
-
59
- if ( simply.toolbar ) {
60
- var toolbars = app.container.querySelectorAll('.simply-toolbar');
61
- [].forEach.call(toolbars, function(toolbar) {
62
- simply.toolbar.init(toolbar);
63
- if (simply.toolbar.scroll) {
64
- simply.toolbar.scroll(toolbar);
65
- }
66
- });
67
- }
68
-
69
- return resizeSniffer;
70
- };
71
-
72
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
73
- module.exports = resize;
74
- } else {
75
- if (!global.simply) {
76
- global.simply = {};
77
- }
78
- global.simply.resize = resize;
79
- }
80
- })(this);
@@ -1,234 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
-
4
- var routeInfo = [];
5
- var listeners = {
6
- goto: {},
7
- match: {},
8
- call: {},
9
- finish: {}
10
- };
11
-
12
- function getRegexpFromRoute(route) {
13
- return new RegExp('^'+route.replace(/:\w+/g, '([^/]+)').replace(/:\*/, '(.*)'));
14
- }
15
-
16
- function parseRoutes(routes) {
17
- var paths = Object.keys(routes);
18
- var matchParams = /:(\w+|\*)/g;
19
- var matches, params, path;
20
- for (var i=0; i<paths.length; i++) {
21
- path = paths[i];
22
- matches = [];
23
- params = [];
24
- do {
25
- matches = matchParams.exec(path);
26
- if (matches) {
27
- params.push(matches[1]);
28
- }
29
- } while(matches);
30
- routeInfo.push({
31
- match: getRegexpFromRoute(path),
32
- params: params,
33
- action: routes[path]
34
- });
35
- }
36
- }
37
-
38
- var linkHandler = function(evt) {
39
- if (evt.ctrlKey) {
40
- return;
41
- }
42
- if (evt.which != 1) {
43
- return; // not a 'left' mouse click
44
- }
45
- var link = evt.target;
46
- while (link && link.tagName!='A') {
47
- link = link.parentElement;
48
- }
49
- if (link
50
- && link.pathname
51
- && link.hostname==global.location.hostname
52
- && !link.link
53
- && !link.dataset.simplyCommand
54
- ) {
55
- let path = getPath(link.pathname+link.hash);
56
- if ( !route.has(path) ) {
57
- path = getPath(link.pathname);
58
- }
59
- if ( route.has(path) ) {
60
- let params = runListeners('goto', { path: path});
61
- if (params.path) {
62
- route.goto(params.path);
63
- }
64
- evt.preventDefault();
65
- return false;
66
- }
67
- }
68
- };
69
-
70
- var options = {
71
- root: '/'
72
- };
73
-
74
- var getPath = function(path) {
75
- if (path.substring(0,options.root.length)==options.root
76
- ||
77
- ( options.root[options.root.length-1]=='/'
78
- && path.length==(options.root.length-1)
79
- && path == options.root.substring(0,path.length)
80
- )
81
- ) {
82
- path = path.substring(options.root.length);
83
- }
84
- if (path[0]!='/' && path[0]!='#') {
85
- path = '/'+path;
86
- }
87
- return path;
88
- };
89
-
90
- var getUrl = function(path) {
91
- path = getPath(path);
92
- if (options.root[options.root.length-1]==='/' && path[0]==='/') {
93
- path = path.substring(1);
94
- }
95
- return options.root + path;
96
- };
97
-
98
- function runListeners(action, params) {
99
- if (!Object.keys(listeners[action])) {
100
- return;
101
- }
102
- Object.keys(listeners[action]).forEach(function(route) {
103
- var routeRe = getRegexpFromRoute(route);
104
- if (routeRe.exec(params.path)) {
105
- var result;
106
- listeners[action][route].forEach(function(callback) {
107
- result = callback.call(global, params);
108
- if (result) {
109
- params = result;
110
- }
111
- });
112
- }
113
- });
114
- return params;
115
- }
116
-
117
- var route = {
118
- handleEvents: function() {
119
- global.addEventListener('popstate', function() {
120
- if (route.match(getPath(document.location.pathname + document.location.hash)) === false) {
121
- route.match(getPath(document.location.pathname));
122
- }
123
- });
124
- global.document.addEventListener('click', linkHandler);
125
- },
126
- load: function(routes) {
127
- parseRoutes(routes);
128
- },
129
- clear: function() {
130
- routeInfo = [];
131
- listeners = {
132
- match: {},
133
- call: {},
134
- finish: {}
135
- };
136
- },
137
- match: function(path, options) {
138
- var args = {
139
- path: path,
140
- options: options
141
- };
142
- args = runListeners('match',args);
143
- path = args.path ? args.path : path;
144
-
145
- var matches;
146
- if (!path) {
147
- if (route.match(document.location.pathname+document.location.hash)) {
148
- return true;
149
- } else {
150
- return route.match(document.location.pathname);
151
- }
152
- }
153
- path = getPath(path);
154
- for ( var i=0; i<routeInfo.length; i++) {
155
- matches = routeInfo[i].match.exec(path);
156
- if (!matches || !matches.length) {
157
- if (path && path[path.length-1]!='/') {
158
- matches = routeInfo[i].match.exec(path+'/');
159
- if (matches) {
160
- path+='/';
161
- history.replaceState({}, '', getUrl(path));
162
- }
163
- }
164
- }
165
- if (matches && matches.length) {
166
- var params = {};
167
- routeInfo[i].params.forEach(function(key, i) {
168
- if (key=='*') {
169
- key = 'remainder';
170
- }
171
- params[key] = matches[i+1];
172
- });
173
- Object.assign(params, options);
174
- args.route = route;
175
- args.params = params;
176
- args = runListeners('call', args);
177
- params = args.params ? args.params : params;
178
- args.result = routeInfo[i].action.call(route, params);
179
- runListeners('finish', args);
180
- return args.result;
181
- }
182
- }
183
- return false;
184
- },
185
- goto: function(path) {
186
- history.pushState({},'',getUrl(path));
187
- return route.match(path);
188
- },
189
- has: function(path) {
190
- path = getPath(path);
191
- for ( var i=0; i<routeInfo.length; i++) {
192
- var matches = routeInfo[i].match.exec(path);
193
- if (matches && matches.length) {
194
- return true;
195
- }
196
- }
197
- return false;
198
- },
199
- addListener: function(action, route, callback) {
200
- if (['goto','match','call','finish'].indexOf(action)==-1) {
201
- throw new Error('Unknown action '+action);
202
- }
203
- if (!listeners[action][route]) {
204
- listeners[action][route] = [];
205
- }
206
- listeners[action][route].push(callback);
207
- },
208
- removeListener: function(action, route, callback) {
209
- if (['match','call','finish'].indexOf(action)==-1) {
210
- throw new Error('Unknown action '+action);
211
- }
212
- if (!listeners[action][route]) {
213
- return;
214
- }
215
- listeners[action][route] = listeners[action][route].filter(function(listener) {
216
- return listener != callback;
217
- });
218
- },
219
- init: function(params) {
220
- if (params.root) {
221
- options.root = params.root;
222
- }
223
- }
224
- };
225
-
226
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
227
- module.exports = route;
228
- } else {
229
- if (!global.simply) {
230
- global.simply = {};
231
- }
232
- global.simply.route = route;
233
- }
234
- })(this);
package/js/simply.view.js DELETED
@@ -1,35 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
- var view = function(app, view) {
4
-
5
- app.view = view || {};
6
-
7
- var load = function() {
8
- var data = app.view;
9
- var path = global.editor.data.getDataPath(app.container);
10
- app.view = global.editor.currentData[path];
11
- Object.keys(data).forEach(function(key) {
12
- app.view[key] = data[key];
13
- });
14
- };
15
-
16
- if (global.editor && global.editor.currentData) {
17
- load();
18
- } else {
19
- global.document.addEventListener('simply-content-loaded', function() {
20
- load();
21
- });
22
- }
23
-
24
- return app.view;
25
- };
26
-
27
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
28
- module.exports = view;
29
- } else {
30
- if (!global.simply) {
31
- global.simply = {};
32
- }
33
- global.simply.view = view;
34
- }
35
- })(this);