Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-469

Unfriendly JavaScript Array Looping

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.1 Final
    • 2.1 Final
    • admininterface
    • None
    • JavaScript (in all browsers)

      We are integrating our own JavaScript effects into a Magnolia website, but finding that the Magnolia gui admin JavaScript is being broken when we do so.

      Many third party JavaScript libraries implement features by adding 'prototype' methods to inbuilt JavaScript objects. For example, adding the 'push' method to the Array object for browsers that don't have it.

      A side effect of adding prototype methods to the array object is that the new method is then visible when the array is iterated via a "for (i in arr)" loop. It is therefore advisable to avoid that style of loop, but to use "for (i=0; i<arr.length; i++)" instead.

      I've found one place this needs to be fixed, namely on line 343 in:
      /admindocroot/js/general.js

      Old line:
      for (var elem in qs)

      Fixed version:
      for (var elem=0; elem<qs.length; elem++)

        Acceptance criteria

              kraft Boris Kraft
              bruceyeah Bruce Collier
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD