"▤"
@@ -1526,14 +1576,23 @@ pub(crate) async fn share_modal(
if candidates.is_empty() {
} else {
-
+
}
-
(share_copy_script(cx).await?)
+ (share_pick_script(cx).await?)
}?))
}
@@ -1632,6 +1695,34 @@ pub(crate) async fn share_copy_script(cx: &Cx) -> Result {
view! { cx => }
}
+/// The people picker's client half: the All row checks and unchecks every
+/// candidate, and hand-checking rows keeps the All row honest. One delegated
+/// listener, idempotent across the modal's re-renders (`window.__inSharePick`
+/// guards it), so the `in:wire` morph needs no per-element re-init.
+pub(crate) async fn share_pick_script(cx: &Cx) -> Result {
+ use topcoat::view::Unescaped;
+ const JS: &str = "\
+ (function () { \
+ if (window.__inSharePick) { return; } \
+ window.__inSharePick = true; \
+ function rows(box) { return Array.prototype.slice.call(box.querySelectorAll('.pop-list input[type=checkbox]')); } \
+ document.addEventListener('change', function (e) { \
+ var t = e.target; \
+ if (!t || !t.closest) { return; } \
+ var box = t.closest('.share-picker'); \
+ if (!box) { return; } \
+ if (t.classList.contains('share-all-toggle')) { \
+ rows(box).forEach(function (cb) { cb.checked = t.checked; }); \
+ } else { \
+ var all = box.querySelector('.share-all-toggle'); \
+ var list = rows(box); \
+ if (all) { all.checked = list.length > 0 && list.every(function (cb) { return cb.checked; }); } \
+ } \
+ }); \
+ })();";
+ view! { cx => }
+}
+
/// When the link stops opening, or never on its own. Twins the settings
/// page's helper; the share page renders the same expiry line.
fn expiry_line(language: Lang, expires_at: Option