<commit_before>/***
|''Name''|ToggleTiddlerPrivacyPlugin|
|''Version''|0.5.3|
|''Status''|@@beta@@|
|''Description''|Allows you to set the privacy of new tiddlers and external tiddlers within an EditTemplate|
|''Requires''|TiddlySpaceConfig|
|''Source''|http://github.com/TiddlySpace/tiddlyspace/raw/master/src/plugins/ToggleTiddlerPrivacyPlugin.js|
!Notes
When used in conjunction with TiddlySpaceTiddlerIconsPlugin changing the privacy setting will also interact with any privacy icons.

!Params
defaultValue:[private|public]
Allows you to set the default privacy value (Default is private)

!Code
***/
//{{{
(function($) {

var macro = config.macros.setPrivacy = {
	handler: function(place, macroName, params, wikifier, paramString, tiddler) {
		var el = $(story.findContainingTiddler(place));
		var args = paramString.parseParams("name", null, true, false, true)[0];
		var container = $("<div />").addClass("privacySettings").appendTo(place);
		var currentSpace = config.extensions.tiddlyspace.currentSpace.name;
		var currentWorkspace = tiddler ? tiddler.fields["server.workspace"] : false;
		var currentBag = tiddler.fields["server.bag"] || "";
		var isNewTiddler = el.hasClass("missing") || !currentWorkspace; // XXX: is this reliable?
		var privateWorkspace = "bags/%0_private".format([currentSpace]);
		var publicWorkspace = "bags/%0_public".format([currentSpace]);
		var isExternal = currentBag.indexOf("/%0_".format([currentSpace])) > -1 ||
			currentBag == "tiddlyspace";
		var originButton = $(".originButton", el)[0];
		var iconOptions = { labelOptions: { includeLabel: "true" } };
		if(isNewTiddler || isExternal) {
			var rbtn = $("<input />").attr("type", "radio").attr("name", tiddler.title);
			var rPrivate = rbtn.clone().val("private").addClass("isPrivate").appendTo(container);
			$("<label />").text("private").appendTo(container); // TODO: i18n
			var rPublic = rbtn.clone().val("public").addClass("isPublic").appendTo(container);
			$("<label />").text("public").appendTo(container); // TODO: i18n
			var userDefault = args.defaultValue;
			var defaultVal = userDefault ? "bags/%0_%1".format([currentSpace, userDefault[0]]) : currentWorkspace;
			defaultVal = defaultVal ? defaultVal : privateWorkspace;
			var initialStatus = "private";
			if(publicWorkspace == defaultVal) {
				rPublic.attr("checked", true);
				initialStatus = "public";
			} else {
				rPrivate.attr("checked", true);
			}

			var refreshIcon = function(type) {
				var originMacro = config.macros.originMacro;
				if(originButton && originMacro) {
					$(originButton).empty();
					originMacro.showPrivacyRoundel(tiddler, type, originButton, null, iconOptions);
				}
			};
			var setWorkspace = function(workspace) {
				var saveField = $("[edit=server.workspace]", el);
				saveField.val(workspace);
				tiddler.fields["server.workspace"] = workspace; // for external tiddlers
			};
			
			$("[type=radio]", container).click(function() {
				var btn = $(this);
				var name = el.attr("name");
				tiddler.fields["server.page.revision"] = "false";
				if(btn.hasClass("isPrivate")) { // private button clicked.
					el.addClass("isPrivate").removeClass("isPublic");
					setWorkspace(privateWorkspace);
					refreshIcon("private");
				} else {
					el.addClass("isPublic").removeClass("isPrivate");
					setWorkspace(publicWorkspace);
					refreshIcon("public");
				}
			});
			// TODO: replace with a hijack of displayTiddler?
			window.setTimeout(function() {
				setWorkspace(defaultVal);
				refreshIcon(initialStatus);
			}, 200); // not ideal - but need to wait till finished displayTiddler for brand new tiddlers
		}
	}
};

})(jQuery);
//}}}<commit_msg>toggle tiddler privacy plugin<commit_after>/***
|''Name''|ToggleTiddlerPrivacyPlugin|
|''Version''|0.5.5|
|''Status''|@@beta@@|
|''Description''|Allows you to set the privacy of new tiddlers and external tiddlers within an EditTemplate|
|''Requires''|TiddlySpaceConfig|
|''Source''|http://github.com/TiddlySpace/tiddlyspace/raw/master/src/plugins/ToggleTiddlerPrivacyPlugin.js|
!Notes
When used in conjunction with TiddlySpaceTiddlerIconsPlugin changing the privacy setting will also interact with any privacy icons.

