alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lift Framework example source code file (YUIArtifacts.scala)

This example Lift Framework source code file (YUIArtifacts.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lift Framework tags/keywords

ajaxinfo, ajaxinfo, jsartifacts, jscmd, jscmd, jsexp, jsexp, nil, nodeseq, noop, string, string, timespan, yuiartifacts

The Lift Framework YUIArtifacts.scala source code

/*
 * Copyright 2007-2011 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftweb 
package http 
package js 
package yui 

import scala.xml.{Elem, NodeSeq}

import net.liftweb.http.S
import net.liftweb.http.js.JE
import net.liftweb.http.js.JsCmds
import net.liftweb.util.Helpers
import Helpers._
import JsCmds._
import JE._

/**
 * Prerequisite YUI scripts:
 * yahoo.js
 * dom.js
 * connection.js
 * event.js
 */
object YUIArtifacts extends JSArtifacts {
  def toggle(id: String) = new JsExp {
    def toJsCmd = "YAHOO.lift.toggle(this, " + id.encJs + ");";
  }

  def hide(id: String) = new JsExp {
    def toJsCmd = "YAHOO.util.Dom.setStyle(" + id.encJs + ", 'display', 'none');"
  }

  def show(id: String) = new JsExp {
    def toJsCmd = "YAHOO.util.Dom.setStyle(" + id.encJs + ", 'display', 'block');"
  }

  def showAndFocus(id: String) = new JsExp {
    def toJsCmd = "YAHOO.util.Dom.setStyle(" + id.encJs + ", 'display', 'block');" +
            "setTimeout(function() { document.getElementById(" + id.encJs + ").focus(); }, 200);"
  }

  def serialize(id: String) = new JsExp {
    def toJsCmd = "YAHOO.util.Connect.setForm(" + id.encJs + ", false)"
  }

  def setHtml(uid: String, content: NodeSeq): JsCmd = new JsCmd {
    val toJsCmd = fixHtmlCmdFunc(uid, content){s => "try{document.getElementById(" + uid.encJs + ").innerHTML = " + s + ";} catch (e) {}"}
  }

  def onLoad(cmd: JsCmd): JsCmd = new JsCmd {
    def toJsCmd = "YAHOO.util.Event.onDOMReady(function(){" + cmd.toJsCmd + "})"
  }

  def fadeOut(id: String, duration: TimeSpan, fadeTime: TimeSpan) = Noop
 

  def ajax(data: AjaxInfo): String = {
    val url = S.encodeURL(S.contextPath + "/" + LiftRules.ajaxPath + "/")

    "url = YAHOO.lift.buildURI(liftAjax.addPageName(" + url.encJs + ") , " + data.data.toJsCmd + ");" +
            "YAHOO.util.Connect.asyncRequest(" + data.action.encJs + ", url, " + toJson(data) + ");"
  }

  def comet(data: AjaxInfo): String = {
    val url = LiftRules.calcCometPath(LiftRules.cometServer())
    "url = YAHOO.lift.buildURI(" + url.toJsCmd + ", YAHOO.lift.simpleJsonToQS(" + data.data.toJsCmd + "));" +
            "YAHOO.util.Connect.asyncRequest(" + data.action.encJs + ", url, " + toJson(data) + ");";
  }

  def jsonStringify(in: JsExp): JsExp = new JsExp {
    def toJsCmd = "YAHOO.lang.JSON.stringify(" + in.toJsCmd + ")"
  }

  def formToJSON(formId: String): JsExp = new JsExp() {
    def toJsCmd = "YAHOO.lift.formToJSON('" + formId + "')";
  }

  private def toJson(info: AjaxInfo): String =
    ("timeout : " + info.timeout ::
            "cache : " + info.cache ::
            "success : function(resp) { res = YAHOO.lift.eval(resp);" + info.successFunc.map(_ + "(res);").openOr("") + "}" ::
            "failure : " + info.failFunc.openOr("function (arg) {YAHOO.log('Ajax request failed');}") ::
            Nil) mkString ("{ ", ", ", " }")


}

Other Lift Framework examples (source code examples)

Here is a short list of links related to this Lift Framework YUIArtifacts.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.