Author: jruchaud Date: 2014-06-19 13:09:11 +0200 (Thu, 19 Jun 2014) New Revision: 714 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/714 Log: Create first controller with click Added: funjs/public_html/funjs/Controller.js Modified: funjs/public_html/funjs/Boot.js funjs/public_html/funjs/HtmlUtils.js funjs/public_html/funjs/TemplateEngine.js funjs/public_html/index.html Modified: funjs/public_html/funjs/Boot.js =================================================================== --- funjs/public_html/funjs/Boot.js 2014-06-19 09:21:00 UTC (rev 713) +++ funjs/public_html/funjs/Boot.js 2014-06-19 11:09:11 UTC (rev 714) @@ -1,2 +1,6 @@ $scriptReader = new TemplateScriptReader(); $template = new TemplateEngine(); + +window.onload = function() { + $template.parse(document.body); +}; Added: funjs/public_html/funjs/Controller.js =================================================================== --- funjs/public_html/funjs/Controller.js (rev 0) +++ funjs/public_html/funjs/Controller.js 2014-06-19 11:09:11 UTC (rev 714) @@ -0,0 +1,5 @@ +Controller = Class.extend({ + + load : $nop + +}); Modified: funjs/public_html/funjs/HtmlUtils.js =================================================================== --- funjs/public_html/funjs/HtmlUtils.js 2014-06-19 09:21:00 UTC (rev 713) +++ funjs/public_html/funjs/HtmlUtils.js 2014-06-19 11:09:11 UTC (rev 714) @@ -8,3 +8,5 @@ $log = console.log.bind(console); $warm = console.warn.bind(console); + +$nop = new Function(); Modified: funjs/public_html/funjs/TemplateEngine.js =================================================================== --- funjs/public_html/funjs/TemplateEngine.js 2014-06-19 09:21:00 UTC (rev 713) +++ funjs/public_html/funjs/TemplateEngine.js 2014-06-19 11:09:11 UTC (rev 714) @@ -19,11 +19,13 @@ } element.innerHTML = content; - self.parse(element, data || {}); + self.parse(element, data); }); }, parse: function(root, data) { + data = data || {}; + this.parseElement(root, data); var children = root.childNodes, @@ -42,7 +44,20 @@ }, parseElement: function(element, data) { -// $log("Element", element) + var datas = element.dataset; + if (datas) { + + if (datas.ctrl) { + this.currentCtrl = new window[datas.ctrl]; + this.currentCtrl.node = element; + this.currentCtrl.load(); +// element.crtl = currentCtrl; + } + + if (datas.click && this.currentCtrl) { + element.onclick = this.currentCtrl[datas.click]; + } + } }, parseText: function(element, data) { Modified: funjs/public_html/index.html =================================================================== --- funjs/public_html/index.html 2014-06-19 09:21:00 UTC (rev 713) +++ funjs/public_html/index.html 2014-06-19 11:09:11 UTC (rev 714) @@ -9,18 +9,40 @@ <script src="funjs/Deferred.js" type="text/javascript"></script> <script src="funjs/TemplateScriptReader.js" type="text/javascript"></script> <script src="funjs/TemplateEngine.js" type="text/javascript"></script> + <script src="funjs/Controller.js" type="text/javascript"></script> <script src="funjs/Boot.js" type="text/javascript"></script> <script id="hello" type="text/html"> <div id="hello"> - <p>Hello World {{?from}} to {{?to}}!</p> + <p>Hello World {{from}} to {{to?}}!</p> + <p>{{test ? value : other}}</p> </div> </script> + <script type="text/javascript"> + BodyCtrl = Controller.extend({ + load : function() { + $log("Load BodyCtrl", this.node); + + $template.load("hello", "content", { + test : true, + value : "YES", + other : "NO", + from : "me", + to : "you" + }); + }, + + touch : function() { + $log("touch"); + } + }); + </script> + </head> - <body> - <div id="body"></div> - <h1>Empty</h1> + <body data-ctrl="BodyCtrl"> + <h1>Test application</h1> + <div id="content" data-click="touch"></div> </body> </html>