diff --git a/bower.json b/bower.json index 35577501..a76ff6af 100644 --- a/bower.json +++ b/bower.json @@ -27,6 +27,7 @@ "promise-polyfill": "~2.0.0", "format-io": "~0.9.6", "rendy": "~1.1.0", - "github": "~0.10.6" + "github": "~0.10.6", + "vk-openapi": "~0.0.1" } } diff --git a/lib/client/storage/_vk.js b/lib/client/storage/_vk.js index 85ec4584..1e1909e5 100644 --- a/lib/client/storage/_vk.js +++ b/lib/client/storage/_vk.js @@ -14,7 +14,7 @@ var CloudCmd, Util, DOM, VK; console.time('vk'); var lUrl = 'http://vkontakte.ru/js/api/openapi.js', - lLocal = CloudCmd.LIBDIRCLIENT + 'storage/vk/open.js', + lLocal = CloudCmd.PREFIX + '/modules/vk-openapi/openapi/vk-openapi.js', lOnload = function() { console.timeEnd('vk load'); diff --git a/modules/vk-openapi/.bower.json b/modules/vk-openapi/.bower.json new file mode 100644 index 00000000..7a9c01ce --- /dev/null +++ b/modules/vk-openapi/.bower.json @@ -0,0 +1,24 @@ +{ + "name": "vk-openapi", + "version": "0.0.1", + "main": "openapi/vk-openapi.js", + "keywords": [ + "vk", + "openapi", + "javascript" + ], + "dependencies": { + "vk-openapi": "https://github.com/colmer/vk_openapi" + }, + "homepage": "https://github.com/colmer/vk_openapi", + "_release": "0.0.1", + "_resolution": { + "type": "version", + "tag": "0.0.1", + "commit": "162049e7295aba1f979dd5efe8f676d5d03bfdb0" + }, + "_source": "git://github.com/colmer/vk_openapi.git", + "_target": "~0.0.1", + "_originalSource": "vk-openapi", + "_direct": true +} \ No newline at end of file diff --git a/modules/vk-openapi/bower.json b/modules/vk-openapi/bower.json new file mode 100644 index 00000000..a1a082a9 --- /dev/null +++ b/modules/vk-openapi/bower.json @@ -0,0 +1,13 @@ +{ + "name": "vk-openapi", + "version": "0.0.1", + "main": "openapi/vk-openapi.js", + "keywords": [ + "vk", + "openapi", + "javascript" + ], + "dependencies": { + "vk-openapi": "https://github.com/colmer/vk_openapi" + } +} diff --git a/lib/client/storage/vk/openapi.js b/modules/vk-openapi/openapi/vk-openapi.js similarity index 77% rename from lib/client/storage/vk/openapi.js rename to modules/vk-openapi/openapi/vk-openapi.js index 62c550fe..f3f5f6e3 100644 --- a/lib/client/storage/vk/openapi.js +++ b/modules/vk-openapi/openapi/vk-openapi.js @@ -1,1703 +1,1870 @@ -(function(w) { -if (w.fastXDM) return; - -var handlers = {}; -var onEnvLoad = []; -var env = {}; - -// Key generation -function genKey() { - var key = ''; - for (i=0;i<5;i++) key += Math.ceil(Math.random()*15).toString(16); - return key; -} -function waitFor(obj, prop, func, self, count) { - if (obj[prop]) { - func.apply(self); - } else { - count = count || 0; - if (count < 1000) setTimeout(function() { - waitFor(obj, prop, func, self, count + 1) - }, 0); - } -} -function attachScript(url) { - setTimeout(function() { - var newScript = document.createElement('script'); - newScript.type = 'text/javascript'; - newScript.src = url || w.fastXDM.helperUrl; - waitFor(document, 'body', function() { - document.getElementsByTagName('HEAD')[0].appendChild(newScript); - }); - }, 0); -} - -// Env functions -function getEnv(callback, self) { - if (env.loaded) { - callback.apply(self, [env]); - } else { - onEnvLoad.push([self, callback]); - } -} - -function envLoaded() { - env.loaded = true; - var i = onEnvLoad.length; - while (i--) { - onEnvLoad[i][1].apply(onEnvLoad[i][0], [env]); - } -} - -function applyMethod(strData, self) { - getEnv(function(env) { - var data = env.json.parse(strData); - if (data[0]) { - if (!data[1]) data[1] = []; - var i = data[1].length; - while (i--) { - if (data[1][i]._func) { - var funcNum = data[1][i]._func; - data[1][i] = function() { - var args = Array.prototype.slice.call(arguments); - args.unshift('_func'+funcNum); - self.callMethod.apply(self, args); - } - } - } - setTimeout(function() { - if (!self.methods[data[0]]) throw Error('fastXDM: Method ' + data[0] + ' is undefined'); - self.methods[data[0]].apply(self, data[1]); - }, 0); - } - }); -} -// XDM object -w.fastXDM = { - _id: 0, - helperUrl: (location.protocol == 'https:' ? 'https://vk.com/' : 'http://userapi.com/') + 'js/api/xdmHelper.js?2', - - Server: function(methods, filter) { - this.methods = methods || {}; - this.id = w.fastXDM._id++; - this.filter = filter; - this.key = genKey(); - this.methods['%init%'] = this.methods.__fxdm_i = function() { - w.fastXDM.run(this.id); - if (this.methods.onInit) this.methods.onInit(); - }; - this.frameName = 'fXD'+this.key; - this.server = true; - handlers[this.key] = [applyMethod, this]; - }, - - Client: function(methods) { - this.methods = methods || {}; - this.id = w.fastXDM._id++; - w.fastXDM.run(this.id); - if (window.name.indexOf('fXD') === 0) { - this.key = window.name.substr(3); - } else { - throw Error('Wrong window.name property.'); - } - this.caller = window.parent; - handlers[this.key] = [applyMethod, this]; - this.client = true; - - w.fastXDM.on('helper', function() { - w.fastXDM.onClientStart(this); - }, this); - - getEnv(function(env) { - env.send(this, env.json.stringify(['%init%'])); - var methods = this.methods; - setTimeout(function() { - if (methods.onInit) methods.onInit(); - }, 0); - }, this); - }, - - onMessage: function(e) { - if (!e.data) return false; - var key = e.data.substr(0, 5); - if (handlers[key]) { - var self = handlers[key][1]; - if (self && (!self.filter || self.filter(e.origin))) { - handlers[key][0](e.data.substr(6), self); - } - } - }, - - setJSON: function(json) { - env.json = json; - }, - - getJSON: function(callback) { - if (!callback) return env.json; - getEnv(function(env) { - callback(env.json); - }); - }, - - setEnv: function(exEnv) { - var i; - for (i in exEnv) { - env[i] = exEnv[i]; - } - envLoaded(); - }, - - _q: {}, - - on: function(key, act, self) { - if (!this._q[key]) this._q[key] = []; - if (this._q[key] == -1) { - act.apply(self); - } else { - this._q[key].push([act, self]); - } - }, - - run: function(key) { - var len = (this._q[key] || []).length; - if (this._q[key] && len > 0) { - for (var i = 0; i < len; i++) this._q[key][i][0].apply(this._q[key][i][1]); - } - this._q[key] = -1; - }, - - waitFor: waitFor -} - -w.fastXDM.Server.prototype.start = function(obj, count) { - if (obj.contentWindow) { - this.caller = obj.contentWindow; - this.frame = obj; - - w.fastXDM.on('helper', function() { - w.fastXDM.onServerStart(this); - }, this); - - } else { // Opera old versions - var self = this; - count = count || 0; - if (count < 50) setTimeout(function() { - self.start.apply(self, [obj, count+1]); - }, 100); - } -} - -function extend(obj1, obj2){ - for (var i in obj2) { - if (obj1[i] && typeof(obj1[i]) == 'object') { - extend(obj1[i], obj2[i]) - } else { - obj1[i] = obj2[i]; - } - } -} - -w.fastXDM.Server.prototype.append = function(obj, options) { - var div = document.createElement('DIV'); - div.innerHTML = ''; - var frame = div.firstChild; - var self = this; - setTimeout(function() { - frame.frameBorder = '0'; - if (options) extend(frame, options); - obj.insertBefore(frame, obj.firstChild); - self.start(frame); - }, 0); - return frame; -} - -w.fastXDM.Client.prototype.callMethod = w.fastXDM.Server.prototype.callMethod = function() { - var args = Array.prototype.slice.call(arguments); - var method = args.shift(); - var i = args.length; - while (i--) { - if (typeof(args[i]) == 'function') { - this.funcsCount = (this.funcsCount || 0) + 1; - var func = args[i]; - var funcName = '_func' + this.funcsCount; - this.methods[funcName] = function() { - func.apply(this, arguments); - delete this.methods[funcName]; - } - args[i] = {_func: this.funcsCount}; - } - } - waitFor(this, 'caller', function() { - w.fastXDM.on(this.id, function() { - getEnv(function(env) { - env.send(this, env.json.stringify([method, args])); - }, this); - }, this); - }, this); -} - -if (w.JSON && typeof(w.JSON) == 'object' && w.JSON.parse && w.JSON.stringify && w.JSON.stringify({a:[1,2,3]}).replace(/ /g, '') == '{"a":[1,2,3]}') { - env.json = {parse: w.JSON.parse, stringify: w.JSON.stringify}; -} else { - w.fastXDM._needJSON = true; -} - -// PostMessage cover -if (w.postMessage) { - env.protocol = 'p'; - env.send = function(xdm, strData) { - // alert(key+':'+strData); - xdm.caller.postMessage(xdm.key+':'+strData, "*"); - } - if (w.addEventListener) { - w.addEventListener("message", w.fastXDM.onMessage, false); - } else { - w.attachEvent("onmessage", w.fastXDM.onMessage); - } - - if (w.fastXDM._needJSON) { - w.fastXDM._onlyJSON = true; - attachScript(); - } else { - envLoaded(); - } -} else { - attachScript(); -} -})(window); - - -if (!window.VK) window.VK = {}; - - -/* - * Based on JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Copyright (C) Paul Johnston 1999 - 2009 - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - */ -if(!VK.MD5){VK.MD5=function(n){var j=function(o,r){var q=(o&65535)+(r&65535),p=(o>>16)+(r>>16)+(q>>16);return(p<<16)|(q&65535)},g=function(o,p){return(o<
>>(32-p))},k=function(w,r,p,o,v,u){return j(g(j(j(r,w),j(o,u)),v),p)},a=function(q,p,w,v,o,u,r){return k((p&w)|((~p)&v),q,p,o,u,r)},h=function(q,p,w,v,o,u,r){return k((p&v)|(w&(~v)),q,p,o,u,r)},c=function(q,p,w,v,o,u,r){return k(p^w^v,q,p,o,u,r)},m=function(q,p,w,v,o,u,r){return k(w^(p|(~v)),q,p,o,u,r)},b=function(A,u){var z=1732584193,y=-271733879,w=-1732584194,v=271733878,r,q,p,o;A[u>>5]|=128<<((u)%32);A[(((u+64)>>>9)<<4)+14]=u;for(var t=0,s=A.length;t >>(32-p))},k=function(w,r,p,o,v,u){return j(g(j(j(r,w),j(o,u)),v),p)},a=function(q,p,w,v,o,u,r){return k((p&w)|((~p)&v),q,p,o,u,r)},h=function(q,p,w,v,o,u,r){return k((p&v)|(w&(~v)),q,p,o,u,r)},c=function(q,p,w,v,o,u,r){return k(p^w^v,q,p,o,u,r)},m=function(q,p,w,v,o,u,r){return k(w^(p|(~v)),q,p,o,u,r)},b=function(A,u){var z=1732584193,y=-271733879,w=-1732584194,v=271733878,r,q,p,o;A[u>>5]|=128<<((u)%32);A[(((u+64)>>>9)<<4)+14]=u;for(var t=0,s=A.length;t>>6)&31),128|(o&63))}else{if(o<=65535){q+=String.fromCharCode(224|((o>>>12)&15),128|((o>>>6)&63),128|(o&63))}else{if(o<=2097151){q+=String.fromCharCode(240|((o>>>18)&7),128|((o>>>12)&63),128|((o>>>6)&63),128|(o&63))}}}}}return q},e=function(p){var o=Array(p.length>>2),r,q;for(r=0,q=o.length;r>5]|=(p.charCodeAt(r/8)&255)<<(r%32)}return o},l=function(p){var o="";for(var r=0,q=p.length*32;r
>5]>>>(r%32))&255)}return o},d=function(o){return l(b(e(o),o.length*8))},i=function(q){var t="0123456789abcdef",p="",o;for(var s=0,r=q.length;s
'
- );
- el.innerHTML = html;
- el.style.width = el.childNodes[0].offsetWidth + 'px';
- },
- _change: function(state, index) {
- var row = document.getElementById('openapi_UI_' + index).rows[0];
- var elems = [row.cells[0].firstChild.firstChild, row.cells[2].firstChild.firstChild];
- for (var i = 0; i < 2; ++i) {
- var elem = elems[i];
- if (state === 0) {
- elem.style.backgroundColor = '#6D8DB1';
- elem.style.borderTopColor = '#7E9CBC';
- elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#5C82AB';
- } else if (state == 1) {
- elem.style.backgroundColor = '#7693B6';
- elem.style.borderTopColor = '#88A4C4';
- elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#6088B4';
- } else if (state == 2) {
- elem.style.backgroundColor = '#6688AD';
- elem.style.borderBottomColor = '#7495B8';
- elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderTopColor = '#51779F';
- }
- }
- if (state === 0 || state == 2) {
- row.cells[2].firstChild.style.backgroundPosition = '0px -42px';
- } else if (state == 1) {
- row.cells[2].firstChild.style.backgroundPosition = '0px -63px';
- }
- }
-};
-}
-
-if (!VK.XDM) {
-VK.XDM = {
- remote: null,
- init: function() {
- if (this.remote) return false;
- var url = VK._domain.api + VK._path.proxy;
- this.remote = new fastXDM.Server({
- onInit: function() {
- VK.XDM.remote.callMethod('init', VK._apiId, VK._session, VK._userStatus);
- VK.xdReady = true;
- VK.Observer.publish('xdm.init');
- },
- setSession: {
- isVoid: true,
- method: function(session, status) {
- VK.Auth.setSession(session, status);
- }
- },
- alert: {
- isVoid: true,
- method: function(text) {
- alert(text);
- }
- }
- });
-
- this.remote.append(document.getElementById(VK._rootId), {
- src: url
- });
- },
- xdHandler: function(code) {
- try {
- eval('VK.' + code);
- } catch(e) {}
- }
-};
-}
-
-if (!VK.Observer) {
-VK.Observer = {
- _subscribers: function() {
- if (!this._subscribersMap) {
- this._subscribersMap = {};
- }
- return this._subscribersMap;
- },
- publish: function(eventName) {
- var
- args = Array.prototype.slice.call(arguments),
- eventName = args.shift(),
- subscribers = this._subscribers()[eventName],
- i, j;
-
- if (!subscribers) return;
-
- for (i = 0, j = subscribers.length; i < j; i++) {
- if (subscribers[i] != null) {
- subscribers[i].apply(this, args);
- }
- }
- },
- subscribe: function(eventName, handler) {
- var
- subscribers = this._subscribers();
-
- if (typeof handler != 'function') return false;
-
- if (!subscribers[eventName]) {
- subscribers[eventName] = [handler];
- } else {
- subscribers[eventName].push(handler);
- }
- },
- unsubscribe: function(eventName, handler) {
- var
- subscribers = this._subscribers()[eventName],
- i, j;
-
- if (!subscribers) return false;
- if (typeof handler == 'function') {
- for (i = 0, j = subscribers.length; i < j; i++) {
- if (subscribers[i] == handler) {
- subscribers[i] = null;
- }
- }
- } else {
- delete this._subscribers()[eventName];
- }
- }
-};
-}
-
-if (!VK.Widgets) {
- VK.Widgets = {};
-
- VK.Widgets.count = 0;
- VK.Widgets.RPC = {};
-
- VK.Widgets.loading = function(obj, enabled) {
- obj.style.background = enabled ? 'url("' + VK._protocol + '//vk.com/images/upload.gif") center center no-repeat transparent' : 'none';
- };
-
- VK.Widgets.Comments = function(objId, options, page) {
- var pData = VK.Util.getPageData();
- if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
- options = options || {};
- var params = {
- limit: options.limit || 10,
- height: options.height || 0,
- mini: options.mini === undefined ? 'auto' : options.mini,
- norealtime: options.norealtime ? 1 : 0
- }, mouseup = function () {
- rpc.callMethod('mouseUp');
- return false;
- }, move = function (event) {
- rpc.callMethod('mouseMove', {screenY: event.screenY});
- }, iframe, rpc;
-
- if (options.browse) { // browse all comments
- params.browse = 1;
- params.replies = options.replies || 0;
- } else { // page
- VK.extend(params, {
- page: page || 0,
- status_publish: options.autoPublish === undefined ? 1 : options.autoPublish,
- attach: options.attach === undefined ? '*' : (options.attach ? options.attach : ''),
- url: options.pageUrl || pData.url,
- title: options.pageTitle || pData.title,
- description: options.pageDescription || pData.description,
- image: options.pageImage || pData.image
- });
- }
- if (options.onChange) { // DEPRECATED
- VK.Observer.subscribe('widgets.comments.new_comment', options.onChange);
- VK.Observer.subscribe('widgets.comments.delete_comment', options.onChange);
- }
-
- return VK.Widgets._constructor('widget_comments.php', objId, options, params, {
- showBox: function (url, props) {
- var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [props.width, props.height], {
- proxy: function () {
- rpc.callMethod.apply(rpc, arguments);
- }
- });
- box.show();
- },
- startDrag: function() {
- cursorBack = window.document.body.style.cursor;
- window.document.body.style.cursor = 'pointer';
- VK.Util.addEvent('mousemove', move);
- VK.Util.addEvent('mouseup', mouseup);
- },
- stopDrag: function() {
- window.document.body.style.cursor = cursorBack;
- VK.Util.removeEvent('mousemove', move);
- VK.Util.removeEvent('mouseup', mouseup);
- }
- }, {
- startHeight: 133,
- minWidth: 300,
- width: '100%'
- }, function (o, i, r) {iframe = i; rpc = r;});
- };
-
- VK.Widgets.CommentsBrowse = function(objId, options) {
- options = options || {};
- options.browse = 1;
- return VK.Widgets.Comments(objId, options);
- };
-
- VK.Widgets.Recommended = function(objId, options) {
- var pData = VK.Util.getPageData();
- if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
- options = options || {};
- var params = {
- limit: options.limit || 5,
- max: options.max || 0,
- sort: options.sort || 'friend_likes',
- verb: options.verb || 0,
- period: options.period || 'week',
- target: options.target || 'parent'
- };
- return VK.Widgets._constructor('widget_recommended.php', objId, options, params, {}, {
- startHeight: (90 + params.limit * 30),
- minWidth: 150,
- width: '100%'
- });
- };
-
- VK.Widgets.Like = function(objId, options, page) {
- var pData = VK.Util.getPageData();
- if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
- options = VK.extend(options || {}, {allowTransparency: true});
- if (options.type == 'button' || options.type == 'vertical' || options.type == 'mini') delete options.width;
- var
- type = (options.type == 'full' || options.type == 'button' || options.type == 'vertical' || options.type == 'mini') ? options.type : 'full',
- width = type == 'full' ? Math.max(200, options.width || 350) : (type == 'button' ? 180 : (type == 'mini' ? 100 : 41)),
- btnHeight = parseInt(options.height, 10) || 22,
- height = type == 'vertical' ? (2 * btnHeight + 7) : (type == 'full' ? btnHeight + 1 : btnHeight),
- params = {
- page: page || 0,
- url: options.pageUrl || pData.url,
- type: type,
- verb: options.verb == 1 ? 1 : 0,
- title: options.pageTitle || pData.title,
- description: options.pageDescription || pData.description,
- image: options.pageImage || pData.image,
- text: (options.text || '').substr(0, 140),
- h: btnHeight
- },
- ttHere = options.ttHere || false,
- isOver = false,
- obj, buttonIfr, buttonRpc, tooltipIfr, tooltipRpc, checkTO, statsBox;
-
- function showTooltip(force) {
- if ((!isOver && !force) || !tooltipRpc) return;
- if (!tooltipIfr || !tooltipRpc || tooltipIfr.style.display != 'none' && tooltipIfr.getAttribute('vkhidden') != 'yes') return;
- var scrollTop = options.getScrollTop ? options.getScrollTop() : (document.body.scrollTop || document.documentElement.scrollTop || 0);
- var objPos = VK.Util.getXY(obj, options.fixed);
- var startY = ttHere ? 0 : objPos[1];
- if (scrollTop > objPos[1] - 120 && options.tooltipPos != 'top' || type == 'vertical' || options.tooltipPos == 'bottom') {
- tooltipIfr.style.top = (startY + height + 2) + 'px';
- tooltipRpc.callMethod('show', false);
- } else {
- tooltipIfr.style.top = (startY - 125) + 'px';
- tooltipRpc.callMethod('show', true);
- }
- VK.Util.ss(tooltipIfr, {left: ((ttHere ? 0 : objPos[0]) - (type == 'vertical' || type == 'mini' ? 36 : 2)) + 'px', display: 'block', opacity: 1, filter: 'none'});
- tooltipIfr.setAttribute('vkhidden', 'no');
- isOver = true;
- }
-
- function hideTooltip(force) {
- if ((isOver && !force) || !tooltipRpc) return;
- tooltipRpc.callMethod('hide');
- buttonRpc.callMethod('hide');
- setTimeout(function () {
- tooltipIfr.style.display = 'none'
- }, 400);
- }
-
- return VK.Widgets._constructor('widget_like.php', objId, options, params, {
- initTooltip: function (counter) {
- tooltipRpc = new fastXDM.Server({
- onInit: counter ? function() {showTooltip(true)} : function () {},
- proxy: function () {
- buttonRpc.callMethod.apply(buttonRpc, arguments);
- },
- showBox: function (url, props) {
- var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [props.width, props.height], {
- proxy: function () {
- tooltipRpc.callMethod.apply(tooltipRpc, arguments);
- }
- });
- box.show();
- },
- statsBox: function (act) {
- hideTooltip(true);
- statsBox = VK.Util.Box(buttonIfr.src + '&act=a_stats_box', [498, 442]);
- statsBox.show();
- }
- });
- tooltipIfr = tooltipRpc.append(ttHere ? obj : document.body, {
- src: buttonIfr.src + '&act=a_share_tooltip',
- scrolling: 'no',
- allowTransparency: true,
- id: buttonIfr.id + '_tt',
- style: {position: 'absolute', padding: 0, display: 'block', opacity: 0.01, filter: 'alpha(opacity=1)', border: '0', width: '206px', height: '127px', zIndex: 5000, overflow: 'hidden'}
- });
- tooltipIfr.setAttribute('vkhidden', 'yes');
-
- obj.onmouseover = tooltipIfr.onmouseover = function () {isOver = true;};
- obj.onmouseout = tooltipIfr.onmouseout = function () {
- clearTimeout(checkTO);
- isOver = false;
- checkTO = setTimeout(function () {hideTooltip(); }, 200);
- };
- },
- showTooltip: showTooltip,
- hideTooltip: hideTooltip,
- showBox: function (url, props) {
- var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [props.width, props.height], {
- proxy: function () {
- buttonRpc.callMethod.apply(buttonRpc, arguments);
- }
- });
- box.show();
- },
- proxy: function () {if (tooltipRpc) tooltipRpc.callMethod.apply(tooltipRpc, arguments);}
- }, {
- startHeight: height,
- minWidth: width
- }, function (o, i, r) {
- buttonRpc = r;
- VK.Util.ss(obj = o, {height: height + 'px', width: width + 'px', position: 'relative', clear: 'both'});
- VK.Util.ss(buttonIfr = i, {height: height + 'px', width: width + 'px', overflow: 'hidden', zIndex: 150});
- });
- };
-
- VK.Widgets.Poll = function(objId, options, pollId) {
- var pData = VK.Util.getPageData();
- // if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
- if (!pollId) throw Error('No poll id passed');
- options = options || {};
- var params = {
- poll_id: pollId,
- url: options.pageUrl || pData.url || location.href,
- title: options.pageTitle || pData.title,
- description: options.pageDescription || pData.description
- };
- return VK.Widgets._constructor('widget_poll.php', objId, options, params, {}, {
- startHeight: 133,
- minWidth: 300,
- width: '100%'
- });
- };
-
- VK.Widgets.PagePoll = function(objId, options, page) {
- var pData = VK.Util.getPageData();
- // if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
- options = options || {};
- var params = {
- page: page || 0,
- norealtime: options.norealtime ? 1 : 0,
- poll_id: options.pollId || '',
- url: options.pageUrl || pData.url || location.href,
- title: options.pageTitle || pData.title,
- description: options.pageDescription || pData.description
- };
- return VK.Widgets._constructor('al_widget_poll.php', objId, options, params, {}, {
- startHeight: 133,
- minWidth: 300,
- width: '100%'
- });
- };
-
- VK.Widgets.Community = VK.Widgets.Group = function(objId, options, gid) {
- gid = parseInt(gid, 10);
- var RPC;
- if (!gid) {
- throw Error('No group_id passed');
- }
- options.mode = parseInt(options.mode, 10).toString();
- var params = {
- gid: gid,
- mode: (options.mode) ? options.mode : '0'
- };
- if (!options.width) {
- options.width = 200;
- }
- if (options.wall) {
- params.wall = options.wall;
- }
- if (!options.height) {
- options.height = 290;
- }
- if (options.wide) {
- params.wide = 1;
- if (options.width < 300) {
- options.width = 300;
- }
- }
-
- var cursorBack;
-
- function mouseup() {
- RPC.callMethod('mouseUp');
- return false;
- }
-
- function move(event) {
- RPC.callMethod('mouseMove', {screenY: event.screenY});
- return false;
- }
-
- return VK.Widgets._constructor('widget_community.php', objId, options, params, {
- showBox: function (url, props) {
- var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [props.width, props.height], {
- proxy: function () {
- rpc.callMethod.apply(rpc, arguments);
- }
- });
- box.show();
- },
- startDrag: function() {
- cursorBack = window.document.body.style.cursor;
- window.document.body.style.cursor = 'pointer';
- VK.Util.addEvent('mousemove', move);
- VK.Util.addEvent('mouseup', mouseup);
- },
- stopDrag: function() {
- window.document.body.style.cursor = cursorBack;
- VK.Util.removeEvent('mousemove', move);
- VK.Util.removeEvent('mouseup', mouseup);
- },
- auth: function() {
- VK.Auth.login(null, 1);
- }
- }, {
- minWidth: 120,
- width: '200',
- height: '290',
- startHeight: 200
- }, function (o, i, r) {
- RPC = r;
- });
- };
-
- VK.Widgets.Auth = function(objId, options) {
- var pData = VK.Util.getPageData();
- if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
- if (!options.width) {
- options.width = 200;
- }
- if (options.type) {
- type = 1;
- } else {
- type = 0;
- }
- return VK.Widgets._constructor('widget_auth.php', objId, options, {}, {makeAuth: function(data) {
- if (data.session) {
- VK.Auth._loadState = 'loaded';
- VK.Auth.setSession(data.session, 'connected');
- VK.Observer.publish('auth.loginStatus', {session: data.session, status: 'connected'});
- VK.Observer.unsubscribe('auth.loginStatus');
- }
- if (options.onAuth) {
- options.onAuth(data);
- } else {
- if (options.authUrl) {
- var href = options.authUrl;
- } else {
- var href = window.location.href;
- }
- if (href.indexOf('?') == -1) {
- href+='?';
- } else {
- href+='&';
- }
- var vars = [];
-
- for (var i in data) {
- if (i != 'session') vars.push(i+'='+decodeURIComponent(data[i]));
- }
- window.location.href = href + vars.join('&');
- }
- }}, {startHeight: 80});
- };
-
- VK.Widgets.Subscribe = function(objId, options, oid) {
- oid = parseInt(oid, 10);
- var RPC;
- if (!oid) {
- throw Error('No owner_id passed');
- }
- var params = {
- oid: oid
- };
- if (options.mode) {
- params.mode = options.mode;
- }
- if (options.soft) {
- params.soft = options.soft;
- }
-
- return VK.Widgets._constructor('widget_subscribe.php', objId, options, params, {
- showBox: function (url, props) {
- var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [props.width, props.height], {
- proxy: function () {
- rpc.callMethod.apply(rpc, arguments);
- }
- });
- box.show();
- },
- auth: function() {
- VK.Auth.login(null, 1);
- }
- }, {
- minWidth: 220,
- startHeight: 22,
- height: options.height || 22
- }, function (o, i, r) {
- RPC = r;
- });
- };
-
- VK.Widgets.Ads = function(objId, options, paramsExtra) {
- options = options || {};
- paramsExtra = paramsExtra || {};
- var params = {};
- var defaults = {};
- var funcs = {};
- var rpc;
- var iframe;
-
- var paramsExtraFix = {};
- for (var key in paramsExtra) {
- var keyFix = (inArray(key, ['ads_count', 'hash']) ? key : 'ads_' + key);
- paramsExtraFix[keyFix] = paramsExtra[key];
- }
-
- if (paramsExtraFix.ads_ad_unit_width === 'auto' || paramsExtraFix.ads_ad_unit_height === 'auto') {
- var obj = document.getElementById(objId);
- if (obj && obj.getBoundingClientRect) {
- obj.style.width = '100%';
- obj.style.height = '100%';
- var rect = obj.getBoundingClientRect();
- obj.style.width = '';
- obj.style.height = '';
- if (paramsExtraFix.ads_ad_unit_width === 'auto') {
- paramsExtraFix.ads_ad_unit_width = Math.floor(rect.right - rect.left);
- if (!paramsExtraFix.ads_ad_unit_width) {
- delete paramsExtraFix.ads_ad_unit_width;
- }
- }
- if (paramsExtraFix.ads_ad_unit_height === 'auto') {
- paramsExtraFix.ads_ad_unit_height = Math.floor(rect.bottom - rect.top);
- if (!paramsExtraFix.ads_ad_unit_height) {
- delete paramsExtraFix.ads_ad_unit_height;
- }
- }
- }
- if (paramsExtraFix.ads_ad_unit_width === 'auto') {
- delete paramsExtraFix.ads_ad_unit_width;
- }
- if (paramsExtraFix.ads_ad_unit_height === 'auto') {
- delete paramsExtraFix.ads_ad_unit_height;
- }
- }
-
- var width = (paramsExtraFix && parseInt(paramsExtraFix.ads_ad_unit_width) || 100);
- var height = (paramsExtraFix && parseInt(paramsExtraFix.ads_ad_unit_height) || 100);
- var handler = paramsExtraFix.ads_handler;
- var handlerFailOnly = !!paramsExtraFix.ads_handler_fail_only;
- delete paramsExtraFix.ads_handler;
- delete paramsExtraFix.ads_handler_fail_only;
-
- params.act = 'ads_web';
- params.url = location.href;
- VK.extend(params, paramsExtraFix);
-
- options.noDefaultParams = true;
- options.width = width;
- options.allowTransparency = true;
- defaults.startHeight = height;
- defaults.minWidth = width;
- funcs.adsOnInit = adsOnInit;
- funcs.adsCheckVisible = adsCheckVisible;
- funcs.adsAddEvents = adsAddEvents;
-
- return VK.Widgets._constructor('ads_rotate.php', objId, options, params, funcs, defaults, onDone);
-
- function adsOnInit() {
- if (options.onAdsReady) options.onAdsReady.apply(options.onAdsReady, Array.prototype.slice.call(arguments));
- var errorCode = arguments[0];
- if (!handlerFailOnly || errorCode <= 0) {
- adsEvalHandler(handler, errorCode);
- }
- }
- function adsCheckVisible(oneAdMaxWidth, oneAdMaxHeight) {
- var isVisibleAds = true;
- var windowWidth = Math.max(parseInt(window.innerWidth) || 0, parseInt(document.documentElement.clientWidth) || 0);
- var windowHeigth = Math.max(parseInt(window.innerHeight) || 0, parseInt(document.documentElement.clientHeight) || 0);
- if (iframe.getBoundingClientRect) {
- var iframeRect = iframe.getBoundingClientRect();
- var firstAdCenterX = iframeRect.left + oneAdMaxWidth * 0.5;
- var firstAdCenterY = iframeRect.top + oneAdMaxHeight * 0.5;
- isVisibleAds = (isVisibleAds && firstAdCenterX > 0 && firstAdCenterX < windowWidth);
- isVisibleAds = (isVisibleAds && firstAdCenterY > 0 && firstAdCenterY < windowHeigth);
- if (document.elementFromPoint && oneAdMaxWidth && oneAdMaxHeight) {
- isVisibleAds = (isVisibleAds && document.elementFromPoint(firstAdCenterX, firstAdCenterY) === iframe);
- }
- }
- rpc.callMethod('onAdsCheckVisibleResult', isVisibleAds);
- }
- function adsAddEvents(adsScriptVersion) {
- VK.Observer.subscribe('ads.onHasFocus', function(){ rpc.callMethod('onAdsHasFocus'); })
- VK.Observer.subscribe('ads.onFocusWindow', function(){ rpc.callMethod('onAdsFocusWindow'); })
- VK.Observer.subscribe('ads.onBlurWindow', function(){ rpc.callMethod('onAdsBlurWindow'); })
- VK.Observer.subscribe('ads.onMouseDownDocument', function(){ rpc.callMethod('onAdsMouseDownDocument'); })
- VK.Observer.subscribe('ads.onMouseDownDocumentAction', function(){ rpc.callMethod('onAdsMouseDownDocumentAction'); })
-
- adsAttachScript(adsScriptVersion);
- }
- function adsAttachScript(adsScriptVersion) {
- if (window.vk__adsLight) {
- if (vk__adsLight.onInit) {
- vk__adsLight.onInit();
- }
- } else {
- adsScriptVersion = parseInt(adsScriptVersion);
- var attachScriptFucn = (VK.Api && VK.Api.attachScript || VK.addScript);
- var base_domain = (options.base_domain || VK._protocol + '//vk.com');
- attachScriptFucn(base_domain + '/js/al/aes_light.js?' + adsScriptVersion);
- }
- }
- function adsEvalHandler(handler) {
- try {
- if (!handler) {
- return;
- }
- var func = false;
- if (isFunction(handler)) {
- func = handler;
- } else if (isString(handler)) {
- var handlerFuncs = handler.split('.');
- func = window;
- for (var i = 0, len = handlerFuncs.length; i < len; i++) {
- func = func[handlerFuncs[i]];
- if (!func) {
- break;
- }
- }
- if (!func) {
- var handlerResult = (new Function(handler))();
- if (isFunction(handlerResult)) {
- func = handlerResult;
- }
- }
- }
- if (func) {
- var args = Array.prototype.slice.call(arguments, 1);
- func.apply(func, args);
- }
- } catch (e) {
- try {
- console.error(e);
- } catch (e2) {}
- }
- function isFunction(obj) {
- return Object.prototype.toString.call(obj) === '[object Function]';
- }
- function isString(obj) {
- return Object.prototype.toString.call(obj) === '[object String]';
- }
- }
- function indexOf(arr, value, from) {
- for (var i = from || 0, l = (arr || []).length; i < l; i++) {
- if (arr[i] == value) return i;
- }
- return -1;
- }
- function inArray(value, arr) {
- return indexOf(arr, value) != -1;
- }
- function onDone(o, i, r) {
- iframe = i;
- rpc = r;
- }
- };
-
- VK.Widgets._constructor = function(widgetUrl, objId, options, params, funcs, defaults, onDone, widgetId, iter) {
- var obj = document.getElementById(objId);
- widgetId = widgetId || (++VK.Widgets.count);
-
- if (!obj) {
- iter = iter || 0;
- if (iter > 10) {
- throw Error('VK.Widgets: object #' + objId + ' not found.');
- }
- setTimeout(function () {
- VK.Widgets._constructor(widgetUrl, objId, options, params, funcs, defaults, onDone, widgetId, iter + 1);
- }, 500);
- return widgetId;
- }
-
- var ifr, base_domain, width, url, urlQueryString, encodedParam, rpc, iframe, i;
- options = options || {};
- defaults = defaults || {};
- funcs = funcs || {};
-
- base_domain = options.base_domain || VK._protocol + '//vk.com';
- width = (options.width == 'auto') ? obj.clientWidth || '100%' : parseInt(options.width, 10);
-
- if (options.height) {
- params.height = options.height;
- obj.style.height = options.height + 'px';
- } else {
- obj.style.height = (defaults.startHeight || 200) + 'px';
- }
-
- width = width ? (Math.max(defaults.minWidth || 200, Math.min(10000, width)) + 'px') : '100%';
-
- if (!params.url) {
- params.url = options.pageUrl || location.href.replace(/#.*$/, '');
- }
- url = base_domain + '/' + widgetUrl;
- urlQueryString = '';
- if (!options.noDefaultParams) {
- urlQueryString += '&app=' + (VK._apiId || '0') + '&width=' + width
- }
- if (VK._iframeAppWidget) {
- params.iframe_app = 1;
- }
- for (i in params) {
- if (i == 'title' && params[i].length > 80) params[i] = params[i].substr(0, 80)+'...';
- if (i == 'description' && params[i].length > 160) params[i] = params[i].substr(0, 160)+'...';
- if (typeof(params[i]) == 'number') {
- encodedParam = params[i];
- } else {
- try {
- encodedParam = encodeURIComponent(params[i]);
- } catch (e) {
- encodedParam = '';
- }
- }
- urlQueryString += '&' + i + '=' + encodedParam;
- }
- urlQueryString += '&' + (+new Date()).toString(16);
- url += '?' + urlQueryString.substr(1);
-
- obj.style.width = width;
- VK.Widgets.loading(obj, true);
-
- funcs.publish = function () {
- var args = Array.prototype.slice.call(arguments);
- args.push(widgetId);
- VK.Observer.publish.apply(VK.Observer, args);
- };
- funcs.onInit = function() {
- VK.Widgets.loading(obj, false);
- if (funcs.onReady) funcs.onReady();
- if (options.onReady) options.onReady();
- }
- funcs.resize = function(e, cb) {
- obj.style.height = e + 'px';
- var el = document.getElementById('vkwidget' + widgetId);
- if (el) {
- el.style.height = e + 'px';
- }
- }
- funcs.resizeWidget = function(newWidth, newHeight) {
- newWidth = parseInt(newWidth);
- newHeight = parseInt(newHeight);
- var widgetElem = document.getElementById('vkwidget' + widgetId);
- if (isFinite(newWidth)) {
- obj.style.width = newWidth + 'px';
- if (widgetElem) {
- widgetElem.style.width = newWidth + 'px';
- }
- }
- if (isFinite(newHeight)) {
- obj.style.height = newHeight + 'px';
- if (widgetElem) {
- widgetElem.style.height = newHeight + 'px';
- }
- }
- if (options.onResizeWidget) options.onResizeWidget();
- }
- rpc = VK.Widgets.RPC[widgetId] = new fastXDM.Server(funcs, function(origin) {
- if (!origin) return true;
- origin = origin.toLowerCase();
- return (origin.indexOf('.vk.com') != -1 || origin.indexOf('/vk.com') != -1);
- });
- iframe = VK.Widgets.RPC[widgetId].append(obj, {
- src: url,
- width: (width.indexOf('%') != -1) ? width : (parseInt(width) || width),
- height: defaults.startHeight || '100%',
- scrolling: 'no',
- id: 'vkwidget' + widgetId,
- allowTransparency: options.allowTransparency || false,
- style: {
- overflow: 'hidden'
- }
- });
- onDone && setTimeout(function () {onDone(obj, iframe || obj.firstChild, rpc);}, 10);
- return widgetId;
- };
-}
-
-if (!VK.Util) {
-VK.Util = {
- getPageData: function () {
- if (!VK._pData) {
- var metas = document.getElementsByTagName('meta'), pData = {}, keys = ['description', 'title', 'url', 'image', 'app_id'], metaName;
- for (var i in metas) {
- if (!metas[i].getAttribute) continue;
- if (metas[i].getAttribute && ((metaName = metas[i].getAttribute('name')) || (metaName = metas[i].getAttribute('property')))) {
- for (var j in keys) {
- if (metaName == keys[j] || metaName == 'og:'+keys[j] || metaName == 'vk:'+keys[j]) {
- pData[keys[j]] = metas[i].content;
- }
- }
- }
- }
- if (pData.app_id && !VK._apiId) {
- VK._apiId = pData.app_id;
- }
- pData.title = pData.title || document.title || '';
- pData.description = pData.description || '';
- pData.image = pData.image || '';
- if (!pData.url && VK._iframeAppWidget && VK._apiId) {
- pData.url = '/app' + VK._apiId;
- if (VK._browserHash) {
- pData.url += VK._browserHash
- }
- }
- var loc = location.href.replace(/#.*$/, '');
- if (!pData.url || !pData.url.indexOf(loc)) {
- pData.url = loc;
- }
- VK._pData = pData;
- }
- return VK._pData;
- },
- getXY: function (obj, fixed) {
- if (!obj || obj === undefined) return;
- var left = 0, top = 0;
- if (obj.offsetParent) {
- do {
- left += obj.offsetLeft;
- top += obj.offsetTop;
- if (fixed) {
- left -= obj.scrollLeft;
- top -= obj.scrollTop;
- }
- } while (obj = obj.offsetParent);
- }
- if (fixed) {
- top += window.pageYOffset || window.scrollNode && scrollNode.scrollTop || document.documentElement.scrollTop;
- }
- return [left,top];
- },
- Box: function (src, sizes, fnc, options) {
- fnc = fnc || {};
- var rpc = new fastXDM.Server(VK.extend(fnc, {
- onInit: function () {
- iframe.style.background = 'transparent';
- },
- hide: function () {
- iframe.style.display = 'none';
- },
- destroy: function () {
- try {
- iframe.src = 'about: blank;';
- } catch (e) {}
- iframe.parentNode.removeChild(iframe);
- },
- resize: function (w, h) {
- sizes[0] = w;
- sizes[1] = h;
- VK.Util.ss(iframe, {width: sizes[0] + 'px', height: sizes[1] + 'px'});
- updateCoords();
- }
- }, true)),
- iframe = rpc.append(document.body, {
- src: src,
- scrolling: 'no',
- allowTransparency: true,
- style: {position: 'absolute', left: '50%', zIndex: 1002, background: VK._protocol + '//vk.com/images/upload.gif center center no-repeat transparent', padding: '0', border: '0', width: sizes[0] + 'px', height: sizes[1] + 'px', overflow: 'hidden'}
- }),
- updateCoords = function (scrollTop, height) {
- height = Math.min(1000, height || (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight)));
- scrollTop = scrollTop || Math.max(parseInt(window.pageYOffset, 10) || 0, document.documentElement.scrollTop, document.body.scrollTop);
- var top = Math.max(0, scrollTop + (height - sizes[1]) / 3);
- VK.Util.ss(iframe, {'top': top + 'px', margin: '0 0 0 ' + (-sizes[0]/2) + 'px'});
- };
- return {
- show: function (scrollTop, height) {
- updateCoords(scrollTop, height);
- iframe.style.display = 'block';
- },
- hide: function () {
- iframe.style.display = 'none';
- },
- iframe: iframe,
- rpc: rpc
- }
- },
- addEvent: function(type, func) {
- if (window.document.addEventListener) {
- window.document.addEventListener(type, func, false);
- } else if (window.document.attachEvent) {
- window.document.attachEvent('on'+type, func);
- }
- },
- removeEvent: function(type, func) {
- if (window.document.removeEventListener) {
- window.document.removeEventListener(type, func, false);
- } else if (window.document.detachEvent) {
- window.document.detachEvent('on'+type, func);
- }
- },
- ss: function (el, styles) {VK.extend(el.style, styles, true);}
-};
-}
-
-// Init asynchronous library loading
-window.vkAsyncInit && setTimeout(vkAsyncInit, 0);
-
-if (window.vkAsyncInitCallbacks && vkAsyncInitCallbacks.length) {
- setTimeout(function() {
- var callback;
- while (callback = vkAsyncInitCallbacks.pop()) {
- try {
- callback();
- } catch(e) {
- try {
- console.error(e);
- } catch (e2) {}
- }
- }
- }, 0);
-}
\ No newline at end of file
+(function(w) {
+if (w.fastXDM) return;
+
+var handlers = {};
+var onEnvLoad = [];
+var env = {};
+
+// Key generation
+function genKey() {
+ var key = '';
+ for (i=0;i<5;i++) key += Math.ceil(Math.random()*15).toString(16);
+ return key;
+}
+function waitFor(obj, prop, func, self, count) {
+ if (obj[prop]) {
+ func.apply(self);
+ } else {
+ count = count || 0;
+ if (count < 1000) setTimeout(function() {
+ waitFor(obj, prop, func, self, count + 1)
+ }, 0);
+ }
+}
+function attachScript(url) {
+ setTimeout(function() {
+ var newScript = document.createElement('script');
+ newScript.type = 'text/javascript';
+ newScript.src = url || w.fastXDM.helperUrl;
+ waitFor(document, 'body', function() {
+ document.getElementsByTagName('HEAD')[0].appendChild(newScript);
+ });
+ }, 0);
+}
+
+function walkVar(value, clean) {
+ switch (typeof value) {
+ case 'string':
+ if (clean) {
+ return value.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''');
+ }
+ return value.replace(/'/g, '\'').replace(/"/g, '"').replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&');
+
+ case 'object':
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
+ newValue = [];
+ for (var i = 0; i < value.length; i++) {
+ newValue[i] = walkVar(value[i], clean);
+ }
+ } else {
+ for (var k in value) {
+ newValue = {};
+ if (Object.hasOwnProperty.call(value, k)) {
+ newValue[k] = walkVar(value[k], clean);
+ }
+ }
+ }
+ default:
+ newValue = value;
+ }
+
+ return newValue;
+}
+
+// Env functions
+function getEnv(callback, self) {
+ if (env.loaded) {
+ callback.apply(self, [env]);
+ } else {
+ onEnvLoad.push([self, callback]);
+ }
+}
+
+function envLoaded() {
+ env.loaded = true;
+ var i = onEnvLoad.length;
+ while (i--) {
+ onEnvLoad[i][1].apply(onEnvLoad[i][0], [env]);
+ }
+}
+
+function applyMethod(strData, self) {
+ getEnv(function(env) {
+ var data = env.json.parse(strData);
+ if (data[0]) {
+ if (!data[1]) data[1] = [];
+ var i = data[1].length;
+ while (i--) {
+ if (data[1][i]._func) {
+ var funcNum = data[1][i]._func;
+ data[1][i] = function() {
+ var args = Array.prototype.slice.call(arguments);
+ args.unshift('_func'+funcNum);
+ self.callMethod.apply(self, args);
+ }
+ } else if (self.options.safe) {
+ data[1][i] = walkVar(data[1][i], true);
+ }
+ }
+ setTimeout(function() {
+ if (!self.methods[data[0]]) {
+ throw Error('fastXDM: Method ' + data[0] + ' is undefined');
+ }
+ self.methods[data[0]].apply(self, data[1]);
+ }, 0);
+ }
+ });
+}
+
+// XDM object
+w.fastXDM = {
+ _id: 0,
+ helperUrl: ((location.protocol === 'https:') ? 'https:' : 'http:') + '//vk.com/js/api/xdmHelper.js',
+
+ Server: function(methods, filter, options) {
+ this.methods = methods || {};
+ this.id = w.fastXDM._id++;
+ this.options = options || {};
+ this.filter = filter;
+ this.key = genKey();
+ this.methods['%init%'] = this.methods.__fxdm_i = function() {
+ w.fastXDM.run(this.id);
+ if (this.methods.onInit) this.methods.onInit();
+ };
+ this.frameName = 'fXD'+this.key;
+ this.server = true;
+ handlers[this.key] = [applyMethod, this];
+ },
+
+ Client: function(methods, options) {
+ this.methods = methods || {};
+ this.id = w.fastXDM._id++;
+ this.options = options || {};
+ w.fastXDM.run(this.id);
+ if (window.name.indexOf('fXD') === 0) {
+ this.key = window.name.substr(3);
+ } else {
+ throw Error('Wrong window.name property.');
+ }
+ this.caller = window.parent;
+ handlers[this.key] = [applyMethod, this];
+ this.client = true;
+
+ w.fastXDM.on('helper', function() {
+ w.fastXDM.onClientStart(this);
+ }, this);
+
+ getEnv(function(env) {
+ env.send(this, env.json.stringify(['%init%']));
+ var methods = this.methods;
+ setTimeout(function() {
+ if (methods.onInit) methods.onInit();
+ }, 0);
+ }, this);
+ },
+
+ onMessage: function(e) {
+ if (!e.data) return false;
+ var data = e.data;
+ if (typeof data != 'string' && !(data instanceof String)) return false;
+ var key = data.substr(0, 5);
+ if (handlers[key]) {
+ var self = handlers[key][1];
+ if (self && (!self.filter || self.filter(e.origin))) {
+ handlers[key][0](e.data.substr(6), self);
+ }
+ }
+ },
+
+ setJSON: function(json) {
+ env.json = json;
+ },
+
+ getJSON: function(callback) {
+ if (!callback) return env.json;
+ getEnv(function(env) {
+ callback(env.json);
+ });
+ },
+
+ setEnv: function(exEnv) {
+ var i;
+ for (i in exEnv) {
+ env[i] = exEnv[i];
+ }
+ envLoaded();
+ },
+
+ _q: {},
+
+ on: function(key, act, self) {
+ if (!this._q[key]) this._q[key] = [];
+ if (this._q[key] == -1) {
+ act.apply(self);
+ } else {
+ this._q[key].push([act, self]);
+ }
+ },
+
+ run: function(key) {
+ var len = (this._q[key] || []).length;
+ if (this._q[key] && len > 0) {
+ for (var i = 0; i < len; i++) this._q[key][i][0].apply(this._q[key][i][1]);
+ }
+ this._q[key] = -1;
+ },
+
+ waitFor: waitFor
+}
+
+w.fastXDM.Server.prototype.start = function(obj, count) {
+ if (obj.contentWindow) {
+ this.caller = obj.contentWindow;
+ this.frame = obj;
+
+ w.fastXDM.on('helper', function() {
+ w.fastXDM.onServerStart(this);
+ }, this);
+
+ } else { // Opera old versions
+ var self = this;
+ count = count || 0;
+ if (count < 50) setTimeout(function() {
+ self.start.apply(self, [obj, count+1]);
+ }, 100);
+ }
+}
+
+w.fastXDM.Server.prototype.destroy = function() {
+ handlers.splice(handlers.indexOf(this.key), 1);
+}
+
+function extend(obj1, obj2){
+ for (var i in obj2) {
+ if (obj1[i] && typeof(obj1[i]) == 'object') {
+ extend(obj1[i], obj2[i])
+ } else {
+ obj1[i] = obj2[i];
+ }
+ }
+}
+
+w.fastXDM.Server.prototype.append = function(obj, options) {
+ var div = document.createElement('DIV');
+ div.innerHTML = '';
+ var frame = div.firstChild;
+ var self = this;
+ setTimeout(function() {
+ frame.frameBorder = '0';
+ if (options) extend(frame, options);
+ obj.insertBefore(frame, obj.firstChild);
+ self.start(frame);
+ }, 0);
+ return frame;
+}
+
+w.fastXDM.Client.prototype.callMethod = w.fastXDM.Server.prototype.callMethod = function() {
+ var args = Array.prototype.slice.call(arguments);
+ var method = args.shift();
+ var i = args.length;
+ while (i--) {
+ if (typeof(args[i]) == 'function') {
+ this.funcsCount = (this.funcsCount || 0) + 1;
+ var func = args[i];
+ var funcName = '_func' + this.funcsCount;
+ this.methods[funcName] = function() {
+ func.apply(this, arguments);
+ delete this.methods[funcName];
+ }
+ args[i] = {_func: this.funcsCount};
+ } else if (this.options.safe) {
+ args[i] = walkVar(args[i], false);
+ }
+ }
+ waitFor(this, 'caller', function() {
+ w.fastXDM.on(this.id, function() {
+ getEnv(function(env) {
+ env.send(this, env.json.stringify([method, args]));
+ }, this);
+ }, this);
+ }, this);
+}
+
+if (w.JSON && typeof(w.JSON) == 'object' && w.JSON.parse && w.JSON.stringify && w.JSON.stringify({a:[1,2,3]}).replace(/ /g, '') == '{"a":[1,2,3]}') {
+ env.json = {parse: w.JSON.parse, stringify: w.JSON.stringify};
+} else {
+ w.fastXDM._needJSON = true;
+}
+
+// PostMessage cover
+if (w.postMessage) {
+ env.protocol = 'p';
+ env.send = function(xdm, strData) {
+ var win = (xdm.frame ? xdm.frame.contentWindow : xdm.caller);
+ win.postMessage(xdm.key+':'+strData, "*");
+ }
+ if (w.addEventListener) {
+ w.addEventListener("message", w.fastXDM.onMessage, false);
+ } else {
+ w.attachEvent("onmessage", w.fastXDM.onMessage);
+ }
+
+ if (w.fastXDM._needJSON) {
+ w.fastXDM._onlyJSON = true;
+ attachScript();
+ } else {
+ envLoaded();
+ }
+} else {
+ attachScript();
+}
+})(window);
+
+
+if (!window.VK) window.VK = {};
+
+
+/*
+ * Based on JavaScript implementation of the RSA Data Security, Inc. MD5 Message
+ * Copyright (C) Paul Johnston 1999 - 2009
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ */
+if(!VK.MD5){VK.MD5=function(n){var j=function(o,r){var q=(o&65535)+(r&65535),p=(o>>16)+(r>>16)+(q>>16);return(p<<16)|(q&65535)},g=function(o,p){return(o<' +
- ' ' +
- '' +
- ' ' +
- '>>6)&31),128|(o&63))}else{if(o<=65535){q+=String.fromCharCode(224|((o>>>12)&15),128|((o>>>6)&63),128|(o&63))}else{if(o<=2097151){q+=String.fromCharCode(240|((o>>>18)&7),128|((o>>>12)&63),128|((o>>>6)&63),128|(o&63))}}}}}return q},e=function(p){var o=Array(p.length>>2),r,q;for(r=0,q=o.length;r>5]|=(p.charCodeAt(r/8)&255)<<(r%32)}return o},l=function(p){var o="";for(var r=0,q=p.length*32;r
>5]>>>(r%32))&255)}return o},d=function(o){return l(b(e(o),o.length*8))},i=function(q){var t="0123456789abcdef",p="",o;for(var s=0,r=q.length;s
'
+ );
+ el.innerHTML = html;
+ el.style.width = el.childNodes[0].offsetWidth + 'px';
+ },
+ _change: function(state, index) {
+ var row = document.getElementById('openapi_UI_' + index).rows[0];
+ var elems = [row.cells[0].firstChild.firstChild, row.cells[2].firstChild.firstChild];
+ for (var i = 0; i < 2; ++i) {
+ var elem = elems[i];
+ if (state === 0) {
+ elem.style.backgroundColor = '#6D8DB1';
+ elem.style.borderTopColor = '#7E9CBC';
+ elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#5C82AB';
+ } else if (state == 1) {
+ elem.style.backgroundColor = '#7693B6';
+ elem.style.borderTopColor = '#88A4C4';
+ elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#6088B4';
+ } else if (state == 2) {
+ elem.style.backgroundColor = '#6688AD';
+ elem.style.borderBottomColor = '#7495B8';
+ elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderTopColor = '#51779F';
+ }
+ }
+ if (state === 0 || state == 2) {
+ row.cells[2].firstChild.style.backgroundPosition = '0px -42px';
+ } else if (state == 1) {
+ row.cells[2].firstChild.style.backgroundPosition = '0px -63px';
+ }
+ }
+};
+}
+
+if (!VK.XDM) {
+VK.XDM = {
+ remote: null,
+ init: function() {
+ if (this.remote) return false;
+ var url = VK._domain.api + VK._path.proxy;
+ this.remote = new fastXDM.Server({
+ onInit: function() {
+ VK.xdReady = true;
+ VK.Observer.publish('xdm.init');
+ }
+ });
+
+ this.remote.append(document.getElementById(VK._rootId), {
+ src: url
+ });
+ },
+ xdHandler: function(code) {
+ try {
+ eval('VK.' + code);
+ } catch(e) {}
+ }
+};
+}
+
+if (!VK.Observer) {
+VK.Observer = {
+ _subscribers: function() {
+ if (!this._subscribersMap) {
+ this._subscribersMap = {};
+ }
+ return this._subscribersMap;
+ },
+ publish: function(eventName) {
+ var
+ args = Array.prototype.slice.call(arguments),
+ eventName = args.shift(),
+ subscribers = this._subscribers()[eventName],
+ i, j;
+
+ if (!subscribers) return;
+
+ for (i = 0, j = subscribers.length; i < j; i++) {
+ if (subscribers[i] != null) {
+ subscribers[i].apply(this, args);
+ }
+ }
+ },
+ subscribe: function(eventName, handler) {
+ var
+ subscribers = this._subscribers();
+
+ if (typeof handler != 'function') return false;
+
+ if (!subscribers[eventName]) {
+ subscribers[eventName] = [handler];
+ } else {
+ subscribers[eventName].push(handler);
+ }
+ },
+ unsubscribe: function(eventName, handler) {
+ var
+ subscribers = this._subscribers()[eventName],
+ i, j;
+
+ if (!subscribers) return false;
+ if (typeof handler == 'function') {
+ for (i = 0, j = subscribers.length; i < j; i++) {
+ if (subscribers[i] == handler) {
+ subscribers[i] = null;
+ }
+ }
+ } else {
+ delete this._subscribers()[eventName];
+ }
+ }
+};
+}
+
+if (!VK.Widgets) {
+ VK.Widgets = {};
+
+ VK.Widgets.count = 0;
+ VK.Widgets.RPC = {};
+
+ VK.Widgets.loading = function(obj, enabled) {
+ obj.style.background = enabled ? 'url("' + VK._protocol + '//vk.com/images/upload.gif") center center no-repeat transparent' : 'none';
+ };
+
+ VK.Widgets.Comments = function(objId, options, page) {
+ var pData = VK.Util.getPageData();
+ if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
+ options = options || {};
+ var params = {
+ limit: options.limit || 10,
+ height: options.height || 0,
+ mini: options.mini === undefined ? 'auto' : options.mini,
+ norealtime: options.norealtime ? 1 : 0
+ }, mouseup = function() {
+ rpc.callMethod('mouseUp');
+ return false;
+ }, move = function(event) {
+ rpc.callMethod('mouseMove', {screenY: event.screenY});
+ }, iframe, rpc;
+
+ if (options.browse) { // browse all comments
+ params.browse = 1;
+ params.replies = options.replies || 0;
+ } else { // page
+ var url = options.pageUrl || pData.url;
+ if (url.substr(0, 1) == '/') {
+ url = (location.protocol + '//' + location.host) + url;
+ }
+ VK.extend(params, {
+ page: page || 0,
+ status_publish: options.autoPublish === undefined ? 1 : options.autoPublish,
+ attach: options.attach === undefined ? '*' : (options.attach ? options.attach : ''),
+ url: url,
+ title: options.pageTitle || pData.title,
+ description: options.pageDescription || pData.description,
+ image: options.pageImage || pData.image
+ });
+ }
+ if (options.onChange) { // DEPRECATED
+ VK.Observer.subscribe('widgets.comments.new_comment', options.onChange);
+ VK.Observer.subscribe('widgets.comments.delete_comment', options.onChange);
+ }
+
+ return VK.Widgets._constructor('widget_comments.php', objId, options, params, {
+ showBox: function(url, props) {
+ var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com') + '/' + url, [], {
+ proxy: function() {
+ rpc.callMethod.apply(rpc, arguments);
+ }
+ });
+ box.show();
+ },
+ startDrag: function() {
+ cursorBack = window.document.body.style.cursor;
+ window.document.body.style.cursor = 'pointer';
+ VK.Util.addEvent('mousemove', move);
+ VK.Util.addEvent('mouseup', mouseup);
+ },
+ stopDrag: function() {
+ window.document.body.style.cursor = cursorBack;
+ VK.Util.removeEvent('mousemove', move);
+ VK.Util.removeEvent('mouseup', mouseup);
+ }
+ }, {
+ startHeight: 133,
+ minWidth: 300,
+ width: '100%'
+ }, function(o, i, r) {iframe = i; rpc = r;});
+ };
+
+ VK.Widgets.CommentsBrowse = function(objId, options) {
+ options = options || {};
+ options.browse = 1;
+ return VK.Widgets.Comments(objId, options);
+ };
+
+ VK.Widgets.Recommended = function(objId, options) {
+ var pData = VK.Util.getPageData();
+ if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
+ options = options || {};
+ var params = {
+ limit: options.limit || 5,
+ max: options.max || 0,
+ sort: options.sort || 'friend_likes',
+ verb: options.verb || 0,
+ period: options.period || 'week',
+ target: options.target || 'parent'
+ };
+ return VK.Widgets._constructor('widget_recommended.php', objId, options, params, {}, {
+ startHeight: (90 + params.limit * 30),
+ minWidth: 150,
+ width: '100%'
+ });
+ };
+
+ VK.Widgets.Post = function(objId, ownerId, postId, hash, options) {
+ options = options || {};
+ var params = {
+ owner_id: ownerId,
+ post_id: postId,
+ hash: hash || '',
+ width: options.width || 500
+ }, iframe, rpc, cursorBack;
+ return VK.Widgets._constructor('widget_post.php', objId, options, params, {
+ showBox: function(url, props) {
+ var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com') + '/' + url, [], {
+ proxy: function() {
+ rpc.callMethod.apply(rpc, arguments);
+ }
+ });
+ box.show();
+ },
+ startDrag: function() {
+ cursorBack = window.document.body.style.cursor;
+ window.document.body.style.cursor = 'pointer';
+ },
+ stopDrag: function() {
+ window.document.body.style.cursor = cursorBack;
+ }
+ }, {
+ startHeight: 90,
+ minWidth: 250,
+ width: '100%'
+ }, function(o, i, r) {iframe = i; rpc = r;});
+ };
+
+ VK.Widgets.Like = function(objId, options, page) {
+ var pData = VK.Util.getPageData();
+ if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
+ options = VK.extend(options || {}, {allowTransparency: true});
+ if (options.type == 'button' || options.type == 'vertical' || options.type == 'mini') delete options.width;
+ var
+ type = (options.type == 'full' || options.type == 'button' || options.type == 'vertical' || options.type == 'mini') ? options.type : 'full',
+ width = type == 'full' ? Math.max(200, options.width || 350) : (type == 'button' ? 180 : (type == 'mini' ? 100 : 41)),
+ btnHeight = parseInt(options.height, 10) || 22,
+ height = type == 'vertical' ? (2 * btnHeight + 7) : (type == 'full' ? btnHeight + 1 : btnHeight),
+ params = {
+ page: page || 0,
+ url: options.pageUrl || pData.url,
+ type: type,
+ verb: options.verb == 1 ? 1 : 0,
+ color: options.color || '',
+ title: options.pageTitle || pData.title,
+ description: options.pageDescription || pData.description,
+ image: options.pageImage || pData.image,
+ text: (options.text || '').substr(0, 140),
+ h: btnHeight
+ },
+ ttHere = options.ttHere || false,
+ isOver = false,
+ obj, buttonIfr, buttonRpc, tooltipIfr, tooltipRpc, checkTO, statsBox;
+
+ function showTooltip(force) {
+ if ((!isOver && !force) || !tooltipRpc) return;
+ if (!tooltipIfr || !tooltipRpc || tooltipIfr.style.display != 'none' && tooltipIfr.getAttribute('vkhidden') != 'yes') return;
+ var scrollTop = options.getScrollTop ? options.getScrollTop() : (document.body.scrollTop || document.documentElement.scrollTop || 0);
+ var objPos = VK.Util.getXY(obj, options.fixed);
+ var startY = ttHere ? 0 : objPos[1];
+ if (scrollTop > objPos[1] - 120 && options.tooltipPos != 'top' || type == 'vertical' || options.tooltipPos == 'bottom') {
+ tooltipIfr.style.top = (startY + height + 2) + 'px';
+ tooltipRpc.callMethod('show', false);
+ } else {
+ tooltipIfr.style.top = (startY - 125) + 'px';
+ tooltipRpc.callMethod('show', true);
+ }
+ VK.Util.ss(tooltipIfr, {left: ((ttHere ? 0 : objPos[0]) - (type == 'vertical' || type == 'mini' ? 36 : 2)) + 'px', display: 'block', opacity: 1, filter: 'none'});
+ tooltipIfr.setAttribute('vkhidden', 'no');
+ isOver = true;
+ }
+
+ function hideTooltip(force) {
+ if ((isOver && !force) || !tooltipRpc) return;
+ tooltipRpc.callMethod('hide');
+ buttonRpc.callMethod('hide');
+ setTimeout(function() {
+ tooltipIfr.style.display = 'none'
+ }, 400);
+ }
+
+ function handleStatsBox(act) {
+ hideTooltip(true);
+ statsBox = VK.Util.Box(buttonIfr.src + '&act=a_stats_box&widget_width=620');
+ statsBox.show();
+ }
+
+ return VK.Widgets._constructor('widget_like.php', objId, options, params, {
+ initTooltip: function(counter) {
+ tooltipRpc = new fastXDM.Server({
+ onInit: counter ? function() {showTooltip(true)} : function() {},
+ proxy: function() {
+ buttonRpc.callMethod.apply(buttonRpc, arguments);
+ },
+ showBox: function(url, props) {
+ var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [props.width, props.height], {
+ proxy: function() {
+ tooltipRpc.callMethod.apply(tooltipRpc, arguments);
+ }
+ });
+ box.show();
+ },
+ statsBox: handleStatsBox
+ }, false, {safe: true});
+ tooltipIfr = tooltipRpc.append(ttHere ? obj : document.body, {
+ src: buttonIfr.src + '&act=a_like_tooltip',
+ scrolling: 'no',
+ allowTransparency: true,
+ id: buttonIfr.id + '_tt',
+ style: {position: 'absolute', padding: 0, display: 'block', opacity: 0.01, filter: 'alpha(opacity=1)', border: '0', width: '238px', height: '124px', zIndex: 5000, overflow: 'hidden'}
+ });
+ tooltipIfr.setAttribute('vkhidden', 'yes');
+
+ obj.onmouseover = tooltipIfr.onmouseover = function() {
+ clearTimeout(checkTO);
+ isOver = true;
+ };
+ obj.onmouseout = tooltipIfr.onmouseout = function() {
+ clearTimeout(checkTO);
+ isOver = false;
+ checkTO = setTimeout(function() {hideTooltip(); }, 200);
+ };
+ },
+ statsBox: handleStatsBox,
+ showTooltip: showTooltip,
+ hideTooltip: hideTooltip,
+ showBox: function(url, props) {
+ var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [], {
+ proxy: function() {
+ buttonRpc.callMethod.apply(buttonRpc, arguments);
+ }
+ });
+ box.show();
+ },
+ proxy: function() {if (tooltipRpc) tooltipRpc.callMethod.apply(tooltipRpc, arguments);}
+ }, {
+ startHeight: height,
+ minWidth: width
+ }, function(o, i, r) {
+ buttonRpc = r;
+ VK.Util.ss(obj = o, {height: height + 'px', width: width + 'px', position: 'relative', clear: 'both'});
+ VK.Util.ss(buttonIfr = i, {height: height + 'px', width: width + 'px', overflow: 'hidden', zIndex: 150});
+ });
+ };
+
+ VK.Widgets.Poll = function(objId, options, pollId) {
+ var pData = VK.Util.getPageData();
+ // if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
+ if (!pollId) throw Error('No poll id passed');
+ options = options || {};
+ var params = {
+ poll_id: pollId,
+ url: options.pageUrl || pData.url || location.href,
+ title: options.pageTitle || pData.title,
+ description: options.pageDescription || pData.description
+ };
+ return VK.Widgets._constructor('widget_poll.php', objId, options, params, {}, {
+ startHeight: 133,
+ minWidth: 300,
+ width: '100%'
+ });
+ };
+
+ VK.Widgets.PagePoll = function(objId, options, page) {
+ var pData = VK.Util.getPageData();
+ // if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
+ options = options || {};
+ var params = {
+ page: page || 0,
+ norealtime: options.norealtime ? 1 : 0,
+ poll_id: options.pollId || '',
+ url: options.pageUrl || pData.url || location.href,
+ title: options.pageTitle || pData.title,
+ description: options.pageDescription || pData.description
+ };
+ return VK.Widgets._constructor('al_widget_poll.php', objId, options, params, {}, {
+ startHeight: 133,
+ minWidth: 300,
+ width: '100%'
+ });
+ };
+
+ VK.Widgets.Community = VK.Widgets.Group = function(objId, options, gid) {
+ gid = parseInt(gid, 10);
+ var RPC;
+ if (!gid) {
+ throw Error('No group_id passed');
+ }
+ options.mode = parseInt(options.mode, 10).toString();
+ var params = {
+ gid: gid,
+ mode: (options.mode) ? options.mode : '0'
+ };
+ if (!options.width) options.width = 200;
+ if (options.wall) params.wall = options.wall;
+ params.color1 = options.color1 || '';
+ params.color2 = options.color2 || '';
+ params.color3 = options.color3 || '';
+ params.class_name = options.class_name || '';
+ if (options.no_head) params.no_head = 1;
+ if (!options.height) options.height = 290;
+ if (options.wide) {
+ params.wide = 1;
+ if (options.width < 300) {
+ options.width = 300;
+ }
+ }
+
+ var cursorBack;
+
+ function mouseup() {
+ RPC.callMethod('mouseUp');
+ return false;
+ }
+
+ function move(event) {
+ RPC.callMethod('mouseMove', {screenY: event.screenY});
+ return false;
+ }
+
+ return VK.Widgets._constructor('widget_community.php', objId, options, params, {
+ showBox: function(url, props) {
+ var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [], {
+ proxy: function() {
+ rpc.callMethod.apply(rpc, arguments);
+ }
+ });
+ box.show();
+ },
+ startDrag: function() {
+ cursorBack = window.document.body.style.cursor;
+ window.document.body.style.cursor = 'pointer';
+ VK.Util.addEvent('mousemove', move);
+ VK.Util.addEvent('mouseup', mouseup);
+ },
+ stopDrag: function() {
+ window.document.body.style.cursor = cursorBack;
+ VK.Util.removeEvent('mousemove', move);
+ VK.Util.removeEvent('mouseup', mouseup);
+ },
+ auth: function() {
+ VK.Auth.login(null, 1);
+ }
+ }, {
+ minWidth: 120,
+ width: '200',
+ height: '290',
+ startHeight: 200
+ }, function(o, i, r) {
+ RPC = r;
+ });
+ };
+
+ VK.Widgets.Auth = function(objId, options) {
+ var pData = VK.Util.getPageData();
+ if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');
+ if (!options.width) {
+ options.width = 200;
+ }
+ if (options.type) {
+ type = 1;
+ } else {
+ type = 0;
+ }
+ return VK.Widgets._constructor('widget_auth.php', objId, options, {}, {makeAuth: function(data) {
+ if (data.session) {
+ VK.Auth._loadState = 'loaded';
+ VK.Auth.setSession(data.session, 'connected');
+ VK.Observer.publish('auth.loginStatus', {session: data.session, status: 'connected'});
+ VK.Observer.unsubscribe('auth.loginStatus');
+ }
+ if (options.onAuth) {
+ options.onAuth(data);
+ } else {
+ if (options.authUrl) {
+ var href = options.authUrl;
+ } else {
+ var href = window.location.href;
+ }
+ if (href.indexOf('?') == -1) {
+ href+='?';
+ } else {
+ href+='&';
+ }
+ var vars = [];
+
+ for (var i in data) {
+ if (i != 'session') vars.push(i+'='+decodeURIComponent(data[i]).replace(/&/g, '%26').replace(/\?/, '%3F'));
+ }
+ window.location.href = href + vars.join('&');
+ }
+ }}, {startHeight: 80});
+ };
+
+ VK.Widgets.Subscribe = function(objId, options, oid) {
+ oid = parseInt(oid, 10);
+ var RPC;
+ if (!oid) {
+ throw Error('No owner_id passed');
+ }
+ var params = {
+ oid: oid
+ };
+ if (options.mode) {
+ params.mode = options.mode;
+ }
+ if (options.soft) {
+ params.soft = options.soft;
+ }
+
+ return VK.Widgets._constructor('widget_subscribe.php', objId, options, params, {
+ showBox: function(url, props) {
+ var box = VK.Util.Box((options.base_domain || VK._protocol + '//vk.com/') + url, [], {
+ proxy: function() {
+ rpc.callMethod.apply(rpc, arguments);
+ }
+ });
+ box.show();
+ },
+ auth: function() {
+ VK.Auth.login(null, 1);
+ }
+ }, {
+ minWidth: 220,
+ startHeight: 22,
+ height: options.height || 22
+ }, function(o, i, r) {
+ RPC = r;
+ });
+ };
+
+ VK.Widgets.Ads = function(objId, options, paramsExtra) {
+ options = options || {};
+ paramsExtra = paramsExtra || {};
+ var params = {};
+ var defaults = {};
+ var funcs = {};
+ var obj = document.getElementById(objId);
+ var iframe;
+ var rpc;
+
+ var adsParams = {};
+ var adsParamsLocal = {};
+ var adsParamsDefault = {};
+ for (var key in paramsExtra) {
+ var keyFix = (inArray(key, ['hash']) ? key : 'ads_' + key);
+ adsParams[keyFix] = paramsExtra[key];
+ }
+
+ if (obj && obj.getBoundingClientRect) {
+ obj.style.width = '100%';
+ obj.style.height = '100%';
+ var rect = obj.getBoundingClientRect();
+ obj.style.width = '';
+ obj.style.height = '';
+ adsParams.ads_ad_unit_width_auto = Math.floor(rect.right - rect.left);
+ adsParams.ads_ad_unit_height_auto = Math.floor(rect.bottom - rect.top);
+ }
+
+ adsParamsDefault.ads_ad_unit_width = 100;
+ adsParamsDefault.ads_ad_unit_height = 100;
+
+ adsParamsLocal.ads_ad_unit_width = (parseInt(adsParams.ads_ad_unit_width) || adsParams.ads_ad_unit_width === 'auto' && adsParams.ads_ad_unit_width_auto || adsParamsDefault.ads_ad_unit_width);
+ adsParamsLocal.ads_ad_unit_height = (parseInt(adsParams.ads_ad_unit_height) || adsParams.ads_ad_unit_height === 'auto' && adsParams.ads_ad_unit_height_auto || adsParamsDefault.ads_ad_unit_height);
+ if (adsParams.ads_handler) {
+ adsParamsLocal.ads_handler = adsParams.ads_handler;
+ }
+ if (adsParams.ads_handler_empty_html) {
+ adsParamsLocal.ads_handler_empty_html = adsParams.ads_handler_empty_html;
+ }
+
+ delete adsParams.ads_handler;
+ delete adsParams.ads_handler_empty_html;
+
+ params.act = 'ads_web';
+ params.url = location.href;
+ VK.extend(params, adsParams);
+
+ options.noDefaultParams = true;
+ options.width = adsParamsLocal.ads_ad_unit_width;
+ options.allowTransparency = true;
+ defaults.startHeight = adsParamsLocal.ads_ad_unit_height;
+ defaults.minWidth = adsParamsLocal.ads_ad_unit_width;
+ funcs.adsOnInitLoader = adsOnInitLoader;
+ funcs.adsOnInit = adsOnInit;
+
+ return VK.Widgets._constructor('ads_rotate.php', objId, options, params, funcs, defaults, onDone);
+
+ function adsOnInitLoader(adsScriptVersion) {
+ VK.Widgets.loading(obj, true);
+ adsAttachScript(adsScriptVersion);
+ }
+ function adsOnInit(errorCode, adsParamsExport) {
+ VK.Widgets.loading(obj, false);
+ adsProcessParams(adsParamsExport);
+ if (options.onAdsReady) options.onAdsReady.apply(options.onAdsReady, Array.prototype.slice.call(arguments));
+ adsProcessHandler(errorCode);
+ }
+ function adsAttachScript(adsScriptVersion) {
+ if (!('vk__adsLight' in window)) {
+ window.vk__adsLight = false;
+ adsScriptVersion = parseInt(adsScriptVersion);
+ var attachScriptFunc = (VK.Api && VK.Api.attachScript || VK.addScript);
+ var base_domain = (options.base_domain || VK._protocol + '//vk.com');
+ attachScriptFunc(base_domain + '/js/al/aes_light.js?' + adsScriptVersion);
+ } else if (window.vk__adsLight && vk__adsLight.userHandlers && vk__adsLight.userHandlers.onInit) {
+ vk__adsLight.userHandlers.onInit(false); // false - do not publish initial onInit
+ }
+ }
+ function adsProcessParams(adsParamsExport) {
+ if (!adsParamsExport) {
+ return;
+ }
+ for (var paramName in adsParamsExport) {
+ var paramValue = adsParamsExport[paramName];
+ if (paramName === 'ads_ad_unit_width' || paramName === 'ads_ad_unit_height') {
+ if (!(paramName in adsParams)) {
+ adsParamsLocal[paramName] = (parseInt(paramValue) || paramValue === 'auto' && adsParams[paramName + '_auto'] || adsParamsDefault[paramName]);
+ }
+ } else {
+ if (!(paramName in adsParamsLocal)) {
+ adsParamsLocal[paramName] = paramValue;
+ }
+ }
+ }
+ }
+ function adsProcessHandler(errorCode) {
+ var handlerResult = adsEvalHandler(adsParamsLocal.ads_handler, errorCode);
+ if (errorCode <= 0 && handlerResult !== true) {
+ try { console.log('VK: ad_unit_id = ' + adsParams.ads_ad_unit_id, ', errorCode = ', errorCode); } catch (e) {}
+ adsInsertHtmlHandler(adsParamsLocal.ads_handler_empty_html, adsParamsLocal.ads_ad_unit_width, adsParamsLocal.ads_ad_unit_height);
+ }
+ }
+ function adsEvalHandler(handler) {
+ var result = false;
+ try {
+ if (!handler) {
+ return false;
+ }
+ var func = false;
+ if (isFunction(handler)) {
+ func = handler;
+ } else if (isString(handler)) {
+ var handlerFuncs = handler.split('.');
+ func = window;
+ for (var i = 0, len = handlerFuncs.length; i < len; i++) {
+ func = func[handlerFuncs[i]];
+ if (!func) {
+ break;
+ }
+ }
+ if (!func) {
+ if (handler.substr(0, 8) === 'function') {
+ handler = 'return ' + handler + ';';
+ }
+ var handlerResult = (new Function(handler))();
+ if (isFunction(handlerResult)) {
+ func = handlerResult;
+ } else {
+ result = handlerResult;
+ }
+ }
+ }
+ if (func) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ result = func.apply(func, args);
+ }
+ } catch (e) {
+ try {
+ console.error(e);
+ } catch (e2) {}
+ }
+
+ return result;
+
+ function isFunction(obj) {
+ return Object.prototype.toString.call(obj) === '[object Function]';
+ }
+ function isString(obj) {
+ return Object.prototype.toString.call(obj) === '[object String]';
+ }
+ }
+ function adsInsertHtmlHandler(handlerHtml, width, height) {
+ if (!handlerHtml) {
+ return;
+ }
+ if (!obj) {
+ return;
+ }
+
+ width = (width ? width + 'px' : '');
+ height = (height ? height + 'px' : '');
+
+ var iframeHandlerHtml = '' +
+ ' ' +
+ '' +
+ ' ' +
+ '