Skip to content

Commit 36a88f4

Browse files
committed
Refactor webwindow & widgetID query to reduce C&P
1 parent 2ad7d73 commit 36a88f4

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

mlapptools.m

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ function textAlign(uielement, alignment)
2020
alignment = lower(alignment);
2121
mlapptools.validatealignmentstr(alignment)
2222

23-
% Get a handle to the webwindow
24-
win = mlapptools.getWebWindow(uielement.Parent);
25-
26-
% Find which element of the DOM we want to edit
27-
data_tag = mlapptools.getDataTag(uielement);
28-
29-
% Manipulate the DOM via a JS command
30-
widgetID = mlapptools.getWidgetID(win, data_tag);
23+
[win, widgetID] = mlapptools.getWebElements(uielement);
3124

3225
alignsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "textAlign", "%s")', widgetID, alignment);
3326
win.executeJS(alignsetstr);
@@ -37,31 +30,17 @@ function textAlign(uielement, alignment)
3730
function fontWeight(uielement, weight)
3831
weight = mlapptools.validatefontweight(weight);
3932

40-
% Get a handle to the webwindow
41-
win = mlapptools.getWebWindow(uielement.Parent);
42-
43-
% Find which element of the DOM we want to edit
44-
data_tag = mlapptools.getDataTag(uielement);
45-
46-
% Manipulate the DOM via a JS command
47-
widgetID = mlapptools.getWidgetID(win, data_tag);
33+
[win, widgetID] = mlapptools.getWebElements(uielement);
4834

4935
fontwtsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "font-weight", "%s")', widgetID, weight);
5036
win.executeJS(fontwtsetstr);
5137
end
5238

5339

54-
function fontcolor(uielement, newcolor)
40+
function fontColor(uielement, newcolor)
5541
newcolor = mlapptools.validateCSScolor(newcolor);
5642

57-
% Get a handle to the webwindow
58-
win = mlapptools.getWebWindow(uielement.Parent);
59-
60-
% Find which element of the DOM we want to edit
61-
data_tag = mlapptools.getDataTag(uielement);
62-
63-
% Manipulate the DOM via a JS command
64-
widgetID = mlapptools.getWidgetID(win, data_tag);
43+
[win, widgetID] = mlapptools.getWebElements(uielement);
6544

6645
fontwtsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "color", "%s")', widgetID, newcolor);
6746
win.executeJS(fontwtsetstr);
@@ -136,6 +115,18 @@ function fontcolor(uielement, newcolor)
136115
end
137116

138117

118+
function [win, widgetID] = getWebElements(uielement)
119+
% Get a handle to the webwindow
120+
win = mlapptools.getWebWindow(uielement.Parent);
121+
122+
% Find which element of the DOM we want to edit
123+
data_tag = mlapptools.getDataTag(uielement);
124+
125+
% Manipulate the DOM via a JS command
126+
widgetID = mlapptools.getWidgetID(win, data_tag);
127+
end
128+
129+
139130
function togglewarnings(togglestr)
140131
switch lower(togglestr)
141132
case 'on'

0 commit comments

Comments
 (0)