anonymize.js
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Explore plugin.
*/
Draw.loadPlugin(function(editorUi)
{
var div = document.createElement('div');
// Adds resource for action
mxResources.parse('anonymizeCurrentPage=Anonymize Current Page');
function replaceTextContent(elt)
{
if (elt.nodeValue != null)
{
elt.nodeValue = editorUi.anonymizeString(elt.nodeValue);
}
if (elt.nodeType == mxConstants.NODETYPE_ELEMENT)
{
var tmp = elt.firstChild;
while (tmp != null)
{
replaceTextContent(tmp);
tmp = tmp.nextSibling;
}
}
};
function anonymizeHtml(html)
{
div.innerHTML = html;
replaceTextContent(div);
return div.innerHTML;
};
// Adds action
editorUi.actions.addAction('anonymizeCurrentPage', function()
{
var graph = editorUi.editor.graph;
var model = graph.model;
model.beginUpdate();
try
{
// Queue used to fix ancestor placeholders
var queue = [];
for (var id in model.cells)
{
var cell = model.cells[id];
var label = graph.getLabel(cell);
if (graph.isHtmlLabel(cell))
{
label = anonymizeHtml(label);
}
else
{
label = editorUi.anonymizeString(label);
}
queue.push({cell: cell, label: label});
}
for (var i = 0; i < queue.length; i++)
{
model.setValue(queue[i].cell, queue[i].label);
}
// Change page title
if (editorUi.currentPage != null)
{
model.execute(new RenamePage(editorUi, editorUi.currentPage,
editorUi.anonymizeString(editorUi.currentPage.getName())));
}
}
finally
{
model.endUpdate();
}
});
var menu = editorUi.menus.get('extras');
var oldFunct = menu.funct;
menu.funct = function(menu, parent)
{
oldFunct.apply(this, arguments);
editorUi.menus.addMenuItems(menu, ['-', 'anonymizeCurrentPage'], parent);
};
});