onijim/owl-table

View on GitHub
lib/swift-box.js

Summary

Maintainability
F
1 wk
Test Coverage

File swift-box.js has 1379 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * SwiftBox
 * A lightweight combobox plugin for jQuery
 * https://github.com/Knotix/SwiftBox/
 *
Severity: Major
Found in lib/swift-box.js - About 3 days to fix

    Function setSelectedIndexes has 82 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function setSelectedIndexes(elements, indexes, trigger_change) {
            elements = normalizeElementArray(elements);
    
            if(indexes === undefined || indexes === null) {
                indexes = [];
    Severity: Major
    Found in lib/swift-box.js - About 3 hrs to fix

      Function normalizeOptionArray has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function normalizeOptionArray(option_array, sort_function, remove_duplicates) {
              if(option_array === undefined || option_array === null) {
                  option_array = [];
              }
      
      
      Severity: Major
      Found in lib/swift-box.js - About 2 hrs to fix

        Function swiftbox has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function swiftbox(elements, config) {
                elements = normalizeElementArray(elements);
        
                var new_elements = [];
        
        
        Severity: Major
        Found in lib/swift-box.js - About 2 hrs to fix

          Function showOptions has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function showOptions(element) {
                  element = normalizeElementArray(element)[0];
          
                  // If the element is already active, we're done
                  if(active_select === element) {
          Severity: Minor
          Found in lib/swift-box.js - About 1 hr to fix

            Function positionOptions has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function positionOptions() {
                    var bounding_rectangle = active_select.getBoundingClientRect();
                    var window_width       = window.innerWidth;
                    var window_height      = window.innerHeight;
            
            
            Severity: Minor
            Found in lib/swift-box.js - About 1 hr to fix

              Function calculateWidth has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function calculateWidth(element, option_array) {
                      element = normalizeElementArray(element)[0];
              
                      if(!element || !option_array || !option_array.length) {
                          return 0;
              Severity: Minor
              Found in lib/swift-box.js - About 1 hr to fix

                Function setValues has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    function setValues(elements, values, trigger_change) {
                        elements = normalizeElementArray(elements);
                
                        if(!(values instanceof Array)) {
                            values = [values];
                Severity: Minor
                Found in lib/swift-box.js - About 1 hr to fix

                  Function selectAll has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      function selectAll(elements, filtered) {
                          elements = normalizeElementArray(elements);
                  
                          for(var i = 0; i < elements.length; ++i) {
                              var element = elements[i];
                  Severity: Minor
                  Found in lib/swift-box.js - About 1 hr to fix

                    Function filterOptions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        function filterOptions(filter_text) {
                            // Normalize the filter text
                            if(filter_text === undefined || filter_text === null) {
                                filter_text = '';
                            }
                    Severity: Minor
                    Found in lib/swift-box.js - About 1 hr to fix

                      Function renderOptions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          function renderOptions(scroll_top) {
                              // Hide all options initially
                              $option_elements.addClass('swift-box-hidden');
                      
                              // If there are no options, we're done
                      Severity: Minor
                      Found in lib/swift-box.js - About 1 hr to fix

                        Function setOptionHash has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            function setOptionHash(elements, hash) {
                                elements = normalizeElementArray(elements);
                                var option_array = option_arrays[hash];
                        
                                if(hash === undefined || hash === null) {
                        Severity: Minor
                        Found in lib/swift-box.js - About 1 hr to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  if(new_indexes[j] !== selected_indexes[j]) {
                                                      changed = true;
                                                      break;
                                                  }
                          Severity: Major
                          Found in lib/swift-box.js - About 45 mins to fix

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                        for(var j = 0; j < new_indexes.length; ++j) {
                                            var index  = new_indexes[j];
                                            var option = option_array[index];
                            
                                            if(option) {
                            Severity: Major
                            Found in lib/swift-box.js and 2 other locations - About 1 hr to fix
                            lib/swift-box.js on lines 1725..1732
                            lib/swift-box.js on lines 2011..2018

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 71.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                    for(var i = 0; i < selected_indexes.length; ++i) {
                                        var index  = selected_indexes[i];
                                        var option = option_array[index];
                            
                                        if(option) {
                            Severity: Major
                            Found in lib/swift-box.js and 2 other locations - About 1 hr to fix
                            lib/swift-box.js on lines 1725..1732
                            lib/swift-box.js on lines 1879..1886

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 71.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                    for(var i = 0; i < selected_indexes.length; ++i) {
                                        var index  = selected_indexes[i];
                                        var option = option_array[index];
                            
                                        if(option) {
                            Severity: Major
                            Found in lib/swift-box.js and 2 other locations - About 1 hr to fix
                            lib/swift-box.js on lines 1879..1886
                            lib/swift-box.js on lines 2011..2018

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 71.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                    for(var i = 0; i < elements.length; ++i) {
                                        var element = elements[i];
                                        var text_element = getElementCache(element).text;
                            
                                        text_element[textContent] = text;
                            Severity: Major
                            Found in lib/swift-box.js and 1 other location - About 1 hr to fix
                            lib/swift-box.js on lines 1687..1692

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 64.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                    for(var i = 0; i < elements.length; ++i) {
                                        var element           = elements[i];
                                        var container_element = getElementCache(element).container;
                            
                                        container_element.tabIndex = tab_index;
                            Severity: Major
                            Found in lib/swift-box.js and 1 other location - About 1 hr to fix
                            lib/swift-box.js on lines 1972..1977

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 64.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 5 locations. Consider refactoring.
                            Open

                                swiftbox.text = function(elements) {
                                    if(arguments.length <= 1) {
                                        return getText(elements);
                                    }
                            
                            
                            Severity: Major
                            Found in lib/swift-box.js and 4 other locations - About 55 mins to fix
                            lib/swift-box.js on lines 2152..2159
                            lib/swift-box.js on lines 2236..2243
                            lib/swift-box.js on lines 2245..2252
                            lib/swift-box.js on lines 2254..2261

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 54.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 5 locations. Consider refactoring.
                            Open

                                swiftbox.optionHash = function(elements) {
                                    if(arguments.length <= 1) {
                                        return getOptionHash(elements);
                                    }
                            
                            
                            Severity: Major
                            Found in lib/swift-box.js and 4 other locations - About 55 mins to fix
                            lib/swift-box.js on lines 2217..2224
                            lib/swift-box.js on lines 2236..2243
                            lib/swift-box.js on lines 2245..2252
                            lib/swift-box.js on lines 2254..2261

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 54.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 5 locations. Consider refactoring.
                            Open

                                swiftbox.multiple = function(elements) {
                                    if(arguments.length <= 1) {
                                        return getMultiple(elements);
                                    }
                            
                            
                            Severity: Major
                            Found in lib/swift-box.js and 4 other locations - About 55 mins to fix
                            lib/swift-box.js on lines 2152..2159
                            lib/swift-box.js on lines 2217..2224
                            lib/swift-box.js on lines 2236..2243
                            lib/swift-box.js on lines 2254..2261

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 54.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 5 locations. Consider refactoring.
                            Open

                                swiftbox.tabIndex = function(elements) {
                                    if(arguments.length <= 1) {
                                        return getTabIndex(elements);
                                    }
                            
                            
                            Severity: Major
                            Found in lib/swift-box.js and 4 other locations - About 55 mins to fix
                            lib/swift-box.js on lines 2152..2159
                            lib/swift-box.js on lines 2217..2224
                            lib/swift-box.js on lines 2245..2252
                            lib/swift-box.js on lines 2254..2261

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 54.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 5 locations. Consider refactoring.
                            Open

                                swiftbox.disabled = function(elements) {
                                    if(arguments.length <= 1) {
                                        return getDisabled(elements);
                                    }
                            
                            
                            Severity: Major
                            Found in lib/swift-box.js and 4 other locations - About 55 mins to fix
                            lib/swift-box.js on lines 2152..2159
                            lib/swift-box.js on lines 2217..2224
                            lib/swift-box.js on lines 2236..2243
                            lib/swift-box.js on lines 2245..2252

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 54.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                function removeFocusClass(element) {
                                    var container_element = getElementCache(element).container;
                            
                                    $(element).removeClass('swift-box-focus');
                                    $(container_element).removeClass('swift-box-focus');
                            Severity: Minor
                            Found in lib/swift-box.js and 1 other location - About 40 mins to fix
                            lib/swift-box.js on lines 2051..2056

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 49.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                function addFocusClass(element) {
                                    var container_element = getElementCache(element).container;
                            
                                    $(element).addClass('swift-box-focus');
                                    $(container_element).addClass('swift-box-focus');
                            Severity: Minor
                            Found in lib/swift-box.js and 1 other location - About 40 mins to fix
                            lib/swift-box.js on lines 2062..2067

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 49.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                function focus(element) {
                                    var container_element = getElementCache(element).container;
                            
                                    if(container_element) {
                                        container_element.focus();
                            Severity: Minor
                            Found in lib/swift-box.js and 1 other location - About 30 mins to fix
                            lib/swift-box.js on lines 2039..2045

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 45.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                function blur(element) {
                                    var container_element = getElementCache(element).container;
                            
                                    if(container_element) {
                                        container_element.blur();
                            Severity: Minor
                            Found in lib/swift-box.js and 1 other location - About 30 mins to fix
                            lib/swift-box.js on lines 2027..2033

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 45.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            There are no issues that match your filters.

                            Category
                            Status