vk-api-angular
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,6 @@ | ||
### 1.2.0 | ||
- Added base class for widgets. | ||
- Added provider for the configuration phase. | ||
### 1.1.0 | ||
@@ -2,0 +7,0 @@ |
@@ -6,114 +6,124 @@ ;(function() { | ||
app.factory('VKApi', ['$q', '$timeout', function ($q, $timeout) { | ||
app.provider('VKApi', function () { | ||
var apiTimeout = 5000; | ||
this.init = function (auth) { | ||
if (typeof auth === 'object') { | ||
VK.init(auth); | ||
} else { | ||
VK.init({apiId: auth}); | ||
} | ||
}; | ||
return { | ||
this.$get = ['$q', '$timeout', function ($q, $timeout) { | ||
init: function (auth) { | ||
if (typeof auth === 'object') { | ||
VK.init(auth); | ||
} else { | ||
VK.init({apiId: auth}); | ||
} | ||
}, | ||
var apiTimeout = 5000; | ||
Auth: { | ||
login: function (permissions) { | ||
var scope = 0; | ||
if (permissions) { | ||
if (permissions.notify) { scope += 1; } | ||
if (permissions.friends) { scope += 2; } | ||
if (permissions.photos) { scope += 4; } | ||
if (permissions.audio) { scope += 8; } | ||
if (permissions.video) { scope += 16; } | ||
if (permissions.offers) { scope += 32; console.warn('The "offers" permission is outdated.'); } | ||
if (permissions.questions) { scope += 64; console.warn('The "questions" permission is outdated.'); } | ||
if (permissions.pages) { scope += 128; } | ||
if (permissions.links) { scope += 256; } | ||
if (permissions.status) { scope += 1024; } | ||
if (permissions.notes) { scope += 2048; } | ||
if (permissions.messages) { scope += 4096; console.warn('The "messages" permission is unavailable for non-standalone applications.'); } | ||
if (permissions.wall) { scope += 8192; } | ||
if (permissions.ads) { scope += 32768; } | ||
if (permissions.offline) { scope += 65536; } | ||
if (permissions.docs) { scope += 131072; } | ||
if (permissions.groups) { scope += 262144; } | ||
if (permissions.notifications) { scope += 524288; } | ||
if (permissions.stats) { scope += 1048576; } | ||
if (permissions.email) { scope += 4194304; } | ||
if (permissions.market) { scope += 134217728; } | ||
return { | ||
// TODO Remove in major update | ||
init: function (auth) { | ||
if (typeof auth === 'object') { | ||
VK.init(auth); | ||
} else { | ||
VK.init({apiId: auth}); | ||
} | ||
return $q(function (resolve, reject) { | ||
VK.Auth.login(function (response) { | ||
if (response.session) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}, scope); | ||
}); | ||
}, | ||
logout: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.logout(function (response) { | ||
resolve(response); | ||
Auth: { | ||
login: function (permissions) { | ||
var scope = 0; | ||
if (permissions) { | ||
if (permissions.notify) { scope += 1; } | ||
if (permissions.friends) { scope += 2; } | ||
if (permissions.photos) { scope += 4; } | ||
if (permissions.audio) { scope += 8; } | ||
if (permissions.video) { scope += 16; } | ||
if (permissions.offers) { scope += 32; console.warn('The "offers" permission is outdated.'); } | ||
if (permissions.questions) { scope += 64; console.warn('The "questions" permission is outdated.'); } | ||
if (permissions.pages) { scope += 128; } | ||
if (permissions.links) { scope += 256; } | ||
if (permissions.status) { scope += 1024; } | ||
if (permissions.notes) { scope += 2048; } | ||
if (permissions.messages) { scope += 4096; console.warn('The "messages" permission is unavailable for non-standalone applications.'); } | ||
if (permissions.wall) { scope += 8192; } | ||
if (permissions.ads) { scope += 32768; } | ||
if (permissions.offline) { scope += 65536; } | ||
if (permissions.docs) { scope += 131072; } | ||
if (permissions.groups) { scope += 262144; } | ||
if (permissions.notifications) { scope += 524288; } | ||
if (permissions.stats) { scope += 1048576; } | ||
if (permissions.email) { scope += 4194304; } | ||
if (permissions.market) { scope += 134217728; } | ||
} | ||
return $q(function (resolve, reject) { | ||
VK.Auth.login(function (response) { | ||
if (response.session) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}, scope); | ||
}); | ||
}); | ||
}, | ||
revokeGrants: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.revokeGrants(function (response) { | ||
resolve(response); | ||
}, | ||
logout: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.logout(function (response) { | ||
resolve(response); | ||
}); | ||
}); | ||
}); | ||
}, | ||
getLoginStatus: function () { | ||
return $q(function (resolve, reject) { | ||
VK.Auth.getLoginStatus(function (response) { | ||
if (response.session) { | ||
}, | ||
revokeGrants: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.revokeGrants(function (response) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, | ||
getLoginStatus: function () { | ||
return $q(function (resolve, reject) { | ||
VK.Auth.getLoginStatus(function (response) { | ||
if (response.session) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}); | ||
}); | ||
}, | ||
getSession: function () { | ||
return VK.Auth.getSession(); | ||
} | ||
}, | ||
getSession: function () { | ||
return VK.Auth.getSession(); | ||
} | ||
}, | ||
Api: { | ||
call: function (method, params) { | ||
return $q(function (resolve, reject) { | ||
var timeout = $timeout(function () { | ||
reject('VK API Angular (API Call): Timeout'); | ||
}, apiTimeout); | ||
VK.Api.call(method, params || {}, function (r) { | ||
$timeout.cancel(timeout); | ||
// istanbul ignore else | ||
if (r.hasOwnProperty('response')) { | ||
resolve(r.response); | ||
} else if (r.hasOwnProperty('error')) { | ||
reject(r.error); | ||
} else { | ||
reject(r); | ||
} | ||
Api: { | ||
call: function (method, params) { | ||
return $q(function (resolve, reject) { | ||
var timeout = $timeout(function () { | ||
reject('VK API Angular (API Call): Timeout'); | ||
}, apiTimeout); | ||
VK.Api.call(method, params || {}, function (r) { | ||
$timeout.cancel(timeout); | ||
// istanbul ignore else | ||
if (r.hasOwnProperty('response')) { | ||
resolve(r.response); | ||
} else if (r.hasOwnProperty('error')) { | ||
reject(r.error); | ||
} else { | ||
reject(r); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, | ||
setTimeout: function (value) { | ||
apiTimeout = value; | ||
}, | ||
setTimeout: function (value) { | ||
apiTimeout = value; | ||
} | ||
} | ||
} | ||
}; | ||
}]); | ||
}; | ||
}] | ||
}); | ||
module.exports = 'vk-api-angular'; | ||
angular.module('vk-api-angular').directive('vkAllowMessagesFromCommunity', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--allow-messages-from-community" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--allow-messages-from-community" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -132,3 +142,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--auth" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--auth" data-ng-attr-id="{{::id}}"></div>', | ||
scope: { | ||
@@ -151,3 +161,3 @@ onAuth: '&' | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--comments" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--comments" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -173,3 +183,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--community-messages" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--community-messages" data-ng-attr-id="{{::id}}"></div>', | ||
scope: { | ||
@@ -200,3 +210,3 @@ onCanNotWrite: '&' | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--community" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--community" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -222,3 +232,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--contact-us" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--contact-us" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -238,3 +248,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--like" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--like" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -259,3 +269,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--poll" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--poll" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -275,3 +285,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--post" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--post" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -293,3 +303,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--recommended" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--recommended" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -335,3 +345,3 @@ link: function (scope, element, attrs) { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--subscribe" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--subscribe" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -338,0 +348,0 @@ link: function (scope, element, attrs) { |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";var t=angular.module("vk-api-angular",[]);t.factory("VKApi",["$q","$timeout",function(t,e){var i=5e3;return{init:function(t){"object"==typeof t?VK.init(t):VK.init({apiId:t})},Auth:{login:function(e){var i=0;return e&&(e.notify&&(i+=1),e.friends&&(i+=2),e.photos&&(i+=4),e.audio&&(i+=8),e.video&&(i+=16),e.offers&&(i+=32,console.warn('The "offers" permission is outdated.')),e.questions&&(i+=64,console.warn('The "questions" permission is outdated.')),e.pages&&(i+=128),e.links&&(i+=256),e.status&&(i+=1024),e.notes&&(i+=2048),e.messages&&(i+=4096,console.warn('The "messages" permission is unavailable for non-standalone applications.')),e.wall&&(i+=8192),e.ads&&(i+=32768),e.offline&&(i+=65536),e.docs&&(i+=131072),e.groups&&(i+=262144),e.notifications&&(i+=524288),e.stats&&(i+=1048576),e.email&&(i+=4194304),e.market&&(i+=134217728)),t(function(t,e){VK.Auth.login(function(i){i.session?t(i):e(i)},i)})},logout:function(){return t(function(t){VK.Auth.logout(function(e){t(e)})})},revokeGrants:function(){return t(function(t){VK.Auth.revokeGrants(function(e){t(e)})})},getLoginStatus:function(){return t(function(t,e){VK.Auth.getLoginStatus(function(i){i.session?t(i):e(i)})})},getSession:function(){return VK.Auth.getSession()}},Api:{call:function(n,o){return t(function(t,a){var d=e(function(){a("VK API Angular (API Call): Timeout")},i);VK.Api.call(n,o||{},function(i){e.cancel(d),i.hasOwnProperty("response")?t(i.response):a(i.hasOwnProperty("error")?i.error:i)})})},setTimeout:function(t){i=t}}}}]),module.exports="vk-api-angular",angular.module("vk-api-angular").directive("vkAllowMessagesFromCommunity",function(){return{restrict:"AEC",template:'<div class="vk-widget--allow-messages-from-community" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.AllowMessagesFromCommunity(t.id,{height:i.height},i.groupId)}}}),angular.module("vk-api-angular").directive("vkAuth",function(){return{restrict:"AEC",template:'<div class="vk-widget--auth" data-ng-attr-id="{{::id}}"></div>',scope:{onAuth:"&"},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Auth(t.id,{width:i.width,onAuth:t.onAuth(),authUrl:i.authUrl})}}}),angular.module("vk-api-angular").directive("vkComments",function(){return{restrict:"AEC",template:'<div class="vk-widget--comments" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Comments(t.id,{width:i.width,height:i.height,limit:i.limit,attach:i.attach,autoPublish:i.autoPublish,mini:i.mini,norealtime:i.norealtime,pageUrl:i.pageUrl},i.page_id)}}}),angular.module("vk-api-angular").directive("vkCommunityMessages",function(){return{restrict:"AEC",template:'<div class="vk-widget--community-messages" data-ng-attr-id="{{::id}}"></div>',scope:{onCanNotWrite:"&"},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.CommunityMessages(t.id,i.groupId,{onCanNotWrite:t.onCanNotWrite(),welcomeScreen:i.welcomeScreen,expandTimeout:i.expandTimeout,expanded:i.expanded,widgetPosition:i.widgetPosition,buttonType:i.buttonType,disableButtonTooltip:i.disableButtonTooltip,tooltipButtonText:i.tooltipButtonText,disableNewMessagesSound:i.disableNewMessagesSound,disableExpandChatSound:i.disableExpandChatSound,disableTitleChange:i.disableTitleChange})}}}),angular.module("vk-api-angular").directive("vkCommunity",function(){return{restrict:"AEC",template:'<div class="vk-widget--community" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Community(t.id,{width:i.width,height:i.height,mode:i.mode,no_cover:i.no_cover,wide:i.wide,color1:i.color1,color2:i.color2,color3:i.color3},i.groupId)}}}),angular.module("vk-api-angular").directive("vkContactUs",function(){return{restrict:"AEC",template:'<div class="vk-widget--contact-us" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.ContactUs(t.id,{text:i.text,height:i.height},i.ownerId)}}}),angular.module("vk-api-angular").directive("vkLike",function(){return{restrict:"AEC",template:'<div class="vk-widget--like" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Like(t.id,{type:i.type,width:i.width,height:i.height,verb:i.verb,pageTitle:i.pageTitle,pageUrl:i.pageUrl,pageImage:i.pageImage},i.page_id)}}}),angular.module("vk-api-angular").directive("vkPoll",function(){return{restrict:"AEC",template:'<div class="vk-widget--poll" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Poll(t.id,{width:i.width,pageUrl:i.pageUrl},i.pollId)}}}),angular.module("vk-api-angular").directive("vkPost",function(){return{restrict:"AEC",template:'<div class="vk-widget--post" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,i.hash||console.warn("VK API Angular (Post Widget): Hash is not specified."),VK.Widgets.Post(t.id,i.ownerId,i.postId,i.hash,{width:i.width})}}}),angular.module("vk-api-angular").directive("vkRecommended",function(){return{restrict:"AEC",template:'<div class="vk-widget--recommended" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Recommended(t.id,{limit:i.limit,max:i.max,period:i.period},i.verb,i.sort,i.target)}}}),angular.module("vk-api-angular").directive("vkShare",function(){return{restrict:"AEC",scope:{},link:function(t,e,i){var n=["round","round_nocount","button","button_nocount","link","link_noicon","custom"];i.type&&n.indexOf(i.type)===-1&&console.warn('VK API Angular (Share Widget): Unknown button type "'+i.type+'". Available types: '+n.join(", ")),e.html(VK.Share.button({url:i.url,title:i.title,image:i.image,noparse:i.noparse,no_vk_links:i.no_vk_links},{type:i.type||"round",text:i.text}))}}}),angular.module("vk-api-angular").directive("vkSubscribe",function(){return{restrict:"AEC",template:'<div class="vk-widget--subscribe" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Subscribe(t.id,{mode:i.mode,soft:i.soft},i.ownerId)}}})}(); | ||
!function(){"use strict";angular.module("vk-api-angular",[]).provider("VKApi",function(){this.init=function(t){"object"==typeof t?VK.init(t):VK.init({apiId:t})},this.$get=["$q","$timeout",function(t,e){var i=5e3;return{init:function(t){"object"==typeof t?VK.init(t):VK.init({apiId:t})},Auth:{login:function(e){var i=0;return e&&(e.notify&&(i+=1),e.friends&&(i+=2),e.photos&&(i+=4),e.audio&&(i+=8),e.video&&(i+=16),e.offers&&(i+=32,console.warn('The "offers" permission is outdated.')),e.questions&&(i+=64,console.warn('The "questions" permission is outdated.')),e.pages&&(i+=128),e.links&&(i+=256),e.status&&(i+=1024),e.notes&&(i+=2048),e.messages&&(i+=4096,console.warn('The "messages" permission is unavailable for non-standalone applications.')),e.wall&&(i+=8192),e.ads&&(i+=32768),e.offline&&(i+=65536),e.docs&&(i+=131072),e.groups&&(i+=262144),e.notifications&&(i+=524288),e.stats&&(i+=1048576),e.email&&(i+=4194304),e.market&&(i+=134217728)),t(function(t,e){VK.Auth.login(function(i){i.session?t(i):e(i)},i)})},logout:function(){return t(function(t){VK.Auth.logout(function(e){t(e)})})},revokeGrants:function(){return t(function(t){VK.Auth.revokeGrants(function(e){t(e)})})},getLoginStatus:function(){return t(function(t,e){VK.Auth.getLoginStatus(function(i){i.session?t(i):e(i)})})},getSession:function(){return VK.Auth.getSession()}},Api:{call:function(n,o){return t(function(t,d){var a=e(function(){d("VK API Angular (API Call): Timeout")},i);VK.Api.call(n,o||{},function(i){e.cancel(a),i.hasOwnProperty("response")?t(i.response):d(i.hasOwnProperty("error")?i.error:i)})})},setTimeout:function(t){i=t}}}}]}),angular.module("vk-api-angular").directive("vkAllowMessagesFromCommunity",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--allow-messages-from-community" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.AllowMessagesFromCommunity(t.id,{height:i.height},i.groupId)}}}),angular.module("vk-api-angular").directive("vkAuth",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--auth" data-ng-attr-id="{{::id}}"></div>',scope:{onAuth:"&"},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Auth(t.id,{width:i.width,onAuth:t.onAuth(),authUrl:i.authUrl})}}}),angular.module("vk-api-angular").directive("vkComments",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--comments" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Comments(t.id,{width:i.width,height:i.height,limit:i.limit,attach:i.attach,autoPublish:i.autoPublish,mini:i.mini,norealtime:i.norealtime,pageUrl:i.pageUrl},i.page_id)}}}),angular.module("vk-api-angular").directive("vkCommunityMessages",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--community-messages" data-ng-attr-id="{{::id}}"></div>',scope:{onCanNotWrite:"&"},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.CommunityMessages(t.id,i.groupId,{onCanNotWrite:t.onCanNotWrite(),welcomeScreen:i.welcomeScreen,expandTimeout:i.expandTimeout,expanded:i.expanded,widgetPosition:i.widgetPosition,buttonType:i.buttonType,disableButtonTooltip:i.disableButtonTooltip,tooltipButtonText:i.tooltipButtonText,disableNewMessagesSound:i.disableNewMessagesSound,disableExpandChatSound:i.disableExpandChatSound,disableTitleChange:i.disableTitleChange})}}}),angular.module("vk-api-angular").directive("vkCommunity",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--community" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Community(t.id,{width:i.width,height:i.height,mode:i.mode,no_cover:i.no_cover,wide:i.wide,color1:i.color1,color2:i.color2,color3:i.color3},i.groupId)}}}),angular.module("vk-api-angular").directive("vkContactUs",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--contact-us" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.ContactUs(t.id,{text:i.text,height:i.height},i.ownerId)}}}),angular.module("vk-api-angular").directive("vkLike",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--like" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Like(t.id,{type:i.type,width:i.width,height:i.height,verb:i.verb,pageTitle:i.pageTitle,pageUrl:i.pageUrl,pageImage:i.pageImage},i.page_id)}}}),angular.module("vk-api-angular").directive("vkPoll",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--poll" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Poll(t.id,{width:i.width,pageUrl:i.pageUrl},i.pollId)}}}),angular.module("vk-api-angular").directive("vkPost",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--post" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,i.hash||console.warn("VK API Angular (Post Widget): Hash is not specified."),VK.Widgets.Post(t.id,i.ownerId,i.postId,i.hash,{width:i.width})}}}),angular.module("vk-api-angular").directive("vkRecommended",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--recommended" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Recommended(t.id,{limit:i.limit,max:i.max,period:i.period},i.verb,i.sort,i.target)}}}),angular.module("vk-api-angular").directive("vkShare",function(){return{restrict:"AEC",scope:{},link:function(t,e,i){var n=["round","round_nocount","button","button_nocount","link","link_noicon","custom"];i.type&&-1===n.indexOf(i.type)&&console.warn('VK API Angular (Share Widget): Unknown button type "'+i.type+'". Available types: '+n.join(", ")),e.html(VK.Share.button({url:i.url,title:i.title,image:i.image,noparse:i.noparse,no_vk_links:i.no_vk_links},{type:i.type||"round",text:i.text}))}}}),angular.module("vk-api-angular").directive("vkSubscribe",function(){return{restrict:"AEC",template:'<div class="vk-widget vk-widget--subscribe" data-ng-attr-id="{{::id}}"></div>',scope:{},link:function(t,e,i){t.id=i.elementId||"vk-widget-"+t.$id,VK.Widgets.Subscribe(t.id,{mode:i.mode,soft:i.soft},i.ownerId)}}})}(); |
@@ -7,16 +7,16 @@ var gulp = require('gulp'); | ||
gulp.task('default', ['scripts']); | ||
gulp.task('default', ['build', 'watch']); | ||
gulp.task('scripts', function () { | ||
gulp.task('build', function () { | ||
return gulp.src('src/**/*.js') | ||
.pipe(concat('vk-api-angular.js')) | ||
.pipe(iife()) | ||
.pipe(gulp.dest('dist/')) | ||
.pipe(uglify()) | ||
.pipe(rename({suffix: '.min'})) | ||
.pipe(gulp.dest('dist/')); | ||
.pipe(concat('vk-api-angular.js')) | ||
.pipe(iife()) | ||
.pipe(gulp.dest('dist/')) | ||
.pipe(uglify()) | ||
.pipe(rename({suffix: '.min'})) | ||
.pipe(gulp.dest('dist/')); | ||
}); | ||
gulp.task('watch', ['default'], function () { | ||
gulp.watch('src/**/*.js', ['scripts']); | ||
gulp.task('watch', function () { | ||
gulp.watch('src/**/*.js', ['build']); | ||
}); |
{ | ||
"name": "vk-api-angular", | ||
"description": "VK Open API AngularJS wrapper", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "index.js", | ||
"keywords": [ | ||
"vk", | ||
"vkontakte", | ||
"api", | ||
@@ -26,9 +27,9 @@ "angular", | ||
"scripts": { | ||
"start": "gulp watch", | ||
"start": "gulp", | ||
"test": "karma start", | ||
"prepublishOnly": "npm test && gulp" | ||
"prepublishOnly": "npm test && gulp build" | ||
}, | ||
"devDependencies": { | ||
"angular": "^1.6.1", | ||
"angular-mocks": "^1.6.1", | ||
"angular": "^1.6.4", | ||
"angular-mocks": "^1.6.4", | ||
"gulp": "^3.9.1", | ||
@@ -38,10 +39,10 @@ "gulp-concat": "^2.6.1", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-uglify": "^2.0.1", | ||
"jasmine-core": "^2.5.2", | ||
"karma": "^1.4.1", | ||
"gulp-uglify": "^3.0.0", | ||
"jasmine-core": "^2.6.2", | ||
"karma": "^1.7.0", | ||
"karma-cli": "^1.0.1", | ||
"karma-coverage": "^1.1.1", | ||
"karma-jasmine": "^1.1.0", | ||
"karma-phantomjs-launcher": "^1.0.2" | ||
"karma-phantomjs-launcher": "^1.0.4" | ||
} | ||
} |
@@ -13,8 +13,62 @@ # VK API Angular | ||
### VK API (service) | ||
## VK API (service) | ||
You may **initialize** your VK application using the provider during the configuration phase: | ||
```javascript | ||
angular.module('my-app', ['vk-api-angular']) | ||
.config(function (VKApiProvider) { | ||
VKApiProvider.init(10000); // Your VK APP_ID | ||
}); | ||
``` | ||
VKApi factory duplicates the official VK Open API method naming, in particular: | ||
- `VKApi.Api.call` | ||
- `VKApi.Auth.login` | ||
- `VKApi.Auth.logout` | ||
- `VKApi.Auth.revokeGrants` | ||
- `VKApi.Auth.getLoginStatus` | ||
- `VKApi.Auth.getSession` | ||
However, the promises are used instead of callbacks. This gives a better control over the success/error handling mechanism. | ||
- [Methods List](https://vk.com/dev/methods) | ||
- [Permissions List](https://vk.com/dev/permissions) | ||
```javascript | ||
// Log in and request the "photos" and "video" permissions. | ||
// See https://vk.com/dev/permissions for the full permission list. | ||
VKApi.Auth.login({ | ||
photos: true, | ||
video: true | ||
}).then( | ||
// Success: | ||
function (response) { | ||
var name = response.session.user.first_name; | ||
alert('Hello, ' + name + '!'); | ||
}, | ||
// Error: | ||
function (response) { | ||
alert('Sorry, access denied.'); | ||
console.error(response); | ||
} | ||
); | ||
``` | ||
```javascript | ||
// Call "users.get" API method. | ||
// See https://vk.com/dev/methods for the full method list. | ||
VKApi.Api.call('users.get').then( | ||
// Success: | ||
function (response) { | ||
alert('Hello, ' + response[0].first_name); | ||
var name = response[0].first_name; | ||
alert('Hello, ' + name + '!'); | ||
}, | ||
// Error: | ||
function (response) { | ||
alert('Sorry, could not fetch the user data.'); | ||
console.error(response); | ||
} | ||
@@ -24,3 +78,3 @@ ); | ||
### VK Widgets (directives) | ||
## VK Widgets (directives) | ||
@@ -27,0 +81,0 @@ #### VK *Allow Messages From Community* Widget |
var app = angular.module('vk-api-angular', []); | ||
app.factory('VKApi', ['$q', '$timeout', function ($q, $timeout) { | ||
app.provider('VKApi', function () { | ||
var apiTimeout = 5000; | ||
this.init = function (auth) { | ||
if (typeof auth === 'object') { | ||
VK.init(auth); | ||
} else { | ||
VK.init({apiId: auth}); | ||
} | ||
}; | ||
return { | ||
this.$get = ['$q', '$timeout', function ($q, $timeout) { | ||
init: function (auth) { | ||
if (typeof auth === 'object') { | ||
VK.init(auth); | ||
} else { | ||
VK.init({apiId: auth}); | ||
} | ||
}, | ||
var apiTimeout = 5000; | ||
Auth: { | ||
login: function (permissions) { | ||
var scope = 0; | ||
if (permissions) { | ||
if (permissions.notify) { scope += 1; } | ||
if (permissions.friends) { scope += 2; } | ||
if (permissions.photos) { scope += 4; } | ||
if (permissions.audio) { scope += 8; } | ||
if (permissions.video) { scope += 16; } | ||
if (permissions.offers) { scope += 32; console.warn('The "offers" permission is outdated.'); } | ||
if (permissions.questions) { scope += 64; console.warn('The "questions" permission is outdated.'); } | ||
if (permissions.pages) { scope += 128; } | ||
if (permissions.links) { scope += 256; } | ||
if (permissions.status) { scope += 1024; } | ||
if (permissions.notes) { scope += 2048; } | ||
if (permissions.messages) { scope += 4096; console.warn('The "messages" permission is unavailable for non-standalone applications.'); } | ||
if (permissions.wall) { scope += 8192; } | ||
if (permissions.ads) { scope += 32768; } | ||
if (permissions.offline) { scope += 65536; } | ||
if (permissions.docs) { scope += 131072; } | ||
if (permissions.groups) { scope += 262144; } | ||
if (permissions.notifications) { scope += 524288; } | ||
if (permissions.stats) { scope += 1048576; } | ||
if (permissions.email) { scope += 4194304; } | ||
if (permissions.market) { scope += 134217728; } | ||
return { | ||
// TODO Remove in major update | ||
init: function (auth) { | ||
if (typeof auth === 'object') { | ||
VK.init(auth); | ||
} else { | ||
VK.init({apiId: auth}); | ||
} | ||
return $q(function (resolve, reject) { | ||
VK.Auth.login(function (response) { | ||
if (response.session) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}, scope); | ||
}); | ||
}, | ||
logout: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.logout(function (response) { | ||
resolve(response); | ||
Auth: { | ||
login: function (permissions) { | ||
var scope = 0; | ||
if (permissions) { | ||
if (permissions.notify) { scope += 1; } | ||
if (permissions.friends) { scope += 2; } | ||
if (permissions.photos) { scope += 4; } | ||
if (permissions.audio) { scope += 8; } | ||
if (permissions.video) { scope += 16; } | ||
if (permissions.offers) { scope += 32; console.warn('The "offers" permission is outdated.'); } | ||
if (permissions.questions) { scope += 64; console.warn('The "questions" permission is outdated.'); } | ||
if (permissions.pages) { scope += 128; } | ||
if (permissions.links) { scope += 256; } | ||
if (permissions.status) { scope += 1024; } | ||
if (permissions.notes) { scope += 2048; } | ||
if (permissions.messages) { scope += 4096; console.warn('The "messages" permission is unavailable for non-standalone applications.'); } | ||
if (permissions.wall) { scope += 8192; } | ||
if (permissions.ads) { scope += 32768; } | ||
if (permissions.offline) { scope += 65536; } | ||
if (permissions.docs) { scope += 131072; } | ||
if (permissions.groups) { scope += 262144; } | ||
if (permissions.notifications) { scope += 524288; } | ||
if (permissions.stats) { scope += 1048576; } | ||
if (permissions.email) { scope += 4194304; } | ||
if (permissions.market) { scope += 134217728; } | ||
} | ||
return $q(function (resolve, reject) { | ||
VK.Auth.login(function (response) { | ||
if (response.session) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}, scope); | ||
}); | ||
}); | ||
}, | ||
revokeGrants: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.revokeGrants(function (response) { | ||
resolve(response); | ||
}, | ||
logout: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.logout(function (response) { | ||
resolve(response); | ||
}); | ||
}); | ||
}); | ||
}, | ||
getLoginStatus: function () { | ||
return $q(function (resolve, reject) { | ||
VK.Auth.getLoginStatus(function (response) { | ||
if (response.session) { | ||
}, | ||
revokeGrants: function () { | ||
return $q(function (resolve) { | ||
VK.Auth.revokeGrants(function (response) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, | ||
getLoginStatus: function () { | ||
return $q(function (resolve, reject) { | ||
VK.Auth.getLoginStatus(function (response) { | ||
if (response.session) { | ||
resolve(response); | ||
} else { | ||
reject(response); | ||
} | ||
}); | ||
}); | ||
}, | ||
getSession: function () { | ||
return VK.Auth.getSession(); | ||
} | ||
}, | ||
getSession: function () { | ||
return VK.Auth.getSession(); | ||
} | ||
}, | ||
Api: { | ||
call: function (method, params) { | ||
return $q(function (resolve, reject) { | ||
var timeout = $timeout(function () { | ||
reject('VK API Angular (API Call): Timeout'); | ||
}, apiTimeout); | ||
VK.Api.call(method, params || {}, function (r) { | ||
$timeout.cancel(timeout); | ||
// istanbul ignore else | ||
if (r.hasOwnProperty('response')) { | ||
resolve(r.response); | ||
} else if (r.hasOwnProperty('error')) { | ||
reject(r.error); | ||
} else { | ||
reject(r); | ||
} | ||
Api: { | ||
call: function (method, params) { | ||
return $q(function (resolve, reject) { | ||
var timeout = $timeout(function () { | ||
reject('VK API Angular (API Call): Timeout'); | ||
}, apiTimeout); | ||
VK.Api.call(method, params || {}, function (r) { | ||
$timeout.cancel(timeout); | ||
// istanbul ignore else | ||
if (r.hasOwnProperty('response')) { | ||
resolve(r.response); | ||
} else if (r.hasOwnProperty('error')) { | ||
reject(r.error); | ||
} else { | ||
reject(r); | ||
} | ||
}); | ||
}); | ||
}); | ||
}, | ||
setTimeout: function (value) { | ||
apiTimeout = value; | ||
}, | ||
setTimeout: function (value) { | ||
apiTimeout = value; | ||
} | ||
} | ||
} | ||
}; | ||
}]); | ||
module.exports = 'vk-api-angular'; | ||
}; | ||
}] | ||
}); |
angular.module('vk-api-angular').directive('vkAllowMessagesFromCommunity', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--allow-messages-from-community" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--allow-messages-from-community" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkAuth', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--auth" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--auth" data-ng-attr-id="{{::id}}"></div>', | ||
scope: { | ||
@@ -6,0 +6,0 @@ onAuth: '&' |
angular.module('vk-api-angular').directive('vkComments', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--comments" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--comments" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkCommunityMessages', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--community-messages" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--community-messages" data-ng-attr-id="{{::id}}"></div>', | ||
scope: { | ||
@@ -6,0 +6,0 @@ onCanNotWrite: '&' |
angular.module('vk-api-angular').directive('vkCommunity', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--community" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--community" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkContactUs', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--contact-us" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--contact-us" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkLike', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--like" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--like" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkPoll', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--poll" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--poll" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkPost', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--post" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--post" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkRecommended', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--recommended" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--recommended" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
angular.module('vk-api-angular').directive('vkSubscribe', function () { | ||
return { | ||
restrict: 'AEC', | ||
template: '<div class="vk-widget--subscribe" data-ng-attr-id="{{::id}}"></div>', | ||
template: '<div class="vk-widget vk-widget--subscribe" data-ng-attr-id="{{::id}}"></div>', | ||
scope: {}, | ||
@@ -6,0 +6,0 @@ link: function (scope, element, attrs) { |
describe('VK API wrapper', function () { | ||
beforeEach(module('vk-api-angular')); | ||
beforeEach(module('vk-api-angular', function(_VKApiProvider_) { | ||
VKApiProvider = _VKApiProvider_; | ||
})); | ||
@@ -12,8 +14,15 @@ beforeEach(inject(function (_VKApi_, _$rootScope_, _$timeout_) { | ||
it('calls VK.init()', function () { | ||
it('calls VK.init() from the provider', function () { | ||
spyOn(VK, 'init'); | ||
VKApi.init({}); | ||
VKApiProvider.init({}); | ||
expect(VK.init).toHaveBeenCalled(); | ||
}); | ||
it('calls VK.init() from the factory', function () { | ||
spyOn(VK, 'init'); | ||
VKApi.init(1); | ||
VKApi.init({apiId: 1}); | ||
expect(VK.init).toHaveBeenCalled(); | ||
}); | ||
it('calls VK.Auth.login()', function () { | ||
@@ -51,3 +60,3 @@ spyOn(VK.Auth, 'login'); | ||
spyOn(VK, 'init'); | ||
VKApi.init({apiId: 1}); | ||
VKApiProvider.init({apiId: 1}); | ||
expect(VK.init).toHaveBeenCalledWith({apiId: 1}); | ||
@@ -58,3 +67,3 @@ }); | ||
spyOn(VK, 'init'); | ||
VKApi.init(1); | ||
VKApiProvider.init(1); | ||
expect(VK.init).toHaveBeenCalledWith({apiId: 1}); | ||
@@ -61,0 +70,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61702
1456
150