<commit_before>// (c) Copyright 2002-2012 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: tiki-admin_modules.js 39475 2012-01-12 22:47:05Z sylvieg $

$(document).ready(function() {

	var tocDirty = false;

	$(window).bind("beforeunload", function( e ) {
		if (tocDirty) {
			var m = tr("You have unsaved changes to your structure, are you sure you want to leave the page without saving?");
			var e = e || window.event;
			if (e && !($.browser.safari || $.browser.webkit)) {
				e.returnValue = m;
			}
			return m;
		}
	});

	$(".admintoc:first").nestedSortable( {

		disableNesting: 'no-nest',
		forcePlaceholderSize: true,
		handle: 'div',
		helper: 'clone',
		items: 'li',
		//maxLevels: 3,
		opacity: .6,
		tabSize: 20,
		tolerance: 'pointer',
		toleranceElement: '> div',
		placeholder: "ui-state-highlight",
		rootID: "root",

		stop: function (event, ui) {
			if ($(".save_structure a:visible").length === 0) {
				$(".save_structure a").show("fast").parent().show("fast");
				tocDirty = true;
			}
//			$(this).removeClass("ui-state-active");
		},
		start: function (event, ui) {
//			$(this).addClass("ui-state-active");
		}
	}).droppable({
			hoverClass: "ui-state-active",
			drop: function(event, ui) {
				if (!$(ui.draggable).hasClass("admintoclevel")) {
					var pageName = $.trim($(ui.draggable).text());
					$(this).append(
						$('<li class="ui-state-default admintoclevel new"><div>' +
								'<div class="actions"><input type="text" class="page-alias-input" value="" placeholder="Page alias..."></div>' +
								pageName +'</div></li>')
					);
					$(".save_structure a").show("fast").parent().show("fast");
					tocDirty = true;
				}
			}
		})
		.disableSelection();

	$(".page-alias-input").change( function () {
		$(".save_structure a").show("fast").parent().show("fast");
		tocDirty = true;
	});


	$("#page_list_container li").each(function() {
		var el = this;
		$(this).draggable({
			connectToSortable: ".admintoc:first",
			revert: "invalid",
			helper: "clone",
			start: function (event, ui) {
				$(this).css("z-index", 1000);
			},
			stop: function (event, ui) {
				$("#save_structure").show("fast").data("dragged", $(el).attr("id"));
				$(this).css("z-index", "auto");
			}
		}).mouseover(function(event, ui) {	// sortable gets muddled when dragging so disable it
				$(".admintoc:first").sortable("option", "disabled", true);
		}).mouseout(function(event, ui) {
				$(".admintoc:first").sortable("option", "disabled", false);
		}).disableSelection();
	});

	$(".save_structure").click(function(){

		var $sortable = $(this).parent().find(".admintoc:first");
		$sortable.modal(tr("Saving..."));

		var fakeId = 1000000;
		$(".admintoclevel.new").each(function() {
			$(this).attr("id", "node_" + fakeId);
			fakeId++;
		});

		var ary = $sortable.nestedSortable('toArray', {startDepthCount: 0, listType:"ol"});

		for (var i = 1; i < ary.length; i++ ) {
			if (ary[i]["item_id"] != "root") {
				ary[i]["page_alias"] = $(".page-alias-input", "#node_" + ary[i]["item_id"]).val();
				if (ary[i]["item_id"] >= 1000000) {		// new pages
					ary[i]["page_name"] = $("#node_" + ary[i]["item_id"] + " > div").text();
				}
			}
		}


		$.getJSON($.service("wiki", "save_structure", {data: $.toJSON(ary)}), function (data) {
			$sortable.modal();
			if (data) {
				$(".save_structure").hide();
				tocDirty = false;
			}
		});
		return false;
	});

});

function movePageToStructure(element) {
	var id = $(element).parents(".admintoclevel:first").attr("id").match(/\d*$/);
	if (id) {
		id = id[0];
	}
	$("input[name=page_ref_id]", "#move_dialog").val(id);
	$("#move_dialog").dialog({
		title: tr("Move page")
	});
}

<commit_msg>[FIX] structures: Use post to send updated structure data on save to accommodate very large structures (will still be limited by post_max_size in php.ini) thanks Xavi<commit_after>// (c) Copyright 2002-2012 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: tiki-admin_modules.js 39475 2012-01-12 22:47:05Z sylvieg $

