-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d17925
commit 2d5e742
Showing
15 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
// Code in app.js. baseURL set to the lib folder | ||
// containing jquery.color. | ||
define(["https://cdnjs.cloudflare.com/ajax/libs/jquery-color/2.1.2/jquery.color.min.js", | ||
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"], | ||
function(colorPlugin, _) { | ||
// Here we've loaded the jQuery color plugin and Lodash from a CDN | ||
// None of these will be accessible in the global scope, but we | ||
// can easily reference them below. | ||
|
||
// Pseudorandomize an array of colors, selecting the first | ||
// item in the shuffled array | ||
var shuffleColor = _.first(_.shuffle(["#AAA", "#FFF", "#111", "#F16"])); | ||
console.log(shuffleColor); | ||
|
||
// Animate the background color of any elements with the class | ||
// "item" on the page using the shuffled color | ||
$(".item").animate({ "backgroundColor": shuffleColor }); | ||
|
||
// What we return can be used by other modules | ||
return function() {}; | ||
}); |
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 { | ||
doSomething: function () { | ||
console.log('Bar: Doing something else...'); | ||
} | ||
}; | ||
}); |
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 { | ||
doSomething: function () { | ||
console.log('Foo: Doing something...'); | ||
} | ||
}; | ||
}); |
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(["./templates", "text!./template.md", "css!./template.css"], | ||
function (templates, template) { | ||
console.log(templates); | ||
console.log(template); | ||
// Use the templates and template content here | ||
} | ||
); |
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,13 @@ | ||
const mathUtils = require('./math'); | ||
|
||
const result1 = mathUtils.add(5, 3); | ||
console.log('Addition:', result1); | ||
|
||
const result2 = mathUtils.subtract(10, 7); | ||
console.log('Subtraction:', result2); | ||
|
||
/* | ||
››› node main.js | ||
Addition: 8 | ||
Subtraction: 3 | ||
*/ |
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 @@ | ||
function add(a, b) { | ||
return a + b; | ||
} | ||
|
||
function subtract(a, b) { | ||
return a - b; | ||
} | ||
|
||
module.exports = { | ||
add, | ||
subtract | ||
}; |
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(["node/umd_math"], function (mathUtils) { | ||
const outputElement = document.getElementById('output'); | ||
|
||
const result1 = mathUtils.add(5, 3); | ||
outputElement.innerHTML += 'Addition: ' + result1 + '<br>'; | ||
|
||
const result2 = mathUtils.subtract(10, 7); | ||
outputElement.innerHTML += 'Subtraction: ' + result2 + '<br>'; | ||
}); | ||
|
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,25 @@ | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD module | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// Node.js/CommonJS module | ||
module.exports = factory(); | ||
} else { | ||
// Global variable (browser) | ||
root.mathUtils = factory(); | ||
} | ||
}(typeof self !== 'undefined' ? self : this, function () { | ||
var mathUtils = {}; | ||
|
||
mathUtils.add = function (a, b) { | ||
return a + b; | ||
}; | ||
|
||
mathUtils.subtract = function (a, b) { | ||
return a - b; | ||
}; | ||
|
||
return mathUtils; | ||
})); | ||
|
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,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>AMD/RequireJS Example</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script> | ||
</head> | ||
<body> | ||
<h1>AMD/RequireJS Example</h1> | ||
<button id="button">Do Stuff</button> | ||
|
||
<script> | ||
require.config({ | ||
paths: { | ||
foo: './foo', | ||
bar: './bar' | ||
} | ||
}); | ||
|
||
require(['foo', 'bar'], function (foo, bar) { | ||
document.getElementById('button').addEventListener('click', function () { | ||
foo.doSomething(); | ||
bar.doSomething(); | ||
}); | ||
}); | ||
</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,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>RequireJS and jQuery Example</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script> | ||
<script> | ||
// Configure RequireJS to load the main module | ||
require(["app"], function(app) { | ||
// The main module will be executed here | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div class="item">Animated Item</div> | ||
|
||
<script src="https://code.jquery.com/jquery-3.6.0.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,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>AMD/RequireJS Example</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
require.config({ | ||
paths: { | ||
text: "https://cdnjs.cloudflare.com/ajax/libs/require-text/2.0.12/text.min", | ||
css: "https://cdnjs.cloudflare.com/ajax/libs/require-css/0.1.10/css.min", | ||
main: "./main" | ||
} | ||
}); | ||
|
||
require(["main"]); | ||
</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,3 @@ | ||
body { | ||
background: yellow; | ||
} |
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 @@ | ||
This is a template |
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 { | ||
template1: "<div>Template 1</div>", | ||
template2: "<div>Template 2</div>", | ||
template3: "<div>Template 3</div>" | ||
}; | ||
}); |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>UMD Example</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script> | ||
<script> | ||
// Configure RequireJS to load the main module | ||
require(["node/umd_main"], function () { | ||
// The main module will be executed here | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div id="output"></div> | ||
</body> | ||
</html> |