Coder Social home page Coder Social logo

intercept's Introduction

Intercept

INTERCEPT is a module that allows you to register event callbacks to be fired on elements that match provided selectors as they are added to the DOM.

jQuery is a dependency for this module.

INTERCEPT.regester is the method you use to register your callbacks. The first time this method is called, a MutationObserver object is created and is instructed to observe document.body for changes. This means that you can not call this method until document.body exists. For this reason, it is recommened that you place your calls in jQuery's $(document).ready() callback.


####Intercept.register Parameters: The method takes a single parameter, which is an object that acts as a list of options.

  • selector [String] :

  • Required, no default value.

  • String used as jQuery selector. All elements matching this selector will be passed as a parameter to the provided callback function one at a time.

  • callback [Function] :

  • Required, no default value.

  • Function callback. Receives a single element as a parameter. Called one time for every element that is inserted into the DOM and matches selector. Under default behavior, all existing elements that match the provided selector will be passed in as well. To avoid this, set new_only to true.

  • new_only [Boolean] :

  • Optional, default: false.

  • If this parameter is not explicitly set to true, then at the time of invocation, all elements which are already inserted into the DOM that match selector will be passed as individual parameters to callback. In the author's experience, this is usually the desired behavior.


####Examples:

  $(document).ready(function () {
	
	INTERCEPT.register({ 
		selector: '*',
		callback: function(element) {
			console.log(element); 
		}
	});
	
});

In the above example, every child of document.body and all of their descendents will be logged to console. Any new nodes that are inserted during runtime will also be logged to console.

  $(document).ready(function () {
	
	INTERCEPT.register({ 
		selector: '.my-class',
		callback: function(element) {
			console.log(element); 
		},
		new_only: true
	});
	
});

In the above example, elements that are added to the DOM at run time and match the .my-class selector will be logged to console. Any instances of my-class that existed prior to the invocation of this method will not be logged, because new_only is set to true.

intercept's People

Watchers

 avatar  avatar

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.