summaryrefslogtreecommitdiff
path: root/WebInterface/wasm/webhogg/src/page.rs
blob: cb9ee3f8def72463104dea2d2c924015e19f39b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use web_sys;

use crate::webhogg_exception::WebhoggException;

pub struct Page {
    window: web_sys::Window,
    document: web_sys::Document,
}

impl Page {
    pub fn obtain() -> Result<Self, WebhoggException> {
        let window = web_sys::window()
            .ok_or(WebhoggException::DomError("could not obtain window".to_string()))?;
        let document = window.document()
            .ok_or(WebhoggException::DomError("could not obtain document".to_string()))?;
        debug!("initialised page");
        Ok(Self {
            window,
            document,
        })
    }

    pub fn get_element(&self, id: &str) -> Option<web_sys::Element> {
        self.document.get_element_by_id(id)
    }
}