JenScript with Require

S├ębastien Janaud - May 31, 2015 - updated june 2017 / Samples

Require JS

Asynchronous module definition (AMD) is a JavaScript specification that defines an API for defining code modules and their dependencies, and loading them asynchronously if desired. Implementations of AMD provide the following benefits:

In addition to loading multiple JavaScript files at runtime, AMD implementations allow developers to encapsulate code in smaller, more logically-organized files in a way similar to other programming languages such as Java. For production and deployment, developers can concatenate and minify JavaScript modules based on an AMD API into one file, the same as traditional JavaScript.

Resource : Require JS - wikipedia - chart source code

Part : Part 1 - Part 2

First step is to create the view which is the end chart. name attribute refers the root element where view chart is attached.


<div id="viewrequire"></div>

Does not import JenScript as head script, use require as below to get jenscript and view demo file. Use underscore symbol as jenscript name.


require.config({
	  paths: {
	    jen: "/jenscript.min",
	    demo: "/require/2/view-require"
	  }
});
	
requirejs(["jen","demo"], function(_) {
	
	$(window).resize(function() {
		init();
	});
	
	function init(){
		var w = $("#viewrequire").width();
		createView(_,'viewrequire',w,400);
	}
	init();
});