<commit_before>/*globals svgEditor, svgCanvas, $, widget*/
/*jslint vars: true, eqeq: true, regexp: true, continue: true*/
/*
 * ext-storage.js
 *
 * Licensed under the MIT License
 *
 * Copyright(c) 2010 <NAME>
 *
 */
/**
* This extension allows automatic saving of the SVG canvas contents upon
*  page unload (which can later be automatically retrieved upon future
*  editor loads).
*
*  The functionality was originally part of the SVG Editor, but moved to a
*  separate extension to make the setting behavior optional, and adapted
*  to inform the user of its setting of local data.
*/

/*
TODOS
1. Revisit on whether to use $.pref over directly setting curConfig in all
	extensions for a more public API (not only for extPath and imagePath,
	but other currently used config in the extensions)
2. We might provide control of storage settings through the UI besides the
    initial (or URL-forced) dialog.
*/
svgEditor.addExtension('storage', function() {
	// We could empty any already-set data for users when they decline storage,
	//  but it would be a risk for users who wanted to store but accidentally
	// said "no"; instead, we'll let those who already set it, delete it themselves;
	// to change, set the "emptyStorageOnDecline" config setting to true
	// in config.js.
	var emptyStorageOnDecline = svgEditor.curConfig.emptyStorageOnDecline,
		// When the code in svg-editor.js prevents local storage on load per
		//  user request, we also prevent storing on unload here so as to
		//  avoid third-party sites making XSRF requests or providing links
		// which would cause the user's local storage not to load and then
		// upon page unload (such as the user closing the window), the storage
		//  would thereby be set with an empty value, erasing any of the
		// user's prior work. To change this behavior so that no use of storage
		// or adding of new storage takes place regardless of settings, set
		// the "noStorageOnLoad" config setting to true in config.js.
		noStorageOnLoad = svgEditor.curConfig.noStorageOnLoad,
		forceStorage = svgEditor.curConfig.forceStorage,
		storage = svgEditor.storage;

	function replaceStoragePrompt (val) {
		val = val ? 'storagePrompt=' + val : '';
		if (window.location.href.indexOf('storagePrompt=') > -1) {
			window.location.href = window.location.href.replace(/([&?])storagePrompt=[^&]*(&?)/, function (n0, n1, amp) {
				return (val ? n1 : '') + val + (!val && amp ? n1 : (amp || ''));
			});
		}
		else {
			window.location.href += (window.location.href.indexOf('?') > -1 ? '&' : '?') + val;
		}
	}
	function setSVGContentStorage (val) {
		if (storage) {
			var name = 'svgedit-' + svgEditor.curConfig.canvasName;
			if (!val) {
				storage.removeItem(name);
			}
			else {
				storage.setItem(name, val);
			}<commit_msg>Ensure top URL will change in case it wishes to react according to storagePrompt param (such as in the embedded editor).<commit_after>/*globals svgEditor, svgCanvas, $, widget*/
/*jslint vars: true, eqeq: true, regexp: true, continue: true*/
/*
 * ext-storage.js
 *
 * Licensed under the MIT License
 *
 * Copyright(c) 2010 <NAME>
 *
 */
/**
* This extension allows automatic saving of the SVG canvas contents upon
*  page unload (which can later be automatically retrieved upon future
*  editor loads).
*
*  The functionality was originally part of the SVG Editor, but moved to a
*  separate extension to make the setting behavior optional, and adapted
*  to inform the user of its setting of local data.
*/

/*
TODOS
1. Revisit on whether to use $.pref over directly setting curConfig in all
	extensions for a more public API (not only for extPath and imagePath,
	but other currently used config in the extensions)
2. We might provide control of storage settings through the UI besides the
    initial (or URL-forced) dialog.
*/
svgEditor.addExtension('storage', function() {
	// We could empty any already-set data for users when they decline storage,
	//  but it would be a risk for users who wanted to store but accidentally
	// said "no"; instead, we'll let those who already set it, delete it themselves;
	// to change, set the "emptyStorageOnDecline" config setting to true
	// in config.js.
	var emptyStorageOnDecline = svgEditor.curConfig.emptyStorageOnDecline,
		// When the code in svg-editor.js prevents local storage on load per
		//  user request, we also prevent storing on unload here so as to
		//  avoid third-party sites making XSRF requests or providing links
		// which would cause the user's local storage not to load and then
		// upon page unload (such as the user closing the window), the storage
		//  would thereby be set with an empty value, erasing any of the
		// user's prior work. To change this behavior so that no use of storage
		// or adding of new storage takes place regardless of settings, set
		// the "noStorageOnLoad" config setting to true in config.js.
		noStorageOnLoad = svgEditor.curConfig.noStorageOnLoad,
		forceStorage = svgEditor.curConfig.forceStorage,
		storage = svgEditor.storage;

	function replaceStoragePrompt (val) {
		val = val ? 'storagePrompt=' + val : '';
		var loc = top.location; // Allow this to work with the embedded editor as well
		if (loc.href.indexOf('storagePrompt=') > -1) {
			loc.href = loc.href.replace(/([&?])storagePrompt=[^&]*(&?)/, function (n0, n1, amp) {
				return (val ? n1 : '') + val + (!val && amp ? n1 : (amp || ''));
			});
		}
		else {
			loc.href += (loc.href.indexOf('?') > -1 ? '&' : '?') + val;
		}
	}
	function setSVGContentStorage (val) {
		if (storage) {
			var name = 'svgedit-' + svgEditor.curConfig.canvasName;
			if (!val) {
				storage.removeItem(name);
			}
			else {
				storage.setItem(name, val);
			}
{'fraction_non_alphanumeric': 0.10386643233743409, 'fraction_numerical': 0.00421792618629174, 'mean_word_length': 3.578439259855189, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2468518', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1663, 'n_words': 701}