ImpressCMS/impresscms

View on GitHub
htdocs/themes/reflex/js/jquery.keynav.js

Summary

Maintainability
D
2 days
Test Coverage

Function keynav has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  $.fn.keynav = function (onClass,offClass) {
      //Initialization
      var kn = $.keynav;
      if(!kn.init) {
          kn.el = new Array();
Severity: Minor
Found in htdocs/themes/reflex/js/jquery.keynav.js - About 1 hr to fix

    Function getPos has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      $.keynav.getPos = function (e)
      {
        var l = 0;
        var t  = 0;
        var w = $.intval($.css(e,'width'));
    Severity: Minor
    Found in htdocs/themes/reflex/js/jquery.keynav.js - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

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

      $.keynav.goLeft = function () {
          var cur = $.keynav.getCurrent();
          var quad = $.keynav.quad(cur,function (dx,dy) { 
                                            if((dy >= 0) && (Math.abs(dx) - dy) <= 0)
                                                return true;    
    Severity: Major
    Found in htdocs/themes/reflex/js/jquery.keynav.js and 3 other locations - About 4 hrs to fix
    htdocs/themes/reflex/js/jquery.keynav.js on lines 133..142
    htdocs/themes/reflex/js/jquery.keynav.js on lines 144..153
    htdocs/themes/reflex/js/jquery.keynav.js on lines 155..164

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

    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 4 locations. Consider refactoring.
    Open

      $.keynav.goRight = function () {
          var cur = $.keynav.getCurrent();
          var quad = $.keynav.quad(cur,function (dx,dy) { 
                                            if((dy <= 0) && (Math.abs(dx) + dy) <= 0)
                                                return true;    
    Severity: Major
    Found in htdocs/themes/reflex/js/jquery.keynav.js and 3 other locations - About 4 hrs to fix
    htdocs/themes/reflex/js/jquery.keynav.js on lines 123..132
    htdocs/themes/reflex/js/jquery.keynav.js on lines 144..153
    htdocs/themes/reflex/js/jquery.keynav.js on lines 155..164

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

    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 4 locations. Consider refactoring.
    Open

      $.keynav.goUp = function () {
          var cur = $.keynav.getCurrent();
          var quad = $.keynav.quad(cur,function (dx,dy) { 
                                            if((dx >= 0) && (Math.abs(dy) - dx) <= 0)
                                                return true;    
    Severity: Major
    Found in htdocs/themes/reflex/js/jquery.keynav.js and 3 other locations - About 4 hrs to fix
    htdocs/themes/reflex/js/jquery.keynav.js on lines 123..132
    htdocs/themes/reflex/js/jquery.keynav.js on lines 133..142
    htdocs/themes/reflex/js/jquery.keynav.js on lines 155..164

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

    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 4 locations. Consider refactoring.
    Open

      $.keynav.goDown = function () {
          var cur = $.keynav.getCurrent();
          var quad = $.keynav.quad(cur,function (dx,dy) { 
                                            if((dx <= 0) && (Math.abs(dy) + dx) <= 0)
                                                return true;    
    Severity: Major
    Found in htdocs/themes/reflex/js/jquery.keynav.js and 3 other locations - About 4 hrs to fix
    htdocs/themes/reflex/js/jquery.keynav.js on lines 123..132
    htdocs/themes/reflex/js/jquery.keynav.js on lines 133..142
    htdocs/themes/reflex/js/jquery.keynav.js on lines 144..153

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

    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

    Unexpected spaces found.
    Open

                      break;

    Unexpected spaces found.
    Open

          });

    Unexpected spaces found.
    Open

      $.fn.keynav_sethover = function(onClass,offClass) {

    Unexpected spaces found.
    Open

          return this.each(function() {

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

          var cur = $.keynav.getCurrent();

    Unexpected spaces found.
    Open

          if(kn.currentEl) {

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected spaces found.
    Open

          if (e == null) {

    Unexpected spaces found.
    Open

                      $.keynav.goLeft();

    Unexpected spaces found.
    Open

                      break;

    Unexpected spaces found.
    Open

          });

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected spaces found.
    Open

          if(found)

    Unexpected spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected spaces found.
    Open

      $.keynav = new Object();

    Unexpected spaces found.
    Open

            key = e.which;

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected spaces found.
    Open

        $(e).removeClass(e.offClass).addClass(e.onClass);

    Unexpected spaces found.
    Open

          kn.currentEl = e;

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

          if(!kn.init) {

    Unexpected spaces found.
    Open

          var key = 0;

    Unexpected trailing spaces found.
    Open

                    case 39: 

    Unexpected spaces found.
    Open

                      $.keynav.goDown();

    Unexpected spaces found.
    Open

          //Initialization

    Unexpected spaces found.
    Open

                      $.keynav.goUp();

    Unexpected spaces found.
    Open

                      break;

    Unexpected spaces found.
    Open

      $.keynav.reset = function() {

    Unexpected spaces found.
    Open

          e.pos = $.keynav.getPos(e);

    Unexpected spaces found.
    Open

          kn.el.push(e);

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

      }

    Unexpected trailing spaces found.
    Open

                                                return true;    

    Unexpected spaces found.
    Open

          } else { // mozilla

    Unexpected spaces found.
    Open

                      $.keynav.goRight();

    Unexpected spaces found.
    Open

              kn.init = true;

    Unexpected spaces found.
    Open

          }

    Unexpected spaces found.
    Open

        l += e.offsetLeft + (e.currentStyle?$.intval(e.currentStyle.borderLeftWidth):0);

    Unexpected spaces found.
    Open

        return isNaN(v) ? 0 : v;

    Unexpected spaces found.
    Open

          }

    Unexpected trailing spaces found.
    Open

                    case 40: 

    Unexpected spaces found.
    Open

      $.keynav.reg = function(e,onClass,offClass) {

    Unexpected spaces found.
    Open

          $(cur).trigger('blur');

    Unexpected spaces found.
    Open

          }

    Unexpected spaces found.
    Open

          var cur = $.keynav.getCurrent();

    Unexpected spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected spaces found.
    Open

          var cur = $.keynav.getCurrent();

    Unexpected trailing spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected trailing spaces found.
    Open

                                                return true;    

    Unexpected spaces found.
    Open

            l += e.offsetLeft + (e.currentStyle?$.intval(e.currentStyle.borderLeftWidth):0);

    Unexpected spaces found.
    Open

                      break;

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

          $.keynav.activateClosest(cur,quad);

    Unexpected spaces found.
    Open

      /**

    Unexpected spaces found.
    Open

        var l = 0;

    Unexpected spaces found.
    Open

        var h = $.intval($.css(e,'height'));

    Unexpected spaces found.
    Open

          return quad;

    Unexpected spaces found.
    Open

                                       });

    Unexpected spaces found.
    Open

          $.keynav.activateClosest(cur,quad);

    Unexpected spaces found.
    Open

      $.keynav.goDown = function () {

    Unexpected spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected spaces found.
    Open

      $.keynav.activate = function () {

    Unexpected spaces found.
    Open

      $.intval = function (v)

    Unexpected trailing spaces found.
    Open

                    case 38: 

    Unexpected spaces found.
    Open

          $(e).trigger('focus');

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

          }

    Unexpected spaces found.
    Open

          else {

    Unexpected spaces found.
    Open

                                       });

    Unexpected trailing spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected spaces found.
    Open

      $.keynav.getPos = function (e)

    Unexpected spaces found.
    Open

        var w = $.intval($.css(e,'width'));

    Unexpected spaces found.
    Open

              $(document).keydown(function(e) {

    Unexpected spaces found.
    Open

      $.keynav.getCurrent = function () {

    Unexpected spaces found.
    Open

        while (e.offsetParent){

    Unexpected spaces found.
    Open

        }

    Unexpected spaces found.
    Open

      /**

    Unexpected spaces found.
    Open

              kn.el = new Array();

    Unexpected trailing spaces found.
    Open

                    case 37: 

    Unexpected spaces found.
    Open

                      $.keynav.activate();

    Unexpected spaces found.
    Open

          return this.each(function() {

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

      $.keynav.setActive = function(e) {

    Unexpected spaces found.
    Open

          for(var i=0;i<kn.el.length;i++) {

    Unexpected spaces found.
    Open

          for(i=0;i<kn.el.length;i++) {

    Unexpected spaces found.
    Open

      $.keynav.goRight = function () {

    Unexpected spaces found.
    Open

          var cur = $.keynav.getCurrent();

    Unexpected spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected trailing spaces found.
    Open

       * 

    Unexpected spaces found.
    Open

        v = parseInt(v);

    Unexpected spaces found.
    Open

      };

    Unexpected spaces found.
    Open

      $.fn.keynav = function (onClass,offClass) {

    Unexpected spaces found.
    Open

          e.onClass = onClass;

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected spaces found.
    Open

              var cur = kn.el[0];

    Unexpected spaces found.
    Open

          }

    Unexpected spaces found.
    Open

          $.keynav.activateClosest(cur,quad);

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

        t += e.offsetTop  + (e.currentStyle?$.intval(e.currentStyle.borderTopWidth):0);

    Unexpected spaces found.
    Open

        return {x:l, y:t, w:w, h:h, cx:cx, cy:cy};

    Unexpected spaces found.
    Open

      {

    Unexpected spaces found.
    Open

                      break;

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

          e.offClass = offClass;

    Unexpected spaces found.
    Open

          e.onmouseover = function (e) { $.keynav.setActive(this); };

    Unexpected spaces found.
    Open

          $(tmp).removeClass(tmp.onClass).addClass(tmp.offClass);

    Unexpected spaces found.
    Open

          return cur;

    Unexpected spaces found.
    Open

          var kn = $.keynav;

    Unexpected spaces found.
    Open

              quad.push(el);

    Unexpected spaces found.
    Open

      $.keynav.activateClosest = function(cur,quad) {

    Unexpected spaces found.
    Open

          var od = 1000000;

    Unexpected spaces found.
    Open

      }

    Unexpected spaces found.
    Open

        var t  = 0;

    Unexpected spaces found.
    Open

      };

    Unexpected spaces found.
    Open

          var found = false;

    Unexpected trailing spaces found.
    Open

                                                return true;    

    Unexpected spaces found.
    Open

                                       });

    Unexpected spaces found.
    Open

      {

    Unexpected spaces found.
    Open

            e = e.offsetParent;

    Unexpected spaces found.
    Open

            key = event.keyCode;

    Unexpected spaces found.
    Open

              });

    Unexpected spaces found.
    Open

          kn.el = new Array();

    Unexpected spaces found.
    Open

      $.keynav.quad = function(cur,fQuad) {

    Unexpected spaces found.
    Open

          var closest;

    Unexpected spaces found.
    Open

          $.keynav.activateClosest(cur,quad);

    Unexpected spaces found.
    Open

      }

    Unexpected trailing spaces found.
    Open

                    case 13: 

    Unexpected spaces found.
    Open

      $.keynav.goLeft = function () {

    Unexpected spaces found.
    Open

      $.keynav.goUp = function () {

    Unexpected spaces found.
    Open

            t += e.offsetTop  + (e.currentStyle?$.intval(e.currentStyle.borderTopWidth):0);

    Unexpected spaces found.
    Open

          }

    Unexpected spaces found.
    Open

              var tmp = kn.el[i];

    Unexpected spaces found.
    Open

          }

    Unexpected spaces found.
    Open

              var cur = kn.currentEl;

    Unexpected spaces found.
    Open

          var quad = Array();

    Unexpected spaces found.
    Open

          var nd = 0;

    Unexpected spaces found.
    Open

          for(i=0;i<quad.length;i++) {

    Unexpected spaces found.
    Open

          var cur = $.keynav.getCurrent();

    Unexpected trailing spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected spaces found.
    Open

          $(kn.currentEl).trigger('click');

    Unexpected spaces found.
    Open

      }

    Unexpected trailing spaces found.
    Open

          var quad = $.keynav.quad(cur,function (dx,dy) { 

    Unexpected trailing spaces found.
    Open

                                                return true;    

    Unexpected spaces found.
    Open

                                       });

    Unexpected spaces found.
    Open

      }

    There are no issues that match your filters.

    Category
    Status