$(document).ready(function() {

	var tocDirty = false;

	$(window).bind("beforeunload", function( e ) {
		if (tocDirty) {
			var m = tr("You have unsaved changes to your structure, are you sure you want to leave the page without saving?");
			var e = e || window.event;
			if (e && !($.browser.safari || $.browser.webkit)) {
				e.returnValue = m;
			}
			return m;
		}
	});

	$(".admintoc:first").nestedSortable( {

		disableNesting: 'no-nest',
		forcePlaceholderSize: true,
		handle: 'div',
		helper: 'clone',
		items: 'li',
		//maxLevels: 3,
		opacity: .6,
		tabSize: 20,
		tolerance: 'pointer',
		toleranceElement: '> div',
		placeholder: "ui-state-highlight",
		rootID: "root",

		stop: function (event, ui) {
			if ($(".save_structure a:visible").length === 0) {
				$(".save_structure a").show("fast").parent().show("fast");
				tocDirty = true;
			}
//			$(this).removeClass("ui-state-active");
		},
		start: function (event, ui) {
//			$(this).addClass("ui-state-active");
		}
	}).droppable({
			hoverClass: "ui-state-active",
			drop: function(event, ui) {
				if (!$(ui.draggable).hasClass("admintoclevel")) {
					var pageName = $.trim($(ui.draggable).text());
					$(this).append(
						$('<li class="ui-state-default admintoclevel new"><div>' +
								'<div class="actions"><input type="text" class="page-alias-input" value="" placeholder="Page alias..."></div>' +
								pageName +'</div></li>')
					);
					$(".save_structure a").show("fast").parent().show("fast");
					tocDirty = true;
				}
			}
		})
		.disableSelection();

	$(".page-alias-input").change( function () {
		$(".save_structure a").show("fast").parent().show("fast");
		tocDirty = true;
	});


	$("#page_list_container li").each(function() {
		var el = this;
		$(this).draggable({
			connectToSortable: ".admintoc:first",
			revert: "invalid",
			helper: "clone",
			start: function (event, ui) {
				$(this).css("z-index", 1000);
			},
			stop: function (event, ui) {
				$("#save_structure").show("fast").data("dragged", $(el).attr("id"));
				$(this).css("z-index", "auto");
			}
		}).mouseover(function(event, ui) {	// sortable gets muddled when dragging so disable it
				$(".admintoc:first").sortable("option", "disabled", true);
		}).mouseout(function(event, ui) {
				$(".admintoc:first").sortable("option", "disabled", false);
		}).disableSelection();
	});

	$(".save_structure").click(function(){

		var $sortable = $(this).parent().find(".admintoc:first");
		$sortable.modal(tr("Saving..."));

		var fakeId = 1000000;
		$(".admintoclevel.new").each(function() {
			$(this).attr("id", "node_" + fakeId);
			fakeId++;
		});

		var ary = $sortable.nestedSortable('toArray', {startDepthCount: 0, listType:"ol"});

		for (var i = 1; i < ary.length; i++ ) {
			if (ary[i]["item_id"] != "root") {
				ary[i]["page_alias"] = $(".page-alias-input", "#node_" + ary[i]["item_id"]).val();
				if (ary[i]["item_id"] >= 1000000) {		// new pages
					ary[i]["page_name"] = $("#node_" + ary[i]["item_id"] + " > div").text();
				}
			}
		}


		$.post($.service("wiki", "save_structure"), {data: $.toJSON(ary)}, function (data) {
			$sortable.modal();
			if (data) {
				$(".save_structure").hide();
				tocDirty = false;
			}
		}, "json");
		return false;
	});

});

function movePageToStructure(element) {
	var id = $(element).parents(".admintoclevel:first").attr("id").match(/\d*$/);
	if (id) {
		id = id[0];
	}
	$("input[name=page_ref_id]", "#move_dialog").val(id);
	$("#move_dialog").dialog({
		title: tr("Move page")
	});
}


{'fraction_non_alphanumeric': 0.2208799593082401, 'fraction_numerical': 0.01347914547304171, 'mean_word_length': 3.7095808383233533, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, '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': '1993981', 'n_tokens_mistral': 3286, 'n_tokens_neox': 2752, 'n_words': 586}