AstonJ
(AstonJ)
2์ 10, 2016, 2:39์คํ
1
Is it possible to (via a plug-in if necessary) randomly choose a logo (and small logo) from a set of 3 every time someone starts a new session (or until their browser refreshes the assets for the logo)?
The Ruby code is trivial - but how can we incorporate that into Discourse?
You could do it with JS i suppose, here is code i hope it works
<script>
if (document.getElementById) { window.onload = swap };
function swap() {
var numimages=4;
rndimg = new Array("IMAGE URL 1", "IMAGE URL 2", "IMAGE URL 3", "IMAGE URL 4");
x=(Math.floor(Math.random()*numimages));
randomimage=(rndimg[x]);
document.getElementById("banner").style.logo-big = "url("+ randomimage +")";
}
</script>
PS this only works on hard refresh . also the css to big logo would be
.logo-big {
background-image: url('DEFAULT LOGO IMAGE URL HERE');
}
The JS would work because i am using that to rotate my banner image randomly on every hard refresh not sure the exact code for logo CSS.
AstonJ
(AstonJ)
2์ 10, 2016, 5:51์คํ
3
Thanks - Iโll give that a go
Hi,
This is exactly what I need! Is the second part required? Also where does the first part get put exactly?
Best,
Michael
sam
(Sam Saffron)
5์ 6, 2019, 7:39์ค์
6
This is doable in a theme component, the method by @Alankrit_Choudh can work but I would recommend adding a custom ember initializer instead that overrides the URL in discourse instead of relying on window.onload here.
Gunnar
(Gunnar Helliesen)
6์ 10, 2021, 4:52์ค์
7
Sam,
์ ๋ ๊ฐ์ ๋ฌธ์ ์ ๋ถ๋ชํ์ต๋๋ค. window.onload๋ </head> ํ๊ทธ ์ด์ ์ ํธ์ถ๋๋ฉด ์๋ํ์ง๋ง, ์ดํ์ ํธ์ถ๋๋ฉด ์๋ํ์ง ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ ๋๋ฌธ์ document.getElementById๊ฐ ์คํจํฉ๋๋ค(์์ง ID๊ฐ ์ ์๋์ง ์์๊ธฐ ๋๋ฌธ์ด์ฃ ).
ember ๊ฒฝํ์ด ์ ํ ์๋ ์ฌ๋์ด ์ปค์คํ
ember ์ด๊ธฐํ ํ๋ก๊ทธ๋จ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋ํ ์
๋ฌธ ์๋ฃ๋ ์์, ํํ ๋ฆฌ์ผ์ ์๋ ค์ฃผ์ค ์ ์์๊น์?
์ฐธ๊ณ ๋ก, ์ ๊ฐ ํ๋ ค๋ ๊ฒ์ URL ๋ฐฐ์ด์์ ๋๋คํ ๋ฐฐ๋ ์ด๋ฏธ์ง๋ฅผ ํ์ํ๋ ๊ฒ์
๋๋ค:
var jlmyPix = new Array(
'/img/pic0.jpeg',
[ ... ]
'/img/picN.jpeg'
);
function jlchoosePic() {
var jlrandomPicNum = Math.floor(Math.random() * jlmyPix.length);
document.getElementById("jlmyPicture").src = jlmyPix[jlrandomPicNum];
};
window.onload = jlchoosePic;