• Stars
    star
    177
  • Rank 215,985 (Top 5 %)
  • Language
    JavaScript
  • Created almost 12 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Smart, sandboxed, and reprogrammable iframes.

Stuff.js

A secure and easy way to run arbitrary HTML / JS / CSS code in an iframe.

Stuff.js is a client-side JS library that is meant to be loaded from different origins to restrict access from the iframe to it's parent(s). Read more.

Node is only required for testing and developlment and is only used as a static server. Feel free to use your web server of choice.

Run the example

node dist/example/server.js

Navigate browser to http://localhost:8080/example

Running Tests

node server.js

Navigate browser to http://localhost:8080/test/tests.html

Building

An up-to-date pre-built version can be found in the dist folder. To build:

node build.js

Usage

Place the secure folder on a different origin you intend to use stuff.js. Origin could mean different protocol, port, and or domain name.

stuff(secureUrl, function (context) {
  context.load("<body>stuff</body>");
});

API

stuff(url, [options], cb(context))

The main constructor function that loads the secure iframe from url and calls cb with the context (see below). Optionally, you can pass in an options object as the second argument and can contain any of the following:

  • el an element to append the iframe to. Defaults to the body.
  • sandbox You can pass in a space delimited string of the HTML5 sandbox flags or simply true to add the attribute with the minimum flags needed to function:
    • allow-scripts needed for the iframe to function.
    • allow-same-origin needed for basic interactions with the iframe.

stuff.clear()

Clears all stuff iframe instances from the page.

Context

The execution context for the code. It is the class that wraps the secure iframe.

Context#load(htmlCode, cb())

Writes htmlCode to the iframe document and calls cb when the load event fires.

Context#evaljs(jsCode, cb(error, result))

Executes arbitrary javascript jsCode in the context. Calls cb with the error (null if no error) and the result.

Context#html(cb(htmlCode))

Gets the current iframe document html.

Context#iframe

Is just the iframe element available for DOM manipulation. Note that if you move the iframe, it has to reload and will lose all code and state.

Custom events

Sometimes you may find yourself wanting to communicate back to the outside world from inside the execution context.

window.parent.stuffEmit(event, data)

Emit an event to the conetxt. See Context#on to listen on this.

window.parent.stuffOn(event, data)

Listen to event sent by context.emit.

Context#emit(event, data)

Emit events that can be listened on via window.parent.stuffOn.

Context#on(event, cb(data))

Listen on custom events.

Context#off(event, [cb])

Remove callback cb if specified. Otherwise nuke all listeners.

Browser support

Tested on:

  • Latest Chrome and Firefox.
  • Opera 12+
  • IE9 and IE10
  • Safari 6

License

MIT License. Copyright (c) 2022 Codecademy LLC

More Repositories

1

EventHub

An open source event analytics platform
Java
1,332
star
2

docs

Codecademy Docs is a collection of information for all things code. πŸ“•
TypeScript
782
star
3

learn-cpp

Codecademy | Learn C++
C++
681
star
4

learn-python

Codecademy | Learn Python 3
Python
267
star
5

Master-Statistics-Live-Series

Jupyter Notebook
161
star
6

textarea-helper

A small helper library for textareas.
JavaScript
158
star
7

datasets

Data and code behind the Data Science Path curriculum at Codecademy
Jupyter Notebook
152
star
8

learn-swift

Codecademy | Learn Swift
Swift
102
star
9

gamut

Shared frontend design system for Codecademy! ✨
TypeScript
63
star
10

jquery-expect

Simple DOM assertion library
JavaScript
59
star
11

backbone.declarative

A Backbone plugin that adds declarative model and collection event binding to Backbone Views.
JavaScript
53
star
12

engineering-competencies

Evaluation metrics we use for engineering peer feedback.
JavaScript
51
star
13

markov_python

Markov Chain text generator
Python
48
star
14

ugc

User-Generated Content Articles πŸ“
Go
39
star
15

40Phaser

Codecademy's 404 page! ✨
JavaScript
35
star
16

learn-kotlin

Codecademy | Learn Kotlin
Kotlin
29
star
17

deploying-a-static-site-with-netlify-sample

CSS
27
star
18

learn-java

Learn Java | Codecademy β˜•οΈ
Java
25
star
19

build-ios-apps-with-swiftui

Swift
23
star
20

wedding-rsvp-off-platform-project

20
star
21

guidelines

Recommendations and templates for how we set up our open source repositories. 🧹
17
star
22

learn-circuitpython

Learn CircuitPython | Codecademy 🐍
HTML
14
star
23

EventHubClient

The EventHubClient gem is a simple wrapper of EventHub HTTP APIs.
Ruby
14
star
24

deploying-fullstack-with-heroku-sample

JavaScript
13
star
25

codecademy-syntax-theme-vscode

Codecademy syntax theme for Visual Studio Code.
12
star
26

learn-a-frame

Learn A-Frame πŸ‘“ | Codecademy
HTML
10
star
27

CCListView

CCListView is a highly customizable sequential view container.
Objective-C
9
star
28

try-github-CLI-off-platform-project

Python
9
star
29

articles

Curriculum Free Team
Python
8
star
30

python-data-structures-and-algorithms

Python
8
star
31

Linear-Regression-Live-Series

Jupyter Notebook
7
star
32

StoryboardXibController

a View Controller for loading Xibs from your Storyboards
Objective-C
7
star
33

deploying-backend-with-heroku-sample

JavaScript
7
star
34

add-automated-tests-off-platform-project

Python
6
star
35

use-selector-with

Small utility for react-redux's useSelector that allows passing args.
TypeScript
5
star
36

djangovet

This repo is intended for use with "Deploy Your App to PythonAnywhere" article.
Python
5
star
37

eslint-plugin-jest-react

ESLint plugin for Jest with React
TypeScript
4
star
38

client-modules

Shared node modules for codecademy.com & co
JavaScript
4
star
39

learn-emojicode

Codecademy | Learn Emojicode
3
star
40

discourse-codebytes-plugin

JavaScript
3
star
41

jest-globals

Mocks out global variables with Jest spies.
TypeScript
3
star
42

component-test-setup

Standardized test setup methods for React components.
TypeScript
3
star
43

reader-angularjs

CSS
2
star
44

practice-rebase-off-platform-project

2
star
45

calendar-rails

Ruby
2
star
46

computer-architecture

Python
2
star
47

babel-preset-codecademy

A collection of babel plugins and presets used at codecademy
JavaScript
2
star
48

code

The Codecademy Code_
2
star
49

calendar-angularjs

CSS
2
star
50

docs-update-cotw

A scheduled github action that updates the "concept of the week" in https://github.com/Codecademy/docs every sunday at 1:00pm UTC
TypeScript
2
star
51

introduction-to-it

Python
1
star
52

deploying-postgres-backend-with-heroku

JavaScript
1
star
53

pizza-planet-angularjs

CSS
1
star
54

learn-sql

1
star
55

bookmarks-rails

Ruby
1
star
56

run-on-yarn

Composite GitHub Action to run a command with Yarn. ✨
1
star
57

databookshelf

a library of cleaned, straight-forward, short and meaningful datasets to use for teaching learners
1
star
58

top-10-angularjs

CSS
1
star
59

bolt-network-angularjs

CSS
1
star
60

build-chatbots-with-python

Capstone project examples for Build Chatbots with Python skill path
1
star
61

nearme-angularjs

CSS
1
star