-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttons-button-base-elem-types.html
215 lines (172 loc) · 5.12 KB
/
buttons-button-base-elem-types.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!doctype html>
<html>
<head>
<style>
</style>
<style>
html, body {
min-height: 0 !important;
height: auto !important;
}
</style>
<script>
function findAndHandleStylemarkBlocks(languages, handler) {
var blocks = getStylemarkBlocks(languages);
handleStylemarkBlocks(blocks, handler);
}
function getStylemarkBlocks(languages) {
languages = typeof languages === 'string' ? [languages] : languages;
var selectors = [];
for (var i = 0; i < languages.length; i++) {
selectors.push('script[data-language="' + languages[i] + '"]');
}
var selector = selectors.join(',');
var scripts = document.querySelectorAll(selector);
var blocks = [];
for (var i = 0, length = scripts.length; i < length; i++) {
if (scripts[i].innerText) {
blocks.push(scripts[i].innerText);
}
}
return blocks;
}
function handleStylemarkBlocks(blocks, handler) {
for (var i = 0, length = blocks.length; i < length; i++) {
handler(blocks[i], i);
}
}
</script>
<link rel="stylesheet" href="https://annvelents.github.io/dronebase_styleguide_t/dist/assets/admin.css">
<script src="https://annvelents.github.io/dronebase_styleguide_t/dist/assets/admin.js"></script>
</head>
<body> <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<style>
.btn { margin: 5px 10px;}
</style>
<a class="btn btn-primary btn-md">Link</a>
<button class="btn btn-primary btn-md ">Button</button>
<div class="btn btn-primary btn-md ">Div</div>
<input type="submit" class="btn btn-primary btn-md"></input>
<br>
<script type="text/x-stylemark" data-language="html"><link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<style>
.btn { margin: 5px 10px;}
</style>
<a class="btn btn-primary btn-md">Link</a>
<button class="btn btn-primary btn-md ">Button</button>
<div class="btn btn-primary btn-md ">Div</div>
<input type="submit" class="btn btn-primary btn-md"></input>
<br></script>
<!--
Vanilla JS
-->
<script>
findAndHandleStylemarkBlocks('js', function(block) {
eval(block);
});
</script>
<!--
AngularJS
-->
<script>
(function(angular) {
if (!angular) {
return;
}
findAndHandleStylemarkBlocks('angularjs', function(block, index) {
var moduleElem = document.querySelector('[ng-app]');
var module;
if (moduleElem) {
// Uses an existing module
module = angular.module(moduleElem.getAttribute('ng-app'));
}
else {
// Creates a new module
module = angular.module('stylemark-buttons-button-base-elem-types', []);
}
module.controller('stylemark-buttons-button-base-elem-types-' + index, function($scope) {
$scope.$eval(block);
});
});
})(window.angular);
</script>
<!--
React / JSX
-->
<script>
(function(ReactDOM) {
if (!ReactDOM) {
return;
}
findAndHandleStylemarkBlocks('jsx', function(block, index) {
var rootNode = document.querySelectorAll('.stylemark-react-root')[index];
var Component = eval(block);
ReactDOM.render(Component, rootNode);
});
})(window.ReactDOM);
</script>
<!--
Ember
-->
<script>
(function(Ember) {
if (!Ember) {
return;
}
findAndHandleStylemarkBlocks(['handlebars', 'hbs'], function(block, index) {
var render = function() {
var app = window.DronebaseStyleGuide
var container = app.__container__;
var renderer = container.lookup('renderer:-dom');
var template = Ember.HTMLBars.compile(block);
var jsBlocks = getStylemarkBlocks('js');
var jsBlock = jsBlocks && jsBlocks[0] ? jsBlocks[0] : '{}';
var context;
eval('context = ' + jsBlock);
// Credit:
// http://stackoverflow.com/questions/27950413/render-ember-js-hbs-template-to-a-string#answer-35625858
var compile = function(container, template, context) {
return new Ember.RSVP.Promise(function(resolve) {
Ember.Component.extend(Ember.merge({
style: 'display:none;',
layout: template,
container: container,
renderer: renderer,
init: function() {
this._super.apply(this, arguments);
Ember.setOwner(this, container);
},
didRender: function() {
var elem = this.$();
resolve(elem);
this.destroy();
}
}, context))
.create()
.append();
});
};
compile(container, template, context).then(function(elem) {
var node = document.querySelectorAll('.stylemark-ember-root')[index];
jQuery(node).append(elem);
});
};
var isReady = function() {
return window.DronebaseStyleGuide
&& window.DronebaseStyleGuide.__container__;
};
var checkReady = function() {
if (isReady()) {
render();
}
else {
setTimeout(checkReady, 20);
}
};
checkReady();
});
})(window.Ember);
</script>
<script src="https://annvelents.github.io/dronebase_styleguide_t/dist/assets/js/vendor/iframeResizer.contentWindow.min.js"></script>
</body>
</html>