Skip to content

Commit

Permalink
Made liftAjax.js and liftComet.js a single static .js file.
Browse files Browse the repository at this point in the history
  • Loading branch information
eltimn authored and Shadowfiend committed Apr 23, 2014
1 parent a0f83b5 commit 4b51be1
Show file tree
Hide file tree
Showing 13 changed files with 848 additions and 87 deletions.
585 changes: 585 additions & 0 deletions web/webkit/src/main/resources/toserve/lift.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions web/webkit/src/main/scala/net/liftweb/http/CometActor.scala
Expand Up @@ -772,7 +772,7 @@ trait CometActor extends LiftActor with LiftCometActor with BindHelpers {
Box[NodeSeq] = Full(f(defaultHtml))

/**
* Handle messages sent to this Actor before the
* Handle messages sent to this Actor before the
*/
def highPriority: PartialFunction[Any, Unit] = Map.empty

Expand Down Expand Up @@ -1066,7 +1066,7 @@ trait CometActor extends LiftActor with LiftCometActor with BindHelpers {
listeners = Nil
}

def unWatch = partialUpdate(Call("liftComet.lift_unlistWatch", uniqueId))
def unWatch = partialUpdate(Call("lift.unlistWatch", uniqueId))

/**
* Poke the CometActor and cause it to do a partial update Noop which
Expand Down Expand Up @@ -1456,7 +1456,7 @@ object Notice {

/**
* The RenderOut case class contains the rendering for the CometActor.
* Because of the implicit conversions, RenderOut can come from
* Because of the implicit conversions, RenderOut can come from
* <br/>
* @param xhtml is the "normal" render body
* @param fixedXhtml is the "fixed" part of the body. This is ignored unless reRender(true)
Expand Down
60 changes: 25 additions & 35 deletions web/webkit/src/main/scala/net/liftweb/http/LiftMerge.scala
Expand Up @@ -112,22 +112,22 @@ private[http] trait LiftMerge {
var bodyTail = false

v match {
case e: Elem if e.label == "html" &&
case e: Elem if e.label == "html" &&
!inHtml => htmlTag = e; inHtml = true && doMergy

case e: Elem if e.label == "head" && inHtml &&
!inBody => headTag = e;
case e: Elem if e.label == "head" && inHtml &&
!inBody => headTag = e;
inHead = true && doMergy; justHead = true && doMergy

case e: Elem if (e.label == "head" ||
e.label.startsWith("head_")) &&
case e: Elem if (e.label == "head" ||
e.label.startsWith("head_")) &&
inHtml && inBody => bodyHead = true && doMergy

case e: Elem if e.label == "tail" && inHtml &&
case e: Elem if e.label == "tail" && inHtml &&
inBody => bodyTail = true && doMergy

case e: Elem if e.label == "body" && inHtml =>
bodyTag = e; inBody = true && doMergy;
bodyTag = e; inBody = true && doMergy;
justBody = true && doMergy

case _ =>
Expand Down Expand Up @@ -189,55 +189,45 @@ private[http] trait LiftMerge {
_fixHtml(e, true, false, false, true, false, false, true, false)
}

// Appends ajax stript to body
// Appends ajax script to body
if (LiftRules.autoIncludeAjaxCalc.vend().apply(this)) {
bodyChildren +=
<script src={S.encodeURL(contextPath + "/" +
LiftRules.ajaxPath +
"/" + LiftRules.ajaxScriptName())}
<script src={S.encodeURL(contextPath + "/classpath/lift.js")}
type="text/javascript"/>
bodyChildren += nl
}

val cometList = cometTimes.toList

// Appends comet stript reference to head
if (LiftRules.autoIncludeJSSettings.vend().apply(this)) {
S.appendJs(LiftJavaScript.initCmd(LiftRules.javascriptSettings.vend().apply(this)))
}

if (!cometList.isEmpty && LiftRules.autoIncludeComet(this)) {
bodyChildren +=
<script src={S.encodeURL(contextPath + "/" +
LiftRules.cometPath +
"/" + urlEncode(this.uniqueId) +
"/" + LiftRules.cometScriptName())}
type="text/javascript"/>
bodyChildren += nl
S.appendJs(LiftRules.renderCometPageContents(this, cometList))
}

if (LiftRules.enableLiftGC && stateful_?) {
import js.JsCmds._

S.appendJs(JE.Call("window.lift.setPageId", RenderVersion.get))

if (!cometList.isEmpty || hasFuncsForOwner(RenderVersion.get))
S.appendJs(JE.Call("window.lift.register"))
}

S.jsToAppend match {
case Nil =>
case Nil =>
case x :: Nil => addlTail += js.JsCmds.Script(x)
case xs => addlTail += js.JsCmds.Script(xs.foldLeft(js.JsCmds.Noop)(_ & _))
}

for{
for {
node <- HeadHelper.removeHtmlDuplicates(addlTail.toList)
} bodyChildren += node

bodyChildren += nl

if (!cometList.isEmpty && LiftRules.autoIncludeComet(this)) {
bodyChildren += JsCmds.Script(LiftRules.renderCometPageContents(this, cometList))
bodyChildren += nl
}

if (LiftRules.enableLiftGC && stateful_?) {
import js._
import JsCmds._
import JE._

bodyChildren += JsCmds.Script((if (!cometList.isEmpty || hasFuncsForOwner(RenderVersion.get)) OnLoad(JsRaw("liftAjax.lift_successRegisterGC()")) else Noop) &
JsCrVar("lift_page", RenderVersion.get))
}

htmlKids += nl
htmlKids += Elem(headTag.prefix, headTag.label, headTag.attributes, headTag.scope, headTag.minimizeEmpty, headChildren.toList: _*)
htmlKids += nl
Expand Down
49 changes: 29 additions & 20 deletions web/webkit/src/main/scala/net/liftweb/http/LiftRules.scala
Expand Up @@ -656,29 +656,25 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
* request comes in for a session that has no associated comet actors
* (this typically happens when the server restarts).
*
* By default, we invoke liftComet.lift_sessionLost, which can be
* By default, we invoke lift.cometOnSessionLost, which can be
* overridden client-side for more complex work.
* liftComet.lift_sessionLost reloads the current page by default.
* lift.cometOnSessionLost reloads the current page by default.
*/
val noCometSessionCmd = new FactoryMaker[JsCmd](
() => {
JsCmds.Run("liftComet.lift_sessionLost();")
}
() => JsCmds.Run("lift.cometOnSessionLost()")
) {}

/**
* The JsCmd to execute when the ajax session is lost. The ajax
* session is considered lost when either an ajax request comes in for
* a session that does not exist on the server.
*
* By default, we invoke liftAjax.lift_sessionLost, which can be
* By default, we invoke lift.ajaxOnSessionLost, which can be
* overridden client-side for more complex work.
* liftAjax.lift_sessionLost reloads the page by default.
* lift.ajaxOnSessionLost reloads the page by default.
*/
val noAjaxSessionCmd = new FactoryMaker[JsCmd](
() => {
JsCmds.Run("liftAjax.lift_sessionLost();")
}
() => JsCmds.Run("lift.ajaxOnSessionLost()")
) {}

/**
Expand Down Expand Up @@ -812,18 +808,18 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {

/**
* The JavaScript to execute to log a message on the client side when
* liftAjax.lift_logError is called.
* lift.logError is called.
*
* If Empty no logging is performed
* The default when running in DevMode is to call lift_defaultLogError which
* The default when running in DevMode is to call lift.logError which
* will use JavaScript console if available or alert otherwise.
*
*
* To always use alert set:
*
* LiftRules.jsLogFunc = Full(v => JE.Call("alert",v).cmd)
*/
@volatile var jsLogFunc: Box[JsVar => JsCmd] =
if (Props.devMode) Full(v => JE.Call("liftAjax.lift_defaultLogError", v))
if (Props.devMode) Full(v => JE.Call("lift.logError", v))
else Empty

/**
Expand Down Expand Up @@ -1586,11 +1582,24 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
/**
* Tells Lift if the Comet JavaScript should be included. By default it is set to true.
*/
@deprecated("Not used anymore. See LiftJavaScript.scala", "2.6")
@volatile var autoIncludeComet: LiftSession => Boolean = session => true

val autoIncludeAjaxCalc: FactoryMaker[() => LiftSession => Boolean] =
val autoIncludeAjaxCalc: FactoryMaker[() => LiftSession => Boolean] =
new FactoryMaker(() => () => (session: LiftSession) => true) {}

/**
* Tells Lift if the Ajax/Comet JavaScript should be initialized with LiftRules via LiftJavaScript
*/
val autoIncludeJSSettings: FactoryMaker[() => LiftSession => Boolean] =
new FactoryMaker(() => () => (session: LiftSession) => true) {}

/**
* Tells Lift which JavaScript settings to use.
*/
val javascriptSettings: FactoryMaker[() => LiftSession => JsObj] =
new FactoryMaker(() => () => (session: LiftSession) => LiftJavaScript.settings) {}

/**
* Define the XHTML validator
*/
Expand Down Expand Up @@ -1656,8 +1665,8 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
* caught exception.
*
* In development mode, this defaults to Full and the command within
* invokes liftComet.lift_cometError with the exception;
* lift_cometError rethrows the exception by default. In production
* invokes lift.cometOnError with the exception;
* lift.cometOnError rethrows the exception by default. In production
* mode, this defaults to Empty.
*
* Note that if you set this to Full, it is highly advised that you
Expand All @@ -1671,7 +1680,7 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
val cometUpdateExceptionHandler: FactoryMaker[Box[JsCmd]] =
new FactoryMaker[Box[JsCmd]]( () => {
if (Props.devMode)
Full(JE.Call("liftComet.lift_cometError", JE.JsVar("e")).cmd)
Full(JE.Call("lift.cometOnError", JE.JsVar("e")).cmd)
else
Empty
} ) {}
Expand All @@ -1681,7 +1690,7 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
*/
@volatile var renderCometPageContents: (LiftSession, Seq[CometVersionPair]) => JsCmd =
(session, vp) => JsCmds.Run(
"var lift_toWatch = " + vp.map(p => p.guid.encJs + ": " + p.version).mkString("{", " , ", "}") + ";"
"window.lift.registerComet(" + vp.map(p => p.guid.encJs + ": " + p.version).mkString("{", " , ", "}") + ", '"+S.encodeURL(session.uniqueId)+"');"
)

/**
Expand Down Expand Up @@ -1770,7 +1779,7 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
/**
* The name of the Ajax script that manages Ajax requests.
*/
@volatile var ajaxScriptName: () => String = () => "liftAjax.js"
@volatile var ajaxScriptName: () => String = () => "lift.js"

/**
* The name of the Comet script that manages Comet requests.
Expand Down
8 changes: 4 additions & 4 deletions web/webkit/src/main/scala/net/liftweb/http/LiftServlet.scala
Expand Up @@ -281,7 +281,7 @@ class LiftServlet extends Loggable {
} else {
val cmd =
if (isComet)
js.JE.JsRaw(LiftRules.noCometSessionCmd.vend.toJsCmd + ";lift_toWatch = {};").cmd
js.JE.JsRaw(LiftRules.noCometSessionCmd.vend.toJsCmd + ";lift.setToWatch({});").cmd
else
js.JE.JsRaw(LiftRules.noAjaxSessionCmd.vend.toJsCmd).cmd

Expand Down Expand Up @@ -742,7 +742,7 @@ class LiftServlet extends Loggable {
nextAction match {
case Left(future) =>
val result = runAjax(liftSession, requestState) map CachedResponse

if (result.exists(_.failed_?)) {
// The request failed. The client will retry it, so
// remove it from the list of current Ajax requests that
Expand Down Expand Up @@ -837,7 +837,7 @@ class LiftServlet extends Loggable {
sessionActor.getAsyncComponent(name).toList.map(c => (c, toLong(when)))
}

if (actors.isEmpty) Left(Full(new JsCommands(LiftRules.noCometSessionCmd.vend :: js.JE.JsRaw("lift_toWatch = {};").cmd :: Nil).toResponse))
if (actors.isEmpty) Left(Full(new JsCommands(LiftRules.noCometSessionCmd.vend :: js.JE.JsRaw("lift.setToWatch({});").cmd :: Nil).toResponse))
else requestState.request.suspendResumeSupport_? match {
case true => {
setupContinuation(requestState, sessionActor, actors)
Expand All @@ -852,7 +852,7 @@ class LiftServlet extends Loggable {

private def convertAnswersToCometResponse(session: LiftSession, ret: Seq[AnswerRender], actors: List[(LiftCometActor, Long)]): LiftResponse = {
val ret2: List[AnswerRender] = ret.toList
val jsUpdateTime = ret2.map(ar => "if (lift_toWatch['" + ar.who.uniqueId + "'] !== undefined) lift_toWatch['" + ar.who.uniqueId + "'] = '" + ar.when + "';").mkString("\n")
val jsUpdateTime = ret2.map(ar => "lift.updWatch('" + ar.who.uniqueId + "', '" + ar.when + "');").mkString("\n")
val jsUpdateStuff = ret2.map {
ar => {
val ret = ar.response.toJavaScript(session, ar.displayAll)
Expand Down
Expand Up @@ -25,6 +25,7 @@ import java.util.concurrent.{ConcurrentHashMap => CHash}

object ResourceServer {
var allowedPaths: PartialFunction[List[String], Boolean] = {
case "lift.js" :: Nil => true
case "jquery.js" :: Nil => true
case "yui" :: _ => true
case "liftYUI.js" :: Nil => true
Expand All @@ -46,6 +47,7 @@ object ResourceServer {
}

@volatile var pathRewriter: PartialFunction[List[String], List[String]] = rewriter orElse {
case "lift.js" :: Nil => List("lift-min.js")
case "json.js" :: Nil => List("json2-min.js")
case "json2.js" :: Nil => List("json2-min.js")
case xs => xs
Expand Down
14 changes: 7 additions & 7 deletions web/webkit/src/main/scala/net/liftweb/http/S.scala
Expand Up @@ -993,7 +993,7 @@ trait S extends HasParams with Loggable with UserAgentCalculator {


private object resourceValueCache extends TransientRequestMemoize[(String, Locale), String]

/**
* Get a localized string or return the original string.
* We first try your own bundle resources, if that fails, we try
Expand Down Expand Up @@ -1021,7 +1021,7 @@ trait S extends HasParams with Loggable with UserAgentCalculator {
* @see # resourceBundles
*/
def ?(str: String, locale: Locale): String = resourceValueCache.get(str -> locale, ?!(str, resourceBundles(locale)))

/**
* Attempt to localize and then format the given string. This uses the String.format method
* to format the localized string.
Expand Down Expand Up @@ -1113,8 +1113,8 @@ trait S extends HasParams with Loggable with UserAgentCalculator {
req <- request
queryString <- req.request.queryString
} yield queryString


def uriAndQueryString: Box[String] = for {
req <- this.request
} yield req.uri + (queryString.map(s => "?"+s) openOr "")
Expand All @@ -1124,8 +1124,8 @@ trait S extends HasParams with Loggable with UserAgentCalculator {
* the handlers are ignored
*/
def runExceptionHandlers(req: Req, orig: Throwable): Box[LiftResponse] = {
S.assertExceptionThrown()
tryo{(t: Throwable) =>
S.assertExceptionThrown()
tryo{(t: Throwable) =>
logger.error("An error occurred while running error handlers", t)
logger.error("Original error causing error handlers to be run", orig)} {
NamedPF.applyBox((Props.mode, req, orig), LiftRules.exceptionHandler.toList);
Expand Down Expand Up @@ -2661,7 +2661,7 @@ trait S extends HasParams with Loggable with UserAgentCalculator {

(JsonCall(key), JsCmds.Run(name.map(n => onErrorFunc +
"/* JSON Func " + n + " $$ " + key + " */").openOr("") +
"function " + key + "(obj) {liftAjax.lift_ajaxHandler(" +
"function " + key + "(obj) {lift.ajax(" +
"'" + key + "='+ encodeURIComponent(" +
LiftRules.jsArtifacts.
jsonStringify(JE.JsRaw("obj")).
Expand Down

0 comments on commit 4b51be1

Please sign in to comment.