Probable bug - attempt to access global variable from within closure

Probable bug - attempt to access global variable from within closure

colemanwcolemanw Posts: 3Questions: 1Answers: 0

On line 8806 the DataTable.tables function attempts to access jQuery (the global variable) instead of $ (the local variable). This causes a fatal error on sites that use the jQuery.noConflict() method or otherwise have a different way of accessing jQuery. Changing jQuery to $ fixes the problem and the function continues to work as expected.

Answers

  • colemanwcolemanw Posts: 3Questions: 1Answers: 0
    edited October 2014

    We are tracking this bug internally at https://issues.civicrm.org/jira/browse/CRM-15502
    and here is the patch which fixes it:

    diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js
    index 4aab04b..dc1b339 100644
    --- a/media/js/jquery.dataTables.js
    +++ b/media/js/jquery.dataTables.js
    @@ -8803,7 +8803,7 @@
         */
        DataTable.tables = DataTable.fnTables = function ( visible )
        {
    -       return jQuery.map( DataTable.settings, function (o) {
    +       return $.map( DataTable.settings, function (o) {
                if ( !visible || (visible && $(o.nTable).is(':visible')) ) {
                    return o.nTable;
                }
    
  • colemanwcolemanw Posts: 3Questions: 1Answers: 0
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    Agreed - thanks for flagging this up. I've committed the required change now.

    Allan

This discussion has been closed.