Allow empty attribute syntax to mean "same command as ID".
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 2 Oct 2014 15:57:32 +0000 (17:57 +0200)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 2 Oct 2014 15:57:32 +0000 (17:57 +0200)
src/yuu/director.js

index 7f90fd4a30c6399415348e286dffa98fce7ca722..051eb539855d01da348b9b63f324cf8a2acb2427 100644 (file)
     if (!yuu.InputState) require("./input");
     if (!yuu.Material) require("./gfx");
 
+    function getCommand (element) {
+        var command = element.getAttribute('data-yuu-command');
+        if (!command || command === 'data-yuu-command')
+            element.setAttribute('data-yuu-command', command = element.id);
+        return command;
+    }
+
     yuu.Director = yT({
         constructor: function (commandStack, input, tickHz) {
             /** Manage and update a set of Scenes
             var elements = element.querySelectorAll("[data-yuu-command]");
 
             yf.each(function (element) {
-                var command = element.getAttribute("data-yuu-command");
+                var command = getCommand(element);
                 switch (element.tagName.toLowerCase()) {
                 case "input":
                     switch (element.type.toLowerCase()) {
         function handleElement (event) {
             /*jshint validthis:true */
             /* `this` comes from being a DOM element event handler. */
-            var command = this.getAttribute("data-yuu-command");
+            var command = getCommand(this);
             switch (this.tagName.toLowerCase()) {
             case "input":
                 switch (this.type.toLowerCase()) {