Turns out it was pretty damn fast and easy to make a modified
idMemoize that did what I needed. Maybe this could be helpful for
someone else. I haven't tested it thoroughly yet but it seems to work
fine. I'll be back if it turns out broken.
Please note that I had to resolve to JQuery-specific commands to do
the replace. I think replace is not in the common Js-stuff right?
Anyway, since I did that I also replaced the id:s with data-attributes
so I could use the id:s for other stuff (remember - I'm really picky
about not messing with the markup/styling)
Anyway - just gotta say: I love Lift :)
There are so many great ideas from David and others in here and in the
rare occasion it doesn't fit my specific needs It's so damn easy to
just look at the source and modify until it does. There's ALWAYS
options and I haven't one single time felt cornered.
To recap about this memo-function - the difference here is that the
binding function is applied to the whole thing and not just the
children. So if placed next to a pure CssSel like above it will do the
same thing. Still got to think about binding to a single elem though.
That could probably be fixed too…
def idMemoize(f: MemoTransform => NodeSeqFuncOrSeqNodeSeqFunc):
MemoTransform = {
new MemoTransform {
var tmpl: Elem = <span/>
var latestId = Helpers.nextFuncName
private def fixElem(e: Elem): Elem = {
e.attribute("data-lift-memo-id") match {
case Some(id) =>
latestId = id.text; e
case None => e % ("data-lift-memo-id" -> latestId)
}
}
def apply(ns: NodeSeq): NodeSeq =
Helpers.findBox(ns) { e => tmpl = fixElem(e); Full(e) }.
map(ignore => applyAgain()).openOr(NodeSeq.Empty)
def applyAgain(): NodeSeq = f(this)(tmpl)
def setHtml(): JsCmd = (JqMemoId(latestId) ~>
JqJE.JqReplace(applyAgain)).cmd
}
}
trait MemoTransform extends (NodeSeq => NodeSeq) {
def applyAgain(): NodeSeq
def setHtml(): JsCmd
}
case class JqMemoId(id: String) extends JsExp {
override def toJsCmd = """jQuery('[data-lift-memo-id="""" + id + """"]')"""
}
Thanks,
Viktor