Vergleich admin/jscripts/themes.js - 1.8.1 - 1.8.17

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 3Zeile 3
 * a list
*/


 * a list
*/


var ThemeSelector = (function() {
/**
* @var shortcut
*/
var fn = encodeURIComponent;


var ThemeSelector = {






	/**
* Constructor
*

	/**
* Constructor
*

Zeile 21Zeile 17
	 * @param  number the theme id
* @return void
*/

	 * @param  number the theme id
* @return void
*/

	function ThemeSelector(url, saveUrl, selector, styleSheet, file, selectorForm, tid) {

	init: function(url, saveUrl, selector, styleSheet, file, selectorForm, tid) {

		// verify input
if (!url || !saveUrl || !selector || !styleSheet || !file || !selectorForm || !tid) {
return;
}


		// verify input
if (!url || !saveUrl || !selector || !styleSheet || !file || !selectorForm || !tid) {
return;
}


		this.url = url;
this.saveUrl = saveUrl;
this.selector = selector;
this.selectorPrevOpt = this.selector.val();
this.styleSheet = styleSheet;
this.file = file;
this.selectorForm = selectorForm;
this.tid = tid;

		ThemeSelector.url = url;
ThemeSelector.saveUrl = saveUrl;
ThemeSelector.selector = selector;
ThemeSelector.selectorPrevOpt = ThemeSelector.selector.val();
ThemeSelector.styleSheet = styleSheet;
ThemeSelector.file = file;
ThemeSelector.selectorForm = selectorForm;
ThemeSelector.tid = tid;





		this.background = $("#css_bits\\[background\\]").val();
this.width = $("#css_bits\\[width\\]").val();
this.color = $("#css_bits\\[color\\]").val();
this.extra = $("#css_bits\\[extra\\]").val();
this.text_decoration = $("#css_bits\\[text_decoration\\]").val();
this.font_family = $("#css_bits\\[font_family\\]").val();
this.font_size = $("#css_bits\\[font_size\\]").val();
this.font_style = $("#css_bits\\[font_style\\]").val();
this.font_weight = $("#css_bits\\[font_weight\\]").val();












		ThemeSelector.background = $("#css_bits\\[background\\]").val();
ThemeSelector.width = $("#css_bits\\[width\\]").val();
ThemeSelector.color = $("#css_bits\\[color\\]").val();
ThemeSelector.extra = $("#css_bits\\[extra\\]").val();
ThemeSelector.text_decoration = $("#css_bits\\[text_decoration\\]").val();
ThemeSelector.font_family = $("#css_bits\\[font_family\\]").val();
ThemeSelector.font_size = $("#css_bits\\[font_size\\]").val();
ThemeSelector.font_style = $("#css_bits\\[font_style\\]").val();
ThemeSelector.font_weight = $("#css_bits\\[font_weight\\]").val();

$("#save").on('click', function(event) { ThemeSelector.save(event, true); } );
$("#save_close").on('click', function(event) { ThemeSelector.saveClose(event); } );


$(window).on('beforeunload', function(event){
if(ThemeSelector.isChanged())
{
return ' ';
}
});





		$("#save").on('click', function(event) { $.proxy(this, 'save', event, true); } );
$("#save_close").on('click', function(event) { $.proxy(this, 'saveClose', event); } );

ThemeSelector.that = this; // I know this is cheating :D

 
		

		

		window.onbeforeunload = function(event) { saveCheck(event, false, ThemeSelector.that); }
window.onunload = function(event) { save(false, false); }

 
		

		

		
this.selector.on("change", $.proxy(this, 'updateSelector'));
this.selectorForm.on("submit", $.proxy(this, 'updateSelector'));
}

		ThemeSelector.selector.on("change", ThemeSelector.updateSelector);
ThemeSelector.selectorForm.on("submit", ThemeSelector.updateSelector);
},



/**
* prevents no-save warning messaging when saving


/**
* prevents no-save warning messaging when saving

	 *
* @return void
*/
function saveClose(e) {
this.isClosing = true;
}


	 *
* @return void
*/
saveClose: function(e) {
ThemeSelector.isClosing = true;
},


	/**
* updates the stylesheet info to match the current selection, checking
* first that work isn't lost

	/**
* updates the stylesheet info to match the current selection, checking
* first that work isn't lost

Zeile 75Zeile 75
	 * @param  object the event
* @return void
*/

	 * @param  object the event
* @return void
*/

	function updateSelector(e) {

	updateSelector: function(e) {

		var postData;

e.preventDefault()

		var postData;

e.preventDefault()


this.saveCheck(e, true, null);

postData = "file=" + fn(this.file) + "&tid=" + fn(this.tid) + "&selector=" + fn(this.selector.val()) + "&my_post_key=" + fn(my_post_key);

this.selectorGoText = $("#mini_spinner").html();
$("#mini_spinner").html("&nbsp;<img src=\"" + this.miniSpinnerImage + "\" style=\"vertical-align: middle;\" alt=\"\" /> ");

$.ajax({
type: 'post',
url: this.url,
data: postData,
complete: $.proxy(this, 'onComplete'),


ThemeSelector.saveCheck(e, true);

postData = "file=" + encodeURIComponent(ThemeSelector.file) + "&tid=" + encodeURIComponent(ThemeSelector.tid) + "&selector=" + encodeURIComponent(ThemeSelector.selector.val()) + "&my_post_key=" + encodeURIComponent(my_post_key);

ThemeSelector.selectorGoText = $("#mini_spinner").html();
$("#mini_spinner").html("&nbsp;<img src=\"" + ThemeSelector.miniSpinnerImage + "\" style=\"vertical-align: middle;\" alt=\"\" /> ");

$.ajax({
type: 'post',
url: ThemeSelector.url,
data: postData,
complete: ThemeSelector.onComplete,

		});

		});

	}

	},


/**
* handles the AJAX return data


/**
* handles the AJAX return data

Zeile 101Zeile 101
	 * @param  object the request
* @return true
*/

	 * @param  object the request
* @return true
*/

	function onComplete(request) {

	onComplete: function(request) {

		var message, saved;

if (request.responseText.match(/<error>(.*)<\/error>/)) {

		var message, saved;

if (request.responseText.match(/<error>(.*)<\/error>/)) {

Zeile 110Zeile 110
			if (!message[1]) {
message[1] = lang.unknown_error;
}

			if (!message[1]) {
message[1] = lang.unknown_error;
}

			$.jGrowl(lang.theme_info_fetch_error + '\n\n' + message[1]);

			$.jGrowl(lang.theme_info_fetch_error + '\n\n' + message[1], {theme:'jgrowl_error'});

		} else if(request.responseText) {
if ($("#saved").html()) {
saved = $("#saved").html();
}

		} else if(request.responseText) {
if ($("#saved").html()) {
saved = $("#saved").html();
}

			this.styleSheet.html(request.responseText);

			ThemeSelector.styleSheet.html(request.responseText);

		}


		}


		this.background = $("#css_bits\\[background\\]").val();
this.width = $("#css_bits\\[width\\]").val();
this.color = $("#css_bits\\[color\\]").val();
this.extra = $("#css_bits\\[extra\\]").val();
this.text_decoration = $("#css_bits\\[text_decoration\\]").val();
this.font_family = $("#css_bits\\[font_family\\]").val();
this.font_size = $("#css_bits\\[font_size\\]").val();
this.font_style = $("#css_bits\\[font_style\\]").val();
this.font_weight = $("#css_bits\\[font_weight\\]").val();

		ThemeSelector.background = $("#css_bits\\[background\\]").val();
ThemeSelector.width = $("#css_bits\\[width\\]").val();
ThemeSelector.color = $("#css_bits\\[color\\]").val();
ThemeSelector.extra = $("#css_bits\\[extra\\]").val();
ThemeSelector.text_decoration = $("#css_bits\\[text_decoration\\]").val();
ThemeSelector.font_family = $("#css_bits\\[font_family\\]").val();
ThemeSelector.font_size = $("#css_bits\\[font_size\\]").val();
ThemeSelector.font_style = $("#css_bits\\[font_style\\]").val();
ThemeSelector.font_weight = $("#css_bits\\[font_weight\\]").val();


if (saved) {
$("#saved").html(saved);


if (saved) {
$("#saved").html(saved);

Zeile 135Zeile 135
			}, 30000);
}


			}, 30000);
}


		$("#mini_spinner").html(this.selectorGoText);
this.selectorGoText = '';

		$("#mini_spinner").html(ThemeSelector.selectorGoText);
ThemeSelector.selectorGoText = '';


return true;


return true;

	}














	},

