| 1 | /** |
| 2 | * This is a jQuery plugin which adds some helpers for the setup UI. |
| 3 | */ |
| 4 | (function($){ |
| 5 | /** |
| 6 | * Enable or disable an error message. |
| 7 | * |
| 8 | * <p id="my-error-message">The world is one fire.</p> |
| 9 | * Ex: $('#my-error-message').toggleError(false) |
| 10 | * |
| 11 | * @param bool isError |
| 12 | */ |
| 13 | $.fn.toggleError = function (isError) { |
| 14 | this.toggleClass('install-validate-ok', !isError) |
| 15 | .toggleClass('install-validate-bad', isError) |
| 16 | .toggleClass('error', isError); |
| 17 | |
| 18 | var errors = $('.install-validate-bad'); |
| 19 | $('#install_button').prop('disabled', errors.length > 0); |
| 20 | return this; |
| 21 | }; |
| 22 | |
| 23 | /** |
| 24 | * Ex: $('.watch-these').useValidator(function(){ |
| 25 | * $('#some-error-message').toggleError(booleanExpression); |
| 26 | * }) |
| 27 | * @param cb |
| 28 | */ |
| 29 | $.fn.useValidator = function(cb) { |
| 30 | cb(); |
| 31 | this.on('change', cb); |
| 32 | return this; |
| 33 | }; |
| 34 | })(jQuery); |