GithubHelp home page GithubHelp logo

tmcw / happen Goto Github PK

View Code? Open in Web Editor NEW
105.0 5.0 17.0 521 KB

make real events happen in-browser, with pure DOM and optional $

Home Page: http://macwright.org/happen/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 99.76% HTML 0.24%

happen's Introduction

Circle CI Greenkeeper badge

happen wraps the createEvent DOM API to make real event mocking in-browser palatable.

Installation

Raw:

wget https://raw.github.com/tmcw/happen/master/happen.js
component install tmcw/happen

With Browserify

npm install happen

var happen = require('happen');

With bower

bower install tmcw/happen

Native API

once()

happen.once(element, options) fires an event once. The element must be a DOM element. options must have a type for event type, then can have options:

Keyboard Events

  • keyCode
  • charCode
  • shiftKey
  • metaKey
  • ctrlKey
  • altKey

Mouse Events

  • detail
  • screenX
  • screenY
  • clientX
  • clientY
  • ctrlKey
  • altKey
  • shiftKey
  • metaKey
  • button

Touch Events

  • touchstart
  • touchmove
  • touchend
var element = document.getElementById('map');

// click shortcut
happen.click(element);

// dblclick shortcut
happen.dblclick(element);

// custom options
happen.dblclick(element, { shift: true });

// any other event type under MouseEvents
happen.once(element, {
    type: 'mousewheel',
    detail: -100
});

// The once api takes
happen.once(
    // element
    element, {
        // event type (e.type)
        type: 'mousewheel',
        // any other options
        detail: -100
    });

// touch events
happen.once(element, {
        type : 'touchstart',
        touches : [{
                pageX : 800,
                pageY : 800
            },
            {
                pageX : 400,
                pageY : 400
            }]
    });

jQuery Plugin

// Shortcut - 'click' is shorthand for { type: 'click' }
$('.foo').happen('click');

// Longhand - specify any sort of properties
$('.foo').happen({ type: 'keyup', keyCode: 50 });

// Works on any jQuery selection
$('.foo, .bar').happen('dblclick');

Shortcuts:

  • happen.click
  • happen.dblclick
  • happen.mousedown
  • happen.mouseup
  • happen.mousemove
  • happen.keydown
  • happen.keyup
  • happen.keypress

Use it with a testing framework, like Jasmine or Mocha.

(IE tests failing due to Chai)

See Also

happen's People

Contributors

cherniavskii avatar doodlemoonch avatar edmellum avatar fuzhenn avatar greenkeeper[bot] avatar jfirebaugh avatar mortonfox avatar tmcw avatar yohanboniface avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

happen's Issues

needs a fresh release?

the current tag points to a version which had an empty index.js file. I can use the git hash but a fresh release would be nicer.

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.