isChanged: function()
{
return (ThemeSelector.background != $("#css_bits\\[background\\]").val() ||
ThemeSelector.width != $("#css_bits\\[width\\]").val() ||
ThemeSelector.color != $("#css_bits\\[color\\]").val() ||
ThemeSelector.extra != $("#css_bits\\[extra\\]").val() ||
ThemeSelector.text_decoration != $("#css_bits\\[text_decoration\\]").val() ||
ThemeSelector.font_family != $("#css_bits\\[font_family\\]").val() ||
ThemeSelector.font_size != $("#css_bits\\[font_size\\]").val() ||
ThemeSelector.font_style != $("#css_bits\\[font_style\\]").val() ||
ThemeSelector.font_weight != $("#css_bits\\[font_weight\\]").val());
},


/**
* check if anything has changed


/**
* check if anything has changed

Zeile 148Zeile 161
	 * @param  bool true if AJAX, false if not
* @return true
*/

	 * @param  bool true if AJAX, false if not
* @return true
*/

	function saveCheck(e, isAjax, that) {

if(that == null)
that = this;

	saveCheck: function(e, isAjax) {




	

	

		if (that.isClosing == true) {

		if (ThemeSelector.isClosing == true) {

			return true;
}

			return true;
}





		if(e != null && isAjax == true)

		if(e != null && isAjax == true)

			e.preventDefault();

if (that.background != $("#css_bits\\[background\\]").val() ||
that.width != $("#css_bits\\[width\\]").val() ||
that.color != $("#css_bits\\[color\\]").val() ||
that.extra != $("#css_bits\\[extra\\]").val() ||
that.text_decoration != $("#css_bits\\[text_decoration\\]").val() ||
that.font_family != $("#css_bits\\[font_family\\]").val() ||
that.font_size != $("#css_bits\\[font_size\\]").val() ||
that.font_style != $("#css_bits\\[font_style\\]").val() ||
that.font_weight != $("#css_bits\\[font_weight\\]").val()) {

e.preventDefault();

			e.preventDefault();

if (ThemeSelector.isChanged()) {

e.preventDefault();









			
if(isAjax == false)
return save_changes_lang_string;

			
if(isAjax == false)
return save_changes_lang_string;

Zeile 178Zeile 181
			{
confirmReturn = confirm(save_changes_lang_string);
if (confirmReturn == true) {

			{
confirmReturn = confirm(save_changes_lang_string);
if (confirmReturn == true) {

					that.save(false, isAjax);
$.jGrowl('Saved');

					ThemeSelector.save(false, isAjax);
$.jGrowl(lang.saved, {theme:'jgrowl_success'});

				}
}
}
else if(isAjax == true)
{

				}
}
}
else if(isAjax == true)
{

			that.selectorPrevOpt = that.selector.val();

			ThemeSelector.selectorPrevOpt = ThemeSelector.selector.val();

			return true;
}

			return true;
}

	}

	},


