pub struct SpecialAttributes<Dom: RealDom> {
pub dangerous_inner_html: Option<String>,
/* private fields */
}Expand description
A specially supported attributes.
Fields§
§dangerous_inner_html: Option<String>Allows setting the innerHTML of an element.
§Danger
Be sure to escape all untrusted input to avoid cross site scripting attacks.
Implementations§
Source§impl<Dom: RealDom> SpecialAttributes<Dom>
impl<Dom: RealDom> SpecialAttributes<Dom>
Sourcepub fn key(&self) -> Option<&str>
pub fn key(&self) -> Option<&str>
Keys can distinguish two elements that have the same tag.
For example, if one div has key old-key, and another div has key new-key, the two
elements are considered different.
Sourcepub fn on_create_element_key(&self) -> Option<&Cow<'static, str>>
pub fn on_create_element_key(&self) -> Option<&Cow<'static, str>>
Returns the element’s key if an on_create_element function is set.
Sourcepub fn set_key_and_on_create_element<Key, Func>(&mut self, key: Key, func: Func)
pub fn set_key_and_on_create_element<Key, Func>(&mut self, key: Key, func: Func)
Sourcepub fn set_on_create_element<Func>(
&mut self,
func: Func,
) -> Result<(), KeyNotSetError>
pub fn set_on_create_element<Func>( &mut self, func: Func, ) -> Result<(), KeyNotSetError>
Set the [SpecialAttributes.on_create_element] function.
§Key
The SpecialAttributes::key is used when one virtual-node is being patched over another.
If the new node’s key is different from the old node’s key, the on create element function gets called.
If the keys are the same, the function does not get called.
§Examples
use wasm_bindgen::JsValue;
let mut node = VirtualNodeWebSys::new_element("div");
// A key can be any `Into<Cow<'static, str>>`.
let key = "some-key";
let on_create_elem = move |elem: web_sys::Element| {
assert_eq!(elem.id(), "");
};
let elem = node.as_elem_mut().unwrap();
elem.special_attributes.set_key(key);
elem.special_attributes.set_on_create_element(on_create_elem).unwrap();Sourcepub fn maybe_call_on_create_element(&self, element: &Dom::Element)
pub fn maybe_call_on_create_element(&self, element: &Dom::Element)
If an on_create_element function was set, call it.
Source§impl<Dom: RealDom> SpecialAttributes<Dom>
impl<Dom: RealDom> SpecialAttributes<Dom>
Sourcepub fn on_remove_element_key(&self) -> Option<&Cow<'static, str>>
pub fn on_remove_element_key(&self) -> Option<&Cow<'static, str>>
Returns the element’s key if an on_remove_element function is set.
Sourcepub fn set_on_remove_element<Func>(
&mut self,
func: Func,
) -> Result<(), KeyNotSetError>
pub fn set_on_remove_element<Func>( &mut self, func: Func, ) -> Result<(), KeyNotSetError>
Set the [SpecialAttributes.on_remove_element] function.
§Key
The key is used when one virtual-node is being patched over another.
If the old node’s key is different from the new node’s key, the on remove element function gets called for the old element.
If the keys are the same, the function does not get called.
§Examples
use wasm_bindgen::JsValue;
let mut node = VirtualNodeWebSys::new_element("div");
// A key can be any `Into<Cow<'static, str>>`.
let key = "some-key";
let on_remove_elem = move |elem: web_sys::Element| {
assert_eq!(elem.id(), "");
};
let elem = node.as_elem_mut().unwrap();
elem.special_attributes.set_key(key);
elem.special_attributes.set_on_remove_element(on_remove_elem);Sourcepub fn maybe_call_on_remove_element(&self, element: &Dom::Element)
pub fn maybe_call_on_remove_element(&self, element: &Dom::Element)
If an on_remove_element function was set, call it.