GithubHelp home page GithubHelp logo

imclab / happen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tmcw/happen

0.0 1.0 0.0 647 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

happen's Introduction

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
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
    });

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

doodlemoonch avatar edmellum avatar jfirebaugh avatar tmcw avatar

Watchers

 avatar

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.