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

xdm.js

v1.0.3

Published

![unmaintained](http://img.shields.io/badge/status-unmaintained-red.png)

Downloads

6

Readme

xdm.js

unmaintained

Build Status

Cross-domain messaging over postMessage, based on the JSON-RPC 2.0 protocol. It is a stripped down and slightly modified version of easyXDM.

Installation

Install with Bower:

bower install --save xdm.js

The component can be used as a Common JS module, an AMD module, or a browser global.

API

The xdm.js library must be included in both the host and guest application. It will dynamically create the guest application's iframe from the host application.

xdm.version

The version of the library.

xdm.Rpc(xdmConfig, rpcConfig);

The cross-domain RPC constructor.

Creates a proxy object that can be used to call methods implemented on the remote end of the channel, and also to provide the implementation of methods to be called from the remote end.

Creates an iframe to the remote window.

// connect to the host application
var host = xdm.Rpc(xdmConfig, rpcConfig);

xdmConfig.onReady (optional)

Specify a function to call when communication has been established.

xdmConfig.container (host application only)

The DOM node to append the generated iframe to.

xdmConfig.remote (host application only)

The path to the local or remote window. Set to 'about:blank' if using config.html.

xdmConfig.html (optional; host application only)

The HTML to be injected into a sourceless iframe.

xdmConfig.props (optional; host application only)

The additional attributes to set on the iframe. Can contain nested objects, e.g., 'style': { 'border': '1px solid black' }.

xdmConfig.acl (optional; guest application only)

Add domains to an Access Control List. The ACL can contain * and ? as wildcards, or can be regular expressions. If regular expressions they need to begin with ^ and end with $.

rpcConfig.local (optional)

All the methods you which to expose to the remote window.

var rpcConfig = {};

rpcConfig.local = {
    namedMethod: function (data, success, error) { /* ... */ }
};

The function will receive the passed arguments followed by the callback functions success and error. To send a successful result back you can use:

return foo or success(foo)

To return an error you can use:

throw new Error('foo error') or error('foo error')

rpcConfig.remote (optional)

All the remote methods you want to use from the remote window when it's ready. These are just stubs.

rpcConfig.remote = {
    remoteMethod: {}
};

Example

// host application creates new connection with a guest widget

var isReady = false;

var widget = new xdm.Rpc({
    remote: 'http://another.domain.com/widget.html',
    container: document.body,
    props: {
        'height': '300px',
        'style': {
            'border': '2px solid red'
        }
    },
    onReady: function () {
        isReady = true;
    }
}, {
    remote: {
        methodInWidget: {}
    },
    local: {
        methodInHost: function (data) {
            return data;
        }
    }
});

widget.methodInWidget('message');

// guest application creates new connection with host application

var isReady = false;

var host = new xdm.Rpc({
    acl: [
        'http://example.com',
        'http://sub.example.com'
    ],
    onReady: function () {
        isReady = true;
    }
}, {
    remote: {
        methodInHost: {}
    },
    local: {
        methodInWidget: function (data) {
            return data;
        }
    }
});

host.methodInHost('message')

xdm.Rpc.iframe;

A reference to the instance's iframe.

xdm.Rpc.destroy();

Teardown the communication channel and remove the iframe from the DOM.

proxy.remoteMethod(arg1, arg2, successCallback, errorCallback)

Remote method calls can take any number of arguments.

The second last argument is a success callback. The last argument is an error callback.

// from within the widget, request that the host resize the iframe
host.resizeIframe({
    height: calculatedHeight
}, successCallback, errorCallback);

When called with no callback a JSON-RPC 2.0 notification will be executed. Be aware that you will not be notified of any errors with this method.

Development

Install Node (comes with npm).

From the repo root, install the project's development dependencies:

npm install

Testing relies on the Karma test-runner. If you'd like to use Karma to automatically watch and re-run the test file during development, it's easiest to globally install Karma and run it from the CLI.

npm install -g karma
karma start

To run the tests in Firefox, just once, as Travis CI does:

npm test

Browser support

  • Google Chrome
  • Firefox 4+
  • Internet Explorer 8+
  • Safari 5+
  • Opera (latest)