Skip to content

Instantly share code, notes, and snippets.

@aaronmccall
Created September 22, 2014 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aaronmccall/24e44b7096e4c87c6d08 to your computer and use it in GitHub Desktop.
Save aaronmccall/24e44b7096e4c87c6d08 to your computer and use it in GitHub Desktop.
init jquery ui widget on first click
<input class="addDatepicker" name="date">
<span class="dialogControl" id="question" data-dialogTarget="#answer">?</span>
<div class="dialogContent" id="answer">
<!-- dialog content here -->
</div>
$(document).ready(function (){
$('.addDatepicker').on('click', function () {
// If we're not actually a datepicker yet, make us one.
if ($(this).not(':data(datepicker)')) {
$(this).datepicker({
// my datepicker options
});
}
});
$('.dialogControl').on('click', function () {
var $target = $($(this).data('dialogTarget'));
if ($target.length) {
if ($target.not(':data(dialog)'))) {
$target.dialog({
// my dialog options
});
}
$target.dialog("open");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment