zjquery: Extract func to verify selector.

This commit is contained in:
Aman Agrawal 2021-02-22 13:34:22 +00:00 committed by Steve Howell
parent 914533c8bc
commit 269457c58b
1 changed files with 18 additions and 12 deletions

View File

@ -16,6 +16,23 @@ class Event {
stopPropagation() {}
}
function verify_selector_for_zulip(selector) {
const is_valid =
"<#.".includes(selector[0]) ||
selector === "window-stub" ||
selector === "document-stub" ||
selector === "body" ||
selector === "html" ||
selector.location ||
selector.includes("#") ||
selector.includes(".") ||
(selector.includes("[") && selector.indexOf("]") >= selector.indexOf("["));
if (!is_valid) {
throw new Error("Invalid selector: " + selector + " Use $.create() maybe?");
}
}
function make_event_store(selector) {
/*
@ -488,18 +505,7 @@ function make_zjquery() {
throw new Error("zjquery does not know how to wrap this object yet");
}
const valid_selector =
"<#.".includes(selector[0]) ||
selector === "window-stub" ||
selector === "document-stub" ||
selector === "body" ||
selector === "html" ||
selector.location ||
selector.includes("#") ||
selector.includes(".") ||
(selector.includes("[") && selector.indexOf("]") >= selector.indexOf("["));
assert(valid_selector, "Invalid selector: " + selector + " Use $.create() maybe?");
verify_selector_for_zulip(selector);
if (!elems.has(selector)) {
const elem = new_elem(selector);