How can I extend jQueryUI datepicker to accept an additional argument?

How about: var __picker = $.fn.datepicker; $.fn.datepicker = function(options) { __picker.apply(this, [options]); var $self = this; if (options && options.trigger) { $(options.trigger).bind(“click”, function () { $self.datepicker(“show”); }); } } Usage: $(“#date”).datepicker({ trigger: “#button” }); $(“#date2”).datepicker({ trigger: “#button2” }); Example: http://jsfiddle.net/gduhm/ Or, less intrusively with your own jQuery plugin: $.widget(“ui.datepicker2”, { _init: function() { var $el … Read more

Implementing jquery UI autocomplete to show suggestions when you type “@”

You can do this by providing a function to the source option of autocomplete: var availableTags = [ /* Snip */]; function split(val) { return val.split(/@\s*/); } function extractLast(term) { return split(term).pop(); } $(“#tags”) // don’t navigate away from the field on tab when selecting an item .bind(“keydown”, function(event) { if (event.keyCode === $.ui.keyCode.TAB && … Read more

How to detect an audio has finished playing in a web page?

If you are using the html5 audio tag, there is the “onended” event handler. I don´t know if the browsers support it yet. Something like: <audio src=”https://stackoverflow.com/questions/4619917/xpto.mp3″ onended=”DoSomething();”></audio> In the last case you can use a swf that can play the sound, and alert your javascript when it reaches the end.

Can jQuery add commas while user typing numbers?

Run the code snippet to see it work $(‘input.number’).keyup(function(event) { // skip for arrow keys if(event.which >= 37 && event.which <= 40) return; // format number $(this).val(function(index, value) { return value .replace(/\D/g, “”) .replace(/\B(?=(\d{3})+(?!\d))/g, “,”) ; }); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js”></script> <input class=”number”>