Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes #1138 Made SetHtml and Replace use jQuery.html() and jQuery.re…

…placeWith() if JqueryArtifacts is chosen as JSArtifact.
  • Loading branch information...
commit 0b8ce638340df4f50710e2dc4db573178ad6350c 1 parent 28c0dea
@andreak andreak authored
View
7 web/webkit/src/main/scala/net/liftweb/http/js/JSArtifacts.scala
@@ -55,9 +55,14 @@ trait JSArtifacts {
def serialize(id: String): JsExp
/**
+ * Replaces the content of the node with the provided id with the markup given by content
+ */
+ def replace(id: String, content: NodeSeq): JsCmd
+
+ /**
* Sets the inner HTML of the element denominated by the id
*/
- def setHtml(id: String, xml: NodeSeq): JsCmd
+ def setHtml(id: String, content: NodeSeq): JsCmd
/**
* Sets the JavScript that willbe executed when document is ready
View
23 web/webkit/src/main/scala/net/liftweb/http/js/JsCommands.scala
@@ -684,27 +684,8 @@ object JsCmds {
* @param id - the id of the node that will be replaced
* @param node - the new node
*/
- case class Replace(id: String, content: NodeSeq) extends JsCmd with HtmlFixer {
- override val toJsCmd = {
- val (html, js) = fixHtmlAndJs("inline", content)
-
- var ret =
- """
- try {
- var parent1 = document.getElementById(""" + id.encJs + """);
- parent1.innerHTML = """ + html + """;
- for (var i = 0; i < parent1.childNodes.length; i++) {
- var node = parent1.childNodes[i];
- parent1.parentNode.insertBefore(node.cloneNode(true), parent1);
- }
- parent1.parentNode.removeChild(parent1);
- } catch (e) {
- // if the node doesn't exist or something else bad happens
- }
-"""
- if (js.isEmpty) ret else ret + " "+js.toJsCmd
-
- }
+ case class Replace(id: String, content: NodeSeq) extends JsCmd {
+ val toJsCmd = LiftRules.jsArtifacts.replace(id, Helpers.stripHead(content)).toJsCmd
}
/**
View
23 web/webkit/src/main/scala/net/liftweb/http/js/extcore/ExtCoreArtifacts.scala
@@ -49,6 +49,29 @@ object ExtCoreArtifacts extends JSArtifacts {
def toJsCmd = "Ext.Ajax.serializeForm(" + id.encJs + ")"
}
+ def replace(id: String, content: NodeSeq): JsCmd = new JsCmd with HtmlFixer {
+ override val toJsCmd = {
+ val (html, js) = fixHtmlAndJs("inline", content)
+
+ val ret =
+ """
+ try {
+ var parent1 = document.getElementById(""" + id.encJs + """);
+ parent1.innerHTML = """ + html + """;
+ for (var i = 0; i < parent1.childNodes.length; i++) {
+ var node = parent1.childNodes[i];
+ parent1.parentNode.insertBefore(node.cloneNode(true), parent1);
+ }
+ parent1.parentNode.removeChild(parent1);
+ } catch (e) {
+ // if the node doesn't exist or something else bad happens
+ }
+ """
+ if (js.isEmpty) ret else ret + " "+js.toJsCmd
+
+ }
+ }
+
def setHtml(id: String, xml: NodeSeq): JsCmd = new JsCmd {
def toJsCmd = fixHtmlCmdFunc(id, xml){s => "try { Ext.fly(" + id.encJs + ").dom.innerHTML = " + s + "; } catch (e) {}"}
}
View
4 web/webkit/src/main/scala/net/liftweb/http/js/jquery/JQueryArtifacts.scala
@@ -51,7 +51,9 @@ trait JQueryArtifacts extends JSArtifacts {
def toJsCmd = "serialize()"
}
- def setHtml(id: String, xml: NodeSeq): JsCmd = JqJsCmds.JqSetHtml(id, xml)
+ def replace(id: String, content: NodeSeq): JsCmd = JqJsCmds.JqReplace(id, content)
+
+ def setHtml(id: String, content: NodeSeq): JsCmd = JqJsCmds.JqSetHtml(id, content)
def onLoad(cmd: JsCmd): JsCmd = JqJsCmds.JqOnLoad(cmd)
View
13 web/webkit/src/main/scala/net/liftweb/http/js/jquery/JqJsCmds.scala
@@ -251,14 +251,17 @@ object JqJE {
"empty().after(" + fixHtmlFunc("inline", content){str => str} + ")"
}
+ case class JqReplace(content: NodeSeq) extends JsExp with JsMember {
+ override val toJsCmd = fixHtmlCmdFunc("inline", content){"replaceWith(" + _ + ")"}
+ }
+
object JqHtml {
def apply(): JsExp with JsMember with JQueryRight = new JsExp with JsMember with JQueryRight {
def toJsCmd = "html()"
}
def apply(content: NodeSeq): JsExp with JsMember with JQueryRight with JQueryLeft = new JsExp with JsMember with JQueryRight with JQueryLeft {
- val toJsCmd =
- "html(" + fixHtmlFunc("inline", content){str => str} + ")"
+ val toJsCmd = fixHtmlCmdFunc("inline", content){"html(" + _ + ")"}
}
}
@@ -359,13 +362,15 @@ object JqJsCmds {
JqJE.JqId(JE.Str(uid)) ~> JqJE.JqPrependTo(content)
}
+ case class JqReplace(uid: String, content: NodeSeq) extends JsCmd {
+ val toJsCmd = (JqJE.JqId(JE.Str(uid)) ~> JqJE.JqReplace(content)).cmd.toJsCmd
+ }
case class JqSetHtml(uid: String, content: NodeSeq) extends JsCmd {
/**
* Eagerly evaluate
*/
- val toJsCmd =
- fixHtmlCmdFunc(uid, content){"try{jQuery(" + ("#" + uid).encJs + ").each(function(i) {this.innerHTML = " + _ + ";});} catch (e) {}"}
+ val toJsCmd = (JqJE.JqId(JE.Str(uid)) ~> JqJE.JqHtml(content)).cmd.toJsCmd
}
object Show {
View
23 web/webkit/src/main/scala/net/liftweb/http/js/yui/YUIArtifacts.scala
@@ -58,6 +58,29 @@ object YUIArtifacts extends JSArtifacts {
def toJsCmd = "YAHOO.util.Connect.setForm(" + id.encJs + ", false)"
}
+ def replace(id: String, content: NodeSeq): JsCmd = new JsCmd with HtmlFixer {
+ override val toJsCmd = {
+ val (html, js) = fixHtmlAndJs("inline", content)
+
+ val ret =
+ """
+ try {
+ var parent1 = document.getElementById(""" + id.encJs + """);
+ parent1.innerHTML = """ + html + """;
+ for (var i = 0; i < parent1.childNodes.length; i++) {
+ var node = parent1.childNodes[i];
+ parent1.parentNode.insertBefore(node.cloneNode(true), parent1);
+ }
+ parent1.parentNode.removeChild(parent1);
+ } catch (e) {
+ // if the node doesn't exist or something else bad happens
+ }
+ """
+ if (js.isEmpty) ret else ret + " "+js.toJsCmd
+
+ }
+ }
+
def setHtml(uid: String, content: NodeSeq): JsCmd = new JsCmd {
val toJsCmd = fixHtmlCmdFunc(uid, content){s => "try{document.getElementById(" + uid.encJs + ").innerHTML = " + s + ";} catch (e) {}"}
}
Please sign in to comment.
Something went wrong with that request. Please try again.