<commit_before>define(["sugar-web/activity/activity", "sugar-web/datastore", "notepalette", "zoompalette", "sugar-web/graphics/presencepalette", "humane", "tutorial", "sugar-web/env", "webL10n", "sugar-web/graphics/journalchooser"], function (activity, datastore, notepalette, zoompalette, presencepalette, humane, tutorial, env, l10n, journalchooser) {
	var defaultColor = '#FFF29F';
	var isShared = false;
	var isHost = false;
	var network = null;
	var connectedPeople = {};
	var xoLogo = '<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC \'-//W3C//DTD SVG 1.1//EN\'  \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\' [<!ENTITY stroke_color "#010101"><!ENTITY fill_color "#FFFFFF">]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="stock-xo_1_"><path d="M33.233,35.1l10.102,10.1c0.752,0.75,1.217,1.783,1.217,2.932   c0,2.287-1.855,4.143-4.146,4.143c-1.145,0-2.178-0.463-2.932-1.211L27.372,40.961l-10.1,10.1c-0.75,0.75-1.787,1.211-2.934,1.211   c-2.284,0-4.143-1.854-4.143-4.141c0-1.146,0.465-2.184,1.212-2.934l10.104-10.102L11.409,24.995   c-0.747-0.748-1.212-1.785-1.212-2.93c0-2.289,1.854-4.146,4.146-4.146c1.143,0,2.18,0.465,2.93,1.214l10.099,10.102l10.102-10.103   c0.754-0.749,1.787-1.214,2.934-1.214c2.289,0,4.146,1.856,4.146,4.145c0,1.146-0.467,2.18-1.217,2.932L33.233,35.1z" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/><circle cx="27.371" cy="10.849" fill="&fill_color;" r="8.122" stroke="&stroke_color;" stroke-width="3.5"/></g></svg>';

	// Manipulate the DOM only when it is ready.
	requirejs(['domReady!'], function (doc) {

		// Initialize the activity.
		activity.setup();

		// Handle toolbar mode switch
		var currentMode = 0;
		var nodetextButton = document.getElementById("nodetext-button");
		var removeButton = document.getElementById("delete-button");
		var switchMode = function(newMode) {
			currentMode = newMode;
			nodetextButton.classList.remove('active');
			removeButton.classList.remove('active');
			saveAndFinishEdit();
			if (newMode == 0) nodetextButton.classList.add('active');
			else if (newMode == 1) removeButton.classList.add('active');
			if (lastSelected != null) {
				unselectAllNode();
				lastSelected = null;
			}
		}
		nodetextButton.addEventListener('click', function () { switchMode(0); }, true);
		removeButton.addEventListener('click', function () { switchMode(1); }, true);
		var colorButton = document.getElementById("color-button");
		colorPalette = new notepalette.NotePalette(colorButton);
		colorPalette.setColor('rgb(255, 242, 159)');
		colorPalette.addEventListener('colorChange', function(e) {
			if (isSelectedNode(lastSelected)) {
				pushState({
					redo: {action:"update", id:lastSelected.id(), color: e.detail.color},
					undo: {action:"update", id:lastSelected.id(), color: lastSelected.data('background-color')}
				});
				lastSelected.style('background-color', e.detail.color);
				lastSelected.data('background-color', e.detail.color);
			}
			textValue.style.backgroundColor = e.detail.color;
			defaultColor = e.detail.color;
		});
		var zoomButton = document.getElementById("zoom-button");
		zoomPalette = new zoompalette.zoomPalette(zoomButton);
		zoomPalette.addEventListener('pop', function(e) {
		});
		zoomPalette.addEventListener('zoom', function(e) {
			var action = e.detail.zoom;
			var currentZoom = cy.zoom();
			var zoomStep = 0.25;
			if (action == 0) {
				if (currentZoom != cy.minZoom() && currentZoom-zoomStep > cy.minZoom()) cy.zoom(currentZoom-zoomStep);
			} else if (action == 1) {
				if (currentZoom != cy.maxZoom()) cy.zoom(currentZoom+zoomStep);
			} else if (action == 2) {
				cy.fit();
			} else if (action == 3) {
				cy.center();
			}
		});
		var pngButton = document.getElementById("png-button");
		pngButton.addEventListener('click', function(e) {
			var inputData = cy.png();
			var mimetype = inputData.split(";")[0].split(":")[1];
			var type = mimetype.split("/")[0];
			var metadata = {
				mimetype: mimetype,
				title: type.charAt(0).toUpperCase() + type.slice(1) + " Shared Notes",
				activity: "org.olpcfrance.MediaViewerActivity",
				timestamp: new Date().getTime(),
				creation_time: new Date().getTime(),
				file_size: 0
			};
			datastore.create(metadata, function() {
				humane.log(l10n.get('NotesSaved'));
				console.log("export done.")
			}, inputData);
		});
		var networkButton = document.getElementById("network-button");
		var presence = new presencepalette.PresencePalette(networkButton, undefined);

		var background_img_x = 0;
		var background_img_y = 0;
		var prev_background_img_shift_x = 0;
		var prev_background_img_shift_y = 0;
		var zoom_background = 1;
		var img_url = '';

		function set_background_img(data) {
			img_url = data;
			document.getElementById("cy").style.backgroundImage = "url('"+data+"')";
			document.getElementById("cy").style.backgroundRepeat = "no-repeat";
			document.getElementById("cy").style.backgroundSize = "cover";
			var new_x = background_img_x + prev_background_img_shift_x;
			var new_y = background_img_y + prev_background_img_shift_y;
			document.getElementById("cy").style.backgroundPositionX = new_x.toString() + 'px';
			document.getElementById("cy").style.backgroundPositionY = new_y.toString() + 'px';
			document.getElementById("cy").style.backgroundSize = "" + zoom_background*100 + "%";
		}

		document.getElementById("background-image-button").addEventListener('click', function (e) {
			journalchooser.show(function (entry) {
				// No selection
				if (!entry) {
					return;
				}
				// Get object content
				var dataentry = new datastore.DatastoreObject(entry.objectId);
				dataentry.loadAsText(function (err, metadata, data) {
					set_background_img(data);
				});
			}, { mimetype: 'image/png' }, { mimetype: 'image/jpeg' });
		});

		// Handle graph save/world
		var stopButton = document.getElementById("stop-button");<commit_msg>Removed cover as initial size of background image<commit_after>define(["sugar-web/activity/activity", "sugar-web/datastore", "notepalette", "zoompalette", "sugar-web/graphics/presencepalette", "humane", "tutorial", "sugar-web/env", "webL10n", "sugar-web/graphics/journalchooser"], function (activity, datastore, notepalette, zoompalette, presencepalette, humane, tutorial, env, l10n, journalchooser) {
	var defaultColor = '#FFF29F';
	var isShared = false;
	var isHost = false;
	var network = null;
	var connectedPeople = {};
	var xoLogo = '<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC \'-//W3C//DTD SVG 1.1//EN\'  \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\' [<!ENTITY stroke_color "#010101"><!ENTITY fill_color "#FFFFFF">]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="stock-xo_1_"><path d="M33.233,35.1l10.102,10.1c0.752,0.75,1.217,1.783,1.217,2.932   c0,2.287-1.855,4.143-4.146,4.143c-1.145,0-2.178-0.463-2.932-1.211L27.372,40.961l-10.1,10.1c-0.75,0.75-1.787,1.211-2.934,1.211   c-2.284,0-4.143-1.854-4.143-4.141c0-1.146,0.465-2.184,1.212-2.934l10.104-10.102L11.409,24.995   c-0.747-0.748-1.212-1.785-1.212-2.93c0-2.289,1.854-4.146,4.146-4.146c1.143,0,2.18,0.465,2.93,1.214l10.099,10.102l10.102-10.103   c0.754-0.749,1.787-1.214,2.934-1.214c2.289,0,4.146,1.856,4.146,4.145c0,1.146-0.467,2.18-1.217,2.932L33.233,35.1z" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/><circle cx="27.371" cy="10.849" fill="&fill_color;" r="8.122" stroke="&stroke_color;" stroke-width="3.5"/></g></svg>';

	// Manipulate the DOM only when it is ready.
	requirejs(['domReady!'], function (doc) {

		// Initialize the activity.
		activity.setup();

		// Handle toolbar mode switch
		var currentMode = 0;
		var nodetextButton = document.getElementById("nodetext-button");
		var removeButton = document.getElementById("delete-button");
		var switchMode = function(newMode) {
			currentMode = newMode;
			nodetextButton.classList.remove('active');
			removeButton.classList.remove('active');
			saveAndFinishEdit();
			if (newMode == 0) nodetextButton.classList.add('active');
			else if (newMode == 1) removeButton.classList.add('active');
			if (lastSelected != null) {
				unselectAllNode();
				lastSelected = null;
			}
		}
		nodetextButton.addEventListener('click', function () { switchMode(0); }, true);
		removeButton.addEventListener('click', function () { switchMode(1); }, true);
		var colorButton = document.getElementById("color-button");
		colorPalette = new notepalette.NotePalette(colorButton);
		colorPalette.setColor('rgb(255, 242, 159)');
		colorPalette.addEventListener('colorChange', function(e) {
			if (isSelectedNode(lastSelected)) {
				pushState({
					redo: {action:"update", id:lastSelected.id(), color: e.detail.color},
					undo: {action:"update", id:lastSelected.id(), color: lastSelected.data('background-color')}
				});
				lastSelected.style('background-color', e.detail.color);
				lastSelected.data('background-color', e.detail.color);
			}
			textValue.style.backgroundColor = e.detail.color;
			defaultColor = e.detail.color;
		});
		var zoomButton = document.getElementById("zoom-button");
		zoomPalette = new zoompalette.zoomPalette(zoomButton);
		zoomPalette.addEventListener('pop', function(e) {
		});
		zoomPalette.addEventListener('zoom', function(e) {
			var action = e.detail.zoom;
			var currentZoom = cy.zoom();
			var zoomStep = 0.25;
			if (action == 0) {
				if (currentZoom != cy.minZoom() && currentZoom-zoomStep > cy.minZoom()) cy.zoom(currentZoom-zoomStep);
			} else if (action == 1) {
				if (currentZoom != cy.maxZoom()) cy.zoom(currentZoom+zoomStep);
			} else if (action == 2) {
				cy.fit();
			} else if (action == 3) {
				cy.center();
			}
		});
		var pngButton = document.getElementById("png-button");
		pngButton.addEventListener('click', function(e) {
			var inputData = cy.png();
			var mimetype = inputData.split(";")[0].split(":")[1];
			var type = mimetype.split("/")[0];
			var metadata = {
				mimetype: mimetype,
				title: type.charAt(0).toUpperCase() + type.slice(1) + " Shared Notes",
				activity: "org.olpcfrance.MediaViewerActivity",
				timestamp: new Date().getTime(),
				creation_time: new Date().getTime(),
				file_size: 0
			};
			datastore.create(metadata, function() {
				humane.log(l10n.get('NotesSaved'));
				console.log("export done.")
			}, inputData);
		});
		var networkButton = document.getElementById("network-button");
		var presence = new presencepalette.PresencePalette(networkButton, undefined);

		var background_img_x = 0;
		var background_img_y = 0;
		var prev_background_img_shift_x = 0;
		var prev_background_img_shift_y = 0;
		var zoom_background = 1;
		var img_url = '';

		function set_background_img(data) {
			img_url = data;
			document.getElementById("cy").style.backgroundImage = "url('"+data+"')";
			document.getElementById("cy").style.backgroundRepeat = "no-repeat";
			var new_x = background_img_x + prev_background_img_shift_x;
			var new_y = background_img_y + prev_background_img_shift_y;
			document.getElementById("cy").style.backgroundPositionX = new_x.toString() + 'px';
			document.getElementById("cy").style.backgroundPositionY = new_y.toString() + 'px';
			document.getElementById("cy").style.backgroundSize = "" + zoom_background*100 + "%";
		}

		document.getElementById("background-image-button").addEventListener('click', function (e) {
			journalchooser.show(function (entry) {
				// No selection
				if (!entry) {
					return;
				}
				// Get object content
				var dataentry = new datastore.DatastoreObject(entry.objectId);
				dataentry.loadAsText(function (err, metadata, data) {
					set_background_img(data);
				});
			}, { mimetype: 'image/png' }, { mimetype: 'image/jpeg' });
		});

		// Handle graph save/world
		var stopButton = document.getElementById("stop-button");
{'fraction_non_alphanumeric': 0.1783550502116358, 'fraction_numerical': 0.07386505104158021, 'mean_word_length': 4.430374042361424, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 2, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5992278', 'n_tokens_mistral': 5173, 'n_tokens_neox': 4278, 'n_words': 690}