Coder Social home page Coder Social logo

jquery-ante's Introduction

jQuery Ante (jquery-ante)

jQuery Ante will bind events to execute before any bound jQuery event.

Demo

A quick example of preloading content before showing it as a modal: http://acavailhez.github.io/jquery-ante/demo.html

Super quick example

var $a = $('#link');
$a.click(function(){
	alert('executed after');
});
$a.ante('click',function(){
	alert('executed before');
});

In this example, clicking on the #link will show the "executed before" alert before showing the "executed after"

Quick example

The real power of jquery-ante comes when you associate it with asynchronous events (such as AJAX calls, or any jQuery Promise)

Imagine you have a button to display a modal, but the modal content is not yet in the DOM and needs to be fetched through an API call

<a id="show-modal-button">Show the modal</a>
//show the modal on click
$('#show-modal-button').on('click',function(){
	$('#modal').modal('show');
});

//before showing the modal, fetch the modal content with an api call
$('#show-modal-button').ante('click',function(){
	return $.ajax({
		url:'/modal-content',
		dataType:'html',
		success:function(html){
			$('body').append(html);
			//now the content of the modal is in the DOM and can be shown
		}
	});
});

When clicking the button, the ajax call will be made and the page will wait for the html to be added to the DOM before displaying the modal

jquery-ante's People

Watchers

James Cloos avatar Arnaud CAVAILHEZ 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.