Simplified markup and added simple templating
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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
diff --git a/code.js b/code.js
index cc2f871..3252f2d 100644
--- a/code.js
+++ b/code.js
@@ -1,21 +1,35 @@
-$$('pre[data-src]').forEach(function(pre) {
- var src = pre.getAttribute('data-src');
+$$('[data-src]').forEach(function(element) {
+ var src = element.getAttribute('data-src'),
+ html = element.getAttribute('data-type') === 'text/html',
+ contentProperty = html? 'innerHTML' : 'textContent';
+ $u.xhr({
+ url: src,
+ callback: function(xhr) {
+ element[contentProperty] = xhr.responseText;
+
+ $u.event.fire(element, 'contentreceived', {
+ src: src
+ });
+ }
+ });
+});
+
+document.body.addEventListener('contentreceived', function(evt) {
+ var pre = evt.target;
+
+ if(!/pre/i.test(pre.nodeName)) {
+ return;
+ }
+
var language = {
'js': 'javascript',
'css': 'css',
'html': 'markup',
'svg': 'markup'
- }[(src.match(/\.(\w+)$/) || [,''])[1]]
+ }[(evt.src.match(/\.(\w+)$/) || [,''])[1]];
pre.className = 'prism language-' + language;
- $u.xhr({
- url: src,
- callback: function(xhr) {
- pre.textContent = xhr.responseText;
-
- Prism.highlight(pre, true);
- }
- });
+ Prism.highlight(pre, true);
});
\ No newline at end of file
diff --git a/examples.html b/examples.html
index 7ade7a9..dad43dc 100644
--- a/examples.html
+++ b/examples.html
@@ -11,19 +11,12 @@
</head>
<body>
-<header><div class="wrapper">
- <div class="intro">
- <h1><img src="logo.svg" alt="Prism" /></h1>
-
- <p>
- Prism is a new elegant, robust and lightweight syntax highlighter, built with modern web standards in mind.
- It’s a spin-off project from the popular code playground <a href="http://dabblet.com">Dabblet</a> and is extensively tested there daily by thousands of users.
- </p>
- </div>
+<header>
+ <div class="intro" data-src="templates/header-main.html" data-type="text/html"></div>
<h2>Examples</h2>
<p>The examples in this page serve a dual purpose: They act as unit tests, making it easy to spot bugs, and at the same time demonstrate what Prism can do, on simple and on edge cases.</p>
-</div></header>
+</header>
<section>
<h1>Markup</h1>
@@ -128,11 +121,11 @@ var comment = /\/\*[\w\W]*?\*\//g;</code></pre>
<pre class="prism"><code class="language-javascript">env.content + '</' + env.tag + '>'</code></pre>
</section>
-<footer><div class="wrapper">
- <p>Handcrafted with love, by Lea Verou</p>
-</div></footer>
+<footer data-src="templates/footer.html" data-type="text/html"></footer>
<script src="prism.js"></script>
+<script src="utopia.js"></script>
+<script src="code.js"></script>
</body>
</html>
\ No newline at end of file
diff --git a/index.html b/index.html
index 51448f1..6a6a699 100644
--- a/index.html
+++ b/index.html
@@ -15,15 +15,8 @@
</head>
<body>
-<header><div class="wrapper">
- <div class="intro">
- <h1><img src="logo.svg" alt="Prism" /></h1>
-
- <p>
- Prism is a new elegant, robust and lightweight syntax highlighter, built with modern web standards in mind.
- It’s a spin-off project from the popular code playground <a href="http://dabblet.com">Dabblet</a> and is extensively tested there daily by thousands of users.
- </p>
- </div>
+<header>
+ <div class="intro" data-src="templates/header-main.html" data-type="text/html"></div>
<p class="download">
<a href="" class="full-script">Download Prism</a>
@@ -49,8 +42,7 @@
</li>
</ul>
-
-</div></header>
+</header>
<section id="features-full">
<h1>Full list of features</h1>
@@ -226,9 +218,7 @@
</ul>
</section>
-<footer><div class="wrapper">
- <p>Handcrafted with love, by Lea Verou</p>
-</div></footer>
+<footer data-src="templates/footer.html" data-type="text/html"></footer>
<script src="prism.js"></script>
<script src="utopia.js"></script>
diff --git a/plugins/line-highlight/index.html b/plugins/line-highlight/index.html
index 917722f..0c8afbd 100644
--- a/plugins/line-highlight/index.html
+++ b/plugins/line-highlight/index.html
@@ -12,12 +12,12 @@
</head>
<body>
-<header><div class="wrapper">
+<header>
<h1><img src="../../logo.svg" alt="Prism" /> plugins</h1>
<h2>Line highlight plugin</h2>
<p>Highlights specific lines and/or line ranges.</p>
-</div></header>
+</header>
<section>
<h1>How to use</h1>
@@ -88,9 +88,7 @@
}</code></pre>
</section>
-<footer><div class="wrapper">
- <p>Handcrafted with love, by Lea Verou</p>
-</div></footer>
+<footer data-src="templates/footer.html" data-type="text/html"></footer>
<script src="../../prism.js"></script>
<script src="prism-line-highlight.js"></script>
diff --git a/style.css b/style.css
index 7003fd4..9512708 100644
--- a/style.css
+++ b/style.css
@@ -9,21 +9,6 @@ section h1,
font: italic 100% Baskerville, Palatino Linotype, Georgia, serif;
}
-header > .wrapper,
-footer > .wrapper {
- padding: 30px 0;
-}
-
-header:after,
-footer:before {
- content: '';
- display: block;
- height: 10px;
- background-size: 20px 20px;
- background-repeat: repeat-x;
-}
-
-
/*
Styles
*/
@@ -80,23 +65,27 @@ pre {
box-sizing: border-box;
}
-.wrapper,
+header,
body > section {
display: block;
max-width: 900px;
margin: auto;
}
-header {
- background: black url(img/spectrum.png) repeat-x top;
- background-size: cover;
+header, footer {
+ padding: 30px calc(50% - 450px);
+ background-size: 20px 20px, 20px 20px, cover;
+ background-repeat: repeat-x;
+ background-position: bottom, bottom, top;
color: white;
text-shadow: 0 -1px 2px black;
}
-header:after {
+header {
background-image: linear-gradient(45deg, white 50%, transparent 50%),
- linear-gradient(-45deg, transparent 50%, white 50%);
+ linear-gradient(-45deg, transparent 50%, white 50%),
+ url(img/spectrum.png);
+
}
header .intro,
@@ -189,26 +178,16 @@ header:after {
text-decoration: none;
}
-iframe, #innerHTML {
- width: 100%;
- height: 30em;
- border: 1px solid rgba(0,0,0,.2);
- overflow: auto;
-}
-
-#api section h1 {
- font-style: normal;
-}
-
footer {
margin-top: 2em;
- background: black url(img/spectrum.png) repeat-x bottom;
- background-size: cover;
+ background-image: linear-gradient(45deg, transparent 50%, white 50%),
+ linear-gradient(-45deg, white 50%, transparent 50%),
+ url(img/spectrum.png);
+ background-position: top, top, bottom;
color: white;
text-shadow: 0 -1px 2px black;
}
-footer:before {
- background-image: linear-gradient(45deg, transparent 75%, white 75%),
- linear-gradient(-45deg, white 25%, transparent 25%);
+#api section h1 {
+ font-style: normal;
}
diff --git a/templates/footer.html b/templates/footer.html
new file mode 100644
index 0000000..485b208
--- /dev/null
+++ b/templates/footer.html
@@ -0,0 +1 @@
+<p>Handcrafted with love, by Lea Verou</p>
\ No newline at end of file
diff --git a/templates/header-main.html b/templates/header-main.html
new file mode 100644
index 0000000..ffc7c64
--- /dev/null
+++ b/templates/header-main.html
@@ -0,0 +1,6 @@
+<h1><img src="logo.svg" alt="Prism" /></h1>
+
+<p>
+ Prism is a new elegant, robust and lightweight syntax highlighter, built with modern web standards in mind.
+ It’s a spin-off project from the popular code playground <a href="http://dabblet.com">Dabblet</a> and is extensively tested there daily by thousands of users.
+</p>
\ No newline at end of file
diff --git a/utopia.js b/utopia.js
index 948a45d..ed9fe74 100644
--- a/utopia.js
+++ b/utopia.js
@@ -325,7 +325,7 @@ var _ = window.Utopia = {
evt.custom = true;
if(properties) {
- _.merge(evt, properties);
+ _.attach(evt, properties);
}
target.dispatchEvent(evt);