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

@financial-times/o-ads-embed

v4.7.0-beta.1

Published

Tiny library used in the creative wrappers for ads. Facilitates communication between the ad iframes and the o-ads library on the main browser page

Downloads

13

Readme

o-ads-embed

This module facilitates communication between advertising creatives in iframes and the main o-ads library via post message and so is dependant on o-ads existing in the top window to listen for the message.

This module is designed to be included in advertising creatives and not installed as a dependency.

Touch Events

On touch screen devices touch events are captured by iframes and not passed on to the parent page, this can be an issue under some circumstances such as an ad included in a gallery where swiping is required to move forwards.

To mitigate these circumstances o-ads-embed will detect when a touch screen is present and post the touchstart, touchend and touchmove events to o-ads via post message, you can listen for oAds.touch events in the top window if you need to react to these events.

Usage

Initialising

In a creative wrapper, include the following:

<script src="https://www.ft.com/__origami/service/build/v2/bundles/js?modules=o-ads-embed@^3.0.0"></script>
if (window !== window.top) {
	window.Origami['o-ads-embed'].init();
}

Collapsing

In a creative in DFP, include the following:

<div data-o-ads-collapse></div>
<script src="https://www.ft.com/__origami/service/build/v2/bundles/js?modules=o-ads-embed@^3.0.0"></script>
if (window !== window.top) {
	window.Origami['o-ads-embed'].init();
}

This will collapse any ad slot that serves the creative with this code inside it.

Send a 'slotClass' message

Since v4 o-ads-embed will send a postMessage to the top browsing context (usually the main window in a production setup) whenever an html element is found in its browsing context (i.e. the creative wrapper) that contains a data-o-ads-class attribute.

The postMessage will contain an object containing type: "oAds.slotClass". Additionally it will contain a property slotClass with the value of the data-o-ads-class attribute.

Example:

If the creative wrapper contains an element like this <div data-o-ads-class="sticky"></div>, a postMessage will be sent with a payload object like this:

{
  type: "oAds.slotClass",
  slotClass: "sticky"
}

Developers

Demos

There are two demos that demonstrate the two uses mentioned above. In order to get things running, you'll need to add the following lines at the bottom of main.js and run obt build.

window.Origami = {
	'o-ads-embed': oAdsEmbed
}

The reason for this is that in a creative wrapper, we would load o-ads-embed through the Origami registry, which places a global Origmai object on the page with all of the modules requested. When we run the demos, we simply include a built version of the module from /build/main.js.

Run the demo with obt demo --runServer.

Run the o-ads demos alongside (npm run demo-server), then visit http://localhost:3002/demos/local/o-ads-embed.html. You should see both the o-ads-embed demos load up in iframes on this page.

Testing

Run obt test or obt test --debug.

Upgrading from v2

v3 is a BIG simplification over v2, after analysing which functionality is still being used by the FT. This is what changed:

  • Removed event listeners for oAds.resive, oAds.responsive, oAds.collapse
  • Removed the message queue
  • Removed youare message from oAds. There is now a one way line of communication from o-ads-embed -> o-ads
  • Removed defaultSwipePrevented option.
  • Renamed oAds to oAdsEmbed to differentiate between oAds library on the parent page.
  • Renamed oAds.whoami postMessage to oAds.collapse and is only sent if an element with the data-o-ads-collapse attrbute is present in the iframe.
  • Touch event listeners are added on init().

To upgrade from v2, you will need to update all the creative wrappers in DFP with the code snippets above.

The main o-ads library is backwards compatible (at the time of writing) with o-ads-embed v2, for collapsing and touch event functionality.

Licence

This software is published by the Financial Times under the MIT licence.