<commit_before>var sketchModule = (function () 
{
	/******************************** Configurable options ********************************************/
	var isStandalone = true;
	var lcConfig = {
//			onInit:				
					imageURLPrefix: 	'libs/literallycanvas-0.4.14/img',
					backgroundColor:	'#fff',
					toolbarPosition: 	'bottom',
					tools:				[
					      				 LC.tools.Pencil,
					      				 LC.tools.Eraser,
					      				 LC.tools.Line,
					      				 LC.tools.Rectangle,
					      				 LC.tools.Text,    						
					      				 ],
					      				 defaultStrokeWidth: 3,
					      				 strokeWidths: 		[1, 2, 3, 5]
	};
	
	/******************************** "Private" variables ********************************************/
	
	var moduleName = 'sketchModule'; // needs to correspond to the name of the variable this module is held in
	var localStorageSupported = typeof(Storage) == "undefined" ? false : true;
	var currentSnapshot = null;
	var currentSnapshotName = null;
	var lc = null;
	
	/******************************** "Private" functions ********************************************/
	
	/*
	 * Displays extra control buttons for the basic functions.
	 */
	initExtraControls = function()
	{
		$('#controls').append(
			 '<button type="button" class="controls" onclick="' + moduleName + '.load()">Laden</button>'
			+'<button type="button" class="controls" onclick="' + moduleName + '.save()">Speichern</button>'
			+'<button type="button" class="controls" onclick="' + moduleName + '.save(true)">Speichern unter</button>'
			+'<button type="button" class="controls" onclick="' + moduleName + '.exportAs(\'png\')">Exportieren</button>'
		);
	},
	
	
	/*
	 * Persists the current state to local storage under the given name.
	 */
	saveSnapshotUnderName = function(snapshotName)
	{
		if (!snapshotName) {
			return;
		}
		currentSnapshot = lc.getSnapshot();
		
		if (localStorageSupported) {
				localStorage.setItem(snapshotName, JSON.stringify(currentSnapshot));
		}
		else {
			// TODO error handling no storage
		}
	};

	/*
	 * Loads a persisted snapshot (as identified by the name) and renders it.
	 */
	loadSnapshotByName = function(snapshotName) 
	{
		if (!snapshotName) {
			return;
		}
		if (localStorageSupported) {
			var snapshot = JSON.parse(localStorage.getItem(snapshotName));
			if (snapshot) {
				lc.loadSnapshot(snapshot); // render snapshot
				currentSnapshot = snapshot;
			}
			else {
				// TODO
				alert("Keine Skizze mit diesem Namen gefunden!");
			}	
		} else {
			// TODO error handling no storage
		}
	}
	
	/******************************** "Public" API ********************************************/
	return {
		
		/*
		 * Initializes the literallyCanvas object and the extra buttons (if standalone)
		 */
		init: function() 
		{
			lc = LC.init(
					document.getElementById('lc'),
					lcConfig
			);
			if (isStandalone) {
				initExtraControls();
			}
		},

		/*
		 * Wraps the logic of persisting snapshots by getting a file name if necessary
		 * and then persisting the current state under that name.
		 */
		save : function(getNewName = false) {
			if (getNewName || !currentSnapshotName) { 
				currentSnapshotName = prompt('Speichern als:'); // TODO
				// TODO user feedback: Name der aktuellen Skizze anzeigen
				if (!currentSnapshotName)
					return;
			}
			saveSnapshotUnderName(currentSnapshotName);
			// TODO user feedback
		},
	
		/*
		 * Wraps the logic of loading a sketch by getting the name of the sketch
		 * and loading it.
		 */
		load : function() {
			// TODO alten snapshot speichern?
			currentSnapshotName = prompt('Name der zu ladenden Skizze:');
			if (currentSnapshotName) {
				loadSnapshotByName(currentSnapshotName);	
			}
		},
	
		/*
		 * Returns the current state as either png or svg
		 */
		exportAs : function(format) {
			if (format == 'png') {
				var image = lc.getImage();
				if(image) {
					return image.toDataURL();
				} else {
					//TODO warn: empty image
					return null;
				}
			}
			else if (format == 'svg'){
	
			}
			else {
				// Format nicht unterstützt
			}
		}
	};
})();

