PDA

View Full Version : MouseImage BBCode not working



NotThatGuy
07-09-2017, 04:49 PM
So, I was looking through the BBCode options here (http://harem-battle.club/misc.php?do=bbcode), when I noticed the MouseImage (http://harem-battle.club/misc.php?do=bbcode#MO) code. Intrigue, I decided to test out the Value tag to see how it worked, given the sample there was not very helpful. As I soon discovered, provided you use an img url in place of option, the result will display that image, however the selection for value seemed to be ignored.

Looking at the page's html, I discovered the problem. If add the following to a post:
http://harem-battle.club/images/vNulletin/statusicon/forum_new-48.png
I get:
http://harem-battle.club/images/vNulletin/statusicon/forum_new-48.png
This has the html code:

<img onmouseover="Javascript<b></b>: this.firstsrc=
this.getAttribute('src'); this.secondsrc=
'http://harem-battle.club/images/vNulletin/statusicon/forum_new-48.png'; this.setAttribute('src',this.
secondsrc);" alt="" onmouseout="Javascript<b></b>: this.setAttribute
('src',this.firstsrc);" src="http://harem-battle.club/images/vNulletin/statusicon/forum_old-48.png">
The problem here is the "Javascript<b></b>: " in the onmouseover and onmouseout attributes. If this is removed, the code works as intended, though I suspect it would be more intuitive to reverse which image is the default and which is the one seen when moused over.

If this could be fixed, it would be appreciated.

MiqDoloran
07-09-2017, 09:26 PM
It works fine on the wiki. Might be some vBulletin issue. On a side note it would be great if the BBCode was modified to load both images at the same time. Right now there's a delay when mousing over. Mentioned this to @Tomaa a long time ago but I forgot what he said about it, lel

Also, want to request a nice fade transition when mousing over.

NotThatGuy
07-09-2017, 10:33 PM
On a side note it would be great if the BBCode was modified to load both images at the same time. Right now there's a delay when mousing over. Mentioned this to @Tomaa a long time ago but I forgot what he said about it, lel

Pretty sure this could be handled by changing the code to something like:

<span onmouseover="this.lastElementChild.style.display = 'inline';
this.firstElementChild.style.display = 'none';" onmouseout="this.firstElementChild.style.display = 'inline';
this.lastElementChild.style.display = 'none';">
<img style="display: inline;" alt="" src="http://harem-battle.club/images/vNulletin/statusicon/forum_old-48.png">
<img style="display: none;" alt="" src="http://harem-battle.club/images/vNulletin/statusicon/forum_new-48.png">
</span>
Images set to display: none should still load, they just won't be rendered until such a time as the display is set to something that renders them (such as inline).

Kotono
07-10-2017, 12:35 AM
This code was ONLY made to be used in the wiki. It was never looked into for making this a forum option.

NotThatGuy
07-10-2017, 02:07 AM
This code was ONLY made to be used in the wiki. It was never looked into for making this a forum option.

Would it be possible to set it up to work on the forum? There are contexts in which it could be handy. As an offhand example based on what I had considered using it for: Posting unit icons from Agis that toggle between the normal icon and the awakened one on hover.

MiqDoloran
07-10-2017, 06:44 AM
^ is there a technical reason it doesn't work in the forums?

Kotono
07-10-2017, 01:07 PM
The problem here is that the <b></b> parts get added automatically in the forums areas, even though they are not in the actual bbcode. I'm not currently aware of how to prevent this from happening so that it can work on the forums.

Edit:
I have adjusted to code to the above suggestion that included the preloading request and it seems to work fine for both wiki and forums. Please feel free to test this and make sure.

NotThatGuy
07-11-2017, 08:28 PM
I have adjusted to code to the above suggestion that included the preloading request and it seems to work fine for both wiki and forums. Please feel free to test this and make sure.
Thanks. A practical demonstration of the code's use in the forum can be found in the second post here (http://harem-battle.club/millennium-war-aigis/3580-super-tanks.html) if you are interested.

MiqDoloran
07-12-2017, 08:26 AM
The problem here is that the <b></b> parts get added automatically in the forums areas, even though they are not in the actual bbcode. I'm not currently aware of how to prevent this from happening so that it can work on the forums.

Edit:
I have adjusted to code to the above suggestion that included the preloading request and it seems to work fine for both wiki and forums. Please feel free to test this and make sure.

Do you think we can add some CSS transitions to it? Actually, I think you can do the switch without using an inline handler at all and just use animations: JSFiddle (https://jsfiddle.net/cpmam9jt/1/). Though I'm not sure if this will work in the forums.

NotThatGuy
07-12-2017, 09:44 PM
Do you think we can add some CSS transitions to it? Actually, I think you can do the switch without using an inline handler at all and just use animations: JSFiddle (https://jsfiddle.net/cpmam9jt/1/). Though I'm not sure if this will work in the forums.
That method unfortunately has a few issues. For instance, it relies upon the default image being as larger or larger than the mouseover image in order to conceal it. If the default image is either smaller or contains transparency it will show the second image through it. Admittedly, this could be handled by making the second image innately transparent, and having it fade in while the other fades out. However, there is then the second issue, which is that absolute positioning means the images do not take up space in the document flow. If you were to place text following the images, it will be placed behind them. This can be handled via title="Example of setting the dimensions of the span found in a discussion of a similar feature on a different forum." |javascript (https://jsfiddle.net/n0L4qvsj/3/) getting the dimensions of the images and assigning them to the span, but that begins to get more complicated (and depending on the method used, may run into problems if the images are slow in loading). There is also the arguable issue that the transition is tied to hovering over the default image rather than the span, which could potentially be problematic if the images are of sufficiently different size.

That isn't to say such a method couldn't be worked out to utilize the fade in/out, but it would need to be more complex.

Kotono
07-12-2017, 10:49 PM
I was not able to find a way to make it work so far. The best success so far just made the images vanish and not come back after the first mouseover.

MiqDoloran
07-13-2017, 11:15 AM
That method unfortunately has a few issues. For instance, it relies upon the default image being as larger or larger than the mouseover image in order to conceal it. If the default image is either smaller or contains transparency it will show the second image through it. Admittedly, this could be handled by making the second image innately transparent, and having it fade in while the other fades out. However, there is then the second issue, which is that absolute positioning means the images do not take up space in the document flow. If you were to place text following the images, it will be placed behind them. This can be handled via title="Example of setting the dimensions of the span found in a discussion of a similar feature on a different forum." |javascript (https://jsfiddle.net/n0L4qvsj/3/) getting the dimensions of the images and assigning them to the span, but that begins to get more complicated (and depending on the method used, may run into problems if the images are slow in loading). There is also the arguable issue that the transition is tied to hovering over the default image rather than the span, which could potentially be problematic if the images are of sufficiently different size.

That isn't to say such a method couldn't be worked out to utilize the fade in/out, but it would need to be more complex.

Yeah, it wouldn't work well with variable sized images. The whole BBCode system is really restrictive so it's kinda hard to make it work for all cases. I experimented with it a bit more though, and managed to get something which seems to work by using event listeners combined with animations: https://jsfiddle.net/cpmam9jt/4/.

Basically involves changing the opacity on mouse enter/leave and attaching transition listeners to flip the other image's opacity. At first I tried this:



<span
class="hbc-mo"
onmouseover="this.firstElementChild.style.opacity = 0;"
onmouseout="this.lastElementChild.style.opacity = 0;"
>
<img
class="hbc-mo__init"
src="http://lorempixel.com/400/200/city/1/"
style="display: initial;"
>
<img
class="hbc-mo__alt"
src="http://lorempixel.com/600/300/city/2/"
style="display: none; opacity: 0;"
>
</span>


but then it kept switching the images while I hovered over the span. Didn't know wtf was happening then I ended up switching it to mouseleave instead. I guess it's cause the images were registering mouseout events whenever I switch them out? fuck me