Hi Lift coders,
I found several additions to JqJsCmds quite helpful. 
I attached the source code.

Basically it's a few JsExp and a few objects, like the other JqJsCmds 
constructs.
It includes Remove, ReplaceWith and toggle. Toggle is probably not very useful 
for most because it renders html which may not fit for other projects. 
apply(...) of Toggle includes a call to XHtml.randomId which just returns a 
new HTML id. I guess there's a Lift equivalent for it but I was unable to find 
it.

If you like please include the things you find helpful in JqJsCmds. If 
necessary I can provide a patch for JqJsCmds.

Thanks a lot for Lift, which is a pleasure to use,
Joachim



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

package de.ansorgs.clouds.lib.lift

import _root_.net.liftweb.http.js.jquery.{JQueryLeft, JqJE, JQueryRight}
import _root_.net.liftweb.http.js.{JE, JsCmd, JsExp, JsCmds}
import _root_.scala.xml.{Text, NodeSeq}
import MoreJs.{JqRemove, JqToggle}

/**
 * Collection of several JQuery JavaScript extensions to the original Lift 
JqJsCmds.
 */
object MoreJs {
  import JsCmds.jsExpToJsCmd

  /**
   * JsExp which removes the result of the jQuery match.
   */
  case class JqRemove() extends JsExp with JQueryRight {
    override def toJsCmd = "remove()"
  }

  /**
   * JsExp which replaces the result of a JQuery match with something new.
   */
  case class JqReplace(content: NodeSeq) extends JsExp with JQueryRight {
    override def toJsCmd = "replaceWith(" + fixHtml("inline", content) + ")"
  }

  /**
   * JsExp which toggles the result of the JQuery match.
   */
  case class JqToggle() extends JsExp with JQueryRight {
    override def toJsCmd = "toggle()"
  }

  /**
   * This object helps with the removal of the content of JQUery selectors.
   */
  object Remove {
    /**
     * This removes the element with the given id from the xhtml document.
     * @param The if of the html parameter to match.
     * @return the JsCmd which executes the JQuery command
     */
    def apply(uid: String): JsCmd = JqJE.JqId(JE.Str(uid)) >> JqRemove()
  }

  /**
   * Replace an element with an id with the given new content. The original 
element is removed and
   * the new content is added instead.
   */
  object ReplaceWith {
    def apply(uid: String, content: NodeSeq): JsCmd = JqJE.JqId(JE.Str(uid)) >> 
JqReplace(content)
  }

  /**
   * Encloses the content in a toggleable div. The default is hidden.
   * It generates a random id which is used for the toggle effect.
   */
  object Toggle {
    def apply(title: String, content: NodeSeq): NodeSeq = {
      if (content.isEmpty) return NodeSeq.Empty

      val id = JE.Str(XHtml.randomId)
      val onClick: JsExp = JqJE.JqId(id) >> JqToggle()

      <div>
      <a href="#" onclick= {JE.Str(onClick.toJsCmd)}> {Text(title)} </a>
      <div id= {id} style="display:none;"> {content} </div>
      </div>
    }
  }
}

Reply via email to