Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto resize example iframes when the content changes #109

Merged
merged 2 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"config": "config/",
"deploy": "deploy",
"public": "deploy/public/",
"govukfrontend": "node_modules/@govuk-frontend/",
"nodemodules": "node_modules/",
"govukfrontend": "node_modules/@govuk-frontend/",
"iframeresizer": "node_modules/iframe-resizer/",
"source": "src/",
"components": "src/components/",
"images": "src/images/",
Expand Down
15 changes: 13 additions & 2 deletions lib/metalsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ module.exports = metalsmith(__dirname) // __dirname defined by node.js: name of
includePaths: ['node_modules'] // an array of paths that sass can look in when attempt to resolve @import declarations
}))

// copy static assets from node_modules
// copy static assets from node_modules/@govukfrontend
.use(assets({
source: '../' + paths.govukfrontend + 'icons/',
destination: 'icons'
}))

// copy static assets from node_modules/iframe-resizer
.use(assets({
source: '../' + paths.iframeresizer + 'js/',
destination: 'javascripts/vendor'
}))

// concatenate javascript files
.use(concat({
files: [
'javascripts/vendor/jquery.js',
'javascripts/vendor/clipboard.js',
'javascripts/vendor/iframeResizer.min.js',
'javascripts/components/example.js',
'javascripts/components/tabs.js',
'javascripts/components/copy.js',
Expand All @@ -65,7 +72,11 @@ module.exports = metalsmith(__dirname) // __dirname defined by node.js: name of
}))
// concatenate IE only javascript files
.use(concat({
files: ['javascripts/vendor/html5shiv-printshiv.js', 'javascripts/ie-only.js'],
files: [
'javascripts/vendor/html5shiv-printshiv.js',
'javascripts/vendor/ie8.polyfils.min.js',
'javascripts/ie-only.js'
],
output: 'javascripts/ie.js'
}))

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"devDependencies": {
"gulp": "^3.9.1",
"gulp-sass-lint": "^1.3.4",
"iframe-resizer": "^3.5.15",
"jstransformer-markdown": "^1.2.1",
"jstransformer-nunjucks": "^0.5.0",
"metalsmith": "^2.3.0",
Expand Down
12 changes: 8 additions & 4 deletions src/javascripts/components/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

GOVUK.example = {
init: function (selector) {
// Example iframe; set the height equal to the body height
$(selector).on('load', function () {
this.style.height = this.contentDocument.body.scrollHeight + 'px'
})
try {
// Example iframe; set the height equal to the body height
$(selector).iFrameResize({scrolling: 'auto'})
} catch (err) {
if (err) {
console.error(err.message)
}
}
}
}
global.GOVUK = GOVUK
Expand Down
8 changes: 5 additions & 3 deletions views/layouts/layout-example.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ title }}</title>
<link href="/stylesheets/main.css" rel="stylesheet" media="all" />
<!--[if lt IE 9]><script src="/javascripts/ie.js"></script><![endif]-->

{#- Include any additional stylesheets specified in the example frontmatter #}
{% for stylesheet in stylesheets %}
<link href="{{ stylesheet }}" rel="stylesheet" media="all" />
{%- endfor %}

<script src="/javascripts/application.js"></script>
<!--[if lt IE 9]>
<script src="/javascripts/ie.js"></script>
<![endif]-->
<script src="/javascripts/vendor/modernizr.js"></script>
</head>
<body class="app-o-example-page">
{% block body %}
{{ contents | safe }}
{% endblock %}
<script src="/javascripts/vendor/iframeResizer.contentWindow.js"></script>
</body>
</html>