Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2018-11-11 04:20:29, last edited by SirJosh3917 (2018-11-11 19:24:36)

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

consider less js for spoiler onclick

This is a spoiler.

every single spoiler has that piece of javascript

if i go ahead and spam spoilers like a madman

a

this page now has a lot of repeated javascript for no reason - 27,374 bytes

now here is my suggestion - create a simple spoilerScript function that accepts one input, c

now compare this output - 5427 bytes

the latter is much cleaner, and probably saves somewhere of 350-450 bytes per spoiler.

heres the spoilerScript function - i didn't even have to do much to modify it

var spoilerScript = function(c)
{
var e,d,a=c.getElementsByTagName('div')[1],b=c.getElementsByTagName('span')[0];if(a.style.display!=''){while(c.parentNode&&(!d||!e||d==e)){e=d;d=(window.getComputedStyle?getComputedStyle(c, null):c.currentStyle)['backgroundColor'];if(d=='transparent'||d=='rgba(0, 0, 0, 0)')d=e;c=c.parentNode;}a.style.display='';b.innerHTML='▲';}else{a.style.display='none';b.innerHTML='▼';}
}

Offline

#2 2018-11-11 12:09:48

peace
Member
From: admin land
Joined: 2015-08-10
Posts: 9,226

Re: consider less js for spoiler onclick

ninjasupeatsninja wrote:

if i go ahead and spam quotes like a madman

ahem that are spoiler snot quotes


peace.png

thanks hg for making this much better and ty for my avatar aswell

Offline

Wooted by:

#3 2018-11-11 18:57:51

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: consider less js for spoiler onclick

peace wrote:
ninjasupeatsninja wrote:

if i go ahead and spam quotes like a madman

ahem that are spoiler snot quotes

fixed

Also some improvements has been made. I've created this minified js

var ssoc=function(e){var t,n,a=e.parentNode,r=a.getElementsByTagName("div")[1],l=e.getElementsByTagName("span")[0],o="none",p=6;if(""!=r.style.display){for(;a.parentNode&&(!n||!t||n==t);)t=n,"transparent"!=(n=(window.getComputedStyle?getComputedStyle(a,null):a.currentStyle).backgroundColor)&&"rgba(0, 0, 0, 0)"!=n||(n=t),a=a.parentNode;o="",--p}r.style.display=o,l.innerHTML="&#96"+p+"0;"}

which should behave exactly the same as the spoiler code, however, it is 10 bytes smaller than the js attatched to every onclick handler - and it should work properly now

Offline

SirJosh39171541959071731652

Board footer

Powered by FluxBB

[ Started around 1732378947.2843 - Generated in 0.064 seconds, 12 queries executed - Memory usage: 1.49 MiB (Peak: 1.66 MiB) ]