-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgridBuilder.umd.js
125 lines (109 loc) · 3.1 KB
/
gridBuilder.umd.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['exports', './powergrid.js'], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require('./powergrid.js'));
} else {
var mod = {
exports: {}
};
factory(mod.exports, global.powergrid);
global.gridBuilder = mod.exports;
}
})(this, function (exports, _powergrid) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var powergrid = _interopRequireWildcard(_powergrid);
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};
if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
}
var gridBuilder = {
html: '',
init: function init(event) {
this.el = event.currentTarget;
},
onstatechange: function onstatechange() {
this.render();
},
onconnected: function onconnected() {
window.addEventListener('statechange', this);
},
render: function render() {
this.html = this.createGrid($(this.el), config);
var css = this.createStyles(config);
$('#grid-css').html(css);
},
createGrid: function createGrid($grid, config) {
var self = this;
$grid.attr('class', config.prefix + 'grid fluid');
if (config.align) {
$grid.addClass(config.prefix + 'align-' + config.align);
}
if (config.justify) {
$grid.addClass(config.prefix + 'justify-' + config.justify);
}
$grid.html('');
var htmlText = '';
config.cells.forEach(function (cell, index) {
var cls = [];
if (!cell) {
return;
}
if (cell.col) {
cls.push(config.prefix + 'col-' + cell.col);
}
if (cell.row) {
cls.push(config.prefix + 'row-' + cell.row);
}
if (cell.colSpan) {
cls.push(config.prefix + 'col-span-' + cell.colSpan);
}
if (cell.rowSpan) {
cls.push(config.prefix + 'row-span-' + cell.rowSpan);
}
if (cell.order) {
cls.push(config.prefix + 'order-' + cell.order);
}
if (cell.align) {
cls.push(config.prefix + 'align-self-' + cell.align);
}
if (cell.justify) {
cls.push(config.prefix + 'justify-self-' + cell.justify);
}
var cls = cls.join(' ').trim();
$grid.append('<div' + (cls ? ' class="' + cls + '"' : '') + '>' + self.format(encodeURIComponent(cell.text || index)) + '</div>');
htmlText += " " + '<div' + (cls ? ' class="' + cls + '"' : '') + '>' + self.format(encodeURIComponent(cell.text || index)) + '</div>' + "\r\n";
});
return htmlText;
},
format: function format(htmlString) {
var html = htmlString;
var arr = html.split('-');
if (arr.length == 3 && arr[0] == 'img') {
html = '<img src="https://via.placeholder.com/' + arr[1] + 'x' + arr[2] + '">';
}
return html;
},
createStyles: function createStyles(config) {
return powergrid.toCss(config);
}
}; /**
* Grid builder
* @module
* @todo Remove jQuery. Make it work with component and use this.el
*/
exports.default = gridBuilder;
});