Skip to content

Commit cb9c465

Browse files
committed
Update query methodology, rename alignment method
Previous method was flawed in that it operates on one element "too high" in the DOM. Instead, query the widgetid and utilize this to modify the style of the DOM. Renamed the text alignment method to textAlign to better match the CSS terminology.
1 parent 3d1eb61 commit cb9c465

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

mlapptools.m

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
%
44
% MLAPPTOOLS methods:
55

6+
properties
7+
% TODO: Move generic portions of repeated dojo query strings here
8+
% to reduce copypasta errors as the number of methods expands
9+
end
10+
611
methods
712
function obj = mlapptools
813
% Dummy constructor so we don't return an empty class instance
@@ -11,24 +16,28 @@
1116
end
1217

1318
methods (Static)
14-
function alignstring(uielement, alignment)
19+
function textAlign(uielement, alignment)
1520
alignment = lower(alignment);
1621
mlapptools.validatealignmentstr(alignment)
1722
mlapptools.togglewarnings('off')
1823

1924
rez = '';
2025
while ~strcmp(rez, sprintf('"%s"', alignment))
2126
try
22-
% 1. Get a handle to the webwindow:
27+
% Get a handle to the webwindow
2328
win = struct(struct(uielement.Parent).Controller).Container.CEF;
24-
% 2. Find which element of the DOM we want to edit (as before):
29+
30+
% Find which element of the DOM we want to edit
2531
data_tag = char(struct(uielement).Controller.ProxyView.PeerNode.getId);
26-
% 3. Manipulate the DOM via a JS command
27-
JSstr = sprintf('dojo.style(dojo.query("[data-tag^=''%s'']")[0], "textAlign", "%s")', ...
28-
data_tag, alignment);
29-
rez = win.executeJS(JSstr);
32+
33+
% Manipulate the DOM via a JS command
34+
widgetquerystr = sprintf('dojo.getAttr(dojo.query("[data-tag^=''%s''] > div")[0], "widgetid")', data_tag);
35+
widgetID = win.executeJS(widgetquerystr);
36+
widgetID = widgetID(2:end-1);
37+
38+
alignsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "textAlign", "%s")', widgetID, alignment);
39+
rez = win.executeJS(alignsetstr);
3040
catch
31-
% TODO: See if an infinite loop condition is possible
3241
pause(1); % Give the figure (webpage) some more time to load
3342
end
3443
end

0 commit comments

Comments
 (0)