Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simpler method for pulling in an external script.

  • Loading branch information...
commit 60c7e895139df6edd5492a315b653d160777cf81 1 parent c35c721
@mikeabdullah mikeabdullah authored
Showing with 16 additions and 2 deletions.
  1. +3 −1 KSHTMLWriter.h
  2. +13 −1 KSHTMLWriter.m
View
4 KSHTMLWriter.h
@@ -85,11 +85,13 @@
media:(NSString *)media;
-#pragma mark Script
+#pragma mark Scripts
+- (void)writeScriptWithSrc:(NSString *)src;
- (void)writeScriptSrc:(NSString *)src // Note: You should either use src OR contents, not both.
orContents:(NSString *)contents // However you can specify contents for comments, which is OK.
useCDATA:(BOOL)useCDATA;
+
#pragma mark Style
- (void)startStyleElementWithType:(NSString *)type;
View
14 KSHTMLWriter.m
@@ -149,12 +149,24 @@ - (void)writeLinkToStylesheet:(NSString *)href
[self writeLinkWithHref:href type:@"text/css" rel:@"stylesheet" title:title media:media];
}
-#pragma mark javascript
+#pragma mark Scripts
+
+- (void)writeScriptWithSrc:(NSString *)src;
+{
+ [self startElement:@"script" attribute:@"src" value:src];
+ [self endElement];
+}
- (void)writeScriptSrc:(NSString *)src // Note: You should either use src OR contents, not both.
orContents:(NSString *)contents // However you can specify contents for comments, which is OK.
useCDATA:(BOOL)useCDATA;
{
+ // Use clean API when possible…
+ if (src && !contents) return [self writeScriptWithSrc:src];
+
+
+ // …otherwise bodge it:
+
[self openTag:@"script"];
[self writeAttribute:@"type" value:@"text/javascript"];
Please sign in to comment.
Something went wrong with that request. Please try again.