From 1ad0ca51d5c2e7682a136c8cf53bafc55cb98a49 Mon Sep 17 00:00:00 2001 From: Frederic Ye Date: Tue, 18 Oct 2011 19:13:01 +0200 Subject: [PATCH] [enhance] xhtml.opa: added a function to update an xhtml attribute by appending a new value to it (usefull for updating class attribute especially) --- stdlib/core/xhtml/xhtml.opa | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/stdlib/core/xhtml/xhtml.opa b/stdlib/core/xhtml/xhtml.opa index 64da89cf..9efd9182 100644 --- a/stdlib/core/xhtml/xhtml.opa +++ b/stdlib/core/xhtml/xhtml.opa @@ -1155,6 +1155,25 @@ Xhtml = end aux(x) + /** + * Update (by appending) an attribute to an xhtml node, add it if not already present + */ + update_attribute(name: string, value: string, x:xhtml):xhtml = + rec aux(x)= + match x : xhtml + {fragment=[x]} -> aux(x) + {~args namespace=_ tag=_ content=_ specific_attributes=_} as x-> + args = match find_attr(name,args) with + {some=val} -> + value = "{val} {value}" + l = remove_attr(name,args) + [{~name namespace="" ~value}|l] + {none} -> [{~name namespace="" ~value}|args] + @opensums({x with ~args}) + _ -> x + end + aux(x) + /** * Set an attribute to an xhtml node. Replace if already_exists */