• Stars
    star
    212
  • Rank 185,055 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Replace a node with an iframe version of itself

Iframify

Replaces a node with an iframe version of itself. Read the introduction article.

Install

npm install edenspiekermann/iframify

Usage

iframify(HTMLElement, [options])

Where options is an object where keys can be:

  • headExtra
    Type: string
    Default: none
    Description: extra content to be injected at the end of <head>.
    Example: <link rel="stylesheet" href="foo.css" />

  • bodyExtra
    Type: string
    Default: none
    Description: extra content to be injected at the end of <body>. g Example: <script src="/assets/js/main.js"></script>

  • htmlAttr
    Type: object
    Default: none
    Description: An object of attributes to pass to the <html> element.
    Example: { class: 'no-js', 'data-foo': 'bar' }

  • bodyAttr
    Type: object
    Default: none
    Description: An object of attributes to pass to the <body> element.
    Example: { class: 'body', id: 'top' }

  • stylesSelector
    Type: string
    Default: link[rel*=stylesheet], style
    Description: The selector to use to define what styles to import.
    Example: link[rel*=stylesheet]:not([href$="styleguide.css"]), style

  • metaCharset
    Type: string
    Default: the one in the outer document (if any).
    Description: The string representation of the charset <meta> tag to import.
    Example: <meta charset="utf-8" />

  • metaViewport
    Type: string
    Default: the one in the outer document (if any).
    Description: The string representation of the viewport <meta> tag to import.
    Example: <meta name="viewport" content="width=device-width, initial-scale=1">

  • sizingTimeout
    Type: number
    Default: 500
    Description: Number of milliseconds to wait before sizing the height of the iframe based on its content. Can be useful when injecting asynchronously loaded content.
    Example: 1000

Examples

// Single node
var component = document.querySelector('.component');
var iframe = iframify(component);
// Collection of nodes
var components = document.querySelectorAll('.component');
var iframes = Array.prototype.map.call(components, function (component) {
  return iframify(component, {});
});
// With options
var component = document.querySelector('.component');
var iframe = iframify(component, {
  headExtra: '<style>.component { color: red; }</style>',
  metaViewport: '<meta name="viewport" content="width=device-width">'
});

Check out the demo on CodePen.

Notes

It does not work on browsers which do not support the srcdoc attribute on <iframe> out of the box. However, there is a very good polyfill for srcdoc that you could include after iframify to make it work on these browsers.

Other major thing to note: JavaScript is not imported into the iframes, but can be with scripts option.

Tests

open tests/index.html

More Repositories

1

sprite.sh

A Bash script to build a SVG sprite from a folder of SVG files (typically icons).
JavaScript
327
star
2

a11y-toggle

A tiny script for accessible content toggles.
HTML
304
star
3

minwidth-relocate

JavaScript
125
star
4

outline-audit

A script to test the heading outline of a document
HTML
114
star
5

faster-react-tabs

JavaScript
48
star
6

gatsby-source-shopify-storefront

Gatsby source plugin for building websites using product data from the Shopify Storefront API
JavaScript
31
star
7

craft3-heroku-starterkit

This is a starter kit for Craft3 which helps you to install the CMS on Heroku
JavaScript
18
star
8

transync

A npm module to synchronise translation files.
JavaScript
10
star
9

nanoc-html5-template

A nanoc template using Sass, Haml and Compass Html5 Boilerplate
JavaScript
10
star
10

espi-devblog

Edenspiekermann Developer Blog
HTML
9
star
11

craft-jwt-auth

Enable authentication to Craft through the use of Javascript Web Tokens (JWT)
PHP
5
star
12

espi-eslint-config

ESLint configuration
JavaScript
3
star
13

espi-dni

PostBot for DNI Project
Elixir
3
star
14

themer

A Tumblr theme parser for local development.
PHP
3
star
15

edenspiekermann-storybook-starter

Boilerplate repo for React-based component libraries
CSS
2
star
16

bright

JavaScript
2
star
17

site-status

Keep track of website development status
Ruby
2
star
18

static-importer

JavaScript
1
star
19

card-builder-docs

Docs to assist with the implementation of Card Builder (http://cards.edenspiekermann.com/)
1
star
20

signals

Signals from content
JavaScript
1
star
21

react-project-examples

Example projects to test styleguide usage
JavaScript
1
star
22

kupong_integration

Ruby
1
star