Skip to content

[3.0] Theme split (wave 4, part 17) — move the signature counter's wiring into profile.js - #9438

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-signature-script
Open

[3.0] Theme split (wave 4, part 17) — move the signature counter's wiring into profile.js#9438
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-signature-script

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Part of the #7933 split, wave 4.
Profile area.

template_profile_signature_modify() generated a script to declare maxLength, call
calcCharLeft() once and bind the preview button, and the textarea carried an onkeyup
attribute. Both functions already live in profile.js, which every profile page loads, so
it can do its own wiring.

The limit travels on the textarea as data-max-length rather than as a global written into
the page, so the number exists in one place. It is only emitted when there is a limit —
#signatureLeft, the counter it feeds, only exists then too, and calcCharLeft() already
returns early without it.

The handler is on input rather than keyup, so pasting a signature in counts it.

Not taken from the theme branch

It puts maxlength on the textarea instead. That would stop you typing past the limit, but
SMF counts the signature with \r stripped, so the browser would cut you off earlier than
the server would on anything with line breaks. The counting here is unchanged.

It also drops id="preview_button" and binds f.preview_button — which is undefined,
because the input is name="preview_signature". That would leave the preview button dead.
The id stays.

Checked

Forum Profile page, same signature limit (300), before and after:

textarea counter class
empty (on load) 300
hello 295
500 × x -200 error

Identical both ways, including the error class lingering at the last step — that is
calcCharLeft() re-initialising oldSignature to "" on every call and skipping its body
when the signature is empty, which is untouched here.

Preview still renders: A [b]bold[/b] signature. comes back as
A <strong>bold</strong> signature. into #preview_signature_display, with both the
current and preview rows revealed.

Issues References (Fixes|Related|Closes)

Part of #7933

Co-Authored-By: live627 john@jbrock.us

The signature editor generated a script to declare maxLength, call
calcCharLeft() once and bind the preview button, and the textarea carried
an onkeyup attribute. profile.js is loaded on every profile page anyway,
so it can do all of that itself.

The limit rides on the textarea as data-max-length instead of a global
written into the page, so the number is in one place. It is only emitted
when there is a limit, since the counter it feeds is only rendered then
either.

The handler is on "input" rather than "keyup", so pasting a signature in
counts it as well.

Signed-off-by: Mathias Alberts <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant