Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made the "Open Modally" optional.

Now one can use "referrer=ExternalBaker" to open ins Safari as it was
before or "referrer=ModalBaker" to open in the new modal UIWebView or
leave out the referrer to open in the same UIWebView the book is loaded
in.
  • Loading branch information...
commit 0d467dbc69c9c4dfd7144c03a286838455d6a7f6 1 parent 9f32e4d
@steiny2k authored
Showing with 23 additions and 4 deletions.
  1. +20 −3 Classes/RootViewController.m
  2. +3 −1 book/Book Cover.html
View
23 Classes/RootViewController.m
@@ -58,7 +58,8 @@
#define INDEX_FILE_NAME @"index.html"
-#define URL_OPEN_EXTERNAL @"referrer=Baker"
+#define URL_OPEN_MODALLY @"referrer=ModalBaker"
+#define URL_OPEN_EXTERNAL @"referrer=ExternalBaker"
// IOS VERSION >= 5.0 MACRO
@@ -1122,8 +1123,11 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
if (params != nil)
{
- NSRegularExpression *referrerRegex = [NSRegularExpression regularExpressionWithPattern:URL_OPEN_EXTERNAL options:NSRegularExpressionCaseInsensitive error:NULL];
- NSUInteger matches = [referrerRegex numberOfMatchesInString:params options:0 range:NSMakeRange(0, [params length])];
+ NSRegularExpression *referrerExternalRegex = [NSRegularExpression regularExpressionWithPattern:URL_OPEN_EXTERNAL options:NSRegularExpressionCaseInsensitive error:NULL];
+ NSUInteger matches = [referrerExternalRegex numberOfMatchesInString:params options:0 range:NSMakeRange(0, [params length])];
+
+ NSRegularExpression *referrerModalRegex = [NSRegularExpression regularExpressionWithPattern:URL_OPEN_MODALLY options:NSRegularExpressionCaseInsensitive error:NULL];
+ NSUInteger matchesModal = [referrerModalRegex numberOfMatchesInString:params options:0 range:NSMakeRange(0, [params length])];
if (matches > 0) {
NSLog(@" Link contain param \"%@\" --> open link in Safari", URL_OPEN_EXTERNAL);
@@ -1136,6 +1140,19 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
NSString *newURL = [replacerRegexp stringByReplacingMatchesInString:oldURL options:0 range:NSMakeRange(0, [oldURL length]) withTemplate:@""];
NSLog(@" Opening with updated URL: %@", newURL);
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:newURL]];
+ return NO;
+ } else if (matchesModal) {
+ NSLog(@" Link contain param \"%@\" --> open link modally", URL_OPEN_MODALLY);
+
+ // Generate new URL without
+ // We are regexp-ing three things: the string alone, the string first with other content, the string with other content in any other position
+ NSRegularExpression *replacerRegexp = [NSRegularExpression regularExpressionWithPattern:[[NSString alloc] initWithFormat:@"\\?%@$|(?<=\\?)%@&?|()&?%@", URL_OPEN_MODALLY, URL_OPEN_MODALLY, URL_OPEN_MODALLY] options:NSRegularExpressionCaseInsensitive error:NULL];
+ NSString *oldURL = [url absoluteString];
+ NSLog(@" replacement pattern: %@", [replacerRegexp pattern]);
+ NSString *newURL = [replacerRegexp stringByReplacingMatchesInString:oldURL options:0 range:NSMakeRange(0, [oldURL length]) withTemplate:@""];
+
+ NSLog(@" Opening with updated URL: %@", newURL);
[self loadModalWebView:url];
return NO;
}
View
4 book/Book Cover.html
@@ -22,7 +22,9 @@
<div class="footer">
<p>Illustrated by Sidney Paget, Richard Gutschmidt, Frank Wiles, Frederic Dorr Steele et. al.</p>
- <a href="http://bakerframework.com/?referrer=Baker"><img src="gfx/baker-badge.png"/></a>
+ Open with Safari:<a href="http://bakerframework.com/?referrer=ExternalBaker"><img src="gfx/baker-badge.png"/></a>
+ Open in modal UIWebView:<a href="http://bakerframework.com/?referrer=ModalBaker"><img src="gfx/baker-badge.png"/></a>
+ Open in this same frame:<a href="http://bakerframework.com/"><img src="gfx/baker-badge.png"/></a>
</div>
</div>
</body>
Please sign in to comment.
Something went wrong with that request. Please try again.