Use document() function

This commit is contained in:
Kitaiti Makoto 2021-02-12 18:48:33 +09:00
parent f2411f4607
commit 6599179174

View File

@ -95,14 +95,11 @@ pub fn main() -> Result<(), JsValue> {
/// It should normally be working fine even without this code /// It should normally be working fine even without this code
/// But :focus-within is not yet supported by Webkit/Blink /// But :focus-within is not yet supported by Webkit/Blink
fn menu() { fn menu() {
let document = window().unwrap().document().unwrap(); let document = document();
if let Ok(Some(button)) = document.query_selector("#menu a") { if let Ok(Some(button)) = document.query_selector("#menu a") {
if let Some(menu) = document.get_element_by_id("content") { if let Some(menu) = document.get_element_by_id("content") {
let show_menu = Closure::wrap(Box::new(|_: TouchEvent| { let show_menu = Closure::wrap(Box::new(|_: TouchEvent| {
window() self::document()
.unwrap()
.document()
.unwrap()
.get_element_by_id("menu") .get_element_by_id("menu")
.map(|menu| menu.class_list().add_1("show")) .map(|menu| menu.class_list().add_1("show"))
.unwrap() .unwrap()
@ -114,10 +111,7 @@ fn menu() {
show_menu.forget(); show_menu.forget();
let close_menu = Closure::wrap(Box::new(|_: TouchEvent| { let close_menu = Closure::wrap(Box::new(|_: TouchEvent| {
window() self::document()
.unwrap()
.document()
.unwrap()
.get_element_by_id("menu") .get_element_by_id("menu")
.map(|menu| menu.class_list().remove_1("show")) .map(|menu| menu.class_list().remove_1("show"))
.unwrap() .unwrap()
@ -132,17 +126,9 @@ fn menu() {
/// Clear the URL of the search page before submitting request /// Clear the URL of the search page before submitting request
fn search() { fn search() {
if let Some(form) = window() if let Some(form) = document().get_element_by_id("form") {
.unwrap()
.document()
.unwrap()
.get_element_by_id("form")
{
let normalize_query = Closure::wrap(Box::new(|_: Event| { let normalize_query = Closure::wrap(Box::new(|_: Event| {
window() document()
.unwrap()
.document()
.unwrap()
.query_selector_all("#form input") .query_selector_all("#form input")
.map(|inputs| { .map(|inputs| {
for i in 0..inputs.length() { for i in 0..inputs.length() {