npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

asynchronous-interactive

v0.0.15

Published

Asynchronously load interactive elements in the AMD-interactive format

Downloads

17

Readme

Asynchronous Interactive

A common desire for online math textbooks is to provide "interactive figures," i.e., graphics that are, in some fashion, interactive so that learners can explore a mathematical context, make discoveries, form conjectures, etc. A challenge is the format in which to store such interactive graphics: there are platforms like Desmos and GeoGebra but such platforms don't provide the full power of JavaScript.

An "asynchronous interactive" is an interactive widget described via JavaScript code stored in an AMD module. This is similar to the Sqwidget project. Just like Premasagar Rose's sandie, we load JavaScript from inside an iframe. Then we provide access to a div or canvas element.

Working demo

Go to https://rawgit.com/kisonecat/asynchronous-interactive/master/examples/ to see a live demo.

Getting Started

In the <head> include

<script type="text/javascript" src="//unpkg.com/asynchronous-interactive"></script>

to load the code from this project from an npm cdn. Once loaded, a div with class asynchronous-interactive will have its data-src attribute inspected, and the JavaScript pointed there will be loaded.

For instance, place interactive code in sample.js. As a concrete example, sample.js might consist of

define(['canvas'],function(canvas) {
    var ctx = canvas.getContext('2d');
    ctx.fillRect(0, 0, 200, 200);
    ctx.clearRect(30, 30, 140, 140);
    ctx.strokeRect(45, 45, 110, 110);
});

Then in your html file, load sample.js with

<div class="asynchronous-interactive" id="sample" data-src="sample.js" style="width: 200pt; height: 200pt;"></div>

Instructions

The interactive graphics are stored as an AMD module, i.e., the JavaScript file looks like

define(['module','names','go','here'], function(module,names,go,here) {
   // 'module' and such are loaded...
   // and this function is called with the expected parameters.
});

For example,

define(['jquery'], function($) {
   // and now $ is what you expect it to be.
});

Multiple versions

The names of modules are resolved via the node package manager, and can include versions such as

define(['div', '[email protected]'], function(container, THREE) {
    renderer = new THREE.CanvasRenderer(); 
    container.appendChild( renderer.domElement );

    // do more with three.js here
});

Special module names

There are a few special module names:

  • div refers to the container DOM element.
  • canvas refers to a canvas element (created as a child of the parent div).
  • db refers to a local "database" which, depending on the surrounding application, may be persisted for the current user.