Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit daeedd1

Browse files
committed
feat(plugin:inAppBrowser): refractor into a provider to set default options + override default options in opne() method
1 parent 600b30e commit daeedd1

File tree

13 files changed

+294
-194
lines changed

13 files changed

+294
-194
lines changed

demo/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<author email="[email protected]" href="http://paolobernasconi.com">
1111
Paolo Bernasconi
1212
</author>
13-
<content src="index.html"/>
13+
<content src="http://140.233.187.163:8100" original-src="index.html"/>
1414
<access origin="*"/>
1515
<preference name="fullscreen" value="true"/>
1616
<preference name="webviewbounce" value="false"/>

demo/www/app/app.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ angular.module('demo', [
2424
'demo.geolocation.ctrl',
2525
'demo.globalization.ctrl',
2626
'demo.googleAnalytics.ctrl',
27+
'demo.inAppBrowser.ctrl',
2728
'demo.localNotification.ctrl',
2829
'demo.media.ctrl',
2930
'demo.network.ctrl',
@@ -61,53 +62,59 @@ angular.module('demo', [
6162
"alert": true
6263
};
6364
$cordovaPush.register(iosConfig).then(function (result) {
64-
alert("device token: " + result.deviceToken);
65+
//alert("device token: " + result.deviceToken);
6566
}, function (error) {
66-
alert("error " + error);
67+
//alert("error " + error);
6768
});
6869

6970
$rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
70-
if (notification.alert)
71+
if (notification.alert) {
7172
navigator.notification.alert(notification.alert);
72-
73-
if (notification.sound)
73+
}
74+
if (notification.sound) {
7475
var snd = new Media(event.sound);
75-
snd.play();
76-
76+
snd.play();
77+
}
7778
if (notification.badge) {
78-
$cordovaPush.setBadgeNumber(notification.badge)
79-
.then(function (result) {
80-
// Success!
81-
}, function (err) {
82-
// An error occurred. Show a message to the user
83-
});
79+
$cordovaPush.setBadgeNumber(notification.badge).then(function (result) {
80+
// Success!
81+
}, function (err) {
82+
// An error occurred. Show a message to the user
83+
});
8484
}
8585
});
8686

8787

88-
$rootScope.$on("$cordovaNetwork:offline", function () {
88+
$rootScope.$on("$cordovaNetwork:offline", function (event, result) {
8989
alert("Device is now Offline!");
9090
});
9191

9292

93-
$rootScope.$on("$cordovaNetwork:online", function () {
93+
$rootScope.$on("$cordovaNetwork:online", function (event, result) {
9494
alert("Device is Online!");
9595
});
9696

97-
$cordovaBatteryStatus.$on("$cordovaBatteryStatus:status", function (status) {
98-
alert("status :" + status);
97+
$rootScope.$on("$cordovaBatteryStatus:status", function (event, status) {
98+
//alert("status: " + status);
9999
})
100100
})
101101
})
102102

103-
.config(function ($stateProvider, $urlRouterProvider, $cordovaFacebookProvider) {
103+
.config(function ($stateProvider, $urlRouterProvider, $cordovaFacebookProvider, $cordovaInAppBrowserProvider) {
104104

105105
if (!window.cordova) {
106106
var appID = 1234567890;
107107
var version = "v2.0"; // or leave blank and default is v2.0
108108
$cordovaFacebookProvider.browserInit(appID, version);
109109
}
110110

111+
var browserOptions = {
112+
location: "yes",
113+
toolbar: "yes"
114+
};
115+
116+
$cordovaInAppBrowserProvider.setDefaultOptions(browserOptions);
117+
111118
$stateProvider
112119

113120
.state('menu', {
@@ -243,6 +250,12 @@ angular.module('demo', [
243250
controller: "GoogleAnalyticsCtrl"
244251
})
245252

253+
.state('inAppBrowser', {
254+
url: '/inAppBrowser',
255+
templateUrl: 'app/inAppBrowser/inAppBrowser.html',
256+
controller: "InAppBrowserCtrl"
257+
})
258+
246259
.state('localNotification', {
247260
url: '/localNotification',
248261
templateUrl: 'app/localNotification/localNotification.html',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
angular.module('demo.inAppBrowser.ctrl', [])
2+
3+
.controller('InAppBrowserCtrl', function ($scope, $rootScope, $cordovaInAppBrowser) {
4+
$scope.openBrowser = function () {
5+
document.addEventListener('deviceready', function () {
6+
7+
var options = {
8+
location: "no"
9+
};
10+
11+
$cordovaInAppBrowser.open('http://ngcordova.com', '_blank', options);
12+
13+
}, false);
14+
};
15+
16+
document.addEventListener('deviceready', function () {
17+
18+
$rootScope.$on("$cordovaInAppBrowser:exit", function (event, result) {
19+
alert("Exited Browser");
20+
})
21+
}, false);
22+
23+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ion-view title="In App Browser">
2+
<ion-content padding="true">
3+
4+
<button class="button button-block button-positive" ng-click="openBrowser()">Open Browser</button>
5+
</ion-content>
6+
</ion-view>

demo/www/app/menu.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
Globalization
9898
</a>
9999

100+
101+
<a class="item item-icon-right" ui-sref="inAppBrowser">
102+
<i class="icon ion-iphone"></i>
103+
In App Browser
104+
</a>
105+
100106
<a class="item item-icon-right" ui-sref="localNotification">
101107
<i class="icon ion-alert assertive"></i>
102108
Local Notification

demo/www/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<script src="app/geolocation/geolocation.ctrl.js"></script>
5757
<script src="app/globalization/globalization.ctrl.js"></script>
5858
<script src="app/googleAnalytics/googleAnalytics.ctrl.js"></script>
59+
<script src="app/inAppBrowser/inAppBrowser.ctrl.js"></script>
5960
<script src="app/localNotification/localNotification.ctrl.js"></script>
6061
<script src="app/media/media.ctrl.js"></script>
6162
<script src="app/network/network.ctrl.js"></script>

demo/www/lib/ngCordova/dist/ng-cordova.js

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -409,28 +409,30 @@ angular.module('ngCordova.plugins.batteryStatus', [])
409409
var batteryStatus = function (status) {
410410
$timeout(function () {
411411
$rootScope.$broadcast('$cordovaBatteryStatus:status', status);
412-
})
412+
});
413413
};
414414

415415
var batteryCritical = function (status) {
416416
$timeout(function () {
417417
$rootScope.$broadcast('$cordovaBatteryStatus:critical', status);
418-
})
418+
});
419419
};
420420

421421
var batteryLow = function (status) {
422422
$timeout(function () {
423423
$rootScope.$broadcast('$cordovaBatteryStatus:low', status);
424-
})
424+
});
425425
};
426426

427427
document.addEventListener("deviceready", function () {
428428
if (navigator.battery) {
429429
$window.addEventListener('batterystatus', batteryStatus, false);
430430
$window.addEventListener('batterycritical', batteryCritical, false);
431431
$window.addEventListener('batterylow', batteryLow, false);
432+
432433
}
433434
}, false);
435+
return true;
434436
}])
435437
.run(function ($cordovaBatteryStatus) {
436438
});
@@ -3012,77 +3014,92 @@ angular.module('ngCordova.plugins.imagePicker', [])
30123014

30133015
angular.module('ngCordova.plugins.inAppBrowser', [])
30143016

3015-
.factory('$cordovaInAppBrowser', ['$rootScope', '$q', '$window', function ($rootScope, $q, $window) {
3017+
.provider('$cordovaInAppBrowser', [function ($rootScope, $q, $window, $timeout) {
30163018

3017-
var win, options;
3018-
var scope = $rootScope.$new();
3019+
var ref;
3020+
var defaultOptions = this.defaultOptions = {};
30193021

3020-
return {
3021-
init: function (config) {
3022-
if (angular.isObject(config)) {
3023-
var opt = [];
3024-
for (var i in config) {
3025-
opt.push([i + '=' + config[i]]);
3026-
}
3027-
options = opt.join();
3028-
} else {
3029-
options = config;
3030-
}
3022+
this.setDefaultOptions = function (config) {
3023+
defaultOptions = angular.extend(this.defaultOptions, config);
3024+
};
30313025

3032-
return scope;
3033-
},
3026+
this.$get = ['$rootScope', '$q', '$window', '$timeout', function ($rootScope, $q, $window, $timeout) {
3027+
return {
3028+
open: function (url, target, requestOptions) {
3029+
var q = $q.defer();
30343030

3035-
open: function (url, target) {
3036-
var q = $q.defer();
3031+
if (!angular.isObject(requestOptions)) {
3032+
q.reject("options must be an object");
3033+
return q.promise;
3034+
}
3035+
var overrideOptions = angular.extend(defaultOptions, requestOptions);
3036+
var opt = [];
3037+
angular.forEach(overrideOptions, function (value, key) {
3038+
opt.push(key + '=' + value);
3039+
});
3040+
var optionsString = opt.join();
30373041

3038-
win = $window.open(url, target, options);
3042+
ref = $window.open(url, target, optionsString);
30393043

3040-
win.addEventListener('loadstart', function (event) {
3041-
scope.$broadcast('$cordovaInAppBrowser:loadstart', event);
3042-
}, false);
3044+
ref.addEventListener('loadstart', function (event) {
3045+
$timeout(function () {
3046+
$rootScope.$broadcast('$cordovaInAppBrowser:loadstart', event);
3047+
});
3048+
}, false);
30433049

3044-
win.addEventListener('loadstop', function (event) {
3045-
q.resolve(event);
3046-
scope.$broadcast('$cordovaInAppBrowser:loadstop', event);
3047-
}, false);
3050+
ref.addEventListener('loadstop', function (event) {
3051+
q.resolve(event);
3052+
$timeout(function () {
3053+
$rootScope.$broadcast('$cordovaInAppBrowser:loadstop', event);
3054+
});
3055+
}, false);
30483056

3049-
win.addEventListener('loaderror', function (event) {
3050-
q.reject(event);
3051-
scope.$broadcast('$cordovaInAppBrowser:loaderror', event);
3052-
}, false);
3057+
ref.addEventListener('loaderror', function (event) {
3058+
q.reject(event);
3059+
$timeout(function () {
3060+
$rootScope.$broadcast('$cordovaInAppBrowser:loaderror', event);
3061+
});
3062+
}, false);
30533063

3054-
win.addEventListener('exit', function (event) {
3055-
scope.$broadcast('$cordovaInAppBrowser:exit', event);
3056-
}, false);
3064+
ref.addEventListener('exit', function (event) {
3065+
$timeout(function () {
3066+
$rootScope.$broadcast('$cordovaInAppBrowser:exit', event);
3067+
});
3068+
}, false);
30573069

3058-
return q.promise;
3059-
},
3070+
return q.promise;
3071+
},
30603072

3061-
close: function () {
3062-
win.close();
3063-
},
3073+
close: function () {
3074+
ref.close();
3075+
},
30643076

3065-
executeScript: function (details) {
3066-
var q = $q.defer();
3077+
show: function () {
3078+
ref.show();
3079+
},
30673080

3068-
win.executeScript(details, function (result) {
3069-
q.resolve(result);
3070-
});
30713081

3072-
return q.promise;
3073-
},
3082+
executeScript: function (details) {
3083+
var q = $q.defer();
30743084

3075-
insertCSS: function (details) {
3076-
var q = $q.defer();
3085+
ref.executeScript(details, function (result) {
3086+
q.resolve(result);
3087+
});
30773088

3078-
win.insertCSS(details, function (result) {
3079-
q.resolve(result);
3080-
});
3089+
return q.promise;
3090+
},
30813091

3082-
return q.promise;
3083-
}
3084-
};
3092+
insertCSS: function (details) {
3093+
var q = $q.defer();
30853094

3095+
ref.insertCSS(details, function (result) {
3096+
q.resolve(result);
3097+
});
3098+
3099+
return q.promise;
3100+
}
3101+
};
3102+
}];
30863103
}]);
30873104

30883105
// install : cordova plugin add https://github.com/driftyco/ionic-plugins-keyboard.git

demo/www/lib/ngCordova/dist/ng-cordova.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)