Sha256: aad19a6fcc51471732df98f309c6d1c0258ef82bcf4e63d5cb569f8d4a5289e8

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

/*
 01conf.js: javascript for preferences pages of tDiary

 Copyright (C) 2011 by TADA Tadashi <t@tdtds.jp>
 You can redistribute it and/or modify it under GPL2.
 */

$(function(){
	$('#saving')
		.hide()
		.css('text-align', 'center')
		.css('margin-top', '10em');

	$('#conf-form').submit(function(){
		var form = $(this);
		$.ajax({
			type: 'post',
			url: form.attr('action'),
			data: form.serialize() + '&saveconf=OK',
			dataType: 'html',
			beforeSend: function(){
				form.hide();
				$('#saving').show();
			},
			success: function(data){
				if(location.search.match(/conf=(sp|csrf_protection)$/)){
					location.reload();
				} else {
					var result = data.match(/<form id="conf-form"[\s\S]*<\/form>/)[0];
					$('#saving').hide();
					form.empty().append($('div:first', result)).show();
				}
			},
			error: function(){
				$('#saving').hide();
				form.show();
				alert('cannot save!');
			}
		});
		return false;
	});

	/*
	 * theme thumbnail changer
	 */
	$(document).on('change', '#theme_selection',function(){
		var list = $(this);
		var image = $('#theme_thumbnail');

		var theme = '';
		if ( list.selectedIndex == 0 ) {
			theme = 'nowprinting';
		} else {
			theme = list.val().replace(/^.*\//, '');
		}
		image.attr('src', 'http://www.tdiary.org/theme.image/' + theme + '.jpg');
	});

	/*
	 * old ruby alert
	 */
	$('#alert-old-ruby').on('click', function(){
		var data = 'conf=old_ruby_alert;saveconf=OK';
		var csrf_key = $('#conf-form input[name=csrf_protection_key]').attr('value');
		if (csrf_key){ data += ';csrf_protection_key=' + csrf_key; }

		$.ajax({
			url: $('#conf-form').attr('action'),
			type: 'POST',
			dataType: 'html',
			data: data
		}).done(function(html){
			$('.alert-warn').hide();
		}).fail(function(XMLHttpRequest, textStatus, errorThrown){
			alert('failed saving settings.' + textStatus);
		});
	});
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tdiary-4.0.5.1 js/01conf.js
tdiary-4.0.5 js/01conf.js
tdiary-4.0.4 js/01conf.js
tdiary-4.0.3 js/01conf.js