Last active
August 29, 2015 14:11
-
-
Save jeffdonthemic/fdf1e3df66eb0e58c9c7 to your computer and use it in GitHub Desktop.
Topcoder Blog Gists
This file contains 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
<aura:application> | |
<aura:handler event="forcelogic2:BlogRequireJSEvent" action="{!c.initJS}"/> | |
<aura:registerEvent type="forcelogic2:BlogRequireJSEvent" name="requireJSEvent"/> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> | |
<div id="afterLoad">Old value</div> | |
</aura:application> |
This file contains 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
({ | |
/* | |
Sets up the RequireJS library (async load) | |
*/ | |
doInit : function(component, event, helper){ | |
if (typeof require !== "undefined") { | |
var evt = $A.get("e.forcelogic2:BlogRequireJSEvent"); | |
evt.fire(); | |
} else { | |
var head = document.getElementsByTagName('head')[0]; | |
var script = document.createElement('script'); | |
script.src = "/resource/RequireJS"; | |
script.type = 'text/javascript'; | |
script.key = "/resource/RequireJS"; | |
script.helper = this; | |
script.id = "script_" + component.getGlobalId(); | |
var hlp = helper; | |
script.onload = function scriptLoaded(){ | |
var evt = $A.get("e.forcelogic2:BlogRequireJSEvent"); | |
evt.fire(); | |
}; | |
head.appendChild(script); | |
} | |
}, | |
initJS : function(component, event, helper){ | |
require.config({ | |
paths: { | |
"jquery": "/resource/BlogScripts/jquery.min.js?", | |
"bootstrap": "/resource/BlogScripts/boostrap.min.js?" | |
} | |
}); | |
console.log("RequiresJS has been loaded? "+(require !== "undefined")); | |
//loading libraries sequentially | |
require(["jquery"], function($) { | |
console.log("jQuery has been loaded? "+($ !== "undefined")); | |
require(["bootstrap"], function(bootstrap) { | |
console.log("bootstrap has been loaded? "+(bootstrap !== "undefined")); | |
$A.run(function(){ | |
//do whatever GUI initialization you want | |
//in the aura context | |
$("#afterLoad").html("VALUE CHANGED!!!"); | |
}); | |
});//require end | |
});//require end | |
} | |
}) |
This file contains 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
https://na17.salesforce.com/resource/Gordonk66__jquery/jquery.jsresource/Gordonk66__jquery/jquery.js |
This file contains 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
<aura:handler event="Gordonk66:requiresReady" action="{!c.initScripts}"/> |
This file contains 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
requirejs.config({ | |
baseUrl: "/resource/", | |
paths: { | |
jquery: "/resource/Gordonk66__jquery/jquery", | |
bootstrap: "/resource/Gordonk66__aotp_bootstrap/js/bootstrap", | |
bootstrapValidator: "/resource/Gordonk66__bootstrapvalidator/bootstrapvalidator/dist/js/bootstrapValidator" | |
}, | |
shim: { | |
bootstrap: {deps: ["jquery"]}, | |
bootstrapValidator: {deps: ["jquery"]} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment