Giter VIP home page Giter VIP logo

dom-filter's Introduction

DOM Filter class

Provides a simple interface for filtering a list of dom nodes.

Filtering a list of nodes in a ul

Example usage:

Basic, search input at top:

new DomFilter({
	insertBefore : 'nav ul',
	filterNodes : 'nav ul li'
});

Basic, search input at bottom:

new DomFilter({
	insertAfter : 'nav ul',
	filterNodes : 'nav ul li'
});

Altering the text used on the filter

new DomFilter({
	insertBefore : 'nav ul',
	filterNodes : 'nav ul li',
	strings: {
			'en': {
				'feedback': {
					'no_results'              : 'No matches',
					'default_feedback_message': ''
				},
				'input'   : {
					'placeholder': 'Search',
					'label'      : '&#1F50D;:'
				}
			}
		}
});

Custom match function (matching title as well as text content):

Custom filter function

new DomFilter({
	insertBefore : 'nav ul',
	filterNodes : 'nav ul li',
	/**
	 *
	 * @param node
	 * @param searchText
	 * @returns {boolean}
	 */
	matchFunction  : function ( node, searchText ) {
		var title = node.getAttribute('title'),
			nodeText = node.innerText.toLocaleLowerCase();
		searchText = searchText.toLocaleLowerCase();


		if ( typeof title !== 'string' ) {
			title = '';
		}

		title = title.toLocaleLowerCase();

		return (title.indexOf(searchText) > -1) || (nodeText.indexOf(searchText) > -1);
	}
});

Multiple filters on the same page, including tables

new DomFilter({
	insertBefore : '.primary-nav ul',
	filterNodes : '.primary-nav ul li'
});

new DomFilter({
	insertBefore : '.secondary-nav ul',
	filterNodes : '.secondary-nav ul li'
});

new DomFilter({
	insertBefore : '.datatable',
	filterNodes : '.datatable tbody > tr'
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.