Permalink
Browse files

[enhance] dom: added functions to manipualte dom attribute ≠ property

  • Loading branch information...
1 parent f443f4e commit e911cc0928d1299493c663b69183c8f7c654cf48 @Aqua-Ye Aqua-Ye committed Nov 25, 2011
Showing with 46 additions and 1 deletion.
  1. +18 −0 opabsl/jsbsl/bslDom.js
  2. +28 −1 stdlib/core/xhtml/dom.opa
View
@@ -575,6 +575,12 @@ function bsldom_unbind(dom, handler)
dom.prop(name, value);
}
+##register set_attribute_unsafe: Dom.private.element, string, string -> void
+##args(dom, name, value)
+{
+ dom.attr(name, value);
+}
+
##register set_style_property_unsafe: Dom.private.element, string, string -> void
##args(dom, name, value)
{
@@ -634,6 +640,18 @@ function bsldom_unbind(dom, handler)
return dom.prop(name) || ""
}
+##register get_attribute: Dom.private.element, string -> opa[option(string)]
+##args(dom, name)
+{
+ return js2option(dom.attr(name))
+}
+
+##register get_attribute_unsafe: Dom.private.element, string -> string
+##args(dom, name)
+{
+ return dom.attr(name) || ""
+}
+
##register add_class: Dom.private.element, string -> void
##args(dom, name)
{
View
@@ -1195,7 +1195,12 @@ Dom = {{
void
)
-
+ /**
+ * Get the value of an attribute for the first element in the set of matched elements.
+ * /!\ Different from get_attribute
+ *
+ * @see http://api.jquery.com/prop/
+ */
get_property(dom: dom, string: string): option(string) =
(
%% BslDom.get_property %%(of_selection(dom), string)
@@ -1212,6 +1217,28 @@ Dom = {{
void
)
+ /**
+ * Get the value of an attribute for the first element in the set of matched elements.
+ * /!\ Different from get_property
+ *
+ * @see http://api.jquery.com/attr/
+ */
+ get_attribute(dom: dom, string: string): option(string) =
+ (
+ %% BslDom.get_attribute %%(of_selection(dom), string)
+ )
+
+ get_attribute_unsafe(dom:dom, string:string): string = //return "" when the attribute is undefined
+ (
+ %% BslDom.get_attribute_unsafe %%(of_selection(dom), string)
+ )
+
+ set_attribute_unsafe(dom:dom, name:string, value:string): void =
+ (
+ do %% BslDom.set_attribute_unsafe %%(of_selection(dom), name, value)
+ void
+ )
+
set_style_property_unsafe(dom:dom, name:string, value:string): void =
(
do %% BslDom.set_style_property_unsafe %%(of_selection(dom), name, value)

0 comments on commit e911cc0

Please sign in to comment.