/**
* saves the selector info


/**
* saves the selector info

Zeile 197Zeile 200
	 * @param  bool true if AJAX, false if not
* @return true
*/

	 * @param  bool true if AJAX, false if not
* @return true
*/

	function save(e, isAjax) {

	save: function(e, isAjax) {

		var cssBits, postData, completeMethod = 'onUnloadSaveComplete';

if (e) {

		var cssBits, postData, completeMethod = 'onUnloadSaveComplete';

if (e) {

Zeile 216Zeile 219
			'font_weight': $('#css_bits\\[font_weight\\]').val()
};


			'font_weight': $('#css_bits\\[font_weight\\]').val()
};


		postData = "css_bits=" + fn(jsArrayToPhpArray(cssBits)) + "&selector=" + fn(this.selectorPrevOpt) + "&file=" + fn(this.file) + "&tid=" + fn(this.tid) + "&my_post_key=" + fn(my_post_key) + "&serialized=1";

		postData = "css_bits=" + encodeURIComponent(jsArrayToPhpArray(cssBits)) + "&selector=" + encodeURIComponent(ThemeSelector.selectorPrevOpt) + "&file=" + encodeURIComponent(ThemeSelector.file) + "&tid=" + encodeURIComponent(ThemeSelector.tid) + "&my_post_key=" + encodeURIComponent(my_post_key) + "&serialized=1";


if (isAjax == true) {
postData += "&ajax=1";
}



if (isAjax == true) {
postData += "&ajax=1";
}


		this.isAjax = isAjax;

		ThemeSelector.isAjax = isAjax;


if (isAjax == true) {
completeMethod = 'onSaveComplete';


if (isAjax == true) {
completeMethod = 'onSaveComplete';

			$.jGrowl(lang.saving);
}


			$.jGrowl(lang.saving, {theme:'jgrowl_process'});
}


		$.ajax({
type: 'post',

		$.ajax({
type: 'post',

			url: this.saveUrl,

			url: ThemeSelector.saveUrl,

			data: postData,

			data: postData,

			complete: $.proxy(this, completeMethod),

			complete: ThemeSelector[completeMethod],

		});
return !isAjax;

		});
return !isAjax;

	}

	},


/**
* handle errors, reset values and clean up


/**
* handle errors, reset values and clean up

Zeile 244Zeile 247
	 * @param  object the request
* @return true
*/

	 * @param  object the request
