tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

Add "before" and "after" macros for DOM manipulation #222

Open BawdyInkSlinger opened 1 year ago

BawdyInkSlinger commented 1 year ago

Is your feature request related to a problem? I needed to use jQuery's before and after and it would have been convenient if these macros already existed.

Describe the solution you'd like. Implement a <<before>> and <<after>> that functions like <<prepend>> and <<append>>, only they call jQuery's before and after, respectively.

Describe alternatives you've considered. I've implemented my own <<before>> and <<after>> by copying, pasting, and modifying the <<append>> macro:

https://github.com/tmedwards/sugarcube-2/blob/bac3c41252bd5a7bcc51b9721c31528e8d2ae663/src/macros/macrolib.js#L2348

Additional context. This conversation started on discord.

This may help summarize the difference between append and after:

$(x).append(y):

<x><y></y></x>

$(x).after(y):

<x></x><y></y>
tmedwards commented 1 year ago

I'll think about it, but this is kind of a 1% problem.