-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
131 lines (108 loc) · 3.14 KB
/
index.html
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
126
127
128
129
130
131
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example</title>
<style>
.text__small {
font-size: 30pt;
}
.text__small--color-red {
color: #F00;
cursor: pointer;
}
.text__small--hover-color-blue:hover {
color: #00F;
}
</style>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="index.js"></script>
<script type="application/x-javascript">
let stringDecorator = new Decorator(String);
stringDecorator.decoration({
decorMethod: 'small',
name: "addClass",
fnDecor: function (className) {
let container = $('<div>');
let html = $(this.valueOf());
let $this = this;
html.addClass([...arguments].join(' '));
html.bind('click', function (e) {
console.log({
event: e,
element: this,
$this
});
});
container.append(html);
return container;
}
});
stringDecorator.decoration({
decorMethod: 'small',
name: "setColor",
fnDecor: function (color) {
let container = $('<div>');
let html = $(this.valueOf());
html.css({color});
console.log(this, html);
return html;
}
});
stringDecorator.decoration({
decorMethod: 'small',
name: "p",
fnDecor: function (arg) {
let p = $('<p>');
p.append(this);
return p;
}
});
stringDecorator.decoration({
decorMethod: 'big',
name: "addClass",
fnDecor: function (arg) {
return this + ' addClass for big'
}
});
</script>
<base href="/">
</head>
<body>
<script type="application/javascript">
let test = 'test'.small()
.decorate('addClass', [
'text__small',
'text__small--color-red',
'text__small--hover-color-blue'
]);
$('body').append(test);
let test2 = 'test2'.small().decorate({
"setColor": ["#00FF00"],
"addClass": ['text__small', 'text__small--hover-color-blue'],
"p": [],
});
$('body').append(test2);
</script>
<script type="application/javascript">
function Cls() {
}
Cls.prototype.method = function () {
return [1985];
};
let cls = new Cls();
let clsDecorator = new Decorator(cls);
clsDecorator.decoration({
decorMethod: 'method',
name: "push",
fnDecor: function () {
return `(${[...this, ...arguments].join("-")})`;
}
}, true);
let result = cls.method().decorate('push', ['foo', 'bar']);
console.log(result);
</script>
</body>
</html>