Guest User

Untitled

a guest
Apr 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. case class MySetHtml(uid:String, xhtml:NodeSeq) extends JsCmd {
  2.  
  3.  
  4. def filterScripts(xhtml:NodeSeq):(String, NodeSeq) = {
  5. def xform(in: NodeSeq): NodeSeq = in flatMap {
  6. case e: Elem if e.label == "script" => NodeSeq.Empty
  7. case e: Elem => Elem(e.prefix, e.label, e.attributes, e.scope, xform(e.child) :_*)
  8. case g: Group => xform(g.child)
  9. case x => x
  10. }
  11. val scripts = for(script <- xhtml \\ "script") yield script.text
  12.  
  13. (scripts.toList.mkString, xform(xhtml))
  14. }
  15.  
  16. override def toJsCmd = {
  17. val (script, nodes) = filterScripts(S.session.map(s => s.fixHtml(s.processSurroundAndInclude("JS SetHTML id: " + uid, xhtml))).openOr(xhtml))
  18. val html = AltXML.toXML(Group(nodes),false, true, S.ieMode).encJs
  19. "try{jQuery(" + ("#" + uid).encJs + ").each(function(i) {this.innerHTML = " + html + ";}); " + script + "} catch (e) {}"
  20. }
  21. }
Add Comment
Please, Sign In to add comment