Skip to content

Commit

Permalink
patch for ios9
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Laidig authored and Tony Laidig committed Sep 17, 2015
1 parent 881670d commit b8b5a62
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
!www/js/services.js
!www/js/services-spec.js
!www/lib/angular-cache/*
!www/lib/angular-ios9-patch/*
!www/lib/angular-leaflet/*
!www/lib/leaflet/*
!www/lib/leaflet/images/*
Expand Down
1 change: 1 addition & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<script src="lib/angular-leaflet/angular-leaflet-directive.min.js"></script>
<script src="lib/round-progress/roundProgress.min.js"></script>
<script src="lib/angular-inview/angular-inview.js"></script>
<script src="lib/angular-ios9-patch/angular-ios9-uiwebview.patch.js"></script>
<!-- app's js -->
<script src="js/config.js"></script>
<script src="js/app.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
* @authors https://github.com/camsys/onebusaway-nyc-atstop/graphs/contributors
*/

angular.module('atstop', ['ionic', 'atstop.controllers', 'atstop.services', 'atstop.directives', 'leaflet-directive', 'ngCordova', 'angular-cache', 'timer', 'angular-svg-round-progress'])
angular.module('atstop', ['ionic', 'atstop.controllers', 'atstop.services', 'atstop.directives', 'leaflet-directive',
'ngCordova', 'angular-cache', 'timer', 'angular-svg-round-progress', 'ngIOS9UIWebViewPatch'])

// global timeout variable for HTTP requests
.value('httpTimeout', 5000)
.value('httpTimeout', 10000)

.constant('$ionicLoadingConfig', {
template: '<ion-spinner></ion-spinner>',
Expand Down
31 changes: 31 additions & 0 deletions www/lib/angular-ios9-patch/angular-ios9-uiwebview.patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Created by tonylaidig on 9/17/15.
*/
angular.module('ngIOS9UIWebViewPatch', ['ng']).config(function($provide) {
$provide.decorator('$browser', ['$delegate', '$window', function($delegate, $window) {
if (isIOS9UIWebView($window.navigator.userAgent)) {
return applyIOS9Shim($delegate);
}
return $delegate;
function isIOS9UIWebView(userAgent) {
return /(iPhone|iPad|iPod).* OS 9_\d/.test(userAgent) && !/Version\/9\./.test(userAgent);
}
function applyIOS9Shim(browser) {
var pendingLocationUrl = null;
var originalUrlFn= browser.url;
browser.url = function() {
if (arguments.length) {
pendingLocationUrl = arguments[0];
return originalUrlFn.apply(browser, arguments);
}
return pendingLocationUrl || originalUrlFn.apply(browser, arguments);
};
window.addEventListener('popstate', clearPendingLocationUrl, false);
window.addEventListener('hashchange', clearPendingLocationUrl, false);
function clearPendingLocationUrl() {
pendingLocationUrl = null;
}
return browser;
}
}]);
});

0 comments on commit b8b5a62

Please sign in to comment.