1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | #import "CDVInAppBrowserOptions.h"
|
21 |
|
22 | @implementation CDVInAppBrowserOptions
|
23 |
|
24 | - (id)init
|
25 | {
|
26 | if (self = [super init]) {
|
27 | // default values
|
28 | self.location = YES;
|
29 | self.toolbar = YES;
|
30 | self.closebuttoncaption = nil;
|
31 | self.toolbarposition = @"bottom";
|
32 | self.cleardata = NO;
|
33 | self.clearcache = NO;
|
34 | self.clearsessioncache = NO;
|
35 | self.hidespinner = NO;
|
36 |
|
37 | self.enableviewportscale = NO;
|
38 | self.mediaplaybackrequiresuseraction = NO;
|
39 | self.allowinlinemediaplayback = NO;
|
40 | self.hidden = NO;
|
41 | self.disallowoverscroll = NO;
|
42 | self.hidenavigationbuttons = NO;
|
43 | self.closebuttoncolor = nil;
|
44 | self.lefttoright = false;
|
45 | self.toolbarcolor = nil;
|
46 | self.toolbartranslucent = YES;
|
47 | self.beforeload = @"";
|
48 | }
|
49 |
|
50 | return self;
|
51 | }
|
52 |
|
53 | + (CDVInAppBrowserOptions*)parseOptions:(NSString*)options
|
54 | {
|
55 | CDVInAppBrowserOptions* obj = [[CDVInAppBrowserOptions alloc] init];
|
56 |
|
57 | // NOTE: this parsing does not handle quotes within values
|
58 | NSArray* pairs = [options componentsSeparatedByString:@","];
|
59 |
|
60 | // parse keys and values, set the properties
|
61 | for (NSString* pair in pairs) {
|
62 | NSArray* keyvalue = [pair componentsSeparatedByString:@"="];
|
63 |
|
64 | if ([keyvalue count] == 2) {
|
65 | NSString* key = [[keyvalue objectAtIndex:0] lowercaseString];
|
66 | NSString* value = [keyvalue objectAtIndex:1];
|
67 | NSString* value_lc = [value lowercaseString];
|
68 |
|
69 | BOOL isBoolean = [value_lc isEqualToString:@"yes"] || [value_lc isEqualToString:@"no"];
|
70 | NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
|
71 | [numberFormatter setAllowsFloats:YES];
|
72 | BOOL isNumber = [numberFormatter numberFromString:value_lc] != nil;
|
73 |
|
74 | // set the property according to the key name
|
75 | if ([obj respondsToSelector:NSSelectorFromString(key)]) {
|
76 | if (isNumber) {
|
77 | [obj setValue:[numberFormatter numberFromString:value_lc] forKey:key];
|
78 | } else if (isBoolean) {
|
79 | [obj setValue:[NSNumber numberWithBool:[value_lc isEqualToString:@"yes"]] forKey:key];
|
80 | } else {
|
81 | [obj setValue:value forKey:key];
|
82 | }
|
83 | }
|
84 | }
|
85 | }
|
86 |
|
87 | return obj;
|
88 | }
|
89 |
|
90 | @end
|