Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 463 lines (332 sloc) 10.164 kb
fce0a39 @soffes Started on TWWebView
soffes authored
1 //
f3d43b6 @soffes The Great Rename
soffes authored
2 // SSWebView.m
3 // SSToolkit
fce0a39 @soffes Started on TWWebView
soffes authored
4 //
5 // Created by Sam Soffes on 4/26/10.
e8c3ce3 @soffes Updated comments and renamed SSDrawingMacros to SSDrawingUtilities
soffes authored
6 // Copyright 2010-2011 Sam Soffes. All rights reserved.
fce0a39 @soffes Started on TWWebView
soffes authored
7 //
8
f3d43b6 @soffes The Great Rename
soffes authored
9 #import "SSWebView.h"
10 #import "NSString+SSToolkitAdditions.h"
fce0a39 @soffes Started on TWWebView
soffes authored
11
f3d43b6 @soffes The Great Rename
soffes authored
12 @interface SSWebView (PrivateMethods)
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
13 - (void)_initialize;
fce0a39 @soffes Started on TWWebView
soffes authored
14 - (void)_loadingStatusChanged;
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
15 - (void)_startLoading;
fce0a39 @soffes Started on TWWebView
soffes authored
16 - (void)_finishedLoading;
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
17 - (void)_DOMLoaded;
fce0a39 @soffes Started on TWWebView
soffes authored
18 @end
19
454e654 @soffes Require Apple LLVM compiler 3.0
soffes authored
20 @implementation SSWebView {
21 UIWebView *_webView;
22 NSUInteger _requestCount;
23 BOOL _testedDOM;
24 }
25
fce0a39 @soffes Started on TWWebView
soffes authored
26
bf2d0ec @soffes Started overhauling documentation
soffes authored
27 #pragma mark - Accessors
62be25e @soffes Updated coding style and started on extremitiesStyle
soffes authored
28
62a51a9 @soffes Implemented better load checking
soffes authored
29 @synthesize delegate = _delegate;
ca73512 @soffes Cached shadows hidden value
soffes authored
30 @synthesize shadowsHidden = _shadowsHidden;
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
31 @synthesize consoleEnabled = _consoleEnabled;
621e3ac @soffes Expose last request
soffes authored
32 @synthesize lastRequest = _lastRequest;
c31cd94 @soffes * Started documenting
soffes authored
33 @synthesize loadingPage = _loadingPage;
fce0a39 @soffes Started on TWWebView
soffes authored
34
bf2d0ec @soffes Started overhauling documentation
soffes authored
35 #pragma mark - NSObject
fce0a39 @soffes Started on TWWebView
soffes authored
36
f5708fd @soffes Added display error category
soffes authored
37 - (void)dealloc {
621e3ac @soffes Expose last request
soffes authored
38 _delegate = nil;
39 _webView.delegate = nil;
40 [_webView stopLoading];
fce0a39 @soffes Started on TWWebView
soffes authored
41 }
42
7d34821 @soffes Updated coding convention
soffes authored
43
bf2d0ec @soffes Started overhauling documentation
soffes authored
44 #pragma mark - UIView
fce0a39 @soffes Started on TWWebView
soffes authored
45
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
46 - (id)initWithCoder:(NSCoder *)aDecoder {
47 if ((self = [super initWithCoder:aDecoder])) {
48 [self _initialize];
49 }
50 return self;
51 }
52
53
fce0a39 @soffes Started on TWWebView
soffes authored
54 - (id)initWithFrame:(CGRect)frame {
f643aac @soffes Switched to LLVM 1.6 and enabled additional warnings. Updated code to…
soffes authored
55 if ((self = [super initWithFrame:frame])) {
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
56 [self _initialize];
fce0a39 @soffes Started on TWWebView
soffes authored
57 }
58 return self;
59 }
60
61
621e3ac @soffes Expose last request
soffes authored
62 - (void)layoutSubviews {
f643aac @soffes Switched to LLVM 1.6 and enabled additional warnings. Updated code to…
soffes authored
63 _webView.frame = CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height);
621e3ac @soffes Expose last request
soffes authored
64 }
65
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
66
bf2d0ec @soffes Started overhauling documentation
soffes authored
67 #pragma mark - SSWebView Methods
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
68
668f85b @soffes Added dismissKeyboard TWWebView
soffes authored
69 - (void)dismissKeyboard {
70 [_webView stringByEvaluatingJavaScriptFromString:@"document.activeElement.blur()"];
71 }
72
73
698457a @soffes Added removeTextSelection to SSWebView
soffes authored
74 - (void)removeTextSelection {
75 if (_webView.userInteractionEnabled == NO) {
76 return;
77 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
78
698457a @soffes Added removeTextSelection to SSWebView
soffes authored
79 _webView.userInteractionEnabled = NO;
80 _webView.userInteractionEnabled = YES;
81 }
82
83
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
84 - (void)reset {
85 BOOL loadPreviousSettings = NO;
86 UIDataDetectorTypes tempDataDetectorTypes;
87 BOOL tempScalesPageToFit;
f3c6c83 @soffes * Removed injecting CSS in SSWebView since it is rarely used and supe…
soffes authored
88 BOOL tempAllowsInlineMediaPlayback;
89 BOOL tempMediaPlaybackRequiresUserAction;
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
90
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
91 if (_webView) {
92 _webView.delegate = nil;
93 [_webView stopLoading];
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
94
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
95 loadPreviousSettings = YES;
96 tempDataDetectorTypes = _webView.dataDetectorTypes;
97 tempScalesPageToFit = _webView.scalesPageToFit;
f3c6c83 @soffes * Removed injecting CSS in SSWebView since it is rarely used and supe…
soffes authored
98 tempAllowsInlineMediaPlayback = _webView.allowsInlineMediaPlayback;
99 tempMediaPlaybackRequiresUserAction = _webView.mediaPlaybackRequiresUserAction;
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
100
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
101 [_webView removeFromSuperview];
102 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
103
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
104 _webView = [[UIWebView alloc] initWithFrame:CGRectZero];
105 _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
106
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
107 if (loadPreviousSettings) {
108 _webView.dataDetectorTypes = tempDataDetectorTypes;
109 _webView.scalesPageToFit = tempScalesPageToFit;
f3c6c83 @soffes * Removed injecting CSS in SSWebView since it is rarely used and supe…
soffes authored
110 _webView.allowsInlineMediaPlayback = tempAllowsInlineMediaPlayback;
111 _webView.mediaPlaybackRequiresUserAction = tempMediaPlaybackRequiresUserAction;
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
112 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
113
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
114 _webView.delegate = self;
115 [self addSubview:_webView];
4baa578 @inamiy SSWebView: set lastRequest = nil for other webview loading methods & …
inamiy authored
116
117 _lastRequest = nil;
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
118 }
119
120
bf2d0ec @soffes Started overhauling documentation
soffes authored
121 #pragma mark - Convenience Methods
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
122
123 - (void)loadHTMLString:(NSString *)string {
55e94aa @soffes Set default for baseURL
soffes authored
124 [self loadHTMLString:string baseURL:nil];
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
125 }
126
127
128 - (void)loadURL:(NSURL *)aURL {
129 [self loadRequest:[NSURLRequest requestWithURL:aURL]];
130 }
131
132
6de18fe @soffes TWWebView improvements
soffes authored
133 - (void)loadURLString:(NSString *)string {
b48a818 @soffes Don't load bad urls
soffes authored
134 if ([string length] < 5) {
135 return;
136 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
137
6de18fe @soffes TWWebView improvements
soffes authored
138 if ([string hasPrefix:@"http://"] == NO && [string hasPrefix:@"https://"] == NO) {
139 string = [NSString stringWithFormat:@"http://%@", string];
140 }
141 [self loadURL:[NSURL URLWithString:string]];
142 }
143
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
144
bf2d0ec @soffes Started overhauling documentation
soffes authored
145 #pragma mark - Private Methods
fce0a39 @soffes Started on TWWebView
soffes authored
146
5b58afc @soffes Add `initWithCoder:` to views to allow for use in Interface Builder. …
soffes authored
147 - (void)_initialize {
148 [self reset];
149
150 _loadingPage = NO;
151 _shadowsHidden = NO;
152 _consoleEnabled = NO;
153 }
154
155
fce0a39 @soffes Started on TWWebView
soffes authored
156 - (void)_loadingStatusChanged {
c31cd94 @soffes * Started documenting
soffes authored
157 if (self.loading == NO) {
fce0a39 @soffes Started on TWWebView
soffes authored
158 [self _finishedLoading];
159 }
160 }
161
162
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
163 - (void)_startLoading {
c31cd94 @soffes * Started documenting
soffes authored
164 _loadingPage = YES;
270e428 @soffes Fixed typeo in delegate calls
soffes authored
165 if ([_delegate respondsToSelector:@selector(webViewDidStartLoadingPage:)]) {
c31cd94 @soffes * Started documenting
soffes authored
166 [_delegate webViewDidStartLoadingPage:self];
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
167 }
168 }
169
170
fce0a39 @soffes Started on TWWebView
soffes authored
171 - (void)_finishedLoading {
c31cd94 @soffes * Started documenting
soffes authored
172 _loadingPage = NO;
270e428 @soffes Fixed typeo in delegate calls
soffes authored
173 if ([_delegate respondsToSelector:@selector(webViewDidFinishLoadingPage:)]) {
c31cd94 @soffes * Started documenting
soffes authored
174 [_delegate webViewDidFinishLoadingPage:self];
fce0a39 @soffes Started on TWWebView
soffes authored
175 }
176 }
177
178
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
179 - (void)_DOMLoaded {
180 if ([_delegate respondsToSelector:@selector(webViewDidLoadDOM:)]) {
181 [_delegate webViewDidLoadDOM:self];
182 }
183 }
184
185
bf2d0ec @soffes Started overhauling documentation
soffes authored
186 #pragma mark - Getters
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
187
188 - (BOOL)shadowsHidden {
f9c5417 @soffes Improved hiding TWWebView shadows. Thanks @flyosity
soffes authored
189 for (UIView *view in [_webView subviews]) {
190 if ([view isKindOfClass:[UIScrollView class]]) {
191 for (UIView *innerView in [view subviews]) {
192 if ([innerView isKindOfClass:[UIImageView class]]) {
193 return [innerView isHidden];
194 }
195 }
196 }
197 }
198 return NO;
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
199 }
200
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
201
bf2d0ec @soffes Started overhauling documentation
soffes authored
202 #pragma mark - Setters
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
203
204 - (void)setOpaque:(BOOL)o {
205 [super setOpaque:o];
206 _webView.opaque = o;
207 }
208
209
210 - (void)setBackgroundColor:(UIColor *)color {
211 [super setBackgroundColor:color];
212 _webView.backgroundColor = color;
213 }
214
215
216 - (void)setShadowsHidden:(BOOL)hide {
ca73512 @soffes Cached shadows hidden value
soffes authored
217 if (_shadowsHidden == hide) {
218 return;
219 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
220
ca73512 @soffes Cached shadows hidden value
soffes authored
221 _shadowsHidden = hide;
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
222
c0d31bf @soffes Much better scrolling enabled solution for TWWebView. I've heard this…
soffes authored
223 // Thanks @flyosity http://twitter.com/flyosity/status/17951035384
f9c5417 @soffes Improved hiding TWWebView shadows. Thanks @flyosity
soffes authored
224 for (UIView *view in [_webView subviews]) {
225 if ([view isKindOfClass:[UIScrollView class]]) {
226 for (UIView *innerView in [view subviews]) {
227 if ([innerView isKindOfClass:[UIImageView class]]) {
ca73512 @soffes Cached shadows hidden value
soffes authored
228 innerView.hidden = _shadowsHidden;
f9c5417 @soffes Improved hiding TWWebView shadows. Thanks @flyosity
soffes authored
229 }
230 }
9108baf @soffes Updated hideShadows
soffes authored
231 }
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
232 }
233 }
234
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
235
bf2d0ec @soffes Started overhauling documentation
soffes authored
236 #pragma mark - UIWebView Methods
fce0a39 @soffes Started on TWWebView
soffes authored
237
238 - (BOOL)canGoBack {
239 return [_webView canGoBack];
240 }
241
242
243 - (BOOL)canGoForward {
244 return [_webView canGoForward];
245 }
246
247 - (void)setDataDetectorTypes:(UIDataDetectorTypes)types {
248 [_webView setDataDetectorTypes:types];
249 }
250
251
252 - (UIDataDetectorTypes)dataDetectorTypes {
253 return [_webView dataDetectorTypes];
254 }
255
256
c31cd94 @soffes * Started documenting
soffes authored
257 - (BOOL)isLoading {
fce0a39 @soffes Started on TWWebView
soffes authored
258 return [_webView isLoading];
259 }
260
261
262 - (NSURLRequest *)request {
263 return [_webView request];
264 }
265
266
267 - (BOOL)scalesPageToFit {
268 return [_webView scalesPageToFit];
269 }
270
271
272 - (void)setScalesPageToFit:(BOOL)scales {
273 [_webView setScalesPageToFit:scales];
274 }
275
276
277 - (void)goBack {
278 [_webView goBack];
279 }
280
281
282 - (void)goForward {
283 [_webView goForward];
284 }
285
286
287 - (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL {
4baa578 @inamiy SSWebView: set lastRequest = nil for other webview loading methods & …
inamiy authored
288 _lastRequest = nil;
289
fce0a39 @soffes Started on TWWebView
soffes authored
290 [_webView loadData:data MIMEType:MIMEType textEncodingName:encodingName baseURL:baseURL];
291 }
292
293
294 - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL {
4baa578 @inamiy SSWebView: set lastRequest = nil for other webview loading methods & …
inamiy authored
295 _lastRequest = nil;
296
55e94aa @soffes Set default for baseURL
soffes authored
297 if (!baseURL) {
bf2d0ec @soffes Started overhauling documentation
soffes authored
298 baseURL = [NSURL URLWithString:@"http://localhost/"];
55e94aa @soffes Set default for baseURL
soffes authored
299 }
fce0a39 @soffes Started on TWWebView
soffes authored
300 [_webView loadHTMLString:string baseURL:baseURL];
301 }
302
303
304 - (void)loadRequest:(NSURLRequest *)aRequest {
4baa578 @inamiy SSWebView: set lastRequest = nil for other webview loading methods & …
inamiy authored
305 _lastRequest = nil;
306
fce0a39 @soffes Started on TWWebView
soffes authored
307 [_webView loadRequest:aRequest];
308 }
309
310
311 - (void)reload {
40a0344 @soffes Force start loading delegate message on refresh
soffes authored
312 _lastRequest = nil;
fce0a39 @soffes Started on TWWebView
soffes authored
313 [_webView reload];
314 }
315
316
317 - (void)stopLoading {
318 [_webView stopLoading];
319 }
320
321
322 - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script {
323 return [_webView stringByEvaluatingJavaScriptFromString:script];
324 }
325
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
326
c7b6561 @soffes Added scrollView property to SSWebView to get the internal UIScrollView
soffes authored
327 - (UIScrollView *)scrollView {
8da3646 @inamiy Replaced compile-time conditional to run-time one at [SSWebView scrol…
inamiy authored
328 if (([[[UIDevice currentDevice] systemVersion] compare:@"5.0"] == NSOrderedAscending)) {
329 for (UIView *view in [_webView subviews]) {
330 if ([view isKindOfClass:[UIScrollView class]]) {
331 return (UIScrollView *)view;
332 }
c7b6561 @soffes Added scrollView property to SSWebView to get the internal UIScrollView
soffes authored
333 }
8da3646 @inamiy Replaced compile-time conditional to run-time one at [SSWebView scrol…
inamiy authored
334 return nil;
335 }
336 else {
337 return _webView.scrollView;
c7b6561 @soffes Added scrollView property to SSWebView to get the internal UIScrollView
soffes authored
338 }
bf2d0ec @soffes Started overhauling documentation
soffes authored
339 }
b146d5e @soffes Removed hacks from SSWebView and fixed a few deprecations
soffes authored
340
341
c31cd94 @soffes * Started documenting
soffes authored
342 - (BOOL)allowsInlineMediaPlayback {
343 return _webView.allowsInlineMediaPlayback;
344 }
345
346
347 - (void)setAllowsInlineMediaPlayback:(BOOL)allow {
348 _webView.allowsInlineMediaPlayback = allow;
349 }
350
351
352 - (BOOL)mediaPlaybackRequiresUserAction {
353 return _webView.mediaPlaybackRequiresUserAction;
354 }
355
356
357 - (void)setMediaPlaybackRequiresUserAction:(BOOL)requires {
358 _webView.mediaPlaybackRequiresUserAction = requires;
359 }
360
361
bf2d0ec @soffes Started overhauling documentation
soffes authored
362 #pragma mark - UIWebViewDelegate
fce0a39 @soffes Started on TWWebView
soffes authored
363
364 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
62a51a9 @soffes Implemented better load checking
soffes authored
365 // Forward delegate message
fce0a39 @soffes Started on TWWebView
soffes authored
366 if ([_delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
367 [_delegate webView:self didFailLoadWithError:error];
368 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
369
370 _requestCount--;
371 if (_requestCount == 0) {
372 [self _loadingStatusChanged];
373 }
fce0a39 @soffes Started on TWWebView
soffes authored
374 }
375
376
377 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)aRequest navigationType:(UIWebViewNavigationType)navigationType {
62a51a9 @soffes Implemented better load checking
soffes authored
378 BOOL should = YES;
14ecdf5 @soffes Fixed webViewDidLoadDOM reliability
soffes authored
379 NSURL *url = [aRequest URL];
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
380 NSString *scheme = [url scheme];
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
381
981b27e @soffes Improved DOM loaded delegate message and added scrollingEnabled prope…
soffes authored
382 // Check for DOM load message
d8f80cb @soffes Prefer isEqualToString: over isEqual:
soffes authored
383 if ([scheme isEqualToString:@"x-sswebview"]) {
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
384 NSString *host = [url host];
d8f80cb @soffes Prefer isEqualToString: over isEqual:
soffes authored
385 if ([host isEqualToString:@"dom-loaded"]) {
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
386 [self _DOMLoaded];
d8f80cb @soffes Prefer isEqualToString: over isEqual:
soffes authored
387 } else if ([host isEqualToString:@"log"] && _consoleEnabled) {
f3d43b6 @soffes The Great Rename
soffes authored
388 NSLog(@"[SSWebView Console] %@", [[url query] URLDecodedString]);
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
389 }
981b27e @soffes Improved DOM loaded delegate message and added scrollingEnabled prope…
soffes authored
390 return NO;
391 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
392
62a51a9 @soffes Implemented better load checking
soffes authored
393 // Forward delegate message
fce0a39 @soffes Started on TWWebView
soffes authored
394 if ([_delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)]) {
62a51a9 @soffes Implemented better load checking
soffes authored
395 should = [_delegate webView:self shouldStartLoadWithRequest:aRequest navigationType:navigationType];
396 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
397
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
398 // Only load http or http requests if delegate doesn't care
399 else {
02f0f17 @soffes Made TWWebView less picky by default
soffes authored
400 should = [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [scheme isEqualToString:@"file"];
62a51a9 @soffes Implemented better load checking
soffes authored
401 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
402
62a51a9 @soffes Implemented better load checking
soffes authored
403 // Stop if we shouldn't load it
14ecdf5 @soffes Fixed webViewDidLoadDOM reliability
soffes authored
404 if (should == NO) {
405 return NO;
62a51a9 @soffes Implemented better load checking
soffes authored
406 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
407
62a51a9 @soffes Implemented better load checking
soffes authored
408 // Starting a new request
409 if ([[aRequest mainDocumentURL] isEqual:[_lastRequest mainDocumentURL]] == NO) {
c893cb4 @soffes ARC
soffes authored
410 _lastRequest = aRequest;
981b27e @soffes Improved DOM loaded delegate message and added scrollingEnabled prope…
soffes authored
411 _testedDOM = NO;
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
412
f43ed94 @soffes Added reset to SSWebView and fixed isLoading
soffes authored
413 [self _startLoading];
fce0a39 @soffes Started on TWWebView
soffes authored
414 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
415
62a51a9 @soffes Implemented better load checking
soffes authored
416 // Child request for same page
417 else {
418 // Reset load timer
419 [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(_loadingStatusChanged) object:nil];
420 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
421
62a51a9 @soffes Implemented better load checking
soffes authored
422 return should;
fce0a39 @soffes Started on TWWebView
soffes authored
423 }
424
425
426 - (void)webViewDidFinishLoad:(UIWebView *)webView {
62a51a9 @soffes Implemented better load checking
soffes authored
427 // Check DOM
981b27e @soffes Improved DOM loaded delegate message and added scrollingEnabled prope…
soffes authored
428 if (_testedDOM == NO) {
429 _testedDOM = YES;
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
430
14ecdf5 @soffes Fixed webViewDidLoadDOM reliability
soffes authored
431 // The internal delegate will intercept this load and forward the event to the real delegate
432 // Crazy javascript from http://dean.edwards.name/weblog/2006/06/again
eb9c018 @soffes * Organized project
soffes authored
433 static NSString *testDOM = @"var _SSWebViewDOMLoadTimer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){clearInterval(_SSWebViewDOMLoadTimer);location.href='x-sswebview://dom-loaded'}},10);";
0e90139 @soffes Improved TWWebView and added NSURL+queryDictionary
soffes authored
434 [self stringByEvaluatingJavaScriptFromString:testDOM];
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
435
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
436 // Override console to pass messages to NSLog
437 if (_consoleEnabled) {
eb9c018 @soffes * Organized project
soffes authored
438 [self stringByEvaluatingJavaScriptFromString:@"console.log=function(msg){location.href='x-sswebview://log/?'+escape(msg.toString())}"];
e8c8125 Added option to TWWebView to intercept console.log messages and write…
Sam Soffes authored
439 }
62a51a9 @soffes Implemented better load checking
soffes authored
440 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
441
62a51a9 @soffes Implemented better load checking
soffes authored
442 // Forward delegate message
fce0a39 @soffes Started on TWWebView
soffes authored
443 if ([_delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
444 [_delegate webViewDidFinishLoad:self];
445 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
446
447 _requestCount--;
448 if (_requestCount == 0) {
449 [self _loadingStatusChanged];
450 }
fce0a39 @soffes Started on TWWebView
soffes authored
451 }
452
453
454 - (void)webViewDidStartLoad:(UIWebView *)webView {
62a51a9 @soffes Implemented better load checking
soffes authored
455 // Forward delegate message
fce0a39 @soffes Started on TWWebView
soffes authored
456 if ([_delegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
457 [_delegate webViewDidStartLoad:self];
458 }
6e1acb8 @alaborie Fixed an issue with the SSWebView (related to the method
alaborie authored
459 _requestCount++;
fce0a39 @soffes Started on TWWebView
soffes authored
460 }
461
462 @end
Something went wrong with that request. Please try again.