• This repository has been archived on 18/Nov/2021
  • Stars
    star
    322
  • Rank 130,398 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 12 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create and manage a DOM event delegator

ftdomdelegate

FT's dom delegate library is a component for binding to events on all target elements matching the given selector, irrespective of whether anything exists in the DOM at registration time or not. This allows developers to implement the event delegation pattern.

Usage

Check out how to include Origami components in your project to get started with ftdomdelegate.

JavaScript

To import ftdomdelegate:

import Delegate from 'ftdomdelegate';
let myDel = new Delegate(document.body);

To instantiate Delegate on the body and listen to some events:

function handleButtonClicks(event) {
  // Do some things
}

function handleTouchMove(event) {
  // Do some other things
}

document.addEventListener('DOMContentLoaded', function() {
  var delegate = new Delegate(document.body);
  delegate.on('click', 'button', handleButtonClicks);

  // Listen to all touch move
  // events that reach the body
  delegate.on('touchmove', handleTouchMove);
});

A cool trick to handle images that fail to load:

function handleImageFail() {
  this.style.display = 'none';
}

document.addEventListener('DOMContentLoaded', function() {
  var delegate = new Delegate(document.body);
  delegate.on('error', 'img', handleImageFail);
});

.on(eventType[, selector], handler[, useCapture])

eventType (string)

The event to listen for e.g. mousedown, mouseup, mouseout, error, click, etc.

selector (string)

Any kind of valid CSS selector supported by matchesSelector. Some selectors, like #id or tag will use optimized functions internally that check for straight matches between the ID or tag name of elements.

null is also accepted and will match the root element set by root(). Passing a handler function into .on's second argument is equivalent to .on(eventType, null, handler).

handler (function)

Function that will handle the specified event on elements matching the given selector. The function will receive two arguments: the native event object and the target element, in that order.

useCapture (boolean)

Whether or not to listen during the capturing (pass in true) or bubbling phase (pass in false). If no value passed in, it will fallback to a 'sensible default', which is true for error, blur and focus events and false for all other types.

.off([eventType][, selector][, handler][, useCapture])

Calling off with no arguments will remove all registered listeners, effectively resetting the instance.

eventType (string)

Remove handlers for events matching this type considering the other parameters.

selector (string)

Only remove listeners registered with the given selector, among the other arguments.

If null passed listeners registered to the root element will be removed. Passing in a function into off's second parameter is equivalent to .off(eventType, null, handler[, useCapture]) (the third parameter will be ignored).

handler (function)

Only remove listeners registered with the given handler function, among the other arguments. If not provided, remove all handlers.

useCapture (boolean)

Only remove listeners with useCapture set to the value passed in. If not provided, remove listeners added with useCapture set to true and false.

.root([element])

element (Node)

Set the delegate's root node. If no element passed in the root node will be deleted and the event listeners will be removed.

.destroy()

Short hand for off() and root(), ie both with no parameters. Used to reset the delegate object.

Credits and collaboration

FT DOM Delegate was developed by FT Labs, part of the Financial Times. It's now maintained by the Origami Team. The developers of ftdomdelegate were Matthew Andrews and Matthew Caruana Galizia. Test engineering by Sam Giles. The API is influenced by jQuery Live.

Migration guide

State Major Version Last Minor Release Migration guide
active 5 N/A migrate to v5
maintained 4 4.0.6 migrate to v4
maintained 3 3.1 migrate to v3
╳ deprecated 2 2.2 N/A
╳ deprecated 1 1.0 N/A

More Repositories

1

chart-doctor

Sample files to accompany the FT's Chart Doctor column
HTML
2,791
star
2

github-label-sync

Synchronise your GitHub labels with as few destructive operations as possible
JavaScript
223
star
3

coronavirus-excess-mortality-data

Excess mortality data compiled by the FT Visual & Data Journalism team
159
star
4

engineering-progression

Careers and progression for engineers in the CTO organisation.
JavaScript
103
star
5

o-grid

Responsive grid system
95
star
6

ft-origami

The Old Origami Website, do not use
HTML
78
star
7

k8s_traffic_plug

Traffic endpoint and graceful shutdown for Elixir Plug apps
Elixir
72
star
8

tapper

Zipkin client for Elixir
Elixir
68
star
9

docker-elixir-build

Dockerfile for building Elixir projects
Dockerfile
56
star
10

n-express-monitor

