GithubHelp home page GithubHelp logo

maestro-script / h5p-standalone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tunapanda/h5p-standalone

0.0 0.0 0.0 7.38 MB

Server free H5P Content

License: MIT License

CSS 15.49% JavaScript 81.62% HTML 0.51% TypeScript 2.38%

h5p-standalone's Introduction

h5p-standalone 2.1.3 CircleCI

Display H5P content without using a webserver

Install

yarn add h5p-standalone

Basic Usage

import { H5P } from 'h5p-standalone'; // ES6
// const { H5P } = require('h5p-standalone'); AMD
// <script src="node_modules/h5p-standalone/dist/main.bundle.js"> // Globals
// const { H5P } = 'H5PStandalone';

const el = document.getElementById('h5p-container');
const h5pLocation = './workspace';

const h5p = new H5P(el, h5pLocation);

Advanced Usage

There are several options for configuring h5p-standalone, if you would like to do things after rendering the H5P be sure to use await or .then(), as it is asynchronous.

import { H5P } from 'h5p-standalone';

const el = document.getElementById('h5p-container');
const h5pLocation = './workspace';

const options = {
  id: 'lesson-one', // Optional unique ID, by default will be randomly generated
  frameJs: './frame.bundle.js',
  frameCss: './styles/h5p.css'
};

const displayOptions = { // Customise the look of the H5P
    frame: true,
    copyright: true,
    embed: false,
    download: false,
    icon: true,
    export: false
  };


const librariesPath = "/path/to/shared/libaries"; // Optional path to h5p activity libraries outside of content directory
const h5p = await new H5P(el, h5pLocation, options, displayOptions, librariesPath);

// OR

const h5p = new H5P(el, h5pLocation, options, displayOptions);

h5p.then(() => {
  // do stuff
});

Multiple H5Ps on the same page

To render multiple H5Ps make sure your code is async aware.

import { H5P } from 'h5p-standalone';

await new H5P(document.getElementById('h5p-container-1'), './h5p-1');
await new H5P(document.getElementById('h5p-container-2'), './h5p-2');

// OR

const h5p1 = new H5P(document.getElementById('h5p-container-1'), './h5p-1');

h5p1.then(() => {
  return new H5P(document.getElementById('h5p-container-2'), './h5p-2');
}).then(( => {
  // do stuff
}));

Testing

yarn test

h5p-standalone's People

Contributors

benabel avatar jakeii avatar tdxdave avatar usernamenumber avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.