When used with Adminimal theme, the Media Browser modal popup gives these errors:

media.views.js:10 Uncaught ReferenceError: namespace is not defined
    at media.views.js:10
    at media.views.js:213

media.popups.js?v=7.x-2.9:131 Uncaught TypeError: Cannot read property 'browser' of undefined
    at HTMLIFrameElement.Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad (media.popups.js?v=7.x-2.9:131)
    at HTMLIFrameElement.dispatch (jquery.min.js?v=1.8.3:2)
    at HTMLIFrameElement.u (jquery.min.js?v=1.8.3:2)

The line in media.views.js that causes the problem is

namespace('Drupal.media.browser.views');

It happens with all versions of jQuery available through the jQuery Update module, but doesn't happen with other themes or when I choose a different theme in the media browser settings at /admin/config/media_browser. Because of that, I wasn't sure whether to create this issue in the Media queue or the Adminimal queue. Please let me know if I've added it to the wrong one :-)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

FrankH created an issue. See original summary.

FrankH’s picture

Issue summary: View changes
bziraoui’s picture

FileSize
14.95 KB

Hey :)
I have the same error when i upgrade media form 7.x-1.6 to 7.x-2.9, Have you find a solution ?

bziraoui’s picture

Assigned: Unassigned » bziraoui

Try this, it's work for me

:: Media

Admin Config: /admin/config/media/browser

- Verify appropriate “Enabled browser plugins” are selected.

- (Re)Enable "Use the media browser" permission
https://www.drupal.org/node/2281631
https://www.drupal.org/node/2283057
Path: /admin/people/permissions

bziraoui’s picture

Assigned: bziraoui » Unassigned
FrankH’s picture

I tried those changes but they didn’t work. I didn’t expect them to because all the problems I’ve encountered have been while logged in as admin.

I have investigated a bit more since posting this report but have not made much progress. As a workaround, I configured the media browser to use the Seven theme. It's not ideal but it worked and it reduced the urgency of trying to find a proper fix.

I don’t know how useful the info below will be, but hopefully it will help.

The error

media.views.js:10 Uncaught ReferenceError: namespace is not defined

refers to the namespace function, which is defined in media.core.js. An issue relating to this file was raised several years ago but is still open:

https://www.drupal.org/node/1123534

I removed the namespacefunction and replaced it with

    Drupal.media.browser.views = Drupal.media.browser.views || {};

as recommended in the above-mentioned issue. It’s also implemented by many other Drupal modules, so I assume the Media module maintainers had good reasons for not implementing it.

Perhaps irrelevant but the patch provided on that page does not patch media.views.js - I don’t know if this is intentional or an oversight.

Back to the problem at hand, the lines (based, admittedly, on copying the syntax of similar files more so than any deep understanding of how the module is structured), replacing the call to the namespace function in media.views.js with this line:

    Drupal.media.browser.views = Drupal.media.browser.views || {};

did not eliminate the error, but adding the following lines did:

    Drupal.media = Drupal.media || {};
    Drupal.media.browser = Drupal.media.browser || {};
    Drupal.media.browser.views = Drupal.media.browser.views || {};

However, then I got the following error:

Uncaught TypeError: Cannot read property 'length' of undefined
    at HTMLIFrameElement.Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad (media.popups.js:137)

At that point I realised I was most likely barking up the wrong tree. It seems unlikely that a module as important and widely used as Media would be released if it contained such a basic error as an undefined function. Even if it was, other people would be reporting the issue too, and nobody did until today.

Next, I created a test site on simplytest.me with Media 7.x-2.9, Adminimal theme 7.x-1.24, and Adminimal admin menu 7.x-1.7. Everything worked perfectly there. Back on my own site, when I tried to use these three modules together I got the errors we’ve both seen.

That’s as far as I’ve got. Even though I haven’t modified the modules, the evidence suggests the problem is related to my environment but whether the root cause is something I've misconfigured, a bug in the Media module, or a bug in Adminimal, remains to be seen. When I get time I will look into it further but I hope someone who knows the module in more detail might see this and offer some guidance.

Hope it helps...

joseph.olstad’s picture

try changing your jQuery version for the admin theme from 1.8 to 1.7.x or 1.10.x
this is a jquery_update thing.

double check the jquery requirements of adminimal theme

weird that simplytest.me test worked but your environment didn't.

Suspect that you might have more than one copy of the media module. Have you tried the duplicate module files module it helps you locate duplicate files in your filesystem. Potentially different versions of modules of the same module in the same website.

joseph.olstad’s picture

Category: Bug report » Support request
joseph.olstad’s picture