🎯 configurable express decorator to automate log, metrics for more consistent monitor and debugging across micro-services
JavaScript
55
star
11

origami-build-tools

Standard Origami component development tools.
JavaScript
49
star
12

x-dash

❌➖📰 shared front-end components for FT.com and the FT Apps
JavaScript
38
star
13

ig-images-backend

JavaScript
37
star
14

origami

The Origami Component System
JavaScript
33
star
15

careers

💼 Engineering jobs at the Financial Times.
32
star
16

n-makefile

🍭 Shared build tools.
Makefile
32
star
17

fastly-tools

Command Line Utility for interacting with fastly
JavaScript
30
star
18

ftplottools

R Package for FT ggplot graphs
R
27
star
19

data-journalism-covid-hospital-counterfactual

Methodology behind story on how poor vaccine coverage in the US greatly increased its exposure to Covid hospitalisations relative to peer countries
R
25
star
20

node-health-check

Build health check functions which comply with the FT health check standard
JavaScript
24
star
21

ec2-powercycle

Lambda function to stop and start EC2 instances based on tag
Shell
22
star
22

mongo-hot-backup

A mongodb backup tool for FT Universal Publishing
Go
21
star
23

zipkin-helm

A helm chart for zipkin
Mustache
20
star
24

athloi

💪 Athloi is a tool to assist with the management of multi-package repositories (a.k.a. monorepos)
JavaScript
19
star
25

origami-website

The Origami website
18
star
26

bertha

Service to convert google spreadsheets to JSON, CSV and TSV and cache the result
JavaScript
18
star
27

origami-image-service

Optimises and resizes images
JavaScript
17
star
28

dotcom-page-kit

📰 Page Kit provides a high quality, well tested, and thoroughly documented set of tools for assembling and delivering FT.com based upon the best industry standards.
TypeScript
17
star
29

lambda-logger

Logger for lambda functions. Logs in JSON format using pino
JavaScript
15
star
30

public-people-api

Public API for retrieving information about a person
Go
14
star
31

origami-registry-ui

Get information about Origami components, services, and repositories.
JavaScript
14
star
32

n-heroku-tools

FT.com deployment tools
JavaScript
14
star
33

o-ads

Deprecated see README
JavaScript
14
star
34

grafana-tools

Automate your project Grafana dashboards
JavaScript
13
star
35

serverless-plugin-healthcheck

Scheduled health checks of lambdas
JavaScript
12
star
36

google-amp

⚡️ FT.com's implementation of the AMP project.
JavaScript
12
star
37

n-search-parser

🔎 A sane, fast, not too smart, search expression parser.
JavaScript
11
star
38

coco-splunk-http-forwarder

Go
11
star
39

ui-style-guide

Deprecated
HTML
11
star
40

nori

🍙 exploratory command-line tool to make changes across multiple repositories & track their progress
JavaScript
11
star
41

ft-api-client

A Node.js client for the Financial Times Content and Notifications APIs
JavaScript
11
star
42

ft-poller

Scheduled, asynchronous JSON fetching for Node.js applications
JavaScript
11
star
43

dotcom-tool-kit

🧰 modern, maintainable, modular developer tooling for FT.com projects
TypeScript
10
star
44

g-components

Reusable layout and structural components
JavaScript
10
star
45

o-typography

Typography and vertical rhythm styles for FT branding
10
star
46

treecreeper

A set of tools for working with graph data - Not supported
JavaScript
10
star
47

ebi

🦐 Ebi: GitHub repositories contents search
JavaScript
9
star
48

structured-google-docs-client

A client library for fetching and transforming markup from Google Docs
JavaScript
9
star
49

n-gage

Shared developer and build tools for FT.com applications and components
Makefile
9
star
50

fec-donor-overlaps

Scripts and data used to generate donor overlap figures between 2020 and 2022 candidates in US elections, based off of FEC/ActBlue/WinRed data
Python
9
star
51

n-jsonp

❌Deprecated: This package is no longer maintained, consider using fetch() and CORS instead
JavaScript
9
star
52

n-auto-logger

a configurable logger decorator to automate function logs, compatible with winston, n-logger, n-mask-logger, etc.
JavaScript
9
star
53

scrumple

A fast (and scrappy) JavaScript bundler for developing Origami components.
Rust
9
star
54

coco-kafka-bridge

Kafka consumer forwarding messages to an HTTP endpoint.
Go
9
star
55

