Skip to content

Commit d25f7e8

Browse files
committed
Added support in setStyle for non-scalar IDs
It is now possible to apply the same style to multiple elements "in one go".
1 parent 0810e7b commit d25f7e8

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

mlapptools.m

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,21 @@ function fontWeight(uiElement, weight)
356356
ID_obj = varargin{4};
357357
end
358358

359-
styleSetStr = sprintf('dojo.style(dojo.query("[%s = ''%s'']")[0], "%s", "%s")',...
360-
ID_obj.ID_attr, ID_obj.ID_val, styleAttr, styleValue);
361-
% ^ this might result in junk if widgetId=='null'.
362-
try
363-
win.executeJS(styleSetStr);
364-
% ^ this might crash in case of invalid styleAttr/styleValue.
365-
catch ME
366-
% Test for "Invalid or unexpected token":
367-
ME = mlapptools.checkJavascriptSyntaxError(ME, styleSetStr);
368-
rethrow(ME);
359+
% Handle the case of a non-scalar ID_obj recursively:
360+
if ~isscalar(ID_obj)
361+
arrayfun(@(x)mlapptools.setStyle(win, styleAttr, styleValue, x), ID_obj);
362+
else
363+
styleSetStr = sprintf('dojo.style(dojo.query("[%s = ''%s'']")[0], "%s", "%s")',...
364+
ID_obj.ID_attr, ID_obj.ID_val, styleAttr, styleValue);
365+
% ^ this might result in junk if widgetId=='null'.
366+
try
367+
win.executeJS(styleSetStr);
368+
% ^ this might crash in case of invalid styleAttr/styleValue.
369+
catch ME
370+
% Test for "Invalid or unexpected token":
371+
ME = mlapptools.checkJavascriptSyntaxError(ME, styleSetStr);
372+
rethrow(ME);
373+
end
369374
end
370375

371376
% Assign outputs:

0 commit comments

Comments
 (0)