UNPKG

3.14 kBPlain TextView Raw
1/*
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
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