| Conditions | 1 |
| Paths | 16 |
| Total Lines | 101 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // Copyright Zikula Foundation, licensed MIT. |
||
| 3 | ( function($) { |
||
| 4 | |||
| 5 | // use bootstrap noConflict. See http://getbootstrap.com/javascript/#js-noconflict |
||
| 6 | var bootstrapButton = $.fn.button.noConflict() |
||
| 7 | $.fn.bootstrapBtn = bootstrapButton |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Confirmation modal |
||
| 11 | * |
||
| 12 | * Usage: <a data-toggle="confirmation" data-title="..." data-text="..." href="...">...</a> |
||
| 13 | */ |
||
| 14 | $(document).on('click.bs.modal.data-api', '[data-toggle="confirmation"]', function (e) { |
||
| 15 | |||
| 16 | e.preventDefault(); |
||
| 17 | |||
| 18 | var $this = $(this); |
||
| 19 | var title = $this.data('title') || ''; |
||
| 20 | var text = $this.data('text') || ''; |
||
| 21 | |||
| 22 | if ($("#confimationModal").length === 0) { |
||
| 23 | var Modal = '<div class="modal fade" id="confimationModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h4 class="modal-title">'+title+'</h4></div><div class="modal-body">' + text + '</div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">' + Zikula.__('No') + '</button><button id="confirmationOkButton" type="button" class="btn btn-primary" data-dismiss="modal">' + Zikula.__('Yes') + '</button></div></div></div></div>'; |
||
|
|
|||
| 24 | $(document.body).append(Modal); |
||
| 25 | $(document).on('click', '#confirmationOkButton', function (e) { |
||
| 26 | window.location = $this.attr('href'); |
||
| 27 | }); |
||
| 28 | } |
||
| 29 | |||
| 30 | $('#confimationModal').modal({}, this).one('hide', function () { |
||
| 31 | $this.is(':visible') && $this.focus(); |
||
| 32 | }); |
||
| 33 | }); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Return a value of input. |
||
| 37 | * |
||
| 38 | * @param element e The input element |
||
| 39 | * |
||
| 40 | * @return string Value |
||
| 41 | */ |
||
| 42 | function getValueOfElement(e) { |
||
| 43 | if ($(e).is(':checkbox')) { |
||
| 44 | return $(e).is(':checked') ? '1' : '0'; |
||
| 45 | } else if ($(e).is(':radio')) { |
||
| 46 | var name = $(e).attr('name'); |
||
| 47 | return $('input[name="' + name + '"]:checked').val(); |
||
| 48 | } else { |
||
| 49 | return $(e).val(); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | $(document).ready(function() { |
||
| 54 | |||
| 55 | |||
| 56 | // remove class hide because bootstrap is using important, that is not |
||
| 57 | // working with jQuery.show(); |
||
| 58 | // $('.hide').hide().removeClass('hide'); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Input switch container. |
||
| 62 | * |
||
| 63 | * This code shows/hide an container dependent on a value of an input |
||
| 64 | * element. |
||
| 65 | * |
||
| 66 | * Example: |
||
| 67 | * <input type="text" name="abc" value="a"> |
||
| 68 | * <div data-switch="abc" data-switch-value="a">...</div> |
||
| 69 | * |
||
| 70 | * This example shows the div container if the input value is equal "a" |
||
| 71 | */ |
||
| 72 | $('[data-switch]').each(function() { |
||
| 73 | var containerElement = $(this); |
||
| 74 | var containerValues = containerElement.data('switch-value') || '0'; |
||
| 75 | containerValues = containerValues.toString(); |
||
| 76 | containerValues = containerValues.split(','); |
||
| 77 | var inputName = containerElement.data('switch'); |
||
| 78 | var inputElement = $('[name="'+inputName+'"]'); |
||
| 79 | |||
| 80 | var inputValue = getValueOfElement(inputElement); |
||
| 81 | if ($.inArray(inputValue, containerValues) === -1) { |
||
| 82 | containerElement.hide(); |
||
| 83 | } |
||
| 84 | |||
| 85 | inputElement.change(function() { |
||
| 86 | inputValue = getValueOfElement(inputElement); |
||
| 87 | if ($.inArray(inputValue, containerValues) === -1) { |
||
| 88 | containerElement.slideUp(); |
||
| 89 | } else { |
||
| 90 | containerElement.slideDown(); |
||
| 91 | } |
||
| 92 | }); |
||
| 93 | }); |
||
| 94 | |||
| 95 | $('.tooltips').each(function() { |
||
| 96 | var placement = 'top'; |
||
| 97 | if ($(this).hasClass('tooltips-bottom')) { |
||
| 98 | placement = 'bottom'; |
||
| 99 | } |
||
| 100 | $(this).tooltip({placement: placement, animation: false}); |
||
| 101 | }); |
||
| 102 | }); |
||
| 103 | })(jQuery); |
||
| 104 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.