FanaHOVA/blazer

View on GitHub
app/assets/javascripts/blazer/selectize.js

Summary

Maintainability
F
2 wks
Test Coverage

File selectize.js has 2379 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * sifter.js
 * Copyright (c) 2013 Brian Reavis & contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
Severity: Major
Found in app/assets/javascripts/blazer/selectize.js - About 6 days to fix

    Function setup has 134 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        setup: function() {
          var self      = this;
          var settings  = self.settings;
          var eventNS   = self.eventNS;
          var $window   = $(window);
    Severity: Major
    Found in app/assets/javascripts/blazer/selectize.js - About 5 hrs to fix

      Function selectize has 115 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        $.fn.selectize = function(settings_user) {
          var defaults             = $.fn.selectize.defaults;
          var settings             = $.extend({}, defaults, settings_user);
          var attr_data            = settings.dataAttr;
          var field_label          = settings.labelField;
      Severity: Major
      Found in app/assets/javascripts/blazer/selectize.js - About 4 hrs to fix

        Function refreshOptions has 94 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            refreshOptions: function(triggerDropdown) {
              var i, j, k, n, groups, groups_order, option, option_html, optgroup, optgroups, html, html_children, has_create_option;
              var $active, $active_before, $create;
        
              if (typeof triggerDropdown === 'undefined') {
        Severity: Major
        Found in app/assets/javascripts/blazer/selectize.js - About 3 hrs to fix

          Function onKeyDown has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              onKeyDown: function(e) {
                var isInput = e.target === this.$control_input[0];
                var self = this;
          
                if (self.isLocked) {
          Severity: Major
          Found in app/assets/javascripts/blazer/selectize.js - About 3 hrs to fix

            Function getSortFunction has 65 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              Sifter.prototype.getSortFunction = function(search, options) {
                var i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort;
            
                self   = this;
                search = self.prepareSearch(search, options);
            Severity: Major
            Found in app/assets/javascripts/blazer/selectize.js - About 2 hrs to fix

              Function Selectize has 65 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                var Selectize = function($input, settings) {
                  var key, i, n, dir, input, self = this;
                  input = $input[0];
                  input.selectize = self;
              
              
              Severity: Major
              Found in app/assets/javascripts/blazer/selectize.js - About 2 hrs to fix

                Function init_select has 62 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    var init_select = function($input, settings_element) {
                      var i, n, tagName, $children, order = 0;
                      var options = settings_element.options;
                      var optionsMap = {};
                
                
                Severity: Major
                Found in app/assets/javascripts/blazer/selectize.js - About 2 hrs to fix

                  Function mixin has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    MicroPlugin.mixin = function(Interface) {
                      Interface.plugins = {};
                  
                      /**
                       * Initializes the listed plugins (with options).
                  Severity: Major
                  Found in app/assets/javascripts/blazer/selectize.js - About 2 hrs to fix

                    Function getScoreFunction has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      Sifter.prototype.getScoreFunction = function(search, options) {
                        var self, fields, tokens, token_count;
                    
                        self        = this;
                        search      = self.prepareSearch(search, options);
                    Severity: Major
                    Found in app/assets/javascripts/blazer/selectize.js - About 2 hrs to fix

                      Function setActiveItem has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          setActiveItem: function($item, e) {
                            var self = this;
                            var eventName;
                            var i, idx, begin, end, item, swap;
                            var $last;
                      Severity: Minor
                      Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                        Function autoGrow has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          var autoGrow = function($input) {
                            var currentWidth = null;
                        
                            var update = function(e, options) {
                              var value, keyCode, printable, placeholder, width;
                        Severity: Minor
                        Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                          Function deleteSelection has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              deleteSelection: function(e) {
                                var i, n, direction, selection, values, caret, option_select, $option_select, $tail;
                                var self = this;
                          
                                direction = (e && e.keyCode === KEY_BACKSPACE) ? -1 : 1;
                          Severity: Minor
                          Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                            Function update has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                var update = function(e, options) {
                                  var value, keyCode, printable, placeholder, width;
                                  var shift, character, selection;
                                  e = e || window.event || {};
                                  options = options || {};
                            Severity: Minor
                            Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                              Function addItem has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  addItem: function(value, silent) {
                                    var events = silent ? [] : ['change'];
                              
                                    debounce_events(this, events, function() {
                                      var $item, $option, $options;
                              Severity: Minor
                              Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                                Function updateOption has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    updateOption: function(value, data) {
                                      var self = this;
                                      var $item, $item_new;
                                      var value_new, index_item, cache_items, cache_options, order_old;
                                
                                
                                Severity: Minor
                                Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                                  Function createItem has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      createItem: function(input, triggerDropdown) {
                                        var self  = this;
                                        var caret = self.caretPos;
                                        input = input || $.trim(self.$control_input.val() || '');
                                  
                                  
                                  Severity: Minor
                                  Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                                    Consider simplifying this complex logical expression.
                                    Open

                                          if (e.type && e.type.toLowerCase() === 'keydown') {
                                            keyCode = e.keyCode;
                                            printable = (
                                              (keyCode >= 97 && keyCode <= 122) || // a-z
                                              (keyCode >= 65 && keyCode <= 90)  || // A-Z
                                    Severity: Critical
                                    Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                                      Function render has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          render: function(templateName, data) {
                                            var value, id, label;
                                            var html = '';
                                            var cache = false;
                                            var self = this;
                                      Severity: Minor
                                      Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

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

                                            Interface.prototype.initializePlugins = function(plugins) {
                                              var i, n, key;
                                              var self  = this;
                                              var queue = [];
                                        
                                        
                                        Severity: Minor
                                        Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

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

                                            var highlight = function($element, pattern) {
                                              if (typeof pattern === 'string' && !pattern.length) return;
                                              var regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern;
                                          
                                              var highlight = function(node) {
                                          Severity: Minor
                                          Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

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

                                                onBlur: function(e, dest) {
                                                  var self = this;
                                                  if (!self.isFocused) return;
                                                  self.isFocused = false;
                                            
                                            
                                            Severity: Minor
                                            Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                                              Function search has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                              Open

                                                Sifter.prototype.search = function(query, options) {
                                                  var self = this, value, score, search, calculateScore;
                                                  var fn_sort;
                                                  var fn_score;
                                              
                                              
                                              Severity: Minor
                                              Found in app/assets/javascripts/blazer/selectize.js - About 1 hr to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                          return;
                                                Severity: Major
                                                Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                            return;
                                                  Severity: Major
                                                  Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                              return;
                                                    Severity: Major
                                                    Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                return;
                                                      Severity: Major
                                                      Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                return;
                                                        Severity: Major
                                                        Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                    return;
                                                          Severity: Major
                                                          Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                      return;
                                                            Severity: Major
                                                            Found in app/assets/javascripts/blazer/selectize.js - About 30 mins to fix

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

                                                                  if (self.settings.optgroups) {
                                                                    for (i = 0, n = self.settings.optgroups.length; i < n; i++) {
                                                                      self.registerOptionGroup(self.settings.optgroups[i]);
                                                                    }
                                                                    delete self.settings.optgroups;
                                                              Severity: Major
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 3 hrs to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 1113..1118

                                                              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 95.

                                                              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

                                                                  if (self.settings.options) {
                                                                    for (i = 0, n = self.settings.options.length; i < n; i++) {
                                                                      self.registerOption(self.settings.options[i]);
                                                                    }
                                                                    delete self.settings.options;
                                                              Severity: Major
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 3 hrs to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 1121..1126

                                                              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 95.

                                                              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(root, factory) {
                                                                if (typeof define === 'function' && define.amd) {
                                                                  define('microplugin', factory);
                                                                } else if (typeof exports === 'object') {
                                                                  module.exports = factory();
                                                              Severity: Major
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 2 hrs to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 17..470

                                                              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 84.

                                                              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(root, factory) {
                                                                if (typeof define === 'function' && define.amd) {
                                                                  define('sifter', factory);
                                                                } else if (typeof exports === 'object') {
                                                                  module.exports = factory();
                                                              Severity: Major
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 2 hrs to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 490..608

                                                              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 84.

                                                              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

                                                                  self.lock = (function() {
                                                                    var original = self.lock;
                                                                    return function() {
                                                                      var sortable = self.$control.data('sortable');
                                                                      if (sortable) sortable.disable();
                                                              Severity: Major
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 2 hrs to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 3418..3425

                                                              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 83.

                                                              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

                                                                  self.unlock = (function() {
                                                                    var original = self.unlock;
                                                                    return function() {
                                                                      var sortable = self.$control.data('sortable');
                                                                      if (sortable) sortable.enable();
                                                              Severity: Major
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 2 hrs to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 3409..3416

                                                              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 83.

                                                              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

                                                                      } else if (y < scroll) {
                                                                        self.$dropdown_content.stop().animate({scrollTop: scroll_top}, animate ? self.settings.scrollDuration : 0);
                                                                      }
                                                              Severity: Minor
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 35 mins to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 1924..1928

                                                              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 47.

                                                              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

                                                                      if (y + height_item > height_menu + scroll) {
                                                                        self.$dropdown_content.stop().animate({scrollTop: scroll_bottom}, animate ? self.settings.scrollDuration : 0);
                                                                      } else if (y < scroll) {
                                                                        self.$dropdown_content.stop().animate({scrollTop: scroll_top}, animate ? self.settings.scrollDuration : 0);
                                                                      }
                                                              Severity: Minor
                                                              Found in app/assets/javascripts/blazer/selectize.js and 1 other location - About 35 mins to fix
                                                              app/assets/javascripts/blazer/selectize.js on lines 1926..1928

                                                              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 47.

                                                              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