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

@openseadragon-imaging/openseadragon-viewerinputhook

v2.2.1

Published

OpenSeadragon plugin which provides hooks into the viewer input event pipeline.

Downloads

2,418

Readme

OpenSeadragonViewerInputHook

Gitter

OpenSeadragonViewerInputHook is a plugin for OpenSeadragon 1.0.0+ which provides hooks into the user input event pipeline for providing additional behavior and/or overriding the default behavior.

View the Documentation

Demo/Test Site

Usage

Prerequisite note: OpenSeadragonViewerInputHook requires OpenSeadragon version 2.0+.

The OpenSeadragonViewerInputHook bundle can be obtained the following ways:

  1. Direct download openseadragon-viewerinputhook.js (and optionally openseadragon-viewerinputhook.js.map)
  2. npm
    npm install @openseadragon-imaging/openseadragon-viewerinputhook

The OpenSeadragonViewerInputHook bundle can be included using a script tag in HTML or imported as a library module (ES2015, CommonJS, AMD).

A ViewerInputHook object can be created and attached (if desired) to an OpenSeadragon.Viewer two ways:

  1. Call the addViewerInputHook method on the viewer
  2. Create a new ViewerInputHook object, passing a viewer reference in the options parameter (optional)

Both methods return a new ViewerInputHook object, and both methods take an options parameter where the event handlers to be hooked may be specified (see the 'Details' section below).

Example using an HTML script tag

<script
  type="text/javascript"
  src="path_to/openseadragon/openseadragon.js"
></script>
<script
  type="text/javascript"
  src="path_to/openseadragon-imaging/openseadragon-viewerinputhook.js"
></script>
    // Example 1 - Use the Viewer.addViewerInputHook() method to create a ViewerInputHook

    // create an OpenSeadragon viewer
    var viewer = window.OpenSeadragon({...});
    // add a ViewerInputHook to the viewer
    var viewerInputHook = viewer.addViewerInputHook({ hooks: [...] });


    // Example 2 - Attach a new ViewerInputHook to an existing OpenSeadragon.Viewer

    var viewerInputHook = new window.OpenSeadragonImaging.ViewerInputHook({ viewer: existingviewer, hooks: [...] });

Example importing as a module

    npm install openseadragon --save
    npm install @openseadragon-imaging/openseadragon-viewerinputhook --save
import OpenSeadragon from 'openseadragon';
import OpenSeadragonViewerInputHook from '@openseadragon-imaging/openseadragon-viewerinputhook';

    // Example 1 - Use the Viewer.addViewerInputHook() method to create a ViewerInputHook

    // create an OpenSeadragon viewer
    var viewer = OpenSeadragon({...});
    // add a ViewerInputHook to the viewer
    var viewerInputHook = viewer.addViewerInputHook({ hooks: [...] });


    // Example 2 - Attach a new ViewerInputHook to an existing OpenSeadragon.Viewer

    var viewerInputHook = new OpenSeadragonViewerInputHook({ viewer: existingviewer, hooks: [...] });

Details

Event handler callbacks are specified in the hooks property (array) of the options object passed when creating a ViewerInputHook object (see example code below). Any number of hooks can be specified.

Each hook specification in the array should have three properties - tracker, handler, and hookHandler.

The tracker property of each hook definition can be a reference to any OpenSeadragon.MouseTracker instance, or one of the pre-defined OpenSeadragon viewer trackers - currently 'viewer' or 'viewer_outer'.

The handler property of each hook definition specifies which MouseTracker handler to hook. Valid values are:

  1. 'enterHandler'
  2. 'exitHandler'
  3. 'pressHandler'
  4. 'nonPrimaryPressHandler' (OpenSeadragon v1.2.1+)
  5. 'releaseHandler'
  6. 'nonPrimaryReleaseHandler' (OpenSeadragon v1.2.1+)
  7. 'moveHandler'
  8. 'stopHandler'
  9. 'scrollHandler'
  10. 'clickHandler'
  11. 'dblClickHandler'
  12. 'dragHandler'
  13. 'dragEndHandler'
  14. 'pinchHandler'
  15. 'keyDownHandler'
  16. 'keyUpHandler'
  17. 'keyHandler'
  18. 'focusHandler'
  19. 'blurHandler'

The hookHandler property of each hook definition should be the user-defined event handler callback. All event handler callbacks have the following signature:

handlerFunc(event)

The ViewerInputHook class inserts your event hook handler methods in front of any existing event handler methods so the attached handler will be called first. Additional ViewerInputHook objects can be added on the same viewer/MouseTracker to create a chain of hook methods, where the last added handler(s) will be called first. Note: If multiple ViewerInputHook are attached to the same viewer/MouseTracker, destroy() should be called for each ViewerInputHook in reverse order of attachment!

Your hook event handler methods can control the event handling behavior in one or more of the following ways:

  1. Set event.stopHandlers = true to prevent any more handlers in the event handler chain from being called
  2. Set event.stopBubbling = true to prevent the original DOM event from bubbling up the DOM tree (all handlers returning false will also disable bubbling)
  3. Set event.preventDefaultAction = true to prevent the viewer's default action in response to the event (currently applies to clickHandler, dragHandler, and scrollHandler on the viewer (tracker = 'viewer'))
    // Example

    var viewer = OpenSeadragon({...});

    viewer.addViewerInputHook({hooks: [
        {tracker: 'viewer', handler: 'scrollHandler', hookHandler: onViewerScroll},
        {tracker: 'viewer', handler: 'clickHandler', hookHandler: onViewerClick}
    ]});

    function onViewerScroll(event) {
        // Disable mousewheel zoom on the viewer and let the original mousewheel events bubble
        if (!event.isTouchEvent) {
            event.preventDefaultAction = true;
            return true;
        }
    }

    function onViewerClick(event) {
        // Disable click zoom on the viewer using event.preventDefaultAction
        event.preventDefaultAction = true;
        event.stopBubbling = true;
    }

Demo/Test Site

The demo site uses OpenSeadragonViewerInputHook to monitor cursor position and provide custom click and mousewheel event actions.

The source code can be found here.

TODO

  1. jsdoc documentation
  2. Provide hooks on reference strip events
  3. Provide hooks on navigator events