LeaVerou/prism — pull request #304 by apfelbox (2014-07-23 07:52:43+00:00)
Title: Fix workers & download page

The current check for the environment:
```js
var self = (typeof window !== 'undefined') ? window : {};
```

The issue is that in workers `window` is undefined.
Therefore, in the first line, `self` will be set to `{}`.

This will destroy the check for workers later on:
```js
if (!self.document) {
if (!self.addEventListener) { // <- this will be true
// in Node.js
return self.Prism;
}
// In worker
// ... <- this will no be executed
}
```

because `self.addEventListener` will then be undefined (due to `self = {}`).

The fix is to make the check for the environment more sophisticated:

1. check for the browser: `(typeof window !== 'undefined')`
2. check for a worker: `(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)` (from http://stackoverflow.com/questions/7931182/reliably-detect-if-the-script-is-executing-in-a-web-worker)
3. assume we are in node

Fixes #302