Created
May 11, 2016 22:37
-
-
Save adamrights/b6fbbbfa414c3c69bc60ad8f2b8f4343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* requireModuleInit.js | |
* Initialize require modules on article pages | |
* | |
* TODO: Move config into separate files - separate based on dev config and prod config | |
*/ | |
require.config({ | |
enforceDefine: true, | |
map: { | |
'*' : { | |
'vendor.asset.jquery/jquery' : 'jquery', | |
'vendor.asset.hogan/hogan' : 'hogan', | |
'vendor.asset.moment/moment' : 'moment' | |
} | |
}, | |
paths: { | |
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min", | |
"backbone": "//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.10/backbone-min", | |
"hogan": "//cdnjs.cloudflare.com/ajax/libs/hogan.js/3.0.0/hogan.min.amd", | |
"moment": "//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min", | |
"async": "//cdnjs.cloudflare.com/ajax/libs/async/1.5.2/async.min" | |
} | |
}); | |
define('article.app.requireModuleInit', ['jquery'], function ($) { | |
function init() { | |
var requirejs = window.require, | |
registry = requirejs.s.contexts._.registry, | |
hasOwn = Object.prototype.hasOwnProperty, | |
isArticleRe = /article\.app/, | |
isModuleRe = /\.module\./, | |
isTealiumRe = /tealium/; | |
for (var name in registry) { | |
if (!hasOwn.call(registry, name)) { continue; } | |
var isModule = (isModuleRe.test(name) || isArticleRe.test(name) || isTealiumRe.test(name)); | |
if (!isModule) { | |
continue; | |
} | |
requirejs([name], onRequire); | |
} | |
function onRequire(module) { | |
if (module === undefined) { | |
return; | |
} | |
if (module && typeof(module.init) !== 'function') { | |
return; | |
} | |
try { | |
module.init.call(module); | |
} catch (e) { | |
console.error('module init error' + e); | |
return; | |
} | |
} | |
} | |
return {init: init}; | |
}); | |
require(['article.app.requireModuleInit'], function (moduleInit) { | |
moduleInit.init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment