Created
December 5, 2012 14:30
-
-
Save themasch/4215909 to your computer and use it in GitHub Desktop.
security questions made easy (with bootstrap)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="/delete/stuff" class="btn btn-delete" data-sure-text="sure?"> delete </a> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function() { | |
| $('.btn-delete').usure(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment