Created
December 2, 2009 18:38
-
-
Save hoffrocket/247425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class MySetHtml(uid:String, xhtml:NodeSeq) extends JsCmd { | |
def filterScripts(xhtml:NodeSeq):(String, NodeSeq) = { | |
def xform(in: NodeSeq): NodeSeq = in flatMap { | |
case e: Elem if e.label == "script" => NodeSeq.Empty | |
case e: Elem => Elem(e.prefix, e.label, e.attributes, e.scope, xform(e.child) :_*) | |
case g: Group => xform(g.child) | |
case x => x | |
} | |
val scripts = for(script <- xhtml \\ "script") yield script.text | |
(scripts.toList.mkString, xform(xhtml)) | |
} | |
override def toJsCmd = { | |
val (script, nodes) = filterScripts(S.session.map(s => s.fixHtml(s.processSurroundAndInclude("JS SetHTML id: " + uid, xhtml))).openOr(xhtml)) | |
val html = AltXML.toXML(Group(nodes),false, true, S.ieMode).encJs | |
"try{jQuery(" + ("#" + uid).encJs + ").each(function(i) {this.innerHTML = " + html + ";}); " + script + "} catch (e) {}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment