Permalink
Browse files

Closes #886. Adds custom function to determine iPad and iPhone

  • Loading branch information...
1 parent 2018263 commit db6292d946e59995440ce49c298e104dcd6e6a73 @dpp dpp committed Mar 2, 2011
Showing with 27 additions and 2 deletions.
  1. +27 −2 web/webkit/src/main/scala/net/liftweb/http/Req.scala
@@ -109,6 +109,23 @@ object UserAgentCalculator extends Factory {
Box[Double]](defaultChromeCalcFunction _)
/**
+ * You can change the mechanism by which Lift calculates
+ * if the User-Agent represents an iPhone. Put your
+ * special calculation function in here
+ */
+ object iPhoneCalcFunction extends FactoryMaker[Box[Box[String] =>
+ Boolean]](Empty)
+
+ /**
+ * You can change the mechanism by which Lift calculates
+ * if the User-Agent represents an iPad. Put your
+ * special calculation function in here
+ */
+ object iPadCalcFunction extends FactoryMaker[Box[Box[String] =>
+ Boolean]](Empty)
+
+
+ /**
* The built-in mechanism for calculating Chrome
*/
def defaultChromeCalcFunction(userAgent: Box[String]): Box[Double] =
@@ -143,12 +160,20 @@ trait UserAgentCalculator {
/**
* Is the Req coming from an iPhone
*/
- lazy val isIPhone = isSafari && (userAgent.map(s => s.indexOf("(iPhone") >= 0) openOr false)
+ lazy val isIPhone: Boolean =
+ UserAgentCalculator.iPhoneCalcFunction.vend.
+ map(_.apply(userAgent)) openOr
+ isSafari && (userAgent.map(s =>
+ s.indexOf("(iPhone") >= 0) openOr false)
/**
* Is the Req coming from an iPad
*/
- lazy val isIPad = isSafari && (userAgent.map(s => s.indexOf("(iPad") >= 0) openOr false)
+ lazy val isIPad: Boolean =
+ UserAgentCalculator.iPadCalcFunction.vend.
+ map(_.apply(userAgent)) openOr
+ isSafari && (userAgent.map(s =>
+ s.indexOf("(iPad") >= 0) openOr false)
lazy val firefoxVersion: Box[Double] =
UserAgentCalculator.firefoxCalcFunction.vend.apply(userAgent)

0 comments on commit db6292d

Please sign in to comment.