<sidejar-content>
Holds what a payment unlocks, and reveals it when its <sidejar-pay> is paid, including when a returning payer loads the page.
Two jobs: expose and decrypt
Each <sidejar-content> follows a jar (for="…") and does one of two jobs. Use either or both; any number can follow the same jar.
| Expose | Decrypt | |
|---|---|---|
| Holds | Content in your page, as ordinary HTML | An encrypted string in a <template> |
| Search engines | Can find it | Can't see it |
| Before payment | Shown as is, or with a reveal effect | Not shown |
| When paid | The effect undoes itself (a fade expands) | Decrypted by onpaid, then fades in |
| Set up with | effect="…" |
onpaid="Sidejar.decrypt" |
Common combinations:
- A preview and the rest: expose the intro with
effect="fade", decrypt the rest. Put the jar between them, or anywhere. - A classic paywall: the intro as plain page content (no element needed), and an element to decrypt the rest.
- Just the rest: only a decrypting element; nothing shows until it's paid.
- Everything in the page: only an exposing element, with an effect like scramble or redact; nothing is encrypted.
With an encrypted rest, the intro is a preview of what's coming, so show it as is or with fade. Save scramble, redact and the rest for content that's all in the page. If the rest can't be decrypted (a wrong key, say), that element stays locked and fires content_handler_failed. See Encryption and Reveal effects below.
Attributes
| Attribute | Meaning |
|---|---|
for |
The id of the <sidejar-pay> to follow. Optional when the page has exactly one. |
effect |
Expose: how the content looks until paid: fade, scramble, redact, sort-words, sort-letters, flip, blur, hide, or your own function. Without it, the content is shown as is. |
onpaid |
Decrypt: a function that turns the template into what's shown after payment, usually Sidejar.decrypt. Without it, the template is shown as is. |
onlocked |
Optional: a function whose return value stands in for the rest before payment (see Stand-ins). |
onready, onsettled, oncancelled, onfailed |
Functions called on the matching <sidejar-pay> event (onfailed = sidejar:error). Return values are ignored. |
data-key |
A key for Sidejar.decrypt (see Encryption). |
for works like <label for="…">: it names the jar by its id. In React, write for too, not htmlFor (see Frameworks and CSP).
Handlers
Handler attributes name a function: one of the built-in Sidejar methods (Sidejar.blur) or your own. It's called as:
fn(content, detail, el)
// content: the template's HTML (or JSON text) as a string
// detail: the event's detail (null for onlocked)
// el: the <sidejar-content> element
- Return a string of HTML or a DOM node (or a Promise of one) to show it. Return
undefinedif your function displayed things itself. - If
onpaidthrows or rejects, the content stays locked and the element firessidejar:errorwithcontent_handler_failed. - Define your own handlers with a function declaration (or
window.myFn = …). Top-levelconstandletaren't visible to attributes. - In frameworks, set your own functions as properties instead:
el.onpaid = (content) => …. Properties win over attributes. See Frameworks and CSP.
<script>
function shout(content) {
return content.toUpperCase();
}
</script>
<sidejar-content for="tip" onpaid="shout"><template><p>hello</p></template></sidejar-content>
Stand-ins for the rest
Usually the intro is all readers need to see before paying. If you'd like a hint of how much more there is, onlocked can show a stand-in where the rest will appear: Sidejar.placeholder (grey lines about as long as the rest) or Sidejar.blur (blurred gibberish of about the right length). Stand-ins are hidden from screen readers.
JSON content
Put JSON in a <script type="application/json"> instead of a <template>, which would mangle & and <. It's never executed, and your onpaid gets the raw text:
<sidejar-content for="tip" onpaid="showAnswers">
<script type="application/json">{ "answers": ["B", "D", "A"] }</script>
</sidejar-content>
<script>
function showAnswers(content) {
const data = Sidejar.json(content);
return `<p>Answers: ${data.answers.join(", ")}</p>`;
}
</script>
Chained jars
Put another <sidejar-pay> (with its own <sidejar-content>) inside revealed content. It appears only after the first payment, then works on its own: chapter 1, then chapter 2. Give each jar its own item, and set for="…" whenever a page has more than one jar.
Good to know
- Scripts inside revealed content don't run (browsers never run scripts in inserted HTML). Tags like a nested
<sidejar-pay>do work. - Once unlocked, content stays unlocked, even if the payer switches wallets. Sidejar never hides content; your page decides.
- It's a block element by default (override with any CSS).
- For styling, it always has the class
sidejar-content, plus one state, as a class and asdata-state:sidejar-locked,sidejar-unlocking(while decrypting the rest, or while the intro's effect animates),sidejar-unlockedorsidejar-failed. Your own classes are left alone. See the paywall in the demos.