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