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
Comment #1
Sigvard CreditAttribution: Sigvard commentedComment #2
ufku CreditAttribution: ufku commentedIMCE can not do anything about a module that adds its javascript to every page and executes code without checking for the requirements.
Comment #3
Sigvard CreditAttribution: Sigvard commentedDo 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.
Comment #4
ufku CreditAttribution: ufku commentedimce.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".
Comment #5
Sigvard CreditAttribution: Sigvard commentedApparently, 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.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedI had the same issue when installed with External js library - Modernizr.
Check the Console for any errors
Comment #7
brunorios1 CreditAttribution: brunorios1 at Dexa commentedI solved this issue verifying if the Modernizr object exists before calling it, like this:
I hope it helps.
Thanks!
Comment #8
thallesTHis looks solved to me!
Comment #9
thallesComment #10
thalles