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

jquitelight

v2.1.0

Published

Smart jQuery Search Highlight Plugin

Downloads

85

Readme

jQuiteLight

jQuery Smart Search Query Highlight Plugin

Features

  • Works with Regular Expressions.
  • An array of search queries can be applied at once.
  • Smart highlight logic is included.
  • Additional logic can be applied using beforeMark property.
  • Each highlight is held separately, so it is easy to remove highlight by index.

Installation

Installing using node package manager.
Type the following in your console inside your project directory:

npm install jquitelight

If you have bower installed in your pc, you can install it with command:

bower install jquitelight

Inline HTML including

<!-- Note: jQuery version should not be less than 1.6 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script src="path/to/plugin/jquitelight.js"></script>

Usage


// basic highlighting
$(".element-to-be-highlighted").mark("text to be highlighted here");

// With RegExp
$(".element-to-be-highlighted").mark(new RegExp("/test.{1,2}/"));

// An array of queries
$(".element-to-be-highlighted").mark(["test", "another-test"]);

// Using options
$(".element-to-be-highlighted").mark(["test", "another-test"], {
	markData: {
		"class": "my-highlight"
	},
	ignoreCase: false
});
// To remove highlight use:
// Get array of highlights
var HIGHLIGHTS = $(".element-to-be-highlighted").data("marker");
// Destroy
HIGHLIGHTS[0].destroy();

Resolving plugin conflicts

// if you have another plugin with such jQuery method
// you can get overridden method by using noConflict method
var prevMarkMethod = $.fn.mark.noConflict();
$.fn.mark.myCoolMark = prevMarkMethod;

Making changes into plugin

// starting from version v1.2.0 plugin core object is linked to jQuery method
var plugin = $.fn.mark.Marker,
	oldWrapStringMethod = plugin.prototype.wrapString;
plugin.prototype.wrapString = function (content) {
	console.log(content);
	return oldWrapStringMethod.call(this, content);
}

Advanced usage (tricks)

// starting version 2.0.0
// make some strings inside the text links with specific url
$(".some-content").mark([
	{
		query: "test",
		markData: {
			href: "http://www.example.com/test"
		}
	},
	{
		query: "another-test",
		markData: {
			href: "/under-domain-link"
        }
	},
	{
        query: "strict lower case text",
        ignoreCase: false,
        markData: {
            title: "advanced usage test",
            href: "/strict-lower-case"
        }
    }], {
	markData: {
		"class": "linked"
	},
	markTag: "a",
	ignoreCase: true
});

// excluding some sensitive words from matching when using together with smart behaviour
$(".text-container").mark("each word occurence from this sentence should be highlighted".split(" "), {
	useSmartBehavior: true,
	beforeMark: function (match) {
		// exclude words "bee" and "teach" 
		return match !== "bee" && match !== "teach";	
	}
});

Options

skippedTags
Type: array
Default: ["script", "style"]
Expected an array of strings with HTML tag names that should be skipped on highlighting (in lower case).

ignoreCase
Type: bool
Default: true
Expected a boolean value for ignoring query matching case.

useSmartBehavior
Type: bool
Default: false
Expected a boolean value for using RegExp extending function for string queries.

beforeMark
Type: Function
Default: function (text) { return true; }
Function deciding match highlight. Accepts a matched string. Should return a boolean value.

afterMark
Type: Function
Default: function (element) {}
Function for manipulating with highlight. Accepts a jQuery element (wrapper of current match).

markTag
Type: String
Default: "span"
Name of an HTML tag for wrapping matches.

markData
Notice: DEPRECATED
Type: Object
Default: { "class": "marked-text" }
Attributes to be applied for wrapper.

markCss
Type: Object
Default: {}
Css properties to be applied for wrapper.