From 4f825dcb19e107ac82a76f52759c23533ed9936b Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Thu, 2 Oct 2014 17:57:32 +0200 Subject: [PATCH] Allow empty attribute syntax to mean "same command as ID". --- src/yuu/director.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/yuu/director.js b/src/yuu/director.js index 7f90fd4..051eb53 100644 --- a/src/yuu/director.js +++ b/src/yuu/director.js @@ -17,6 +17,13 @@ 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 @@ -564,7 +571,7 @@ 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()) { @@ -625,7 +632,7 @@ 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()) { -- 2.30.2