It looks like the script necessary to generate the upload button located in imce.js (it add the buttons to a div named ops-list) crash because it interact with Javascrip located in several other modules.

On my site I had a script implementing the Select2 Jquery plugin to create more attractive dropdown menus and also the Modernizr javascript library that also crash and prevent the buttons from loading. Given that several other modules seem to crash with IMCE I think it may be appropriate if the IMCE.js file is patched to solve the issue.

I would have loved to help in writing the actual code for it but I am very weak in my coding skills so I can only provide the code I used to solve the issue in my specific case.

My old code:

Drupal.behaviors.searchProtocols = {
  attach: function (context, settings) {
    jQuery('select').select2(); //This is the call that fails when trying to load the buttons.
    
    if (Modernizr.input.placeholder) { //This also causes an exception in the debugger.
       jQuery('body').addClass('mdrnzr-placeholder'); 
    }
    
    var $window = jQuery(window);
    Drupal.molmeth.$searchAreaBoxes = jQuery('.search-area .findProtocols, .search-area .block-block');

    if($window.width() > 549){
      molmethEqualHeights(Drupal.molmeth.$searchAreaBoxes);
    }

    jQuery(window).resize(molmethEqualHeights);
  }
}; 

New non-crashing code:

Drupal.behaviors.searchProtocols = {
  attach: function (context, settings) {
    var selector = jQuery('select');

    if('select2' in selector){ //Test to see if select2 is available before the function is called.
      selector.select2(); 


      if (Modernizr.input.placeholder) {
        jQuery('body').addClass('mdrnzr-placeholder');
      }

      var $window = jQuery(window);
      Drupal.molmeth.$searchAreaBoxes = jQuery('.search-area .findProtocols, .search-area .block-block');

      if($window.width() > 549){
      molmethEqualHeights(Drupal.molmeth.$searchAreaBoxes);
      }
      jQuery(window).resize(molmethEqualHeights);
    }
  }
};

In my case modernizr is only called after the select2 plugin so I only made one check which is a bit lazy but good enough in my case.

Comments

Sigvard’s picture

Issue summary: View changes
ufku’s picture

Category: Bug report » Support request

IMCE can not do anything about a module that adds its javascript to every page and executes code without checking for the requirements.

Sigvard’s picture

Do you have any ideas on why IMCE is unique in this case?

Because I have never seen a comment queue like this on other modules that I use.

ufku’s picture

I have had the same issue and for me it was caused by IMCE.js interfering with the select2 and modernizr javascript libraries.

For some reason these are called (and fail) by the IMCE.js scrip which prevent the Upload button from being created.

imce.js is neither interfering with nor calling other scripts.

If you add your script(implementing Drupal.behaviors) to every page by ignoring the context or availability of required libraries, it is your responsibility to do "Feature Detection".

Sigvard’s picture

Apparently, a huge number of modules and themes do the same thing as other people have the problem when using different modules and themes.

For me this problem is solved as I added the check for select2.

Anonymous’s picture

I had the same issue when installed with External js library - Modernizr.

Check the Console for any errors

brunorios1’s picture

I solved this issue verifying if the Modernizr object exists before calling it, like this:

var select = $('select', context);

if (typeof Modernizr == 'object') { 
  if (!Modernizr.touch && select.length > 0) {
    $('select', context).select2({
      minimumResultsForSearch: 10,
    });
  }
}

I hope it helps.
Thanks!

thalles’s picture

THis looks solved to me!

thalles’s picture

thalles’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.