Skip to content

Instantly share code, notes, and snippets.

@themasch
Created December 5, 2012 14:30
Show Gist options
  • Select an option

  • Save themasch/4215909 to your computer and use it in GitHub Desktop.

Select an option

Save themasch/4215909 to your computer and use it in GitHub Desktop.
security questions made easy (with bootstrap)
<a href="/delete/stuff" class="btn btn-delete" data-sure-text="sure?"> delete </a>
(function($) {
/**
* config: {
* dangerClass: 'btn-danger',
* sureTextDefault: 'sure?'
* }
* @param config
* @return {*}
*/
$.fn.usure = function(config) {
config = config || {};
config.dangerClass = config.dangerClass || 'btn-danger';
config.sureTextDefault = config.sureTextDefault || 'sure?';
return this.each(function(index, value) {
$(value).click(function(evt) {
var btn = $(this);
var text = btn.data('sure-text') ? btn.data('sure-text')
: config.sureTextDefault;
if(btn.data('sure') !== 'yes') {
btn.data('sure-old-text', btn.text())
.text(text)
.addClass('btn-danger')
.data('sure', 'yes');
setTimeout(function() {
btn.text( btn.data('sure-old-text') )
.removeClass('btn-danger')
.data('sure', 'no');
}, 2000);
evt.preventDefault();
return false;
}
});
})
}
})(jQuery);
$(function() {
$('.btn-delete').usure();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment