If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Thursday, April 10, 2014

Using HTML5 dataset attributes

<!DOCTYPE html>
<html>
<head>
<title>Using dataset attributes</title>
<script data-main="scripts/dataset" src="scripts/require.js"></script>
</head>
<body>
<!-- any attribute whose name is lowercase and starts with "data-" is considered
a valid HTML5 attribute -->
<span class="circle" data-radius="50" data-title="Circle of life"/>
</body>
</html>
view raw gistfile1.html hosted with ❤ by GitHub
/**
* circle.js
**/
define({
"draw": function(node) {
var dataset = node.dataset;
var radius = parseInt(dataset.radius);
var title = dataset.title;
alert("Drawing circle with title '" + title + "' and radius " + radius);
}
});
/******************************************************************************************************/
/**
* dataset.js
*
* This demo assumes my project looks like
* projectfolder
* - circle.html
* - scripts
* - dataset.js
* - circle.js
**/
requirejs(["./circle"], function(circle) {
//let's draw the circle <span class="circle" data-radius="50"/>
circle.draw(document.querySelector(".circle"));
});
view raw gistfile1.js hosted with ❤ by GitHub

No comments:

Post a Comment