{COMIC_TITLE} breaks JavaScript

Is something wonky on the site? Describe the problem to us, and we'll fix it ASAP.
Forum rules
Bug Reporting Guidelines

Before Posting
Please make sure someone hasn't already reported the problem you're experiencing before creating a new topic. Confirmed issues have been stickied in this forum.

Rules

    1) Use a descriptive title when starting a bug topic. Example: "Comic images not showing up" Do not use vague titles like, "problem" or "uh ohh"

    2) Describe your problem in detail. Explain exactly what is wrong. Post images, screen shots, links, code snippets - whatever is relevant. The better the information you provide, the better the solution you will receive.

    3) Be polite and patient. We fix these issues as fast as we can. Please be patient with us as we work toward a solution.

{COMIC_TITLE} breaks JavaScript

Postby eishiya » May 2nd, 2018, 6:48 pm

On Patreon early access pages, {COMIC_TITLE} includes a <span> element and some CSS for displaying the Patreon icon next to those page titles. The quotes and linebreaks in this additional code make {COMIC_TITLE} completely unsuitable for use in JavaScript, such as for Disqus code, JS-based stat trackers, fancy JS-based effects, etc. It just throws an unterminated string literal error.

I understand the convenience of including that in {COMIC_TITLE} so that template designers don't have to make their own code for Patreon-only pages, so I don't expect that behaviour to change. Instead, could we please have script-safe versions of any template variables that may include unexpected additional code like this? They could have sort of suffix or prefix, e.g. {COMIC_TITLE.RAW} or {RAW_COMIC_TITLE}.
Alternatively, you could keep the base variables raw and use the .FORMATTED suffix for variables with additional formatting for consistency with {comic_page.FORMATTED} and so that things work as template designers would expect them to, but this would mean existing templates would no longer have the Patreon icons by default. Another alternative is to have a {PATRONS_ONLY_ICON} that inserts the icon code where appropriate, and an empty string otherwise.
Image
User avatar
eishiya
 
Posts: 9454
Joined: December 5th, 2009, 11:17 am

Re: {COMIC_TITLE} breaks JavaScript

Postby Admin » May 2nd, 2018, 8:48 pm

How about {COMIC_JSON} which provides all comic info in javascript object notation?
User avatar
Admin
Site Admin
 
Posts: 1444
Joined: August 17th, 2005, 11:10 pm

Re: {COMIC_TITLE} breaks JavaScript

Postby eishiya » May 2nd, 2018, 9:13 pm

That could work, but it's far from ideal. Don't forget that it gets returned as a full string rather than as a variable that sticks around, so unless people are smart and store it somewhere once and then access it, it'll lead to a lot of extra code on the page.

i.e.
Ideal behaviour:
Code: Select all
var comicData = {COMIC_JSON};
//...
someVar = comicData.comicTitle;
someOtherVar = comicData.comicID;

Likely behaviour:
Code: Select all
someVar = {COMIC_JSON}.comicTitle;
someOtherVar = {COMIC_JSON}.comicID;

Except it won't be so tidy once actually output xP


Edit: Also, JSON limits these variables to just JS. What if I want to make a GET request to another website using some of these variables, e.g. for a JS-free tracker? What if I want to add the comic's name to my Patreon log-in button, which would require using the name in the CSS? With plain text variables, these things are straight-forward. With JSON, I'd have to build the URL or CSS via JavaScript :/
Image
User avatar
eishiya
 
Posts: 9454
Joined: December 5th, 2009, 11:17 am


Return to Bugs & Glitches

Who is online

Users browsing this forum: No registered users and 1 guest