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

knockout-popup-template

v1.9.2

Published

A flexible, simple Knockout binding for popping up a template near an anchor element.

Downloads

4,692

Readme

knockout.popupTemplate

NPM version Build Status Dependency Status

This binding ties an element (called the anchor) to a template (called the popup), which will pop up on screen next to it. By default it works similarly to a dropdown menu, the popup being rendered on initialization, appearing below and aligned to the left edge of the anchor, shown when the anchor is clicked, and hidden if the user clicks outside the popup.

Usage

The basic use of popupTemplate is thus:

<div data-bind="popupTemplate: 'templateName'">Anchor text</div>

This will give the default behavior, outlined above. Alternatively, the binding can take a configuration object, with the following fields:

  • template: Required. A string containing the name of the template to render.
  • data: Data model to use rendering the template.
  • renderOnInit: If truthy, the popup is rendered at init and merely shown or hidden, instead of being rendered on each open.
  • closeOnClickInPopup: If truthy, clicking inside a popup will close it. Useful for menus and similar.
  • openState: An observable that is updated to follow the state of the popup. The popup can also be shown or hidden by setting the observable to true or false.
  • beforeOpen: An event handler to be called before opening the popup.
  • afterOpen: An event handler to be called immediately after opening the popup.
  • beforeClose: An event handler to be called before closing the popup.
  • afterClose: An event handler to be called immediately after closing the popup.
  • anchorHandler: If false, clicking the anchor does not open or close the popup.
  • outsideHandler: If false, clicking outside the popup will not close it.
  • positioning: An object containing positioning information (see below).
  • className: A string containing a class name to put in the class attribute of the popupTemplate container.
  • disposalCallback: A function, that will take care of removing the popupTemplate container from the DOM. This is usefull if you wish to use animations with renderOnOpen mode. The function is passed one argument which is a reference to the element containing the popupTemplate.
  • disable: If this is truthy, or an obseravble containing a truthy value, opening the popup is disabled.
  • openOnMouseOver: If truthy, hovering over the anchor will display the popup.
<div data-bind="popupTemplate: { template: 'templateName' }">Anchor text</div>

Positioning the popup

You can select where the popup will appear in relation to the anchor by passing an object in the positioning field of the configuration object, which should have one or both of vertical and horizontal fields.

These fields can contain either a string, or an observable containing a string. These strings should be selected from the following lists:

Horizontal

  • 'outside-left': Align the right edge of the popup with the left edge of the anchor.
  • 'inside-left': Align the left edge of the popup with the left edge of the anchor.
  • 'middle': Align the horizontal midpoint of the popup with the horizontal middle of the anchor.
  • 'inside-right': Align the right edge of the popup with the right edge of the anchor.
  • 'outside-right': Align the left edge of the popup with the right edge of the anchor.

Vertical

  • 'outside-top': Align the bottom edge of the popup with the top edge of the anchor.
  • 'inside-top': Align the top edge of the popup with the top edge of the anchor.
  • 'middle': Align the vertical midpoint of the popup with the vertical middle of the anchor.
  • 'inside-bottom': Align the bottom edge of the popup with the bottom edge of the anchor.
  • 'outside-bottom': Align the top edge of the popup with the bottom edge of the anchor.

It is also possible to supply a list of positionings where the best fit would be chosen.

For convinience you can also supply strings containing "<horizontal> <vertical>" instead of a position object:

<div data-bind="popupTemplate: {
                  template: 'templateName',
                  'positioning': [
                    { horizontal: 'middle', vertical: 'middle' },
                    'outside-left inside-top',
                    'outside-right middle'
                  ]
                }">
  Anchor text
</div>

Examples

http://one-com.github.io/knockout-popupTemplate/examples/index.html

License

Copyright © 2014, One.com

knockout.popupTemplate is licensed under the BSD 3-clause license, as given at http://opensource.org/licenses/BSD-3-Clause