Currently use of
<<setPrivacy defaultValue:public>> is in conflict with <<newTiddler fields:"server.workspace:x_private">>
!Params
defaultValue:[private|public]
Allows you to set the default privacy value (Default is private)

!Code
***/
//{{{
(function($) {

var macro = config.macros.setPrivacy = {
	handler: function(place, macroName, params, wikifier, paramString, tiddler) {
		var el = $(story.findContainingTiddler(place));
		var args = paramString.parseParams("name", null, true, false, true)[0];
		var container = $("<div />").addClass("privacySettings").appendTo(place)[0];
		var currentSpace = config.extensions.tiddlyspace.currentSpace.name;
		var currentWorkspace = tiddler ? tiddler.fields["server.workspace"] : false;
		var currentBag = tiddler.fields["server.bag"] || "";
		var isNewTiddler = el.hasClass("missing") || !currentWorkspace; // XXX: is this reliable?
		var isExternal = currentBag.indexOf("/%0_".format([currentSpace])) > -1 ||
			currentBag == "tiddlyspace";
		if(isNewTiddler || isExternal) {
			var userDefault = args.defaultValue;
			userDefault = userDefault ? "bags/%0_%1".format([currentSpace, userDefault[0]]) : false;
			var defaultValue = currentWorkspace || userDefault || false;
			macro.createRoundel(container, tiddler, currentSpace, defaultValue);
		}
	},
	createRoundel: function(container, tiddler, currentSpace, defaultValue) {
		var iconOptions = { labelOptions: { includeLabel: "true" } };
		var el = $(story.findContainingTiddler(container));
		var originButton = $(".originButton", el)[0];
		var privateWorkspace = "bags/%0_private".format([currentSpace]);
		var publicWorkspace = "bags/%0_public".format([currentSpace]);
		var rbtn = $("<input />").attr("type", "radio").attr("name", tiddler.title);
		var rPrivate = rbtn.clone().val("private").addClass("isPrivate").appendTo(container);
		$("<label />").text("private").appendTo(container); // TODO: i18n
		var rPublic = rbtn.clone().val("public").addClass("isPublic").appendTo(container);
		$("<label />").text("public").appendTo(container); // TODO: i18n
		var status = "private";

		var refreshIcon = function(type) {
			var originMacro = config.macros.originMacro;
			if(originButton && originMacro) {
				$(originButton).empty();
				originMacro.showPrivacyRoundel(tiddler, type, originButton, null, iconOptions);
			}
		};
		var setWorkspace = function(workspace) {
			var saveField = $("[edit=server.workspace]", el);
			if(!workspace) {
				workspace = saveField.val();
			}
			if(workspace) {
				saveField.val(workspace);
				tiddler.fields["server.workspace"] = workspace; // for external tiddlers
				if(workspace.indexOf("_public") > -1) {
					rPublic.attr("checked", true);
					rPrivate.attr("checked", false);
					status = "public";
				} else {
					rPrivate.attr("checked", true);
					rPublic.attr("checked", false); // explicitly do this for ie
					status = "private";
				}
				refreshIcon(status);
			}
		};

		$("[type=radio]", container).click(function() {
			var btn = $(this);
			tiddler.fields["server.page.revision"] = "false";
			if(btn.hasClass("isPrivate")) { // private button clicked.
				el.addClass("isPrivate").removeClass("isPublic");
				setWorkspace(privateWorkspace);
			} else {
				el.addClass("isPublic").removeClass("isPrivate");
				setWorkspace(publicWorkspace);
			}
		});
		// TODO: replace with a hijack of displayTiddler?
		window.setTimeout(function() {
			setWorkspace(defaultValue);
		}, 200); // not ideal - but need to wait till finished displayTiddler for brand new tiddlers
	}
};

})(jQuery);
//}}}
{'fraction_non_alphanumeric': 0.16382428940568475, 'fraction_numerical': 0.00516795865633075, 'mean_word_length': 4.833458929917106, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, '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': '1678142', 'n_tokens_mistral': 2682, 'n_tokens_neox': 2409, 'n_words': 512}