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

contenteditable-autocomplete

v1.0.2

Published

A jQuery plugin to use <{span|div|...} contenteditable> as expandable inputs.

Downloads

527

Readme

contenteditable-autocomplete

Add Autocomplete/Typeahead to contenteditable tag

Build Status Dependency Status devDependency Status

Download / Installation

You can download the latest JS & CSS code here:

  • https://unpkg.com/contenteditable-autocomplete/dist/contenteditable-autocomplete.js
  • https://unpkg.com/contenteditable-autocomplete/dist/contenteditable-autocomplete.css

Or install via npm

npm install --save contenteditable-autocomplete

The JS code can be required with

var jQuery = require('jquery')
var contenteditableAutocomplete = require('contenteditable-autocomplete')

// init
contenteditableAutocomplete(jQuery)

The CSS code lives at node_modules/contenteditable-autocomplete/contenteditable-autocomplete.css

Usage

<!-- load jquery -->
<script src="jquery.js"></script>


<!-- load contenteditable-autocomplete assets -->
<link rel="stylesheet" type="text/css" href="contenteditable-autocomplete.css">
<script src="contenteditable-autocomplete.js"></script>

<!-- The behaviour is initialzied on first interaction -->
<p>
  <strong>Country:</strong>
  <span contenteditable name="country" placeholder="set country" data-autocomplete-spy></span> |
</p>

<p>
  <strong>Countries:</strong>
</p>
<p contenteditable name="countries" placeholder="set countries" data-autocomplete-spy data-autocomplete-multiple></p>

Suggestions

To pass suggestions for the autocomplete, listen to the autocomplete:request event

$('[name=country]').on('autocomplete:request', function(event, query, callback) {
  var suggestions = getSuggestionsArrayFor(query);
  callback(suggestions);
})

Instead of strings, you can also pass objects with the mandatory properties label and value. label will be shown as suggestions. When selected, value will be added to the input.

$('[name=country]').on('autocomplete:request', function(event, query, callback) { callback([ {label: 'Germany (Europe)', value: 'Germany'}, {label: 'Thailand (Asia)', value: 'Thailand'}, {label: 'Uruguay (South America)', value: 'Uruguay'} ]); })

Select event

To react on when a suggestion has been selected, listen to the autocomplete:select event.

$('[name=country]').on('autocomplete:select', function(event, selected) {
  console.log('selected item:', selected);
})

Selected is always an object with label and value properties (see above). Additional properties passed to suggestions will be passed.

Local Setup

git clone [email protected]:gr2m/contenteditable-autocomplete.git
cd contenteditable-autocomplete
npm install

Test

You can start a local dev server with

npm start

Run tests with

npm test

While working on the tests, you can start Selenium / Chrome driver once, and then tests re-run on each save

npm run test:mocha:watch

Fine Print

The Expandable Input Plugin have been authored by Gregor Martynus, proud member of the Hoodie Community.

License: MIT