Disable the AMD environment when it's no longer needed
External module systems potentially used by external tools might load scripts with a UMD wrapper.
Removing Readium's AMD out of the equation and deferring to the module system of the external tool helps ease interoperability.
MODIFY
js/views/external_agent_support.js
js/views/external_agent_support.js
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
-define([], function() {
+define(["../globals"], function(Globals) {
/**
* This module helps external agents that interact with content documents from
* the level of the iframe browsing context:
@@ -45,6 +45,17 @@ define([], function() {
var contentDocumentStates = {};
var contentDocuments = {};
+ Globals.on(Globals.Events.PLUGINS_LOADED, function() {
+ // Disable the AMD environment since it's not needed anymore at this point.
+ // This is done because external agents with their own module systems (Browserify)
+ // might load third-party scripts that are in the format of
+ // UMD (Universal Module Definition),
+ // and will mistakenly try to use Readium's AMD shim, almond.js, or require.js
+ if (window.define && window.define.amd) {
+ delete window.define.amd;
+ }
+ });
+
function appendMetaTag(_document, property, content) {
var tag = _document.createElement('meta');
tag.setAttribute('name', property);
@@ -52,7 +63,6 @@ define([], function() {
_document.head.appendChild(tag);
}
-
function injectDublinCoreResourceIdentifiers(contentDocument, spineItem) {
var renditionIdentifier = reader.metadata().identifier; // the package unique identifier
var spineItemIdentifier = spineItem.idref; // use the spine item id as an identifier too

MODIFY
plugins/hypothesis/main.js
plugins/hypothesis/main.js
@@ -14,17 +14,10 @@ define(['readium_js_plugins'], function (Plugins) {
// Readium has been fully loaded by the RequireJS/AMD shim.
// We can do this here in this callback when this plugin is invoked.
- // Disable the AMD environment since it's not needed anymore at this point.
- // This is done because some third-party modules in Hypothesis use UMD
- // and will mistakenly try to use Readium's AMD shim, almond.js,
- // instead of the loader for Hypothesis.
- if (window.define && window.define.amd) {
- delete window.define.amd;
- }
-
// Inject the script
var script = document.createElement('script');
script.setAttribute('src', H_EMBED_URL);
+ script.setAttribute('async', 'true');
document.head.appendChild(script);
});
});

Disable the AMD environment when it's no longer needed

External module systems potentially used by external tools might load scripts with a UMD wrapper.
Removing Readium's AMD out of the equation and deferring to the module system of the external tool helps ease interoperability.