$(function() {
	sketchModule.init();
});
<commit_msg>finished refactoring: komplette Funktionalitaet ins Modul gezogen<commit_after>var sketchModule = (function () 
{
	/******************************** Configurable options *****************************************************/
	var isStandalone = true;
	var lcConfig = {
//			onInit:				
					imageURLPrefix: 	'libs/literallycanvas-0.4.14/img',
					backgroundColor:	'#fff',
					toolbarPosition: 	'bottom',
					tools:				[
					      				 LC.tools.Pencil,
					      				 LC.tools.Eraser,
					      				 LC.tools.Line,
					      				 LC.tools.Rectangle,
					      				 LC.tools.Text,    						
					      				 ],
					      				 defaultStrokeWidth: 3,
					      				 strokeWidths: 		[1, 2, 3, 5]
	};
	
	/**********************************************************************************************************/
	
	var localStorageSupported = typeof(Storage) == "undefined" ? false : true;
	var currentSnapshot = null;
	var currentSnapshotName = null;
	var lc = null;
	
	$(function() {
		init();
	});

	/*
	 * Initializes the literallyCanvas object and the extra buttons (if standalone)
	 */
	function init() 
	{
		lc = LC.init($('#lc')[0],lcConfig);
		if (isStandalone) {
			$('<button type="button" class="controls">Laden</button>').appendTo('#controls')
				.on('click',load);
			$('<button type="button" class="controls">Speichern</button>').appendTo('#controls')
				.on('click',save);
			$('<button type="button" class="controls">Speichern unter</button>').appendTo('#controls')
				.on('click',function(){ return save(true)});
			$('<button type="button" class="controls">Exportieren</button>').appendTo('#controls')
				.on('click',function(){ return exportAs('png')});
		}
	}
	
	/*
	 * Wraps the logic of persisting snapshots by getting a file name if necessary
	 * and then persisting the current state under that name.
	 */
	function save(getNewName = false) {
		if (getNewName || !currentSnapshotName) { 
			currentSnapshotName = prompt('Speichern als:'); // TODO
			// TODO user feedback: Name der aktuellen Skizze anzeigen
			if (!currentSnapshotName)
				return;
		}
		saveSnapshotUnderName(currentSnapshotName);
		// TODO user feedback
	}

	/*
	 * Wraps the logic of loading a sketch by getting the name of the sketch
	 * and loading it.
	 */
	 function load() {
		// TODO alten snapshot speichern?
		currentSnapshotName = prompt('Name der zu ladenden Skizze:');
		if (currentSnapshotName) {
			loadSnapshotByName(currentSnapshotName);	
		}
	}

	/*
	 * Returns the current state as either png or svg
	 */
	function exportAs(format) {
		if (format == 'png') {
			var image = lc.getImage();
			if(image) {
				return image.toDataURL();
			} else {
				//TODO warn: empty image
				return null;
			}
		}
		else if (format == 'svg'){

		}
		else {
			// Format nicht unterstützt
		}
	};
	
	/*
	 * Persists the current state to local storage under the given name.
	 */
	function saveSnapshotUnderName(snapshotName)
	{
		if (!snapshotName) {
			return;
		}
		currentSnapshot = lc.getSnapshot();
		
		if (localStorageSupported) {
				localStorage.setItem(snapshotName, JSON.stringify(currentSnapshot));
		}
		else {
			// TODO error handling no storage
		}
	};

	/*
	 * Loads a persisted snapshot (as identified by the name) and renders it.
	 */
	function loadSnapshotByName(snapshotName) 
	{
		if (!snapshotName) {
			return;
		}
		if (localStorageSupported) {
			var snapshot = JSON.parse(localStorage.getItem(snapshotName));
			if (snapshot) {
				lc.loadSnapshot(snapshot); // render snapshot
				currentSnapshot = snapshot;
			}
			else {
				// TODO
				alert("Keine Skizze mit diesem Namen gefunden!");
			}	
		} else {
			// TODO error handling no storage
		}
	}
	
	/******************************** "Public" API ********************************************/
	return {
		load : load,
		save : save,
		exportAs : exportAs
	};
}).call(this);

{'fraction_non_alphanumeric': 0.19262038774233897, 'fraction_numerical': 0.0023764853033145716, 'mean_word_length': 3.054766734279919, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2426555', 'n_tokens_mistral': 2905, 'n_tokens_neox': 2341, 'n_words': 596}