-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New examples for modularisation (based on Grunt)
- Loading branch information
Jonas Bandi
committed
Jul 6, 2014
1 parent
c12b43e
commit bc37fb6
Showing
76 changed files
with
40,083 additions
and
200 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
04-Toolchain/03-Modularization/00-ManualLoading/index.html
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
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> |
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
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
22
04-Toolchain/03-Modularization/00-ManualLoading/js/module1.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
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
21
04-Toolchain/03-Modularization/00-ManualLoading/js/module2.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
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
19
04-Toolchain/03-Modularization/00-ManualLoading/js/module3.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
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
18
04-Toolchain/03-Modularization/00-ManualLoading/js/myapp.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
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; | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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> |
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
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!"); | ||
}); | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(function(){ | ||
return { | ||
greet: function (message) { | ||
console.log("Hello: " + message); | ||
} | ||
} | ||
}) |
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
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
12
04-Toolchain/03-Modularization/03-RequireJS-jQuery/index.html
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
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
10
04-Toolchain/03-Modularization/03-RequireJS-jQuery/js/app.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
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!"); | ||
}); | ||
}); | ||
}) | ||
}) |
7 changes: 7 additions & 0 deletions
7
04-Toolchain/03-Modularization/03-RequireJS-jQuery/js/greeter.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
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
27
04-Toolchain/03-Modularization/03-RequireJS-jQuery/js/main.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
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
54
04-Toolchain/03-Modularization/04-RequireJSExample/Gruntfile.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
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']); | ||
}; |
Oops, something went wrong.