@@ -87,6 +87,7 @@ private[http] final object HtmlNormalizer {
8787 attributes : MetaData ,
8888 contextPath : String ,
8989 shouldRewriteUrl : Boolean , // whether to apply URLRewrite.rewriteFunc
90+ extractInlineJavaScript : Boolean ,
9091 eventAttributes : List [EventAttribute ] = Nil
9192 ): (Option [String ], MetaData , List [EventAttribute ]) = {
9293 if (attributes == Null ) {
@@ -100,6 +101,7 @@ private[http] final object HtmlNormalizer {
100101 attributes.next,
101102 contextPath,
102103 shouldRewriteUrl,
104+ extractInlineJavaScript,
103105 eventAttributes
104106 )
105107
@@ -108,7 +110,7 @@ private[http] final object HtmlNormalizer {
108110 EventAttribute .EventForAttribute (eventName),
109111 attributeValue,
110112 remainingAttributes
111- ) if attributeValue.text.startsWith(" javascript:" ) =>
113+ ) if attributeValue.text.startsWith(" javascript:" ) && extractInlineJavaScript =>
112114 val attributeJavaScript = {
113115 // Could be javascript: or javascript://.
114116 val base = attributeValue.text.substring(11 )
@@ -150,7 +152,7 @@ private[http] final object HtmlNormalizer {
150152
151153 (id, newMetaData, remainingEventAttributes)
152154
153- case UnprefixedAttribute (name, attributeValue, _) if name.startsWith(" on" ) =>
155+ case UnprefixedAttribute (name, attributeValue, _) if name.startsWith(" on" ) && extractInlineJavaScript =>
154156 val updatedEventAttributes =
155157 EventAttribute (name.substring(2 ), attributeValue.text) ::
156158 remainingEventAttributes
@@ -182,13 +184,20 @@ private[http] final object HtmlNormalizer {
182184 }.foldLeft(Noop )(_ & _)
183185 }
184186
185- private [http] def normalizeElementAndAttributes (element : Elem , attributeToNormalize : String , contextPath : String , shouldRewriteUrl : Boolean ): NodeAndEventJs = {
187+ private [http] def normalizeElementAndAttributes (
188+ element : Elem ,
189+ attributeToNormalize : String ,
190+ contextPath : String ,
191+ shouldRewriteUrl : Boolean ,
192+ extractEventJavaScript : Boolean
193+ ): NodeAndEventJs = {
186194 val (id, normalizedAttributes, eventAttributes) =
187195 normalizeUrlAndExtractEvents(
188196 attributeToNormalize,
189197 element.attributes,
190198 contextPath,
191- shouldRewriteUrl
199+ shouldRewriteUrl,
200+ extractEventJavaScript
192201 )
193202
194203 val attributesIncludingEventsAsData =
@@ -226,7 +235,12 @@ private[http] final object HtmlNormalizer {
226235 }
227236 }
228237
229- private [http] def normalizeNode (node : Node , contextPath : String , stripComments : Boolean ): Option [NodeAndEventJs ] = {
238+ private [http] def normalizeNode (
239+ node : Node ,
240+ contextPath : String ,
241+ stripComments : Boolean ,
242+ extractEventJavaScript : Boolean
243+ ): Option [NodeAndEventJs ] = {
230244 node match {
231245 case element : Elem =>
232246 val (attributeToFix, shouldRewriteUrl) =
@@ -250,7 +264,8 @@ private[http] final object HtmlNormalizer {
250264 element,
251265 attributeToFix,
252266 contextPath,
253- shouldRewriteUrl
267+ shouldRewriteUrl,
268+ extractEventJavaScript
254269 )
255270 )
256271
@@ -263,30 +278,28 @@ private[http] final object HtmlNormalizer {
263278 }
264279
265280 /**
266- * Base for all the normalizeHtml* implementations; in addition to what it
267- * usually does, takes an `[[additionalChanges ]]` function that is passed a
268- * state object and the current (post-normalization) node and can adjust the
269- * state and tweak the normalized nodes or even add more JsCmds to be
270- * included. That state is in turn passed to any invocations for any of the
271- * children of the current node. Note that state is '''not''' passed back up
272- * the node hierarchy, so state updates are '''only''' seen by children of
273- * the node.
281+ * Normalizes `nodes` to adjust URLs with the given `contextPath`, stripping
282+ * comments if `stripComments` is `true`, and extracting event JavaScript
283+ * into the `js` part of the returned `NodesAndEventJs` if
284+ * `extractEventJavaScript` is `true`.
274285 *
275286 * See `[[LiftMerge.merge ]]` for sample usage.
276287 */
277288 def normalizeHtmlAndEventHandlers (
278289 nodes : NodeSeq ,
279290 contextPath : String ,
280- stripComments : Boolean
291+ stripComments : Boolean ,
292+ extractEventJavaScript : Boolean
281293 ): NodesAndEventJs = {
282294 nodes.foldLeft(NodesAndEventJs (Vector [Node ](), Noop )) { (soFar, nodeToNormalize) =>
283- normalizeNode(nodeToNormalize, contextPath, stripComments).map {
295+ normalizeNode(nodeToNormalize, contextPath, stripComments, extractEventJavaScript ).map {
284296 case NodeAndEventJs (normalizedElement : Elem , js : JsCmd ) =>
285297 val NodesAndEventJs (normalizedChildren, childJs) =
286298 normalizeHtmlAndEventHandlers(
287299 normalizedElement.child,
288300 contextPath,
289- stripComments
301+ stripComments,
302+ extractEventJavaScript
290303 )
291304
292305 soFar
0 commit comments