Skip to content

Commit

Permalink
New examples for modularisation (based on Grunt)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Bandi committed Jul 6, 2014
1 parent c12b43e commit bc37fb6
Show file tree
Hide file tree
Showing 76 changed files with 40,083 additions and 200 deletions.
19 changes: 19 additions & 0 deletions 04-Toolchain/03-Modularization/00-ManualLoading/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<!--Stuff-->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
</head>
<body>

<!--Stuff-->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="js/myapp.js"></script>
<script src="js/module1.js"></script>
<script src="js/module2.js"></script>
<script src="js/module3.js"></script>
<script src="js/main.js"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions 04-Toolchain/03-Modularization/00-ManualLoading/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var Module1 = MYAPP.subnamespace.Module1;
var module1 = new Module1();

module1.doSomething();
22 changes: 22 additions & 0 deletions 04-Toolchain/03-Modularization/00-ManualLoading/js/module1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function(global) {

// var subnamespace = MYAPP.namespace('subnamespace');
global.MYAPP = global.MYAPP || {};
MYAPP.subnamespace = MYAPP.subnamespace || {};
var subnamespace = MYAPP.subnamespace;

var Module1 = function(){
}

Module1.prototype.doSomething = function(){
var module2 = new subnamespace.Module2();
var module3 = new subnamespace.subsubnamespace.Module3();
module2.doSomething();
module3.doSomething();
console.log("Module 1 did something.")
}

// Export the module
subnamespace.Module1 = Module1;

})(window)
21 changes: 21 additions & 0 deletions 04-Toolchain/03-Modularization/00-ManualLoading/js/module2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function(global) {

// var subnamespace = MYAPP.namespace('subnamespace');
global.MYAPP = global.MYAPP || {};
MYAPP.subnamespace = MYAPP.subnamespace || {};
var subnamespace = MYAPP.subnamespace;

// var module3 = new subnamespace.subsubnamespace.Module3();
// var myInt = module3.getValue();

var Module2 = function(){
}

Module2.prototype.doSomething = function(){
console.log("Module 2 did something.")
}

// Export the module
subnamespace.Module2 = Module2;

})(window)
19 changes: 19 additions & 0 deletions 04-Toolchain/03-Modularization/00-ManualLoading/js/module3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function() {
var subsubnamespace = MYAPP.namespace('subnamespace.subsubnamespace');

var Module3 = function(){
}

Module3.prototype = {
doSomething: function(){
console.log("Module 3 did something.")
},
getValue: function(){
return 42;
}
};

// Export the module
subsubnamespace.Module3 = Module3;

})()
18 changes: 18 additions & 0 deletions 04-Toolchain/03-Modularization/00-ManualLoading/js/myapp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var MYAPP = MYAPP || {};
MYAPP.namespace = function (ns_string) {
var parts = ns_string.split('.'),
parent = MYAPP,
i;
// strip redundant leading global
if (parts[0] === "MYAPP") {
parts = parts.slice(1);
}
for (i = 0; i < parts.length; i += 1) {
// create a property if it doesn't exist
if (typeof parent[parts[i]] === "undefined") {
parent[parts[i]] = {};
}
parent = parent[parts[i]];
}
return parent;
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!DOCTYPE html>
<head>

<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
body {
padding-top: 10px;
padding-bottom: 40px;
}
.hero-unit {padding: 20px; }
</style>
<link rel="stylesheet" href="../css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
</head>
<body>

Expand Down Expand Up @@ -38,8 +38,8 @@ <h1>Course Rater</h1>
</footer>
</div> <!-- /container -->

<script type="text/javascript" src="../vendor/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="../vendor/raphael-2.1.2.min.js"></script>
<script type="text/javascript" src="vendor/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="vendor/raphael-2.1.2.min.js"></script>
<script type="text/javascript" src="drawing_module.js"></script>
<script type="text/javascript" src="rating_widget.js"></script>
<script type="text/javascript" src="main.js"></script>
Expand Down
12 changes: 12 additions & 0 deletions 04-Toolchain/03-Modularization/02-RequireJS/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<button id="btnGreet">Click me for greeting!</button>

<script data-main="js/main" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.11/require.min.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions 04-Toolchain/03-Modularization/02-RequireJS/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define(function(require){
var button = document.getElementById("btnGreet");
button.addEventListener("click", function(){
var greeter = require(["greeter"], function(greeter){
greeter.greet("World!");
});
})
})
7 changes: 7 additions & 0 deletions 04-Toolchain/03-Modularization/02-RequireJS/js/greeter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function(){
return {
greet: function (message) {
console.log("Hello: " + message);
}
}
})
3 changes: 3 additions & 0 deletions 04-Toolchain/03-Modularization/02-RequireJS/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require(["app"], function(app){
console.log("Loading app...")
})
12 changes: 12 additions & 0 deletions 04-Toolchain/03-Modularization/03-RequireJS-jQuery/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<button id="btnGreet">Click me for greeting!</button>

<script data-main="js/main.js" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.11/require.min.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions 04-Toolchain/03-Modularization/03-RequireJS-jQuery/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
define(function(require){

require(['jquery'], function($){
$("#btnGreet").on("click", function(){
var greeter = require(["greeter"], function(greeter){
greeter.greet("World!");
});
});
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function(){
return {
greet: function (message) {
console.log("Hello: " + message);
}
}
})
27 changes: 27 additions & 0 deletions 04-Toolchain/03-Modularization/03-RequireJS-jQuery/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

// Configuration for requirejs
require.config({
// "baseUrl": "js/lib",
"paths": {
// "app": "../app",
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
},
map: {
// '*' means all modules will get 'jquery-private'
// for their 'jquery' dependency.
'*': { 'jquery': 'jquery-private' },

// 'jquery-private' wants the real jQuery module
// though. If this line was not here, there would
// be an unresolvable cyclic dependency.
'jquery-private': { 'jquery': 'jquery' }
}
});

// Define the module jquery-private as a jQuery with no-conflict
define('jquery-private',['jquery'], function (jq) {
return jq.noConflict( true );
});

// Load the main app module to start the app
require(["app"]);
54 changes: 54 additions & 0 deletions 04-Toolchain/03-Modularization/04-RequireJSExample/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

module.exports = function (grunt) {
grunt.initConfig({
clean: {
build: 'build'
},
requirejs: {

// these defaults will be used as a base for every target we define
options: {
// the name is used to find js/amd/app.js, basically
name: 'app',

// this should be set to the path from your project root to the
// root of your AMD JavaScript files.
baseUrl: 'js/amd',

// where we want the compilation result to go
out: 'build/js/app.min.js'
},

debug: {

// These options also get merged with the defaults defined above
options: {

// for some reason, generating source maps requires this to be off
// and it's on by default...
preserveLicenseComments: false,

// we want source maps because we're bundling everything together
// learn more about source maps here:
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
generateSourceMaps: true,

// also required by the generateSourceMaps option
optimize: 'none'
}
},

// This target will inherit the default options, which is
// enough for us. The defaults are tuned to optimize.
release: {}
}
});

grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-requirejs');

grunt.registerTask('build:debug', ['clean', 'requirejs:debug']);
grunt.registerTask('build:release', ['clean', 'requirejs:release']);
grunt.registerTask('default', [ 'build:release']);
};
Loading

0 comments on commit bc37fb6

Please sign in to comment.