git @ Cat's Eye Technologies DAM / develop-0.1
Simplify construction, allow dam.js to be "just dropped into" page. Chris Pressey 2 years ago
4 changed file(s) with 72 addition(s) and 68 deletion(s). Raw diff Collapse all Expand all
2222 If you want to just drop DAM's basic functionality into a web page,
2323 you can use it like this:
2424
25 <script src="dam-plus-widgets-web.js"></script>
25 <script src="dam.js"></script>
2626 <script>
2727 var div=DAM.maker('div'), p=DAM.maker('p'), span=DAM.maker('span'), button=DAM.maker('button');
2828 var d = div(
6464
6565 A simple example based on the code above:
6666
67 <script src="dam-plus-widgets-web.js"></script>
67 <script src="dam.js"></script>
6868 <script>
6969 var div=DAM.maker('div'), p=DAM.maker('p'), span=DAM.maker('span'), button=DAM.maker('button');
7070 function makeGreeting(config) {
1313
1414 <div id="installation"></div>
1515
16 <script>var module = {};</script><script src="../src/dam.js"></script><script>var DAM = module.exports;</script>
16 <script src="../src/dam.js"></script>
1717 <script>
1818 var div=DAM.maker("div"), p=DAM.maker("p"), span=DAM.maker("span"), button=DAM.maker("button"),
1919 canvas=DAM.maker("canvas"), label=DAM.maker("label"), br=DAM.maker("br"), input=DAM.maker("input"),
44 It consists of dam.js followed by dam-widgets.js, both with only small
55 hand modifications to make them load as-is in ES5. */
66
7 if (typeof window === 'undefined' || window.DAM === undefined) var DAM = {};
8
9 DAM.makeElem = function(tag, args) {
10 args = args || [];
11 var elem = document.createElement(tag);
12 for (var i = 0; i < args.length; i++) {
13 var arg = args[i];
14 if (arg instanceof Element) {
15 elem.appendChild(arg);
16 } else if (typeof arg === 'string' || arg instanceof String) {
17 elem.appendChild(document.createTextNode(arg));
18 } else if (typeof arg === 'object' && arg !== null) {
19 Object.keys(arg).forEach(function(key) {
20 if (key.substring(0, 2) === 'on') {
21 elem.addEventListener(key.substring(2), arg[key]);
22 } else if (arg[key] === null) {
23 elem.removeAttribute(key);
24 } else {
25 elem.setAttribute(key, arg[key]);
26 }
27 });
28 } else {
29 console.log(arg);
30 }
31 }
32 return elem;
33 };
34
35 DAM.maker = function(tag) {
36 return function() {
37 return DAM.makeElem(tag, arguments);
7 var DAM = (function() {
8 var DAM = {};
9 DAM.makeElem = function(tag, args) {
10 args = args || [];
11 var elem = document.createElement(tag);
12 for (var i = 0; i < args.length; i++) {
13 var arg = args[i];
14 if (arg instanceof Element) {
15 elem.appendChild(arg);
16 } else if (typeof arg === 'string' || arg instanceof String) {
17 elem.appendChild(document.createTextNode(arg));
18 } else if (typeof arg === 'object' && arg !== null) {
19 Object.keys(arg).forEach(function(key) {
20 if (key.substring(0, 2) === 'on') {
21 elem.addEventListener(key.substring(2), arg[key]);
22 } else if (arg[key] === null) {
23 elem.removeAttribute(key);
24 } else {
25 elem.setAttribute(key, arg[key]);
26 }
27 });
28 } else {
29 console.log(arg);
30 }
31 }
32 return elem;
3833 };
39 };
34 DAM.maker = function(tag) {
35 return function() {
36 return DAM.makeElem(tag, arguments);
37 };
38 };
39 return DAM;
40 })();
4041
4142 (function(DAM) { // ENTER-SCOPE
4243
00 /* dam.js version 0.1. This file is in the public domain. */
11
2 if (typeof window === 'undefined' || window.DAM === undefined) var DAM = {};
3
4 DAM.makeElem = function(tag, args) {
5 args = args || [];
6 var elem = document.createElement(tag);
7 for (var i = 0; i < args.length; i++) {
8 var arg = args[i];
9 if (arg instanceof Element) {
10 elem.appendChild(arg);
11 } else if (typeof arg === 'string' || arg instanceof String) {
12 elem.appendChild(document.createTextNode(arg));
13 } else if (typeof arg === 'object' && arg !== null) {
14 Object.keys(arg).forEach(function(key) {
15 if (key.substring(0, 2) === 'on') {
16 elem.addEventListener(key.substring(2), arg[key]);
17 } else if (arg[key] === null) {
18 elem.removeAttribute(key);
19 } else {
20 elem.setAttribute(key, arg[key]);
21 }
22 });
23 } else {
24 console.log(arg);
2 (function() {
3 var DAM = {};
4 DAM.makeElem = function(tag, args) {
5 args = args || [];
6 var elem = document.createElement(tag);
7 for (var i = 0; i < args.length; i++) {
8 var arg = args[i];
9 if (arg instanceof Element) {
10 elem.appendChild(arg);
11 } else if (typeof arg === 'string' || arg instanceof String) {
12 elem.appendChild(document.createTextNode(arg));
13 } else if (typeof arg === 'object' && arg !== null) {
14 Object.keys(arg).forEach(function(key) {
15 if (key.substring(0, 2) === 'on') {
16 elem.addEventListener(key.substring(2), arg[key]);
17 } else if (arg[key] === null) {
18 elem.removeAttribute(key);
19 } else {
20 elem.setAttribute(key, arg[key]);
21 }
22 });
23 } else {
24 console.log(arg);
25 }
2526 }
27 return elem;
28 };
29 DAM.maker = function(tag) {
30 return function() {
31 return DAM.makeElem(tag, arguments);
32 };
33 };
34 if (typeof module !== 'undefined') {
35 module.exports = DAM;
36 } else if (typeof window !== 'undefined') {
37 window.DAM = DAM;
2638 }
27 return elem;
28 };
29
30 DAM.maker = function(tag) {
31 return function() {
32 return DAM.makeElem(tag, arguments);
33 };
34 };
35
36 if (typeof module !== 'undefined') module.exports = DAM;
39 })();