• Stars
    star
    285
  • Rank 145,115 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

jQuery plugin for highlighting bits of text within a textarea.

highlight-within-textarea

jQuery plugin for highlighting bits of text within a textarea.

Introduction

It's not actually possible to style text in a textarea, because any markup within a textarea is treated as literal text. This plugin aims to fake it, allowing you to highlight pieces of text inside a textarea.

A native textarea element is used and familiar behavior (auto-correct, scrolling, resizing, etc.) works as expected.

Usage

To start, call highlightWithinTextarea() on a textarea, passing in a config object.

$('.my-textarea').highlightWithinTextarea({
    highlight: whatever // string, regexp, array, function, or custom object
});

The highlight property accepts several different types of values to describe what will be highlighted. You can see the various ways to highlight things, along with example code, on the demo page.

Styling

For reference, the demo page has some sample styling (view source to see the CSS).

There are some guidelines for getting your styles in the right places. Here are the classes you'll want to use.

.hwt-container

Use for visibility, positioning, and background.

  • display
  • position
  • top
  • left
  • margin
  • background

.hwt-content

Use for sizing and text formatting.

  • width
  • height
  • padding
  • border
  • color
  • font

.hwt-content mark

Use for highlighted text. Generally, stuff that doesn't change size is fine.

  • background-color
  • border-radius
  • box-shadow

Changes to color won't be visible, since text in the textarea covers colored text in the highlights.

Updating

Highlighting will automatically be updated as the user edits the contents of the textarea. But sometimes other scripts may directly change the contents of the textarea. In these cases, you can manually trigger a highlighting update.

$('.my-textarea').highlightWithinTextarea('update');

Destroying

You can remove the plugin from a textarea with this.

$('.my-textarea').highlightWithinTextarea('destroy');

More Repositories

1

wordpress-export-to-markdown

Converts a WordPress export XML file into Markdown files.
JavaScript
1,075
star
2

diff-cam-engine

Core engine for building motion detection web apps.
JavaScript
148
star
3

gist-syntax-themes

Collection of syntax theme stylesheets for GitHub Gists.
CSS
112
star
4

diff-cam-feed

Web app that uses motion detection to take a snapshot when something moves, then uploads the image to Twitter.
JavaScript
88
star
5

diff-cam-scratchpad

Various quick demos and experiments showing the concepts behind Diff Cam.
JavaScript
75
star
6

regex-storm

Regex Storm, online .NET-based regular expressions tester and resource.
C#
62
star
7

mini-preview

jQuery plugin for adding live mini-previews to links on hover.
JavaScript
57
star
8

hello-houdini

Some demos using Houdini's CSS Paint API.
HTML
56
star
9

atom-autocomplete-boilerplate

Boilerplate package for creating your own custom autocomplete provider for Atom.
JavaScript
34
star
10

background-scroll-physics

Nifty physics-based background scroll effects for your web pages.
26
star
11

atom-autocomplete-font-awesome

Font Awesome autocomplete and icon previews for Atom.
CSS
18
star
12

animation-workshop

Various demos highlighting CSS animation performance.
HTML
17
star
13

super-feed

Fetches content from various social media feeds to combine into one super feed.
C#
11
star
14

javascript-physics

2D physics JavaScript demos using Matter.js.
HTML
10
star
15

web-fish-daily

Web Fish Daily, site for sharing web dev links on a daily basis.
JavaScript
4
star
16

gist-to-prismjs

Converts embedded GitHub gists into PrismJS code blocks.
JavaScript
4
star
17

auto-cache-buster

Automatically generate cache-busting URLs when refreshing a page.
JavaScript
3
star
18

atom-autocomplete-math

Atom autocomplete package that solves math expressions.
JavaScript
2
star
19

heart-light

Simple Netlify site for controlling a light in the real world.
JavaScript
1
star
20

super-toast-story

Just a piece of toast, flying through space.
JavaScript
1
star