Skip to content
Browse files

-writeJavascript:useCDATA: convenience method.

  • Loading branch information...
1 parent 11da4a5 commit 4d9ca246c50d9ca462c43b2197c1e3a9bce14beb @mikeabdullah mikeabdullah committed Jul 21, 2010
Showing with 18 additions and 0 deletions.
  1. +1 −0 KSHTMLWriter.h
  2. +17 −0 KSHTMLWriter.m
View
1 KSHTMLWriter.h
@@ -88,6 +88,7 @@
#pragma mark Scripts
- (void)writeJavascriptWithSrc:(NSString *)src;
+- (void)writeJavascript:(NSString *)script useCDATA:(BOOL)useCDATA;
// Like -startCDATA and -endCDATA, but wrapped in a javascript comment so don't risk tripping up a browser's interpreter
- (void)startJavascriptCDATA;
View
17 KSHTMLWriter.m
@@ -161,6 +161,23 @@ - (void)writeJavascriptWithSrc:(NSString *)src;
[self endElement];
}
+- (void)writeJavascript:(NSString *)script useCDATA:(BOOL)useCDATA;
+{
+ [self openTag:@"script"];
+ [self writeAttribute:@"type" value:@"text/javascript"]; // in theory, HTML5 pages could omit this
+ [self didStartElement];
+
+ if (useCDATA) [self startJavascriptCDATA];
+
+ [self writeString:@"\n"];
+ [self writeString:script];
+ [self writeString:@"\n"];
+
+ if (useCDATA) [self endJavascriptCDATA];
+
+ [self endElement];
+}
+
- (void)startJavascriptCDATA;
{
[self writeString:@"\n/* "];

0 comments on commit 4d9ca24

Please sign in to comment.
Something went wrong with that request. Please try again.