* @return true
*/

	function onSaveComplete(request) {

	onSaveComplete: function(request) {

		var message;

if (request.responseText.match(/<error>(.*)<\/error>/)) {

		var message;

if (request.responseText.match(/<error>(.*)<\/error>/)) {

Zeile 253Zeile 256
			if (!message[1]) {
message[1] = lang.unkown_error;
}

			if (!message[1]) {
message[1] = lang.unkown_error;
}

			$.jGrowl(lang.theme_info_save_error + '\n\n' + message[1]);

			$.jGrowl(lang.theme_info_save_error + '\n\n' + message[1], {theme:'jgrowl_error'});

			return false;
} else if(request.responseText) {
$("#saved").html(" (" + lang.saved + " @ "+ Date() + ")");
if ($("#ajax_alert")) {

			return false;
} else if(request.responseText) {
$("#saved").html(" (" + lang.saved + " @ "+ Date() + ")");
if ($("#ajax_alert")) {

				$("#ajax_alert").html('').hide();
}
}

this.background = $("#css_bits\\[background\\]").val();
this.width = $("#css_bits\\[width\\]").val();
this.color = $("#css_bits\\[color\\]").val();
this.extra = $("#css_bits\\[extra\\]").val();
this.text_decoration = $("#css_bits\\[text_decoration\\]").val();
this.font_family = $("#css_bits\\[font_family\\]").val();
this.font_size = $("#css_bits\\[font_size\\]").val();
this.font_style = $("#css_bits\\[font_style\\]").val();
this.font_weight = $("#css_bits\\[font_weight\\]").val();

return true;
}


				$("#ajax_alert").html('').hide();
}
}

ThemeSelector.background = $("#css_bits\\[background\\]").val();
ThemeSelector.width = $("#css_bits\\[width\\]").val();
ThemeSelector.color = $("#css_bits\\[color\\]").val();
ThemeSelector.extra = $("#css_bits\\[extra\\]").val();
ThemeSelector.text_decoration = $("#css_bits\\[text_decoration\\]").val();
ThemeSelector.font_family = $("#css_bits\\[font_family\\]").val();
ThemeSelector.font_size = $("#css_bits\\[font_size\\]").val();
ThemeSelector.font_style = $("#css_bits\\[font_style\\]").val();
ThemeSelector.font_weight = $("#css_bits\\[font_weight\\]").val();

return true;
},


	/**
* handle leaving page save
*
* @param object the request
* @return true
*/

	/**
* handle leaving page save
*
* @param object the request
* @return true
*/

	function onUnloadSaveComplete(request) {

	onUnloadSaveComplete: function(request) {

		var message;

if (request.responseText.match(/<error>(.*)<\/error>/)) {

		var message;

if (request.responseText.match(/<error>(.*)<\/error>/)) {

Zeile 290Zeile 293
			if (!message[1]) {
message[1] = lang.unkown_error;
}

			if (!message[1]) {
message[1] = lang.unkown_error;
}

			$.jGrowl(lang.theme_info_save_error + '\n\n' + message[1]);

			$.jGrowl(lang.theme_info_save_error + '\n\n' + message[1], {theme:'jgrowl_error'});

			return false;
}
return true;

			return false;
}
return true;

	}

ThemeSelector.prototype = {
url: null,
saveUrl: null,
selector: null,
styleSheet: null,
file: null,
selectorForm: null,
tid: null,
miniSpinnerImage: "../images/spinner.gif",
isAjax: false,
specific_count: 0,
selectorGoText: null,
selectorPrevOpt: null,
isClosing: false,
background: null,
width: null,
color: null,
extra: null,
text_decoration: null,
font_family: null,
font_size: null,
font_style: null,
font_weight: null,
saveClose: saveClose,
updateSelector: updateSelector,
onComplete: onComplete,
saveCheck: saveCheck,
save: save,
onSaveComplete: onSaveComplete,
onUnloadSaveComplete: onUnloadSaveComplete,
}

	},





































	return ThemeSelector;
})();






















	url: null,
saveUrl: null,
selector: null,
styleSheet: null,
file: null,
selectorForm: null,
tid: null,
miniSpinnerImage: "../images/spinner.gif",
isAjax: false,
specific_count: 0,
selectorGoText: null,
selectorPrevOpt: null,
isClosing: false,
background: null,
width: null,
color: null,
extra: null,
text_decoration: null,
font_family: null,
font_size: null,
font_style: null,
font_weight: null
};


/**
* converts a JS object to a JSON of a PHP associative array


/**
* converts a JS object to a JSON of a PHP associative array