humanaut
humanaut

Reputation: 3105

Using Drupal.settings.basePath in Modernizer / yepnope.js loads

I am currently starting development of drupal sites on Acquia. Using git and working locally is a new workflow for me. When building locally and trying to utilize Modernizr load / yepnope, my JS in my script.js file typically looks like this..

Modernizr.load([
    {
    test: Modernizr.mq('only all'),
    nope: '/sitename/docroot/sites/all/themes/theme/js/libs/polyfill.js'
    },
    ....

So that works locally on my machine, but when I commit my changes and push to my acquia development server the file path for the loaded scripts is incorrect, since it's not the same setup I guess.

http://mysite.devcloud.acquia-sites.com/mysite/docroot/sites/all/themes/theme/js/libs/polyfill.js

It needs to be the below, without the mysite/docroot in the URL.

http://mysite.devcloud.acquia-sites.com/sites/all/themes/theme/js/libs/polyfill.js

So that brings me to Drupal.settings.basePath. If I print this out it gives me /mysite/docroot/ on my local setup. If I do it on the dev server, it would print out something different (probably just / ).

So me being the amateur assumed I could do something like this.. (forgive the poor sample, I know it can be done better)

var myroot = Drupal.settings.basePath

Modernizr.load([
{
test: Modernizr.mq('only all'),
nope: myroot + 'sites/all/themes/theme/js/libs/polyfill.js'
},
....

And this of course does not work. Just returns query1 is not defined.

So I am sure there are faults in many of my attempts to make this work.. so if anyone can suggest something to me, either workflow related or how to fix my setup / code, that would be great.

Thanks

Upvotes: 5

Views: 1486

Answers (2)

kartonnade
kartonnade

Reputation: 81

It's a bit late but it may help anyway :

Try something like :

var jsFolderPath = window.location.protocol + "//" + window.location.host+ Drupal.settings.basePath + 'sites/all/themes/theme/js/libs/';

nope: jsFolderPath + 'polyfill.js'

Then you easily add polyfills for each yesnope, regardless of being in dev server or in locahost.

Upvotes: 1

kyletaylored
kyletaylored

Reputation: 759

Maybe I just have a different local setup when using Acquia, but why not just use a relative path like /sites/all/themes/theme/js/libs/polyfill.js?

Upvotes: 1

Related Questions