MediaWiki:Common.js: Difference between revisions

From Protoball
Jump to navigation Jump to search
No edit summary
No edit summary
Line 36: Line 36:
var name = "chk_" + input.attr('name');
var name = "chk_" + input.attr('name');
$.each(available_values, function() {
$.each(available_values, function() {
alert(this); alert(selected_values);
var chk = $('<input type="checkbox" name="' + name + '" value="' + this + '"' + ($.inArray(this, selected_values) ? ' checked="checked"' : '') + ' />');
var chk = $('<input type="checkbox" name="' + name + '" value="' + this + '"' + ($.inArray(this, selected_values) ? ' checked="checked"' : '') + ' />');
$(property_list).append(chk);
$(property_list).append(chk);

Revision as of 14:17, 25 May 2012

/* Any JavaScript here will be loaded for all users on every page load. */

function formPrep() {
 if(wgPageName.indexOf("Special:FormEdit") > -1 || wgAction.indexOf("formedit") > -1) {
	function copy_year_to_year_date() {
		var val = $('[name="Chronology Entry[Year]"]').val();
		$('[name="Chronology Entry[Date][year]"]').val(val);
	}

	function set_date_to_beginning_of_year() {
		if($(this).val() != "") {
			$('[name="Chronology Entry[Date][day]"]').val("1");
			$('[name="Chronology Entry[Date][month]"]').val("01");
		}
	}

	function modify_selected_values() {
		var input = $(this).parent().prev('span').children('input');
		var chk_value = this.value;
		var selected_values = input.val() ? input.val().split(/ *, */) : [];
		if(this.checked) {
			selected_values.push(this.value);
			selected_values.sort();
		} else {
			selected_values = $.grep(selected_values, function(value) { return value != chk_value; });
		}
		input.val(selected_values.join(", "));
	}

	function available_values_to_checkboxes() {
		var property_list = this;
		var input = $(this).prev('span').children('input');
		var available_values = $(this).text().split(", ");
		var selected_values = input.val() ? input.val().split(/ *, */) : [];
		$(this).text("");
		var name = "chk_" + input.attr('name');
		$.each(available_values, function() {
alert(this); alert(selected_values);
			var chk = $('<input type="checkbox" name="' + name + '" value="' + this + '"' + ($.inArray(this, selected_values) ? ' checked="checked"' : '') + ' />');
			$(property_list).append(chk);
			chk.change(modify_selected_values);
			$(property_list).append(document.createTextNode(" " + this + " "));
		});
		$(this).show();
	}

	$(function () {
		$('[name="Chronology Entry[Year]"]').keyup(copy_year_to_year_date).change(copy_year_to_year_date);
		$('[name="Chronology Entry[Year Suffix]"]').change(set_date_to_beginning_of_year);
		$('.property_list').each(available_values_to_checkboxes);
	});

        $.getScript("/tinymce/jscripts/tiny_mce/jquery.tinymce.js", function() { $('textarea.tinymce').tinymce({
                // Location of TinyMCE script
                script_url : '/tinymce/jscripts/tiny_mce/tiny_mce.js',

                // General options
                theme : "advanced",
                plugins : "pagebreak,style,layer,save,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

                // Theme options
                theme_advanced_buttons1 : "justifyleft,justifycenter,justifyright,justifyfull,|,hr,nonbreaking,removeformat,visualaid,|,sub,sup,|,charmap,iespell,advhr,|,fullscreen",
                theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,insertdate,inserttime,preview",
                theme_advanced_buttons3 : "bold,italic,underline,strikethrough,|,link,unlink,anchor,cleanup,help,code" ,
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_statusbar_location : "bottom",
                theme_advanced_resizing : true,

                content_css : "/tinymce/css/custom_content.css",
                theme_advanced_font_sizes: "10px,12px,13px,14px,16px,18px,20px",
                font_size_style_values : "10px,12px,13px,14px,16px,18px,20px",
        })});
 }
}

addOnloadHook(formPrep);