squiffy.ui.processText can't handle much. Why?

When you're working with both squiffy code and JavaScript code in the same section or passage, one thing you have to always consider is that JavaScript always runs first. mrangel taught me a way to work around this. The below work:

    squiffy.ui.processText("{@not falseAttribute}")
    squiffy.ui.processText("{@attribute2+=456}") //or -, *, /
    squiffy.ui.processText("{if attribute=@attribute2:{@theyreEqual}}")
    squiffy.ui.processText("{if not falseAttribute:{@thatsNotTrue}}")
    squiffy.ui.processText("{if @attribute<=579:{@itsLess}}")

But these don't work:

    squiffy.ui.processText("{if @attribute<>122:{@Nope}}")
    squiffy.ui.processText("{if attribute>=122:{@Nope}}")

Seriously, what gives?!

That's bizarre. This looks like a bug in processTextCommand_If … but if the same problem crops up with {if …} blocks in normal text, I would really have expected it to be fixed by now.

Looking at the code for the if text processor command, it looks like the operators it supports are:

  • = - attribute equals value
  • < or &lt; - attribute is less than value
  • <= or &lt;= - attribute is less than or equal to value
  • &gt; - attribute is greater than value
  • &gt;= - attribute is greater than or equal to value
  • <&gt; or &lt;&gt; - attribute is not equal to value

(It uses replace to change < to &lt;, and then compares it to a set of patterns which contain &lt; and &gt;)

To fix this, I think you can look in squiffy.template.js for the line (line 454 on the version I have):
condition = condition.replace("<", "&lt;");
and change to:
condition = condition.replace("<", "&lt;").replace(">", "&gt;");

mrangel, you really are an angel. That fixed it instantly. I'll put that into your 5.1.4 version.

Mrangel, you are a saint.

If I were a saint my name would be Simon, not Angel.
And I'd appreciate the compliments a lot more if the person giving it weren't a spambot.

(Though I'm glad I can help IFforClassroom and other real users)

This topic is now closed. Topics are closed after 60 days of inactivity.