this might be a bug, however I've used the media module with the adminimal theme before and didn't notice this problem.

FrankH’s picture

Thanks. I have tried it with every available version of jQuery via jquery_update. Problem is the same in all cases.

I haven't tried the duplicate files module but I don't think there is any need. If there were duplicates I would see them in my git client.

I also have used Adminimal with Media before without any issues but this is the first time I have used it with 7.x-2.9. I will investigate in more detail, do a clean install, try previous versions, compare with working sites, review recent commits etc. but at this stage it's looking like the problem is specific to my environment.

joseph.olstad’s picture

ok, yes this could very well be a regression.....

see this git blame:
e48215d1 js/media.popups.js (brockfanning 2017-06-13 14:23:43 -0400 131) if (this.contentWindow.Drupal.media.browser == undefined) {

line 128 of media.popups.js

at HTMLIFrameElement.Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad (media.popups.js?v=7.x-2.9:131)

see patch

joseph.olstad’s picture

Status: Active » Needs review

queuing

  • joseph.olstad committed b3c5803 on 7.x-3.x authored by FrankH
    Issue #2895139 by joseph.olstad, bziraoui, FrankH: Javascript error with...

  • joseph.olstad committed 8315202 on 7.x-2.x authored by FrankH
    Issue #2895139 by joseph.olstad, bziraoui, FrankH: Javascript error with...
joseph.olstad’s picture

Status: Needs review » Fixed

Fixed in 7.x-2.x dev and 7.x-3.x dev

joseph.olstad’s picture

@FrankH? or @bziraoui could one or both of you please review the new patch I'm working on in the related issue to see that it doesn't break media functionality when using the adminimal theme:

We hope not to introduce a regression this time.

Please test this patch:
#2885412-19: Javascript error after media upload: Cannot read property 'selectedMedia' of undefined

and please let me know if this works for your adminimal theme without breaking media functionality.

Thanks in advance.

joseph.olstad’s picture

note, the dev release has the patch
so you can test it there, Please let me know if it causes any issue with Adminimal.

FrankH’s picture

Tried the latest dev release. First I got the namespace error again. Then, when I replaced the namespace function call with these lines:

    Drupal.media = Drupal.media || {};
    Drupal.media.browser = Drupal.media.browser || {};
    Drupal.media.browser.views = Drupal.media.browser.views || {};

I got the same error as before:

Uncaught TypeError: Cannot read property 'length' of undefined
    at HTMLIFrameElement.Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad (media.popups.js?v=7.x-3.0-beta5+1-dev:137)
    at HTMLIFrameElement.dispatch (jquery.min.js?v=1.7.2:3)
    at HTMLIFrameElement.i (jquery.min.js?v=1.7.2:3)

I'm using the Media module with no modifications, Adminimal base theme, no subtheme and I have disabled the Adminimal Admin Menu module which I had been using earlier.
name

joseph.olstad’s picture

How about the latest tagged release ? 7.x-2.10 ? Did you try that? Was there a difference? Cache clear css/js between switch versions.

Please Let me know, we'll fix it one way or another

joseph.olstad’s picture

Status: Fixed » Active
FrankH’s picture

Hi Joseph, apologies, I didn't notice the new tagged version. Just tried it - same error:

Uncaught ReferenceError: namespace is not defined
    at media.views.js:10
    at media.views.js:213

I don't understand why media.views.js is not picking up the definition of the namespace function from media.core.js. Since it works everywhere else, and on simplytest.me, it's possible/likely something in my environment is causing the problem. Can't think what it might be - I'll investigate more at the weekend.

joseph.olstad’s picture

Status: Active » Postponed (maintainer needs more info)
FrankH’s picture

Sorry to take so long to reply. In the meantime I have rebuilt the site from scratch (it started off as a site I inherited, with many unnecessary and some deprecated modules). After doing so, the media browser loaded correctly. Unfortunately this leaves me no wiser as to the cause of the error. I guess it was some kind of JavaScript conflict related to the namespace function definition in media.core.js but it was too vague/complicated to debug. Thanks for your help and apologies for having taken up your time.

FrankH’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)
joseph.olstad’s picture

Thanks for the followup, great to hear that you have found a solution (albeit a time consuming one).

disizlapeste01’s picture

hello @Frank H .
The solution is very simple.
First, Consider that i've upgrade Media Module from 1.4 to 2.3 on Drupal 7.
You just need to find where is invocation "media_include_browser_js()" or "media_browser()" in your module. (In my case i found this invocation on dexp.layerslider.module line 291)..
You've to remove this line and replace it with these 2 statements:
drupal_add_library('media', 'media_browser');
drupal_add_library('media', 'media_browser_settings');