origami-build-service

Creates bundles of JavaScript and CSS from building Origami and Origami-compatible modules
JavaScript
8
star
56

content-k8s-provisioner

HTML
8
star
57

n-express

Slightly enhanced Express.
JavaScript
8
star
58

public-brands-api

Provides a public API for Brands stored in a Neo4J graph database
Go
8
star
59

yield-curve-sonification

An experiment to sonify the yield curve
JavaScript
8
star
60

internal-content-api

API for articles that should get the internal content
Go
8
star
61

babel-polyfill-silencer

Microlibrary for use by webpack to avoid babel implicitly importing core-js polyfills
JavaScript
8
star
62

aws-cf-elixir

AWS CloudFormation Templates for Elixir Build and Application Nodes
7
star
63

o-colors

Origami module containing color palette and use case Sass variables.
7
star
64

o-element-visibility

Element visibility tracking
JavaScript
7
star
65

o-table

Data table styling.
7
star
66

useragent_parser

JS and VCL implementation of uap-core
JavaScript
7
star
67

n-tracking

Client-side tracking initialisation and custom events for FT.com
JavaScript
7
star
68

police-misconduct-complaints-analysis

An analysis conducted for the May 28, 2021, Financial Times story "Small share of police draw third of complaints in big US cities"
Jupyter Notebook
7
star
69

n-ui

❌ DEPRECATED Server, build and client side bootstrapping for FT.com's user-facing applications.
JavaScript
7
star
70

o-crossword

An experimental Origami component to implement a responsive crossword.
JavaScript
6
star
71

kubectl-login

Logs you into multiple clusters which use dex
Go
6
star
72

o-tracking

Origami Tracking component
6
star
73

n-automation

Automated regression tests for your app
JavaScript
6
star
74

n-logger

Logging utility
JavaScript
6
star
75

o-ft-icons

Deprecated, please use o-icons instead
CSS
6
star
76

notifications-push

Proactively notifies subscribers about new content publishes/modifications.
Go
6
star
77

n-mask-logger

Version of @financial-times/n-logger that masks sensitive fields
JavaScript
6
star
78

ig-images-frontend

Web interface to upload images
JavaScript
6
star
79

upp-provisioners

Contains the various provisioning projects used by the Universal Publishing Platform
Shell
6
star
80

express-markdown-pages

An Express middleware that transforms plain text files into dynamic pages and fits right into your existing app.
JavaScript
6
star
81

fluent-logging

Fluent, splunk friendly logging
Java
6
star
82

g-deploy

Deploys IG pages to S3
TypeScript
5
star
83

tapper_plug

Plug integration for Tapper
Elixir
5
star
84

zipper-s3

App that is zipping up files from an S3 bucket and uploads the zip file back into the bucket.
Go
5
star
85

upp-aggregate-healthcheck

Aggregate healthcheck that is currently used for Kubernetes cluster
Go
5
star
86

next-metrics

A library for sending metrics to Graphite
JavaScript
5
star
87

coco-neo4j-backup

Docker Image for automated neo4j backups
Go
5
star
88

elasticsearch-reindexer

A tool for migrating data in an ElasticSearch index with updated mappings
Go
5
star
89

o-share

URL and social media sharing
5
star
90

o-header

FT branded page header for responsive sites
5
star
91

splunk-event-reader

Reads Splunk events via the Splunk REST API
Go
5
star
92

o-gallery

A gallery component for slideshows and carousels
JavaScript
5
star
93

express-web-service

Install FT Web Standard web service descriptions in an Express.js application
JavaScript
5
star
94

dotcom-reliability-kit

🪨 A well tested suite of tools designed to help FT.com applications be more reliable and measurable
JavaScript
5
star
95

n-swg

JS, Styles, Templates and utils for FT.com Subscribe with Google implementation
JavaScript
5
star
96

disable-tree-shaking-for-chunk-plugin

🌲 A Webpack plugin to disable tree shaking for all JS modules in the specified chunks.
JavaScript
5
star
97

cookiecutter-upp-golang

Go
5
star
98

next-json-ld

Helpers for producing schema.org markup in JSON LD on ft.com
JavaScript
5
star
99

golang-app-template

Template for golang apps with config reading and logging setup
Go
5
star
100

crypto-signatures

A library that provides capabilities to create cryptographic signatures and verify them.
Java
5
star