mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	fix: skin not changing after login or logout, #7038
This commit is contained in:
		| @@ -139,6 +139,7 @@ app.cacheBuster = null; | |||||||
|  |  | ||||||
| 				Notifications.prepareDOM(); | 				Notifications.prepareDOM(); | ||||||
| 				Chat.prepareDOM(); | 				Chat.prepareDOM(); | ||||||
|  | 				app.reskin(data.config.bootswatchSkin); | ||||||
| 				callback(); | 				callback(); | ||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
| @@ -734,4 +735,21 @@ app.cacheBuster = null; | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | 	app.reskin = function (skinName) { | ||||||
|  | 		var clientEl = Array.prototype.filter.call(document.querySelectorAll('link[rel="stylesheet"]'), function (el) { | ||||||
|  | 			return el.href.indexOf(config.relative_path + '/assets/client') !== -1; | ||||||
|  | 		})[0] || null; | ||||||
|  |  | ||||||
|  | 		// Update client.css link element to point to selected skin variant | ||||||
|  | 		clientEl.href = config.relative_path + '/assets/client' + (skinName ? '-' + skinName : '') + '.css'; | ||||||
|  |  | ||||||
|  | 		var currentSkinClassName = $('body').attr('class').split(/\s+/).filter(function (className) { | ||||||
|  | 			return className.startsWith('skin-'); | ||||||
|  | 		}); | ||||||
|  | 		$('body').removeClass(currentSkinClassName.join(' ')); | ||||||
|  | 		if (skinName) { | ||||||
|  | 			$('body').addClass('skin-' + skinName); | ||||||
|  | 		} | ||||||
|  | 	}; | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -4,9 +4,10 @@ | |||||||
| define('forum/account/settings', ['forum/account/header', 'components', 'sounds'], function (header, components, sounds) { | define('forum/account/settings', ['forum/account/header', 'components', 'sounds'], function (header, components, sounds) { | ||||||
| 	var	AccountSettings = {}; | 	var	AccountSettings = {}; | ||||||
|  |  | ||||||
|  | 	// If page skin is changed but not saved, switch the skin back | ||||||
| 	$(window).on('action:ajaxify.start', function () { | 	$(window).on('action:ajaxify.start', function () { | ||||||
| 		if (ajaxify.data.template.name === 'account/settings' && $('#bootswatchSkin').val() !== config.bootswatchSkin) { | 		if (ajaxify.data.template.name === 'account/settings' && $('#bootswatchSkin').val() !== config.bootswatchSkin) { | ||||||
| 			changePageSkin(config.bootswatchSkin); | 			app.reskin(config.bootswatchSkin); | ||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| @@ -30,7 +31,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' | |||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		$('#bootswatchSkin').on('change', function () { | 		$('#bootswatchSkin').on('change', function () { | ||||||
| 			changePageSkin($(this).val()); | 			app.reskin($(this).val()); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		$('[data-property="homePageRoute"]').on('change', toggleCustomRoute); | 		$('[data-property="homePageRoute"]').on('change', toggleCustomRoute); | ||||||
| @@ -48,23 +49,6 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' | |||||||
| 		components.get('user/sessions').find('.timeago').timeago(); | 		components.get('user/sessions').find('.timeago').timeago(); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	function changePageSkin(skinName) { |  | ||||||
| 		var clientEl = Array.prototype.filter.call(document.querySelectorAll('link[rel="stylesheet"]'), function (el) { |  | ||||||
| 			return el.href.indexOf(config.relative_path + '/assets/client') !== -1; |  | ||||||
| 		})[0] || null; |  | ||||||
|  |  | ||||||
| 		// Update client.css link element to point to selected skin variant |  | ||||||
| 		clientEl.href = config.relative_path + '/assets/client' + (skinName ? '-' + skinName : '') + '.css'; |  | ||||||
|  |  | ||||||
| 		var currentSkinClassName = $('body').attr('class').split(/\s+/).filter(function (className) { |  | ||||||
| 			return className.startsWith('skin-'); |  | ||||||
| 		}); |  | ||||||
| 		$('body').removeClass(currentSkinClassName.join(' ')); |  | ||||||
| 		if (skinName) { |  | ||||||
| 			$('body').addClass('skin-' + skinName); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	function loadSettings() { | 	function loadSettings() { | ||||||
| 		var settings = {}; | 		var settings = {}; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user