Skip to content

Commit

Permalink
Auto resize example iframes when the content changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ju committed Jan 10, 2018
1 parent cd4738f commit d9562c9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/metalsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = metalsmith(__dirname) // __dirname defined by node.js: name of
files: [
'javascripts/vendor/jquery.js',
'javascripts/vendor/clipboard.js',
'javascripts/vendor/iframeResizer.js',
'javascripts/components/example.js',
'javascripts/components/tabs.js',
'javascripts/components/copy.js',
Expand All @@ -65,7 +66,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/iframeResizer.ie8.polyfils.js',
'javascripts/ie-only.js'
],
output: 'javascripts/ie.js'
}))

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
10 changes: 10 additions & 0 deletions src/javascripts/vendor/iframeResizer.contentWindow.js

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

4 changes: 4 additions & 0 deletions src/javascripts/vendor/iframeResizer.ie8.polyfils.js

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

Loading

0 comments on commit d9562c9

Please sign in to comment.