Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit fc23ba6

Browse files
author
Matt Gaunt
committed
Fixing up sharing of the code between layouts
1 parent 8b82bcb commit fc23ba6

File tree

6 files changed

+37
-69
lines changed

6 files changed

+37
-69
lines changed

gulp-tasks/service-worker.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ var packageName = JSON.parse(fs.readFileSync('./package.json', 'utf8')).name;
2525

2626
gulp.task('service-worker:watch', function(cb) {
2727
gulp.watch(GLOBAL.config.src + '/**/*.*', ['service-worker']);
28-
gulp.watch(GLOBAL.config.src + '/../server/layouts/**/*.*',
29-
['service-worker']);
3028
gulp.watch(GLOBAL.config.src + '/../server/views/**/*.*',
3129
['service-worker']);
3230
});

server/controllers/server-controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ ServerController.prototype.setUpServer = function(app) {
2020
app.set('views', path.join(__dirname, '/../views'));
2121
app.engine('handlebars', exphbs({
2222
defaultLayout: 'default',
23-
layoutsDir: path.join(__dirname, '/../layouts')
23+
layoutsDir: path.join(__dirname, '/../views/layouts'),
24+
partialsDir: path.join(__dirname, '/../views/partials'),
2425
}));
2526
app.set('view engine', 'handlebars');
2627

server/layouts/app-shell.handlebars renamed to server/views/layouts/app-shell.handlebars

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,39 +110,7 @@ limitations under the License.
110110
</svg>
111111
</div>
112112

113-
{{#if remoteStyles}}
114-
<script>
115-
var remoteStyles = [
116-
{{#each remoteStyles}}
117-
'{{this}}',
118-
{{~/each}}
119-
];
120-
121-
// Asynchronously load CSS with a Request Animation Frame
122-
// For older browser support see this for a simple shim
123-
// http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
124-
window.requestAnimationFrame(function() {
125-
var elementToInsertLinkBefore =
126-
document.getElementsByTagName('script')[0];
127-
for (var i = 0; i < remoteStyles.length; i++) {
128-
var linkElement = document.createElement('link');
129-
linkElement.rel = 'stylesheet';
130-
linkElement.media = 'all';
131-
linkElement.href = remoteStyles[i];
132-
133-
elementToInsertLinkBefore.parentNode.insertBefore(linkElement,
134-
elementToInsertLinkBefore);
135-
}
136-
});
137-
</script>
138-
139-
<!-- In case the browser has JS disabled -->
140-
<noscript>
141-
{{#each remoteStyles}}
142-
<link href="{{this}}" rel="stylesheet" property="stylesheet" media="all">
143-
{{~/each}}
144-
</noscript>
145-
{{~/if}}
113+
{{> async-css }}
146114

147115
{{#each remoteScripts}}
148116
<script src="{{this}}" async></script>

server/layouts/default.handlebars renamed to server/views/layouts/default.handlebars

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,7 @@ limitations under the License.
6161
</div>
6262
</section>
6363

64-
{{#if remoteStyles}}
65-
<script>
66-
var remoteStyles = [
67-
{{#each remoteStyles}}
68-
'{{this}}',
69-
{{~/each}}
70-
];
71-
72-
// Asynchronously load CSS with a Request Animation Frame
73-
// For older browser support see this for a simple shim
74-
// http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
75-
window.requestAnimationFrame(function() {
76-
var elementToInsertLinkBefore =
77-
document.getElementsByTagName('script')[0];
78-
for (var i = 0; i < remoteStyles.length; i++) {
79-
var linkElement = document.createElement('link');
80-
linkElement.rel = 'stylesheet';
81-
linkElement.media = 'all';
82-
linkElement.href = remoteStyles[i];
83-
84-
elementToInsertLinkBefore.parentNode.insertBefore(linkElement,
85-
elementToInsertLinkBefore);
86-
}
87-
});
88-
</script>
89-
90-
<!-- In case the browser has JS disabled -->
91-
<noscript>
92-
{{#each remoteStyles}}
93-
<link href="{{this}}" rel="stylesheet" property="stylesheet" media="all">
94-
{{~/each}}
95-
</noscript>
96-
{{~/if}}
64+
{{> async-css }}
9765

9866
{{#each remoteScripts}}
9967
<script src="{{this}}" async></script>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{#if remoteStyles}}
2+
<script>
3+
var remoteStyles = [
4+
{{#each remoteStyles}}
5+
'{{this}}',
6+
{{~/each}}
7+
];
8+
9+
// Asynchronously load CSS with a Request Animation Frame
10+
// For older browser support see this for a simple shim
11+
// http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
12+
window.requestAnimationFrame(function() {
13+
var elementToInsertLinkBefore =
14+
document.getElementsByTagName('script')[0];
15+
for (var i = 0; i < remoteStyles.length; i++) {
16+
var linkElement = document.createElement('link');
17+
linkElement.rel = 'stylesheet';
18+
linkElement.media = 'all';
19+
linkElement.href = remoteStyles[i];
20+
21+
elementToInsertLinkBefore.parentNode.insertBefore(linkElement,
22+
elementToInsertLinkBefore);
23+
}
24+
});
25+
</script>
26+
27+
<!-- In case the browser has JS disabled -->
28+
<noscript>
29+
{{#each remoteStyles}}
30+
<link href="{{this}}" rel="stylesheet" property="stylesheet" media="all">
31+
{{~/each}}
32+
</noscript>
33+
{{~/if}}

0 commit comments

Comments
 (0)