All Projects → julianxhokaxhiu → PostEvent

julianxhokaxhiu / PostEvent

Licence: MIT license
A Cross-Domain Event Handler javascript library. Pure Vanilla JS, no dependencies.

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to PostEvent

iframe-communication
Basic two way iframe communication
Stars: ✭ 88 (+528.57%)
Mutual labels:  iframe, cross-domain
rx-postmessenger
Minimal RxJS adapter for the window.postMessage API for request-response streams and notification streams across frame windows.
Stars: ✭ 27 (+92.86%)
Mutual labels:  iframe, postmessage
Postmate
📭 A powerful, simple, promise-based postMessage library.
Stars: ✭ 1,638 (+11600%)
Mutual labels:  iframe, postmessage
post-messenger
👶 ~1 Kb wrapper of window.postMessage for cross-document communication.
Stars: ✭ 28 (+100%)
Mutual labels:  iframe, postmessage
ibridge
Typesafe iframe bridge for easy parent child bidirectional communication
Stars: ✭ 25 (+78.57%)
Mutual labels:  iframe, postmessage
Zoid
Cross domain components
Stars: ✭ 1,672 (+11842.86%)
Mutual labels:  iframe, cross-domain
trainmanjs
TrainmanJS - Cross-Origin Communication Library
Stars: ✭ 16 (+14.29%)
Mutual labels:  iframe, postmessage
chronosjs
JS Channels (Events / Commands / Reqest-Response / Courier) Mechanism
Stars: ✭ 35 (+150%)
Mutual labels:  postmessage
Friendly Code Editor
Try this Friendly Code Editor. You'll love it. I made it with a lot of effort. It has some great features. I will update it adequately later. Very helpful for developers. Enjoy and share.
Stars: ✭ 20 (+42.86%)
Mutual labels:  iframe
Lazyframe
🛀🏽 Dependency-free library for lazyloading iframes
Stars: ✭ 237 (+1592.86%)
Mutual labels:  iframe
React Native Youtube Iframe
A wrapper of the Youtube-iframe API built for react native.
Stars: ✭ 221 (+1478.57%)
Mutual labels:  iframe
React Adal
Azure Active Directory Library (ADAL) support for ReactJS
Stars: ✭ 211 (+1407.14%)
Mutual labels:  iframe
gr-eventstream
gr-eventstream is a set of GNU Radio blocks for creating precisely timed events and either inserting them into, or extracting them from normal data-streams precisely. It allows for the definition of high speed time-synchronous c++ burst event handlers, as well as bridging to standard GNU Radio Async PDU messages with precise timing easily.
Stars: ✭ 38 (+171.43%)
Mutual labels:  event-handling
Awesome-Cross-Domain-Person-Re-identification
Awesome-Cross-Domain-Person-Re-identification
Stars: ✭ 17 (+21.43%)
Mutual labels:  cross-domain
get-css-data
A micro-library for collecting stylesheet data from link and style nodes
Stars: ✭ 29 (+107.14%)
Mutual labels:  iframe
CrossNER
CrossNER: Evaluating Cross-Domain Named Entity Recognition (AAAI-2021)
Stars: ✭ 87 (+521.43%)
Mutual labels:  cross-domain
cdn
🚀 ✈️ 🚄 free CDN for everyone who wants to speed his website freely!😄
Stars: ✭ 16 (+14.29%)
Mutual labels:  iframe
TraND
This is the code for the paper "Jinkai Zheng, Xinchen Liu, Chenggang Yan, Jiyong Zhang, Wu Liu, Xiaoping Zhang and Tao Mei: TraND: Transferable Neighborhood Discovery for Unsupervised Cross-domain Gait Recognition. ISCAS 2021" (Best Paper Award - Honorable Mention)
Stars: ✭ 32 (+128.57%)
Mutual labels:  cross-domain
scion-microfrontend-platform
SCION Microfrontend Platform is a TypeScript-based open-source library that helps to implement a microfrontend architecture using iframes.
Stars: ✭ 51 (+264.29%)
Mutual labels:  iframe
pikaz-iframe
基于vue封装的iframe组件
Stars: ✭ 54 (+285.71%)
Mutual labels:  iframe

PostEvent

A Cross-Domain Event Handler javascript library. Pure Vanilla JS, no dependencies.

Introduction

This library was born with a simple goal in mind: provide a simple way to handle events, without the effort to code multiple times special code in case we are in a Cross-Domain situation.

Say hello to PostEvent.

Feature set

Cross-Domain

Event handling by default is not possible when an iFrame is not sharing the same origin URL, or the headers are not set to allow Cross-Domain communication.

This library therefore is using postMessage API to enable communication, preserving the same capability of a generic event handling.

Method chain

If you prefer, you can chain methods, in a jQuery-like way-ish. This is an example of method chain:

var pe = new PostEvent();

pe
.on( 'myCustomEvent', function (params){
  console.log( params.foo ); // bar
})
.trigger( 'myCustomEvent', { foo: 'bar' } );

Single channel across multiple instances

You can instanciate as much times as you want the library. By default it is always using the same window.parent entrypoint. This allows you to write simple code, without the need to handle special cases.

var pe1 = new PostEvent(),
    pe2 = new PostEvent();

pe1
.on('sayHello', function (params){
  console.log( 'Hello ' + ( params.name || 'World' ) ); // Hello User
});

p2.trigger('sayHello', { name: 'User' });

UMD Ready

You can use this library in the environment you prefer, thanks to the UMD bundling provided by WebPack.

More info here: https://github.com/umdjs/umd

Install

In order to use this library, you can just include the latest release in your browser like this

<!DOCTYPE html>
<html>
	<head>
		...
	</head>
	<body>
		...
		<script src="dist/PostEvent.js"></script>
		<script>
			var pe = new PostEvent();

			// console.log( pe );
		</script>
	</body>
</html>

or if you prefer as a module

// $ npm i post-event

import PostEvent from 'post-event'

let pe = new PostEvent();
// console.log( pe );

Initialization

When you instanciate the library, you can pass some configuration options, if you prefer:

  • debug: if true it will print some warnings, if the library is misused.
  • namespace: if defined, it will be used to filter messages type. Useful if you want to use multiple instances, with different channels. By default is this class name ( PostEvent )

This is an example of custom initialization:

var pe = new PostEvent({
  debug: true,
  namespace: 'MyCustomNamespace'
});

API

This library is made of two simple APIs:

trigger( name, params )

This API mimics $.trigger() from jQuery. The function accepts two arguments:

  • name: the event name you want to trigger.
  • params: the payload that you want to send.

This is an example usage:

var pe = new PostEvent();

pe.trigger( 'myCustomEvent', { foo: 'bar' } );

on( name, callback )

This API mimics $.on() from jQuery, but it's even more simplier. The function accepts two arguments:

  • name: the event name you want to subscribe.
  • callback: the callback function to call, when the event is detected. params object will be given as an argument, or contextual this object. Both can be null if no parameters were given during trigger.

This is an example of usage:

var pe = new PostEvent();

// Example 1
// No arguments, only this
pe.on( 'myCustomEvent', function (){
  console.log( this.foo ); // bar
});

// Example 2
// One argument, we don't use this
pe.on( 'myCustomEvent', function (params){
  console.log( params.foo ); // bar
});

// Example 3
// One argument, we use also this
pe.on( 'myCustomEvent', function (params){
  console.log( this.foo ); // bar
  console.log( params.foo ); // bar
});

License

See LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].