From 1f29a74442193da7401bae2774bde2877128c3f6 Mon Sep 17 00:00:00 2001
From: Daniel M
Date: Wed, 23 Sep 2015 12:37:15 +0200
Subject: [PATCH] fix(callbacks): fix callbacks using ES6
Using ES6 we need to bind the callbacks using `&`, so we have access to `this` in the context of the original scope
---
README.md | 4 ++--
dist/google-picker.js | 12 ++++++------
dist/google-picker.min.js | 2 +-
example/google-picker.min.js | 2 +-
example/index.html | 2 +-
src/google-picker.js | 12 ++++++------
6 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 449745f..dba3d39 100644
--- a/README.md
+++ b/README.md
@@ -73,7 +73,7 @@ Download [https://github.com/softmonkeyjapan/angular-google-picker/archive/0.2.1
5. Add the directive to your HTML element
```html
- Open my Google Drive
+ Open my Google Drive
```
6. That's it, you're done!
@@ -195,7 +195,7 @@ angular.module('myApp', ['lk-google-picker'])
```
```html
-Open my Google Drive
+Open my Google Drive
```
### onPicked
diff --git a/dist/google-picker.js b/dist/google-picker.js
index 1d05446..38b04b8 100644
--- a/dist/google-picker.js
+++ b/dist/google-picker.js
@@ -51,9 +51,9 @@
return {
restrict: 'A',
scope: {
- onLoaded: '=',
- onCancel: '=',
- onPicked: '='
+ onLoaded: '&',
+ onCancel: '&',
+ onPicked: '&'
},
link: function (scope, element, attrs) {
var accessToken = null;
@@ -127,13 +127,13 @@
function pickerResponse (data) {
gapi.client.load('drive', 'v2', function () {
if (data.action == google.picker.Action.LOADED && scope.onLoaded) {
- scope.onLoaded();
+ (scope.onLoaded || angular.noop)();
}
if (data.action == google.picker.Action.CANCEL && scope.onCancel) {
- scope.onCancel();
+ (scope.onCancel || angular.noop)();
}
if (data.action == google.picker.Action.PICKED && scope.onPicked) {
- scope.onPicked(data.docs);
+ (scope.onPicked || angular.noop)({docs: data.docs});
}
scope.$apply();
});
diff --git a/dist/google-picker.min.js b/dist/google-picker.min.js
index 0121c49..cab4192 100644
--- a/dist/google-picker.min.js
+++ b/dist/google-picker.min.js
@@ -1 +1 @@
-!function(){angular.module("lk-google-picker",[]).provider("lkGoogleSettings",function(){this.apiKey=null,this.clientId=null,this.scopes=["https://www.googleapis.com/auth/drive"],this.features=["MULTISELECT_ENABLED"],this.views=["DocsView().setIncludeFolders(true)","DocsUploadView().setIncludeFolders(true)"],this.locale="en",this.$get=["$window",function(e){return{apiKey:this.apiKey,clientId:this.clientId,scopes:this.scopes,features:this.features,views:this.views,locale:this.locale,origin:this.origin||e.location.protocol+"//"+e.location.host}}],this.configure=function(e){for(var o in e)this[o]=e[o]}}).directive("lkGooglePicker",["lkGoogleSettings",function(lkGoogleSettings){return{restrict:"A",scope:{onLoaded:"=",onCancel:"=",onPicked:"="},link:function(scope,element,attrs){function instanciate(){gapi.load("auth",{callback:onApiAuthLoad}),gapi.load("picker")}function onApiAuthLoad(){var e=gapi.auth.getToken();e?handleAuthResult(e):gapi.auth.authorize({client_id:lkGoogleSettings.clientId,scope:lkGoogleSettings.scopes,immediate:!1},handleAuthResult)}function handleAuthResult(e){e&&!e.error&&(accessToken=e.access_token,openDialog())}function openDialog(){var picker=(new google.picker.PickerBuilder).setLocale(lkGoogleSettings.locale).setOAuthToken(accessToken).setCallback(pickerResponse).setOrigin(lkGoogleSettings.origin);lkGoogleSettings.features.length>0&&angular.forEach(lkGoogleSettings.features,function(e,o){picker.enableFeature(google.picker.Feature[e])}),lkGoogleSettings.views.length>0&&angular.forEach(lkGoogleSettings.views,function(view,key){view=eval("new google.picker."+view),picker.addView(view)}),picker.build().setVisible(!0)}function pickerResponse(e){gapi.client.load("drive","v2",function(){e.action==google.picker.Action.LOADED&&scope.onLoaded&&scope.onLoaded(),e.action==google.picker.Action.CANCEL&&scope.onCancel&&scope.onCancel(),e.action==google.picker.Action.PICKED&&scope.onPicked&&scope.onPicked(e.docs),scope.$apply()})}var accessToken=null;gapi.load("auth"),gapi.load("picker"),element.bind("click",function(e){instanciate()})}}}])}();
\ No newline at end of file
+!function(){angular.module("lk-google-picker",[]).provider("lkGoogleSettings",function(){this.apiKey=null,this.clientId=null,this.scopes=["https://www.googleapis.com/auth/drive"],this.features=["MULTISELECT_ENABLED"],this.views=["DocsView().setIncludeFolders(true)","DocsUploadView().setIncludeFolders(true)"],this.locale="en",this.$get=["$window",function(e){return{apiKey:this.apiKey,clientId:this.clientId,scopes:this.scopes,features:this.features,views:this.views,locale:this.locale,origin:this.origin||e.location.protocol+"//"+e.location.host}}],this.configure=function(e){for(var o in e)this[o]=e[o]}}).directive("lkGooglePicker",["lkGoogleSettings",function(lkGoogleSettings){return{restrict:"A",scope:{onLoaded:"&",onCancel:"&",onPicked:"&"},link:function(scope,element,attrs){function instanciate(){gapi.load("auth",{callback:onApiAuthLoad}),gapi.load("picker")}function onApiAuthLoad(){var e=gapi.auth.getToken();e?handleAuthResult(e):gapi.auth.authorize({client_id:lkGoogleSettings.clientId,scope:lkGoogleSettings.scopes,immediate:!1},handleAuthResult)}function handleAuthResult(e){e&&!e.error&&(accessToken=e.access_token,openDialog())}function openDialog(){var picker=(new google.picker.PickerBuilder).setLocale(lkGoogleSettings.locale).setOAuthToken(accessToken).setCallback(pickerResponse).setOrigin(lkGoogleSettings.origin);lkGoogleSettings.features.length>0&&angular.forEach(lkGoogleSettings.features,function(e,o){picker.enableFeature(google.picker.Feature[e])}),lkGoogleSettings.views.length>0&&angular.forEach(lkGoogleSettings.views,function(view,key){view=eval("new google.picker."+view),picker.addView(view)}),picker.build().setVisible(!0)}function pickerResponse(e){gapi.client.load("drive","v2",function(){e.action==google.picker.Action.LOADED&&scope.onLoaded&&(scope.onLoaded||angular.noop)(),e.action==google.picker.Action.CANCEL&&scope.onCancel&&(scope.onCancel||angular.noop)(),e.action==google.picker.Action.PICKED&&scope.onPicked&&(scope.onPicked||angular.noop)({docs:e.docs}),scope.$apply()})}var accessToken=null;gapi.load("auth"),gapi.load("picker"),element.bind("click",function(e){instanciate()})}}}])}();
\ No newline at end of file
diff --git a/example/google-picker.min.js b/example/google-picker.min.js
index 0121c49..cab4192 100644
--- a/example/google-picker.min.js
+++ b/example/google-picker.min.js
@@ -1 +1 @@
-!function(){angular.module("lk-google-picker",[]).provider("lkGoogleSettings",function(){this.apiKey=null,this.clientId=null,this.scopes=["https://www.googleapis.com/auth/drive"],this.features=["MULTISELECT_ENABLED"],this.views=["DocsView().setIncludeFolders(true)","DocsUploadView().setIncludeFolders(true)"],this.locale="en",this.$get=["$window",function(e){return{apiKey:this.apiKey,clientId:this.clientId,scopes:this.scopes,features:this.features,views:this.views,locale:this.locale,origin:this.origin||e.location.protocol+"//"+e.location.host}}],this.configure=function(e){for(var o in e)this[o]=e[o]}}).directive("lkGooglePicker",["lkGoogleSettings",function(lkGoogleSettings){return{restrict:"A",scope:{onLoaded:"=",onCancel:"=",onPicked:"="},link:function(scope,element,attrs){function instanciate(){gapi.load("auth",{callback:onApiAuthLoad}),gapi.load("picker")}function onApiAuthLoad(){var e=gapi.auth.getToken();e?handleAuthResult(e):gapi.auth.authorize({client_id:lkGoogleSettings.clientId,scope:lkGoogleSettings.scopes,immediate:!1},handleAuthResult)}function handleAuthResult(e){e&&!e.error&&(accessToken=e.access_token,openDialog())}function openDialog(){var picker=(new google.picker.PickerBuilder).setLocale(lkGoogleSettings.locale).setOAuthToken(accessToken).setCallback(pickerResponse).setOrigin(lkGoogleSettings.origin);lkGoogleSettings.features.length>0&&angular.forEach(lkGoogleSettings.features,function(e,o){picker.enableFeature(google.picker.Feature[e])}),lkGoogleSettings.views.length>0&&angular.forEach(lkGoogleSettings.views,function(view,key){view=eval("new google.picker."+view),picker.addView(view)}),picker.build().setVisible(!0)}function pickerResponse(e){gapi.client.load("drive","v2",function(){e.action==google.picker.Action.LOADED&&scope.onLoaded&&scope.onLoaded(),e.action==google.picker.Action.CANCEL&&scope.onCancel&&scope.onCancel(),e.action==google.picker.Action.PICKED&&scope.onPicked&&scope.onPicked(e.docs),scope.$apply()})}var accessToken=null;gapi.load("auth"),gapi.load("picker"),element.bind("click",function(e){instanciate()})}}}])}();
\ No newline at end of file
+!function(){angular.module("lk-google-picker",[]).provider("lkGoogleSettings",function(){this.apiKey=null,this.clientId=null,this.scopes=["https://www.googleapis.com/auth/drive"],this.features=["MULTISELECT_ENABLED"],this.views=["DocsView().setIncludeFolders(true)","DocsUploadView().setIncludeFolders(true)"],this.locale="en",this.$get=["$window",function(e){return{apiKey:this.apiKey,clientId:this.clientId,scopes:this.scopes,features:this.features,views:this.views,locale:this.locale,origin:this.origin||e.location.protocol+"//"+e.location.host}}],this.configure=function(e){for(var o in e)this[o]=e[o]}}).directive("lkGooglePicker",["lkGoogleSettings",function(lkGoogleSettings){return{restrict:"A",scope:{onLoaded:"&",onCancel:"&",onPicked:"&"},link:function(scope,element,attrs){function instanciate(){gapi.load("auth",{callback:onApiAuthLoad}),gapi.load("picker")}function onApiAuthLoad(){var e=gapi.auth.getToken();e?handleAuthResult(e):gapi.auth.authorize({client_id:lkGoogleSettings.clientId,scope:lkGoogleSettings.scopes,immediate:!1},handleAuthResult)}function handleAuthResult(e){e&&!e.error&&(accessToken=e.access_token,openDialog())}function openDialog(){var picker=(new google.picker.PickerBuilder).setLocale(lkGoogleSettings.locale).setOAuthToken(accessToken).setCallback(pickerResponse).setOrigin(lkGoogleSettings.origin);lkGoogleSettings.features.length>0&&angular.forEach(lkGoogleSettings.features,function(e,o){picker.enableFeature(google.picker.Feature[e])}),lkGoogleSettings.views.length>0&&angular.forEach(lkGoogleSettings.views,function(view,key){view=eval("new google.picker."+view),picker.addView(view)}),picker.build().setVisible(!0)}function pickerResponse(e){gapi.client.load("drive","v2",function(){e.action==google.picker.Action.LOADED&&scope.onLoaded&&(scope.onLoaded||angular.noop)(),e.action==google.picker.Action.CANCEL&&scope.onCancel&&(scope.onCancel||angular.noop)(),e.action==google.picker.Action.PICKED&&scope.onPicked&&(scope.onPicked||angular.noop)({docs:e.docs}),scope.$apply()})}var accessToken=null;gapi.load("auth"),gapi.load("picker"),element.bind("click",function(e){instanciate()})}}}])}();
\ No newline at end of file
diff --git a/example/index.html b/example/index.html
index 122c8af..7d0c5aa 100644
--- a/example/index.html
+++ b/example/index.html
@@ -40,7 +40,7 @@
-
+
Pick files
diff --git a/src/google-picker.js b/src/google-picker.js
index 1d05446..38b04b8 100644
--- a/src/google-picker.js
+++ b/src/google-picker.js
@@ -51,9 +51,9 @@
return {
restrict: 'A',
scope: {
- onLoaded: '=',
- onCancel: '=',
- onPicked: '='
+ onLoaded: '&',
+ onCancel: '&',
+ onPicked: '&'
},
link: function (scope, element, attrs) {
var accessToken = null;
@@ -127,13 +127,13 @@
function pickerResponse (data) {
gapi.client.load('drive', 'v2', function () {
if (data.action == google.picker.Action.LOADED && scope.onLoaded) {
- scope.onLoaded();
+ (scope.onLoaded || angular.noop)();
}
if (data.action == google.picker.Action.CANCEL && scope.onCancel) {
- scope.onCancel();
+ (scope.onCancel || angular.noop)();
}
if (data.action == google.picker.Action.PICKED && scope.onPicked) {
- scope.onPicked(data.docs);
+ (scope.onPicked || angular.noop)({docs: data.docs});
}
scope.$apply();
});