MediaWiki:VKLikeButton/code.js

// vk.com like widget. doc: https://vk.com/dev/widget_like // //  // data-type: mini/full/button/vertical $(function {   var script,        scriptId = 'vk_like_script',        id = 'vk_like',        head = document.getElementsByTagName('head')[0],        $target = $('div[id^="vk_like"]'),        apiId = window.vklikeapiid,        types = {            mini: 'mini',            full: 'full',            button: 'button',            vertical: 'vertical'        };    if (document.getElementById(scriptId) || !$target.length || !apiId) return;    // openapi    script = document.createElement('script');    script.id = scriptId;    script.type = 'text/javascript';    script.src = '//vk.com/js/api/openapi.js?150';    head.appendChild(script);    // let vk to load    var timer = setInterval(function { if (!window.VK || !window.VK.init) return; clearInterval(timer); window.VK.init({apiId: apiId, onlyWidgets: true}); // in case of async init setTimeout(function {           $target.each(function(index, el) { var type = el.dataset && el.dataset.type ? types[el.dataset.type] || 'mini' : 'mini'; window.VK.Widgets.Like(el.id, type); });       }, 100);    }, 100); });