Created
March 17, 2011 03:45
-
-
Save fmpwizard/873797 to your computer and use it in GitHub Desktop.
Case Class to replace html and if it fails, append some NodeSeq to some other ID
This file contains 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 ReplaceOrAppend(replacementId: String, replacement: NodeSeq, | |
appendingId: String, appending: NodeSeq) extends JsCmd with HtmlFixer { | |
override val toJsCmd = { | |
val (replacementHtml, replacementJs) = fixHtmlAndJs("inline", replacement) | |
val (appendHtml, appendJs) = fixHtmlAndJs("inline", appending) | |
var ret = | |
""" | |
try { | |
var parent1 = document.getElementById(""" + replacementId.encJs + """); | |
parent1.innerHTML = """ + replacementHtml + """; | |
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) { | |
$('#""" + appendingId + """').append(""" + appendHtml + """); | |
} | |
""" | |
ret | |
} | |
} |
This file contains 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
Usage: | |
ReplaceOrAppend( | |
"id1",// the id to call Replace | |
<td id="id1" class={cssClass}>{cellNotes}</td>, //the NodeSeq that will replace the existing id2 | |
"result-grid", //the id of the element we will append a NodeSeq to | |
<tr> | |
<td id={rowName}>{rowName}</td> | |
<td id={((ind + 0) + rowName)} class="notice"><span>N/A</span></td> | |
<td id={((ind + 1) + rowName)} class="notice"><span>N/A</span></td> | |
<td id={((ind + 2) + rowName)} class="notice"><span>N/A</span></td> | |
<td id={((ind + 3) + rowName)} class="notice"><span>N/A</span></td> | |
</tr> // The NodeSeq to append | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment