Last active
December 23, 2015 02:09
-
-
Save zaphar/6564897 to your computer and use it in GitHub Desktop.
A polymer custom element that can load requirejs modules. You may have to modify the paths to suite your setup.
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
| <polymer-element name="require-js" attributes="libname event"> | |
| <script> | |
| (function() { | |
| //console.log("constructing require-js element"); | |
| var _libs = {}; | |
| var addScript = function(src) { | |
| var script = document.createElement('script'); | |
| script.src = src; | |
| var s = document.querySelector('script'); | |
| s.parentNode.insertBefore(script, s); | |
| return script; | |
| }; | |
| var requireScript = addScript("/js/require-jquery.js"); | |
| requireScript.onerror = function() { | |
| // console.log("Failed to construct require-js element"); | |
| }; | |
| requireScript.onload = function() { | |
| require.config({ | |
| baseUrl: "/js/" | |
| }); | |
| Polymer('require-js', { | |
| libname: "common", | |
| eventPrefix: "require-js-loaded-", | |
| created: function() { | |
| var self = this; | |
| //console.log("Loading", self.libname); | |
| require([self.libname], function(lib) { | |
| //console.log("Loaded", self.libname, lib); | |
| self.fire(self.eventPrefix+self.libname, {lib: lib}) | |
| }); | |
| } | |
| }); | |
| }; | |
| })(); | |
| </script> | |
| </polymer-element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment