vue-socials
Version:
Social media share buttons and counts for Vue.js
72 lines (62 loc) • 2.21 kB
JavaScript
import { defineComponent } from 'vue';
import JSONP from '../../utils/jsonp.js';
import getSerialisedParams from '../../utils/getSerialisedParams.js';
import BaseCount from '../../mixins/BaseCount/BaseCount.js';
/**
* Hey!
*
* SVkontakteCount component used for Vkontakte social network
* @link https://vk.com
* @example https://vk.com/share.php?act=count&index=1&url=http
*/
var SVkontakteCount = /* #__PURE__ */defineComponent({
mixins: [BaseCount('Vkontakte')],
methods: {
handleVKResponse: function handleVKResponse(index, count) {
var _window$VK$callbacks;
this.handleLoading(false);
this.handleResult({
index: index,
count: count
});
this.handleCount(count);
(_window$VK$callbacks = window.VK.callbacks) === null || _window$VK$callbacks === void 0 ? true : delete _window$VK$callbacks["cb".concat(index)];
}
},
mounted: function mounted() {
var shareOptions = this.shareOptions;
var url = shareOptions.url;
var BASE_URL = 'https://vk.com/share.php';
if (!window.VK) {
window.VK = {};
}
if (!window.VK.callbacks) {
window.VK.callbacks = {};
}
window.VK.Share = {
count: function (_count) {
function count(_x, _x2) {
return _count.apply(this, arguments);
}
count.toString = function () {
return _count.toString();
};
return count;
}(function (index, count) {
var _window$VK$callbacks2, _window$VK$callbacks3;
return (_window$VK$callbacks2 = window.VK.callbacks) === null || _window$VK$callbacks2 === void 0 ? void 0 : (_window$VK$callbacks3 = _window$VK$callbacks2["cb".concat(index)]) === null || _window$VK$callbacks3 === void 0 ? void 0 : _window$VK$callbacks3.call(_window$VK$callbacks2, index, count);
})
};
var index = Object.keys(window.VK.callbacks).length;
var key = "cb".concat(index);
window.VK.callbacks[key] = this.handleVKResponse;
var finalURL = "".concat(BASE_URL).concat(getSerialisedParams({
act: 'count',
index: index,
url: url
}));
this.handleLoading(true);
JSONP(finalURL);
}
});
export default SVkontakteCount;