Last active
December 23, 2015 02:09
-
-
Save zaphar/6564897 to your computer and use it in GitHub Desktop.
Revisions
-
zaphar revised this gist
Sep 15, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ Polymer('require-js', { // space seperated list of libs to load using requirejs libnames: "", // name of the event to fire when the libs are loaded. event: "require-js-loaded", created: function() { var self = this; -
zaphar revised this gist
Sep 15, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,6 @@ var addScript = function(src) { var script = document.createElement('script'); script.src = src; var s = document.querySelector('script'); s.parentNode.insertBefore(script, s); return script; -
zaphar revised this gist
Sep 15, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ <polymer-element name="require-js" attributes="libnames event"> <script> (function() { // Helper function to add a script. var addScript = function(src) { var script = document.createElement('script'); -
zaphar revised this gist
Sep 15, 2013 . 1 changed file with 17 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ <script> (function() { console.log("constructing require-js element"); // Helper function to add a script. var addScript = function(src) { var script = document.createElement('script'); script.src = src; @@ -11,33 +11,38 @@ s.parentNode.insertBefore(script, s); return script; }; // Add the requireScript to the dom. var requireScript = addScript("/js/require-jquery.js"); requireScript.onload = function() { // Once the require script has loaded then configure our base url require.config({ baseUrl: "/js/" }); // And construct the polymer element. Polymer('require-js', { // space seperated list of libs to load using requirejs libnames: "", // container of the split list of names. event: "require-js-loaded", created: function() { var self = this; // the below only makes sense if there is a non-empty libnames if (self.libnames != "") { // Split the list and pass that as an argument to the require function var libList = self.libnames.split(" "); require(libList, function() { var libs = {}; // marshall the returned libs into a container for (idx in libList) { libs[libList[idx]] = arguments[idx]; } // fire the event method with the libs as a payload self.fire(self.event, {libs: libs}) }); } } }); }; })(); </script> </polymer-element> -
zaphar revised this gist
Sep 15, 2013 . 1 changed file with 20 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,36 +1,43 @@ <polymer-element name="require-js" attributes="libnames event"> <script> (function() { console.log("constructing require-js element"); var _libs = {}; var addScript = function(src) { var script = document.createElement('script'); script.src = src; //script.onerror = this.error.bind(this); var s = document.querySelector('script'); s.parentNode.insertBefore(script, s); return script; }; var requireScript = addScript("/js/require-jquery.js"); requireScript.onload = function() { require.config({ baseUrl: "/js/" }); Polymer('require-js', { libnames: "", libList: [], eventPrefix: "require-js-loaded", created: function() { var self = this; if (self.libnames != "") { self.libList = self.libnames.split(" "); //console.log("Loading", self.libList); //console.log("Loading", self.libnames); require(self.libList, function() { var libs = {}; for (idx in self.libList) { libs[self.libList[idx]] = arguments[idx]; } //console.log("Loaded", libs); self.fire(self.eventPrefix, {libs: libs}) }); } } }); }; })(); </script> </polymer-element> -
zaphar revised this gist
Sep 14, 2013 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,19 @@ <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/" @@ -21,10 +23,10 @@ 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}) }); } }); -
zaphar created this gist
Sep 14, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ <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; //script.onerror = this.error.bind(this); var s = document.querySelector('script'); s.parentNode.insertBefore(script, s); return script; }; var requireScript = addScript("/js/require-jquery.js"); 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>