HomeAccounting
2826 строк · 91.1 Кб
1(function(w) {2if (w.fastXDM) return;3
4var handlers = {};5var onEnvLoad = [];6var env = {};7
8// Key generation9function genKey() {10var key = '';11for (var i = 0; i < 5; i++) {12key += Math.ceil(Math.random() * 15).toString(16);13}14return key;15}16
17function waitFor(obj, prop, func, self, count) {18if (obj[prop]) {19func.apply(self);20} else {21count = count || 0;22if (count < 1000) {23setTimeout(function() {24waitFor(obj, prop, func, self, count + 1);25}, 0);26}27}28}29
30function attachScript(url) {31setTimeout(function() {32var newScript = document.createElement('script');33newScript.type = 'text/javascript';34newScript.src = url || w.fastXDM.helperUrl;35waitFor(document, 'body', function() {36document.getElementsByTagName('HEAD')[0].appendChild(newScript);37});38}, 0);39}40
41function walkVar(value, clean) {42var newValue;43
44switch (typeof value) {45case 'string':46if (clean) {47newValue = value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');48} else {49newValue = value.replace(/'/g, '\'').replace(/"/g, '"').replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&');50}51break;52case 'object':53if (Object.prototype.toString.apply(value) === '[object Array]') {54newValue = [];55for (var i = 0, len = value.length; i < len; i++) {56newValue[i] = walkVar(value[i], clean);57}58} else {59newValue = {};60for (var k in value) {61if (Object.hasOwnProperty.call(value, k)) {62newValue[k] = walkVar(value[k], clean);63}64}65}66break;67default:68newValue = value;69break;70}71
72return newValue;73}74
75// Env functions76function getEnv(callback, self) {77if (env.loaded) {78callback.apply(self, [env]);79} else {80onEnvLoad.push([self, callback]);81}82}83
84function envLoaded() {85env.loaded = true;86
87for (var i = 0, len = onEnvLoad.length; i < len; i++) {88onEnvLoad[i][1].apply(onEnvLoad[i][0], [env]);89}90}91
92function applyMethod(strData, self) {93getEnv(function(env) {94var data = env.json.parse(strData);95if (data[0]) {96if (!data[1]) data[1] = [];97
98for (var i = 0, len = data[1].length; i < len; i++) {99if (data[1][i] && data[1][i]._func) {100var funcNum = data[1][i]._func;101data[1][i] = function() {102var args = Array.prototype.slice.call(arguments);103args.unshift('_func' + funcNum);104self.callMethod.apply(self, args);105}106} else if (self.options.safe) {107data[1][i] = walkVar(data[1][i], true);108}109}110
111setTimeout(function() {112if (!self.methods[data[0]]) {113throw Error('fastXDM: Method ' + data[0] + ' is undefined');114}115self.methods[data[0]].apply(self, data[1]);116}, 0);117}118});119}120
121function extend(obj1, obj2) {122for (var i in obj2) {123if (obj1[i] && typeof(obj1[i]) === 'object') {124extend(obj1[i], obj2[i])125} else {126obj1[i] = obj2[i];127}128}129}130
131// XDM object132w.fastXDM = {133_id: 0,134helperUrl: 'https://vk.com/js/api/xdmHelper.js',135
136Server: function(methods, filter, options) {137this.methods = methods || {};138this.filter = filter;139this.options = options || {};140this.id = w.fastXDM._id++;141this.key = genKey();142this.frameName = 'fXD' + this.key;143this.server = true;144
145this.methods['%init%'] = this.methods.__fxdm_i = function() {146w.fastXDM.run(this.id);147if (this.methods.onInit) {148this.methods.onInit();149}150};151
152handlers[this.key] = [applyMethod, this];153},154
155Client: function(methods, options) {156this.methods = methods || {};157this.options = options || {};158this.id = w.fastXDM._id++;159this.client = true;160
161w.fastXDM.run(this.id);162
163if (window.name.indexOf('fXD') === 0) {164this.key = window.name.substr(3);165} else {166throw Error('Wrong window.name property.');167}168
169this.caller = window.parent;170
171handlers[this.key] = [applyMethod, this];172
173w.fastXDM.on('helper', function() {174w.fastXDM.onClientStart(this);175}, this);176
177getEnv(function(env) {178env.send(this, env.json.stringify(['%init%']));179
180var methods = this.methods;181setTimeout(function() {182if (methods.onInit) {183methods.onInit();184}185}, 0);186}, this);187},188
189onMessage: function(e) {190var data = e.data;191if (!data) {192return false;193}194if (typeof data !== 'string' && !(data instanceof String)) {195return false;196}197
198var key = data.substr(0, 5);199if (handlers[key]) {200var self = handlers[key][1];201if (self && (!self.filter || self.filter(e.origin))) {202handlers[key][0](data.substr(6), self);203}204}205},206
207setJSON: function(json) {208env.json = json;209},210
211getJSON: function(callback) {212if (!callback) {213return env.json;214}215
216getEnv(function(env) {217callback(env.json);218});219},220
221setEnv: function(exEnv) {222for (var i in exEnv) {223env[i] = exEnv[i];224}225
226envLoaded();227},228
229_q: {},230
231on: function(key, act, self) {232if (!this._q[key]) this._q[key] = [];233
234if (this._q[key] == -1) {235act.apply(self);236} else {237this._q[key].push([act, self]);238}239},240
241run: function(key) {242var len = (this._q[key] || []).length;243for (var i = 0; i < len; i++) {244this._q[key][i][0].apply(this._q[key][i][1]);245}246
247this._q[key] = -1;248},249
250waitFor: waitFor251}252
253w.fastXDM.Server.prototype.start = function(obj, count) {254if (obj.contentWindow) {255this.caller = obj.contentWindow;256this.frame = obj;257
258w.fastXDM.on('helper', function() {259w.fastXDM.onServerStart(this);260}, this);261} else { // Opera old versions262var self = this;263count = count || 0;264if (count < 50) {265setTimeout(function() {266self.start.apply(self, [obj, count + 1]);267}, 100);268}269}270}271
272w.fastXDM.Server.prototype.destroy = function() {273delete handlers[this.key];274}275
276w.fastXDM.Server.prototype.append = function(obj, options, attrs) {277var div = document.createElement('DIV');278div.innerHTML = '<iframe name="' + this.frameName + '" ' + (attrs || '') + '></iframe>';279var frame = div.firstChild;280var self = this;281
282setTimeout(function() {283frame.frameBorder = '0';284if (options) extend(frame, options);285obj.insertBefore(frame, obj.firstChild);286self.start(frame);287}, 0);288
289return frame;290}291
292w.fastXDM.Client.prototype.callMethod = w.fastXDM.Server.prototype.callMethod = function() {293var args = Array.prototype.slice.call(arguments);294var method = args.shift();295
296for (var i = 0, len = args.length; i < len; i++) {297if (typeof(args[i]) === 'function') {298this.funcsCount = (this.funcsCount || 0) + 1;299var func = args[i];300var funcName = '_func' + this.funcsCount;301
302this.methods[funcName] = function() {303func.apply(this, arguments);304delete this.methods[funcName];305}306
307args[i] = {_func: this.funcsCount};308} else if (this.options.safe) {309args[i] = walkVar(args[i], false);310}311}312
313waitFor(this, 'caller', function() {314w.fastXDM.on(this.id, function() {315getEnv(function(env) {316env.send(this, env.json.stringify([method, args]));317}, this);318}, this);319}, this);320}321
322if (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]}') {323env.json = {parse: w.JSON.parse, stringify: w.JSON.stringify};324} else {325w.fastXDM._needJSON = true;326}327
328// PostMessage cover329if (w.postMessage) {330env.protocol = 'p';331env.send = function(xdm, strData) {332var win = (xdm.frame ? xdm.frame.contentWindow : xdm.caller);333if (win) {334try {335win.postMessage(xdm.key + ':' + strData, "*");336} catch(e) {337window.postMessage.call(win, xdm.key + ':' + strData, "*");338}339}340}341
342if (w.addEventListener) {343w.addEventListener("message", w.fastXDM.onMessage, false);344} else {345w.attachEvent("onmessage", w.fastXDM.onMessage);346}347
348if (w.fastXDM._needJSON) {349w.fastXDM._onlyJSON = true;350attachScript();351} else {352envLoaded();353}354} else {355attachScript();356}357})(window);358
359if (!window.VK) window.VK = {};360
361/*
362* Based on JavaScript implementation of the RSA Data Security, Inc. MD5 Message
363* Copyright (C) Paul Johnston 1999 - 2009
364* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
365* Distributed under the BSD License
366*/
367if(!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<<p)|(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<s;t+=16){r=z;q=y;p=w;o=v;z=a(z,y,w,v,A[t+0],7,-680876936);v=a(v,z,y,w,A[t+1],12,-389564586);w=a(w,v,z,y,A[t+2],17,606105819);y=a(y,w,v,z,A[t+3],22,-1044525330);z=a(z,y,w,v,A[t+4],7,-176418897);v=a(v,z,y,w,A[t+5],12,1200080426);w=a(w,v,z,y,A[t+6],17,-1473231341);y=a(y,w,v,z,A[t+7],22,-45705983);z=a(z,y,w,v,A[t+8],7,1770035416);v=a(v,z,y,w,A[t+9],12,-1958414417);w=a(w,v,z,y,A[t+10],17,-42063);y=a(y,w,v,z,A[t+11],22,-1990404162);z=a(z,y,w,v,A[t+12],7,1804603682);v=a(v,z,y,w,A[t+13],12,-40341101);w=a(w,v,z,y,A[t+14],17,-1502002290);y=a(y,w,v,z,A[t+15],22,1236535329);z=h(z,y,w,v,A[t+1],5,-165796510);v=h(v,z,y,w,A[t+6],9,-1069501632);w=h(w,v,z,y,A[t+11],14,643717713);y=h(y,w,v,z,A[t+0],20,-373897302);z=h(z,y,w,v,A[t+5],5,-701558691);v=h(v,z,y,w,A[t+10],9,38016083);w=h(w,v,z,y,A[t+15],14,-660478335);y=h(y,w,v,z,A[t+4],20,-405537848);z=h(z,y,w,v,A[t+9],5,568446438);v=h(v,z,y,w,A[t+14],9,-1019803690);w=h(w,v,z,y,A[t+3],14,-187363961);y=h(y,w,v,z,A[t+8],20,1163531501);z=h(z,y,w,v,A[t+13],5,-1444681467);v=h(v,z,y,w,A[t+2],9,-51403784);w=h(w,v,z,y,A[t+7],14,1735328473);y=h(y,w,v,z,A[t+12],20,-1926607734);z=c(z,y,w,v,A[t+5],4,-378558);v=c(v,z,y,w,A[t+8],11,-2022574463);w=c(w,v,z,y,A[t+11],16,1839030562);y=c(y,w,v,z,A[t+14],23,-35309556);z=c(z,y,w,v,A[t+1],4,-1530992060);v=c(v,z,y,w,A[t+4],11,1272893353);w=c(w,v,z,y,A[t+7],16,-155497632);y=c(y,w,v,z,A[t+10],23,-1094730640);z=c(z,y,w,v,A[t+13],4,681279174);v=c(v,z,y,w,A[t+0],11,-358537222);w=c(w,v,z,y,A[t+3],16,-722521979);y=c(y,w,v,z,A[t+6],23,76029189);z=c(z,y,w,v,A[t+9],4,-640364487);v=c(v,z,y,w,A[t+12],11,-421815835);w=c(w,v,z,y,A[t+15],16,530742520);y=c(y,w,v,z,A[t+2],23,-995338651);z=m(z,y,w,v,A[t+0],6,-198630844);v=m(v,z,y,w,A[t+7],10,1126891415);w=m(w,v,z,y,A[t+14],15,-1416354905);y=m(y,w,v,z,A[t+5],21,-57434055);z=m(z,y,w,v,A[t+12],6,1700485571);v=m(v,z,y,w,A[t+3],10,-1894986606);w=m(w,v,z,y,A[t+10],15,-1051523);y=m(y,w,v,z,A[t+1],21,-2054922799);z=m(z,y,w,v,A[t+8],6,1873313359);v=m(v,z,y,w,A[t+15],10,-30611744);w=m(w,v,z,y,A[t+6],15,-1560198380);y=m(y,w,v,z,A[t+13],21,1309151649);z=m(z,y,w,v,A[t+4],6,-145523070);v=m(v,z,y,w,A[t+11],10,-1120210379);w=m(w,v,z,y,A[t+2],15,718787259);y=m(y,w,v,z,A[t+9],21,-343485551);z=j(z,r);y=j(y,q);w=j(w,p);v=j(v,o)}return[z,y,w,v]},f=function(r){var q="",s=-1,p=r.length,o,t;while(++s<p){o=r.charCodeAt(s);t=s+1<p?r.charCodeAt(s+1):0;if(55296<=o&&o<=56319&&56320<=t&&t<=57343){o=65536+((o&1023)<<10)+(t&1023);s++}if(o<=127){q+=String.fromCharCode(o)}else{if(o<=2047){q+=String.fromCharCode(192|((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<q;r++){o[r]=0}for(r=0,q=p.length*8;r<q;r+=8){o[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<q;r+=8){o+=String.fromCharCode((p[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<r;s++){o=q.charCodeAt(s);p+=t.charAt((o>>>4)&15)+t.charAt(o&15)}return p};return i(d(f(n)))}}368
369/*
370* VKontakte Open API JavaScript library
371* http://vk.com/
372*/
373
374VK.extend = function(target, source, overwrite) {375for (var key in source) {376if (overwrite || typeof target[key] === 'undefined') {377target[key] = source[key];378}379}380return target;381};382
383VK._protocol = 'https:';384
385if (!VK.xdConnectionCallbacks) {386
387VK.extend(VK, {388version: 1,389_apiId: null,390_session: null,391_userStatus: 'unknown',392_domain: {393main: 'https://oauth.vk.com/',394api: 'https://api.vk.com/'395},396_path: {397login: 'authorize',398proxy: 'fxdm_oauth_proxy.html'399},400_rootId: 'vk_api_transport',401_nameTransportPath: '',402xdReady: false,403access: {404FRIENDS: 0x2,405PHOTOS: 0x4,406AUDIO: 0x8,407VIDEO: 0x10,408MATCHES: 0x20,409QUESTIONS: 0x40,410WIKI: 0x80411}412});413
414VK.init = function(options) {415var body, root;416
417VK._apiId = null;418if (!options.apiId) {419throw Error('VK.init() called without an apiId');420}421VK._apiId = options.apiId;422
423if (options.onlyWidgets) return true;424
425if (options.nameTransportPath && options.nameTransportPath !== '') {426VK._nameTransportPath = options.nameTransportPath;427}428
429root = document.getElementById(VK._rootId);430if (!root) {431root = document.createElement('div');432root.id = VK._rootId;433body = document.getElementsByTagName('body')[0];434body.insertBefore(root, body.childNodes[0]);435}436root.style.position = 'absolute';437root.style.top = '-10000px';438
439var session = VK.Cookie.load();440if (session) {441VK.Auth._loadState = 'loaded';442VK.Auth.setSession(session, session ? 'connected' : 'unknown');443}444};445
446if (!VK.Cookie) {447VK.Cookie = {448_domain: null,449load: function() {450var cookie = document.cookie.match('\\bvk_app_' + VK._apiId + '=([^;]*)\\b')451var session;452
453if (cookie) {454session = this.decode(cookie[1]);455if (session.secret != 'oauth') {456return false;457}458session.expire = parseInt(session.expire, 10);459VK.Cookie._domain = '.' + window.location.hostname;//session.base_domain;460}461
462return session;463},464setRaw: function(val, ts, domain, time) {465var rawCookie;466rawCookie = 'vk_app_' + VK._apiId + '=' + val + '';467var exp = time ? (new Date().getTime() + time * 1000) : ts * 1000;468rawCookie += (val && ts === 0 ? '' : '; expires=' + new Date(exp).toGMTString());469rawCookie += '; path=/';470rawCookie += (domain ? '; domain=.' + domain : '');471document.cookie = rawCookie;472
473this._domain = domain;474},475set: function(session, resp) {476if (session) {477this.setRaw(this.encode(session), session.expire, window.location.hostname, (resp || {}).time);478} else {479this.clear();480}481},482clear: function() {483this.setRaw('', 0, this._domain, 0);484},485encode: function(params) {486var487pairs = [],488key;489
490for (key in params) {491if (key != 'user') pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));492}493pairs.sort();494
495return pairs.join('&');496},497decode: function(str) {498var499params = {},500parts = str.split('&'),501i,502pair;503
504for (i=0; i < parts.length; i++) {505pair = parts[i].split('=', 2);506if (pair && pair[0]) {507params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);508}509}510
511return params;512}513};514}515
516function obj2qs(obj) {517if (!obj) return '';518var qs = [];519for (var k in obj) {520if (obj.hasOwnProperty(k)) {521qs.push(encodeURIComponent(k) + '=' + encodeURIComponent(obj[k].toString() || ''));522}523}524return qs.length ? '?' + qs.join('&') : '';525}526
527if (!VK.Api) {528VK.Api = {529_headId: null,530_callbacks: {},531
532ie6_7: function() {533if (!VK.Api.ieTested) {534VK.Api.isIE6_7 = navigator.userAgent.match(/MSIE [6|7]/i);535VK.Api.ieTested = true;536}537return VK.Api.isIE6_7;538},539
540supportCORS: function() {541var xhr = new XMLHttpRequest();542if ("withCredentials" in xhr) {543return true;544}545
546if (typeof XDomainRequest != "undefined") {547return true;548}549
550return false;551},552
553makeRequest: function(url, cb) {554var xhr = VK.Api.createRequest('GET', url);555if (!xhr) {556return false;557}558
559xhr.onload = function() {560var text = xhr.responseText;561if (xhr.status === 200) {562cb(text);563} else {564try {565console.error('Open api access error', xhr.response);566} catch(e) {567//nop568}569}570};571
572xhr.onerror = function() {573try {574console.error('Open api access error');575} catch(e) {576//nop577}578};579
580xhr.send();581return true;582},583
584createRequest: function(method, url) {585var xhr = new XMLHttpRequest();586
587if ("withCredentials" in xhr) {588// XHR for Chrome/Firefox/Opera/Safari.589xhr.open(method, url, true);590xhr.withCredentials = true;591} else if (typeof XDomainRequest != "undefined") {592// XDomainRequest for IE.593xhr = new XDomainRequest();594xhr.open(method, url);595xhr.withCredentials = true;596} else {597// CORS not supported.598xhr = null;599}600
601return xhr;602},603
604attachScript: function(url) {605if (!VK.Api._headId) VK.Api._headId = document.getElementsByTagName("head")[0];606var newScript = document.createElement('script');607newScript.type = 'text/javascript';608newScript.setAttribute('encoding', 'UTF-8');609newScript.src = url;610VK.Api._headId.appendChild(newScript);611},612
613checkMethod: function(method, params, cb, queryTry) {614var m = method.toLowerCase();615
616if (m === 'wall.post') {617var validAttacheRegexp = /(^https?:\/\/)|(^(poll|album|photo|video|doc|audio|page|note)-?\d+_-?\d+)$/,618validAttachments = [],619methodAccess,620queryParams,621query,622timer;623
624if (!params.v) {625params.v = '3.0';626}627
628params.attachments = params.attachments || params.attachment || [];629if (typeof params.attachments === 'string') {630params.attachments = params.attachments.split(',')631}632
633for (var i = 0; i < params.attachments.length; i++) {634var attach = params.attachments[i].trim();635if (validAttacheRegexp.test(attach)) {636validAttachments.push(attach);637}638}639
640params.attachments = validAttachments.length ? validAttachments : '';641methodAccess = '_' + (Math.random()).toString(16).substr(2);642queryParams = {643act: 'wall_post_box',644method: m,645widget: 4,646aid: parseInt(VK._apiId, 10),647text: params.message || '',648method_access: methodAccess649};650
651queryParams = VK.extend(queryParams, params);652queryParams.owner_id = parseInt(params.owner_id || 0, 10);653queryParams.publish_date = params.publish_date || '';654query = VK._protocol + '//vk.com/al_apps.php';655query += obj2qs(queryParams);656
657VK.UI.popup({658url: query,659width: 560,660height: 304661});662
663timer = setInterval(function() {664if (VK.UI.active.closed) {665clearInterval(timer);666params.method_access = methodAccess;667VK.Api.call(method, params, cb, queryTry);668}669}, 500);670return false;671}672
673if (m == 'messages.allowmessagesfromgroup') {674methodAccess = '_' + (Math.random()).toString(16).substr(2);675query = VK._protocol + '//vk.com/widget_allow_messages_from_community.php?act=allow_box&group_id=' + parseInt(params.group_id, 10) + '&app_id=' + parseInt(VK._apiId, 10) + '&method_access=' + methodAccess;676
677VK.UI.popup({678url: query,679width: 560,680height: 304681});682
683timer = setInterval(function () {684if (VK.UI.active.closed) {685clearInterval(timer);686params.method_access = methodAccess;687VK.Api.call(method, params, cb, queryTry);688}689}, 500);690
691return false;692}693
694return true;695},696
697call: function(method, params, cb, queryTry) {698var699query = params || {},700qs,701responseCb;702
703if (typeof query != 'object' || typeof cb != 'function') {704return false;705}706if (!params.method_access && !params.method_force && !VK.Api.checkMethod(method, params, cb, queryTry)) {707return;708}709
710if (!queryTry) queryTry = 0;711
712if (VK.Auth._loadState != 'loaded') {713var authFunc = function(result) {714if (result && result.session) {715VK.Observer.unsubscribe('auth.loginStatus', authFunc);716VK.Api.call(method, params, cb);717}718};719VK.Observer.subscribe('auth.loginStatus', authFunc);720VK.Auth.getLoginStatus();721return;722}723
724if (VK.Api.queryLength(query) < 1500 && !VK.Api.ie6_7()) {725var useXDM = false;726var rnd = parseInt(Math.random() * 10000000, 10);727while (VK.Api._callbacks[rnd]) {728rnd = parseInt(Math.random() * 10000000, 10)729}730query.callback = 'VK.Api._callbacks['+rnd+']';731} else {732var useXDM = true;733}734
735if (VK._session && VK._session.sid) {736query.access_token = VK._session.sid;737}738
739qs = VK.Cookie.encode(query);740
741responseCb = function(response) {742if (response.error && (response.error.error_code == 3 || response.error.error_code == 4 || response.error.error_code == 5)) {743if (queryTry > 3) return false;744var repeatCall = function(resp) {745VK.Observer.unsubscribe('auth.sessionChange', repeatCall);746delete params.access_token;747if (resp.session) VK.Api.call(method, params, cb, queryTry + 1);748}749VK.Observer.subscribe('auth.sessionChange', repeatCall);750VK.Auth.getLoginStatus();751} else {752cb(response);753}754if (!useXDM) delete VK.Api._callbacks[rnd];755};756
757if (useXDM) {758if (VK.xdReady) {759VK.XDM.remote.callMethod('apiCall', method, qs, responseCb);760} else {761VK.Observer.subscribe('xdm.init', function() {762VK.XDM.remote.callMethod('apiCall', method, qs, responseCb);763});764VK.XDM.init();765}766} else {767VK.Api._callbacks[rnd] = responseCb;768VK.Api.attachScript(VK._domain.api + 'method/' + method +'?' + qs);769}770},771
772queryLength: function(query) {773var len = 100, i; // sid + sig774for (i in query) {775len += i.length + encodeURIComponent(query[i]).length + 1;776}777return len;778}779};780
781// Alias
782VK.api = function(method, params, cb) {VK.Api.call(method, params, cb);}783};784
785if (!VK.Auth) {786VK.Auth = {787popup: null,788lsCb: {},789
790setSession: function(session, status, settings, resp) {791var792login = !VK._session && session,793logout = VK._session && !session,794both = VK._session && session && VK._session.mid != session.mid,795sessionChange = login || logout || (VK._session && session && VK._session.sid != session.sid),796statusChange = status != VK._userStatus,797response = {798'session': session,799'status': status,800'settings': settings801};802
803VK._session = session;804
805VK._userStatus = status;806
807VK.Cookie.set(session, resp);808
809if (sessionChange || statusChange || both) {810setTimeout(function() {811if (statusChange) {812VK.Observer.publish('auth.statusChange', response);813}814
815if (logout || both) {816VK.Observer.publish('auth.logout', response);817}818
819if (login || both) {820VK.Observer.publish('auth.login', response);821}822
823if (sessionChange) {824VK.Observer.publish('auth.sessionChange', response);825}826}, 0);827}828
829return response;830},831
832// Public VK.Auth methods833login: function(cb, settings) {834if (!VK._apiId) {835return false;836}837
838var url = VK._domain.main + VK._path.login + '?client_id='+VK._apiId+'&display=popup&redirect_uri=close.html&response_type=token';839if (settings && parseInt(settings, 10) > 0) {840url += '&scope=' + settings;841}842
843VK.Observer.unsubscribe('auth.onLogin');844VK.Observer.subscribe('auth.onLogin', cb);845
846VK.UI.popup({847width: 665,848height: 370,849url: url850});851
852var authCallback = function() {853VK.Auth.getLoginStatus(function(resp) {854VK.Observer.publish('auth.onLogin', resp);855VK.Observer.unsubscribe('auth.onLogin');856}, true);857}858
859VK.UI.popupOpened = true;860var popupCheck = function() {861if (!VK.UI.popupOpened) {862return false;863}864
865try {866if (!VK.UI.active.top || VK.UI.active.closed) {867VK.UI.popupOpened = false;868authCallback();869return true;870}871} catch(e) {872VK.UI.popupOpened = false;873authCallback();874return true;875}876setTimeout(popupCheck, 100);877};878
879setTimeout(popupCheck, 100);880},881
882// Logout user from app, vk.com & login.vk.com883logout: function(cb) {884VK.Auth.revokeGrants(cb);885},886
887revokeGrants: function(cb) {888var onLogout = function(resp) {889VK.Observer.unsubscribe('auth.statusChange', onLogout);890if (cb) {891cb(resp);892}893}894
895VK.Observer.subscribe('auth.statusChange', onLogout);896if (VK._session && VK._session.sid) {897var url = 'https://login.vk.com/?act=openapi&oauth=1&aid=' + parseInt(VK._apiId, 10) + '&location=' + encodeURIComponent(window.location.hostname) + '&do_logout=1&token=' + VK._session.sid;898if (VK.Api.supportCORS()) {899var logoutCallback = function() {900VK.Auth.setSession(null, 'unknown');901};902
903VK.Api.makeRequest(url + '&new=1', logoutCallback);904} else {905VK.Api.attachScript(url);906}907}908
909VK.Cookie.clear();910},911
912// Get current login status from session (sync) (not use on load time)913getSession: function() {914return VK._session;915},916
917// Get current login status from vk.com (async)918getLoginStatus: function(cb, force) {919if (!VK._apiId) {920return;921}922
923if (cb) {924if (!force && VK.Auth._loadState == 'loaded') {925cb({status: VK._userStatus, session: VK._session});926return;927} else {928VK.Observer.subscribe('auth.loginStatus', cb);929}930}931
932if (!force && VK.Auth._loadState == 'loading') {933return;934}935
936VK.Auth._loadState = 'loading';937
938var url = 'https://login.vk.com/?act=openapi&oauth=1&aid=' + parseInt(VK._apiId, 10) + '&location=' + encodeURIComponent(window.location.hostname);939if (VK.Api.supportCORS()) {940var loginCallback = function(response) {941if (!this.JSON) {942this.JSON = {};943}944
945if (typeof JSON.parse !== 'function') {946//IE6 and IE7947response = eval(response);948} else {949response = JSON.parse(response);950}951
952VK.Auth._loadState = 'loaded';953if (response && response.auth) {954var session = {955mid: response.user.id,956sid: response.access_token,957sig: response.sig,958secret: response.secret,959expire: response.expire960};961
962if (force) {963session.user = response.user;964}965
966var status = 'connected';967} else {968var session = null;969var status = response.user ? 'not_authorized' : 'unknown';970VK.Cookie.clear();971}972
973VK.Auth.setSession(session, status, false, response);974VK.Observer.publish('auth.loginStatus', {session: session, status: status});975VK.Observer.unsubscribe('auth.loginStatus');976};977
978VK.Api.makeRequest(url + '&new=1', loginCallback);979} else {980var rnd = parseInt(Math.random() * 10000000, 10);981while (VK.Auth.lsCb[rnd]) {982rnd = parseInt(Math.random() * 10000000, 10);983}984
985VK.Auth.lsCb[rnd] = function(response) {986delete VK.Auth.lsCb[rnd];987VK.Auth._loadState = 'loaded';988if (response && response.auth) {989var session = {990mid: response.user.id,991sid: response.access_token,992sig: response.sig,993secret: response.secret,994expire: response.expire995};996if (force) session.user = response.user;997var status = 'connected';998} else {999var session = null;1000var status = response.user ? 'not_authorized' : 'unknown';1001VK.Cookie.clear();1002}1003VK.Auth.setSession(session, status, false, response);1004VK.Observer.publish('auth.loginStatus', {session: session, status: status});1005VK.Observer.unsubscribe('auth.loginStatus');1006};1007
1008// AttachScript here1009VK.Api.attachScript(url+'&rnd='+rnd);1010}1011}1012};1013}1014
1015if (!VK.App) {1016VK.App = {1017_appOpened: false,1018
1019open: function (url, params) {1020if (VK.App._appOpened || !VK._apiId) {1021return;1022}1023
1024if (!VK._session) {1025VK.Auth.login(function(resp) {1026if (resp && resp.session) {1027VK.App._openApp(url, params);1028}1029});1030} else {1031VK.App._openApp(url, params);1032}1033},1034
1035_openApp: function (url, params) {1036var src, box, request = [];1037params = params || {};1038
1039if (!url || !VK._apiId || VK.App._appOpened) {1040return;1041}1042src = VK._protocol + '//vk.com/apps?act=open_external_app_openapi&aid=' + VK._apiId;1043params['aid'] = VK._apiId;1044
1045for (var arg in params) {1046var val = '';1047if (!params.hasOwnProperty(arg)) {1048continue;1049}1050if (params[arg] !== undefined) {1051val = encodeURIComponent(params[arg]);1052}1053request.push(encodeURIComponent(arg) + '=' + val);1054}1055
1056src += '&url=' + url;1057src += '&q=' + encodeURIComponent(request.join('&'));1058
1059box = VK.Util.Box(src, {}, {1060closeExternalApp: function() {1061VK.Observer.publish('app.closed');1062box.hide();1063VK.App._appOpened = false;1064},1065externalAppDone: function (params) {1066VK.Observer.publish('app.done', params);1067box.hide();1068VK.App._appOpened = false;1069}1070});1071box.show();1072VK.App._appOpened = true;1073},1074}1075}1076
1077} else { // if VK.xdConnectionCallbacks1078setTimeout(function() {1079var callback;1080while (callback = VK.xdConnectionCallbacks.pop()) {1081callback();1082}1083}, 0);1084if (VK.Widgets && !VK.Widgets._constructor) {1085VK.Widgets = false;1086}1087}
1088
1089if (!VK.UI) {1090VK.UI = {1091active: null,1092_buttons: [],1093popup: function(options) {1094var1095screenX = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,1096screenY = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,1097outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,1098outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),1099width = options.width,1100height = options.height,1101left = parseInt(screenX + ((outerWidth - width) / 2), 10),1102top = parseInt(screenY + ((outerHeight - height) / 2.5), 10),1103features = (1104'width=' + width +1105',height=' + height +1106',left=' + left +1107',top=' + top1108);1109this.active = window.open(options.url, 'vk_openapi', features);1110},1111button: function(el, handler) {1112var html = '';1113
1114if (typeof el == 'string') {1115el = document.getElementById(el);1116}1117
1118
1119this._buttons.push(el);1120index = this._buttons.length - 1;1121
1122html = (1123'<table cellspacing="0" cellpadding="0" id="openapi_UI_' + index + '" onmouseover="VK.UI._change(1, ' + index + ');" onmouseout="VK.UI._change(0, ' + index + ');" onmousedown="VK.UI._change(2, ' + index + ');" onmouseup="VK.UI._change(1, ' + index + ');" style="cursor: pointer; border: 0px; font-family: tahoma, arial, verdana, sans-serif, Lucida Sans; font-size: 10px;"><tr style="vertical-align: middle">' +1124'<td><div style="border: 1px solid #3b6798;border-radius: 2px 0px 0px 2px;-moz-border-radius: 2px 0px 0px 2px;-webkit-border-radius: 2px 0px 0px 2px;"><div style="border: 1px solid #5c82ab; border-top-color: #7e9cbc; background-color: #6D8DB1; color: #fff; text-shadow: 0px 1px #45688E; height: 15px; padding: 2px 4px 0px 6px;line-height: 13px;">Войти</div></div></td>' +1125'<td><div style="background: url(' + VK._protocol + '//vk.com/images/btns.png) 0px -42px no-repeat; width: 21px; height: 21px"></div></td>' +1126'<td><div style="border: 1px solid #3b6798;border-radius: 0px 2px 2px 0px;-moz-border-radius: 0px 2px 2px 0px;-webkit-border-radius: 0px 2px 2px 0px;"><div style="border: 1px solid #5c82ab; border-top-color: #7e9cbc; background-color: #6D8DB1; color: #fff; text-shadow: 0px 1px #45688E; height: 15px; padding: 2px 6px 0px 4px;line-height: 13px;">Контакте</div></div></td>' +1127'</tr></table>'1128);1129el.innerHTML = html;1130el.style.width = el.childNodes[0].offsetWidth + 'px';1131},1132_change: function(state, index) {1133var row = document.getElementById('openapi_UI_' + index).rows[0];1134var elems = [row.cells[0].firstChild.firstChild, row.cells[2].firstChild.firstChild];1135for (var i = 0; i < 2; ++i) {1136var elem = elems[i];1137if (state === 0) {1138elem.style.backgroundColor = '#6D8DB1';1139elem.style.borderTopColor = '#7E9CBC';1140elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#5C82AB';1141} else if (state == 1) {1142elem.style.backgroundColor = '#7693B6';1143elem.style.borderTopColor = '#88A4C4';1144elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#6088B4';1145} else if (state == 2) {1146elem.style.backgroundColor = '#6688AD';1147elem.style.borderBottomColor = '#7495B8';1148elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderTopColor = '#51779F';1149}1150}1151if (state === 0 || state == 2) {1152row.cells[2].firstChild.style.backgroundPosition = '0px -42px';1153} else if (state == 1) {1154row.cells[2].firstChild.style.backgroundPosition = '0px -63px';1155}1156}1157};1158}
1159
1160if (!VK.XDM) {1161VK.XDM = {1162remote: null,1163init: function() {1164if (this.remote) return false;1165var url = VK._domain.api + VK._path.proxy;1166this.remote = new fastXDM.Server({1167onInit: function() {1168VK.xdReady = true;1169VK.Observer.publish('xdm.init');1170}1171});1172
1173this.remote.append(document.getElementById(VK._rootId), {1174src: url1175});1176},1177xdHandler: function(code) {1178try {1179eval('VK.' + code);1180} catch(e) {}1181}1182};1183}
1184
1185if (!VK.Observer) {1186VK.Observer = {1187_subscribers: function() {1188if (!this._subscribersMap) {1189this._subscribersMap = {};1190}1191return this._subscribersMap;1192},1193publish: function(eventName) {1194var1195args = Array.prototype.slice.call(arguments),1196eventName = args.shift(),1197subscribers = this._subscribers()[eventName],1198i, j;1199
1200if (!subscribers) return;1201
1202for (i = 0, j = subscribers.length; i < j; i++) {1203if (subscribers[i] != null) {1204subscribers[i].apply(this, args);1205}1206}1207},1208subscribe: function(eventName, handler) {1209var1210subscribers = this._subscribers();1211
1212if (typeof handler != 'function') return false;1213
1214if (!subscribers[eventName]) {1215subscribers[eventName] = [handler];1216} else {1217subscribers[eventName].push(handler);1218}1219},1220unsubscribe: function(eventName, handler) {1221var1222subscribers = this._subscribers()[eventName],1223i, j;1224
1225if (!subscribers) return false;1226if (typeof handler == 'function') {1227for (i = 0, j = subscribers.length; i < j; i++) {1228if (subscribers[i] == handler) {1229subscribers[i] = null;1230}1231}1232} else {1233delete this._subscribers()[eventName];1234}1235}1236};1237}
1238
1239if (!VK.Widgets) {1240VK.Widgets = {};1241
1242VK.Widgets.count = 0;1243VK.Widgets.RPC = {};1244
1245VK.Widgets.showBoxUrl = function(domain, url) {1246domain = (domain || VK._protocol + '//vk.com').replace(/\/?\s*$/, '');1247url = url.replace(/^\s*\/?/, '');1248return domain + '/' + url;1249};1250
1251VK.Widgets.loading = function(obj, enabled) {1252obj.style.background = enabled ? 'url("' + VK._protocol + '//vk.com/images/upload.gif") center center no-repeat transparent' : 'none';1253};1254
1255VK.Widgets.Comments = function(objId, options, page) {1256var pData = VK.Util.getPageData();1257if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');1258options = options || {};1259
1260var obj = document.getElementById(objId),1261params = {1262limit: options.limit || 10,1263height: options.height || 0,1264mini: options.mini === undefined ? 'auto' : options.mini,1265norealtime: options.norealtime ? 1 : 01266}, mouseup = function() {1267rpc.callMethod('mouseUp');1268return false;1269}, move = function(event) {1270rpc.callMethod('mouseMove', {screenY: event.screenY});1271}, iframe, rpc;1272
1273if (options.browse) { // browse all comments1274params.browse = 1;1275params.replies = options.replies || 0;1276} else { // page1277var url = options.pageUrl || pData.url;1278if (url.substr(0, 1) == '/') {1279url = (location.protocol + '//' + location.host) + url;1280}1281VK.extend(params, {1282page: page || 0,1283status_publish: options.autoPublish === undefined ? 0 : options.autoPublish,1284attach: options.attach === undefined ? '*' : (options.attach ? options.attach : ''),1285url: url,1286title: options.pageTitle || pData.title,1287description: options.pageDescription || pData.description,1288image: options.pageImage || pData.image1289});1290}1291if (options.onChange) { // DEPRECATED1292VK.Observer.subscribe('widgets.comments.new_comment', options.onChange);1293VK.Observer.subscribe('widgets.comments.delete_comment', options.onChange);1294}1295
1296return VK.Widgets._constructor('widget_comments.php', objId, options, params, {1297showBox: function(url, props) {1298var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {1299proxy: function() {1300rpc.callMethod.apply(rpc, arguments);1301}1302});1303box.show();1304},1305startDrag: function() {1306cursorBack = window.document.body.style.cursor;1307window.document.body.style.cursor = 'pointer';1308VK.Util.addEvent('mousemove', move);1309VK.Util.addEvent('mouseup', mouseup);1310},1311stopDrag: function() {1312window.document.body.style.cursor = cursorBack;1313VK.Util.removeEvent('mousemove', move);1314VK.Util.removeEvent('mouseup', mouseup);1315}1316}, {1317startHeight: 133,1318minWidth: 3001319}, function(o, i, r) {iframe = i; rpc = r;});1320};1321
1322VK.Widgets.CommentsBrowse = function(objId, options) {1323options = options || {};1324options.browse = 1;1325return VK.Widgets.Comments(objId, options);1326};1327
1328VK.Widgets.Recommended = function(objId, options) {1329var pData = VK.Util.getPageData();1330if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');1331options = options || {};1332var params = {1333limit: options.limit || 5,1334max: options.max || 0,1335sort: options.sort || 'friend_likes',1336verb: options.verb || 0,1337period: options.period || 'week',1338target: options.target || 'parent'1339};1340return VK.Widgets._constructor('widget_recommended.php', objId, options, params, {}, {1341startHeight: (116 + params.limit * 47 - 15),1342minWidth: 1501343});1344};1345
1346VK.Widgets.Post = function(objId, ownerId, postId, hash, options) {1347options = options || {};1348var obj = document.getElementById(objId),1349params = {1350owner_id: ownerId,1351post_id: postId,1352hash: hash || ''1353}, iframe, rpc, cursorBack;1354return VK.Widgets._constructor('widget_post.php', objId, options, params, {1355showBox: function(url, props) {1356var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {1357proxy: function() {1358rpc.callMethod.apply(rpc, arguments);1359}1360});1361box.show();1362},1363startDrag: function() {1364cursorBack = window.document.body.style.cursor;1365window.document.body.style.cursor = 'pointer';1366},1367stopDrag: function() {1368window.document.body.style.cursor = cursorBack;1369}1370}, {1371startHeight: 90,1372minWidth: 2501373}, function(o, i, r) {iframe = i; rpc = r;});1374};1375
1376VK.Widgets.Like = (function(Like) {1377if (Like) return Like;1378
1379var instances = [];1380
1381Like = function(objId, options, page) {1382var pData = VK.Util.getPageData();1383if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');1384options = VK.extend(options || {}, {allowTransparency: true});1385var verticalBtnHeightWidth = {138618: 43,138720: 47,138822: 51,138924: 55,139030: 67,1391},1392type = (options.type == 'full' || options.type == 'button' || options.type == 'vertical' || options.type == 'mini') ? options.type : 'full',1393autoWidth = options.width === 'auto' && (type == 'button' || type == 'mini'),1394btnHeight = parseInt(options.height, 10) || 22,1395size = btnHeight && verticalBtnHeightWidth[btnHeight] ? btnHeight : 22,1396width = autoWidth ? 153 : (type == 'full' ? Math.max(200, options.width || 350) : (type == 'button' ? 180 : (type == 'mini' ? 115 : verticalBtnHeightWidth[size]))),1397height = type == 'vertical' ? (2 * btnHeight + 7) : btnHeight,1398params = {1399page: page || 0,1400url: options.pageUrl || pData.url,1401type: type,1402verb: options.verb == 1 ? 1 : 0,1403color: options.color || '',1404title: options.pageTitle || pData.title,1405description: options.pageDescription || pData.description,1406image: options.pageImage || pData.image,1407text: (options.text || '').substr(0, 140),1408h: btnHeight1409},1410ttHere = options.ttHere || false,1411isOver = false,1412hideTimeout = null,1413obj, buttonIfr, buttonRpc, tooltipIfr, tooltipRpc, checkTO;1414if (type == 'vertical' || type == 'button' || type == 'mini') delete options.width;1415if (autoWidth) params.auto_width = 1;1416function showTooltip(force) {1417if ((!isOver && !force) || !tooltipRpc) return;1418if (!tooltipIfr || !tooltipRpc || tooltipIfr.style.display != 'none' && tooltipIfr.getAttribute('vkhidden') != 'yes') return;1419hideTimeout && clearTimeout(hideTimeout);1420checkTO && clearTimeout(checkTO);1421var scrollTop = options.getScrollTop ? options.getScrollTop() : (document.body.scrollTop || document.documentElement.scrollTop || 0);1422var objPos = VK.Util.getXY(obj, options.fixed);1423var startY = ttHere ? 0 : objPos[1];1424if (scrollTop > objPos[1] - 120 && options.tooltipPos != 'top' || type == 'vertical' || options.tooltipPos == 'bottom') {1425tooltipIfr.style.top = (startY + height + 2) + 'px';1426tooltipRpc.callMethod('show', false, type+'_'+size);1427} else {1428tooltipIfr.style.top = (startY - 128) + 'px';1429tooltipRpc.callMethod('show', true, type+'_'+size);1430}1431VK.Util.ss(tooltipIfr, {left: (ttHere ? 0 : objPos[0]) - (type == 'full' || type == 'button' ? 32 : 2) + 'px', display: 'block', opacity: 1, filter: 'none'});1432tooltipIfr.setAttribute('vkhidden', 'no');1433isOver = true;1434}1435
1436function hideTooltip(force) {1437if ((isOver && !force) || !tooltipRpc) return;1438tooltipRpc.callMethod('hide');1439buttonRpc.callMethod('hide');1440hideTimeout = setTimeout(function() {1441tooltipIfr.style.display = 'none'1442}, 400);1443}1444
1445var widgetId = VK.Widgets._constructor('widget_like.php', objId, options, params, {1446initTooltip: function(counter) {1447tooltipRpc = new fastXDM.Server({1448onInit: counter ? function() {1449showTooltip();1450} : function() {},1451proxy: function() {1452buttonRpc.callMethod.apply(buttonRpc, arguments);1453},1454showBox: function(url, props) {1455var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [props.width, props.height], {1456proxy: function() {1457tooltipRpc.callMethod.apply(tooltipRpc, arguments);1458}1459});1460box.show();1461},1462}, false, {safe: true});1463tooltipIfr = tooltipRpc.append(ttHere ? obj : document.body, {1464src: buttonIfr.src + '&act=a_like_tooltip',1465scrolling: 'no',1466allowTransparency: true,1467id: buttonIfr.id + '_tt',1468style: {position: 'absolute', padding: 0, display: 'none', opacity: 0.01, filter: 'alpha(opacity=1)', border: '0', width: '274px', height: '130px', zIndex: 5000, overflow: 'hidden'}1469});1470tooltipIfr.setAttribute('vkhidden', 'yes');1471
1472tooltipIfr.onmouseover = function() {1473clearTimeout(checkTO);1474isOver = true;1475};1476tooltipIfr.onmouseout = function() {1477clearTimeout(checkTO);1478isOver = false;1479checkTO = setTimeout(function() {hideTooltip(); }, 200);1480};1481},1482showTooltip: showTooltip,1483hideTooltip: hideTooltip,1484destroy: function() {1485buttonRpc.destroy();1486try {buttonIfr.src = 'about: blank;';} catch (e) {}1487buttonIfr.parentNode.removeChild(buttonIfr);1488if (tooltipIfr) {1489try {tooltipIfr.src = 'about: blank;';} catch (e) {}1490tooltipIfr.parentNode.removeChild(tooltipIfr);1491}1492tooltipRpc && tooltipRpc.destroy();1493},1494showBox: function(url, props) {1495var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {1496proxy: function() {1497buttonRpc.callMethod.apply(buttonRpc, arguments);1498}1499});1500box.show();1501},1502proxy: function() {if (tooltipRpc) tooltipRpc.callMethod.apply(tooltipRpc, arguments);}1503}, {1504startHeight: height,1505minWidth: width1506}, function(o, i, r) {1507buttonRpc = r;1508VK.Util.ss(obj = o, {height: height + 'px', width: width + 'px', position: 'relative', clear: 'both'});1509VK.Util.ss(buttonIfr = i, {height: height + 'px', width: width + 'px', overflow: 'hidden', zIndex: 150});1510obj.onmouseover = function() {1511clearTimeout(checkTO);1512isOver = true;1513};1514obj.onmouseout = function() {1515clearTimeout(checkTO);1516isOver = false;1517checkTO = setTimeout(function() {hideTooltip(); }, 200);1518};1519});1520
1521instances.push(widgetId);1522return widgetId;1523};1524
1525Like.destroyAll = function() {1526var xdm = null;1527while (instances[0]) {1528xdm = VK.Widgets.RPC[instances.pop()];1529xdm && xdm.methods.destroy();1530}1531}1532
1533return Like;1534})(VK.Widgets.Like);1535
1536VK.Widgets.Poll = function(objId, options, pollId) {1537var pData = VK.Util.getPageData();1538if (!pollId) throw Error('No poll id passed');1539options = options || {};1540var params = {1541poll_id: pollId,1542url: options.pageUrl || pData.url || location.href,1543title: options.pageTitle || pData.title,1544description: options.pageDescription || pData.description1545};1546return VK.Widgets._constructor('al_widget_poll.php', objId, options, params, {}, {1547startHeight: 144,1548minWidth: 3001549});1550};1551
1552VK.Widgets.App = function(objId, app_id, options) {1553if (!app_id) throw Error('No app id passed');1554if (!options) options = {};1555var startHeight = void 0,1556height = void 0,1557minWidth = void 0,1558params = {1559aid: app_id,1560mode: parseInt(options.mode, 10) || 1,1561};1562switch (params.mode) {1563case 1:1564options.width = 144;1565startHeight = 251;1566break;1567case 2:1568options.width = options.width ? Math.max(200, Math.min(10000, parseInt(options.width, 10))) : 200;1569height = startHeight = 193;1570break;1571case 3:1572options.width = options.width ? Math.max(50, Math.min(10000, parseInt(options.width, 10))) : void 0;1573height = startHeight = options.height = ({18: 18, 20: 20, 22: 22, 24: 24, 30: 30})[parseInt(options.height, 10) || 30];1574break;1575}1576minWidth = options.width;1577return VK.Widgets._constructor('widget_app.php', objId, options, params, {}, {1578startHeight: startHeight,1579height: height,1580minWidth: minWidth1581});1582};1583
1584VK.Widgets.Community = VK.Widgets.Group = function(objId, options, gid) {1585gid = parseInt(gid, 10);1586if (!gid) {1587throw Error('No group_id passed');1588}1589options.mode = parseInt(options.mode, 10).toString();1590var params = {1591gid: gid,1592mode: (options.mode) ? options.mode : '0'1593},1594startHeight = options.mode == 3 ? 185 : (options.mode == 1 ? 141 : options.height|0 || 290),1595rpc;1596if (options.wall) params.wall = options.wall;1597params.color1 = options.color1 || '';1598params.color2 = options.color2 || '';1599params.color3 = options.color3 || '';1600params.class_name = options.class_name || '';1601if (options.no_head) params.no_head = 1;1602if (options.no_cover) params.no_cover = 1;1603if (options.wide) {1604params.wide = 1;1605if (!options.width || options.width < 300) {1606options.width = 300;1607}1608}1609if (!options.width|0) options.width = 200;1610
1611var cursorBack;1612
1613function mouseup() {1614rpc.callMethod('mouseUp');1615return false;1616}1617
1618function move(event) {1619rpc.callMethod('mouseMove', {screenY: event.screenY});1620return false;1621}1622
1623return VK.Widgets._constructor('widget_community.php', objId, options, params, {1624showBox: function(url, props) {1625var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {1626proxy: function() {1627rpc.callMethod.apply(rpc, arguments);1628}1629});1630box.show();1631},1632startDrag: function() {1633cursorBack = window.document.body.style.cursor;1634window.document.body.style.cursor = 'pointer';1635VK.Util.addEvent('mousemove', move);1636VK.Util.addEvent('mouseup', mouseup);1637},1638stopDrag: function() {1639window.document.body.style.cursor = cursorBack;1640VK.Util.removeEvent('mousemove', move);1641VK.Util.removeEvent('mouseup', mouseup);1642},1643auth: function() {1644VK.Auth.login(null, 1);1645}1646}, {1647minWidth: 120,1648startHeight: startHeight1649}, function(o, i, r) {1650rpc = r;1651});1652};1653
1654VK.Widgets.Auth = function(objId, options) {1655var pData = VK.Util.getPageData();1656if (!VK._apiId) throw Error('VK not initialized. Please use VK.init');1657if (!options.width) {1658options.width = 200;1659}1660if (options.type) {1661type = 1;1662} else {1663type = 0;1664}1665return VK.Widgets._constructor('widget_auth.php', objId, options, {}, {makeAuth: function(data) {1666if (data.session) {1667VK.Auth._loadState = 'loaded';1668VK.Auth.setSession(data.session, 'connected');1669VK.Observer.publish('auth.loginStatus', {session: data.session, status: 'connected'});1670VK.Observer.unsubscribe('auth.loginStatus');1671}1672if (options.onAuth) {1673options.onAuth(data);1674} else {1675if (options.authUrl) {1676var href = options.authUrl;1677} else {1678var href = window.location.href;1679}1680if (href.indexOf('?') == -1) {1681href+='?';1682} else {1683href+='&';1684}1685var vars = [];1686
1687for (var i in data) {1688if (i != 'session') vars.push(i+'='+decodeURIComponent(data[i]).replace(/&/g, '%26').replace(/\#/g, '%23').replace(/\?/, '%3F'));1689}1690window.location.href = href + vars.join('&');1691}1692}}, {1693startHeight: 1341694});1695};1696
1697VK.Widgets.Subscribe = function(objId, options, oid) {1698oid = parseInt(oid, 10);1699if (!oid) {1700throw Error('No owner_id passed');1701}1702var params = {1703oid: oid1704}, rpc;1705if (options.mode) {1706params.mode = options.mode;1707}1708if (options.soft) {1709params.soft = options.soft;1710}1711
1712return VK.Widgets._constructor('widget_subscribe.php', objId, options, params, {1713showBox: function(url, props) {1714var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {1715proxy: function() {1716rpc.callMethod.apply(rpc, arguments);1717}1718});1719box.show();1720},1721auth: function() {1722VK.Auth.login(null, 1);1723}1724}, {1725minWidth: 220,1726startHeight: 221727}, function(o, i, r) {1728rpc = r;1729});1730};1731
1732VK.Widgets.ContactUs = function(objId, options, oid) {1733oid = parseInt(oid, 10);1734
1735if (!options) options = {};1736if (!oid) throw Error('No group or user id passed');1737
1738var params = {1739oid: oid,1740height: ({18: 18, 20: 20, 22: 22, 24: 24, 30: 30})[parseInt(options.height, 10) || 24],1741text: (options.text || '').substr(0, 140)1742}, rpc;1743
1744return VK.Widgets._constructor('widget_contactus.php', objId, options, params, {}, {1745startHeight: params.height,1746height: params.height1747}, function(o, i, r) {1748rpc = r;1749});1750};1751
1752VK.Widgets.Playlist = function(objId, ownerId, playlistId, hash, options) {1753var params = {1754oid: parseInt(ownerId, 10),1755pid: parseInt(playlistId, 10),1756hash: hash || ''1757}, rpc;1758
1759if (!options) options = {};1760if (!params.oid) throw Error('No owner id passed');1761if (!params.pid) throw Error('No playlist id passed');1762
1763return VK.Widgets._constructor('widget_playlist.php', objId, options, params, {1764showBox: function(url, props) {1765var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {1766proxy: function() {1767rpc.callMethod.apply(rpc, arguments);1768}1769});1770box.show();1771}1772}, {1773minWidth: 2001774}, function(o, i, r) {1775rpc = r;1776});1777};1778
1779VK.Widgets.Ads = function(objId, options, paramsExtra) {1780options = options || {};1781paramsExtra = paramsExtra || {};1782var params = {};1783var defaults = {};1784var funcs = {};1785var obj = document.getElementById(objId);1786var iframe;1787var rpc;1788
1789var adsParams = {};1790var adsParamsLocal = {};1791var adsParamsDefault = {};1792for (var key in paramsExtra) {1793var keyFix = (inArray(key, ['hash']) ? key : 'ads_' + key);1794adsParams[keyFix] = paramsExtra[key];1795}1796
1797if (obj && obj.getBoundingClientRect) {1798obj.style.width = '100%';1799obj.style.height = '100%';1800var rect = obj.getBoundingClientRect();1801obj.style.width = '';1802obj.style.height = '';1803adsParams.ads_ad_unit_width_auto = Math.floor(rect.right - rect.left);1804adsParams.ads_ad_unit_height_auto = Math.floor(rect.bottom - rect.top);1805}1806
1807adsParamsDefault.ads_ad_unit_width = 100;1808adsParamsDefault.ads_ad_unit_height = 100;1809
1810adsParamsLocal.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);1811adsParamsLocal.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);1812if (adsParams.ads_handler) {1813adsParamsLocal.ads_handler = adsParams.ads_handler;1814}1815if (adsParams.ads_handler_empty_html) {1816adsParamsLocal.ads_handler_empty_html = adsParams.ads_handler_empty_html;1817}1818
1819delete adsParams.ads_handler;1820delete adsParams.ads_handler_empty_html;1821
1822params.act = 'ads_web';1823params.url = location.href;1824VK.extend(params, adsParams);1825
1826options.noDefaultParams = true;1827options.width = adsParamsLocal.ads_ad_unit_width;1828options.allowTransparency = true;1829defaults.startHeight = adsParamsLocal.ads_ad_unit_height;1830defaults.minWidth = adsParamsLocal.ads_ad_unit_width;1831funcs.adsOnInitLoader = adsOnInitLoader;1832funcs.adsOnInit = adsOnInit;1833
1834return VK.Widgets._constructor('ads_rotate.php', objId, options, params, funcs, defaults, onDone);1835
1836function adsOnInitLoader(adsScriptVersion) {1837VK.Widgets.loading(obj, true);1838adsAttachScript(adsScriptVersion);1839}1840function adsOnInit(errorCode, adsParamsExport) {1841VK.Widgets.loading(obj, false);1842adsProcessParams(adsParamsExport);1843if (options.onAdsReady) options.onAdsReady.apply(options.onAdsReady, Array.prototype.slice.call(arguments));1844adsProcessHandler(errorCode);1845}1846function adsAttachScript(adsScriptVersion) {1847if (!('vk__adsLight' in window)) {1848window.vk__adsLight = false;1849adsScriptVersion = parseInt(adsScriptVersion);1850var attachScriptFunc = (VK.Api && VK.Api.attachScript || VK.addScript);1851var base_domain = (options.base_domain || VK._protocol + '//vk.com');1852attachScriptFunc(base_domain + '/js/al/aes_light.js?' + adsScriptVersion);1853} else if (window.vk__adsLight && vk__adsLight.userHandlers && vk__adsLight.userHandlers.onInit) {1854vk__adsLight.userHandlers.onInit(false); // false - do not publish initial onInit1855}1856}1857function adsProcessParams(adsParamsExport) {1858if (!adsParamsExport) {1859return;1860}1861for (var paramName in adsParamsExport) {1862var paramValue = adsParamsExport[paramName];1863if (paramName === 'ads_ad_unit_width' || paramName === 'ads_ad_unit_height') {1864if (!(paramName in adsParams)) {1865adsParamsLocal[paramName] = (parseInt(paramValue) || paramValue === 'auto' && adsParams[paramName + '_auto'] || adsParamsDefault[paramName]);1866}1867} else {1868if (!(paramName in adsParamsLocal)) {1869adsParamsLocal[paramName] = paramValue;1870}1871}1872}1873}1874function adsProcessHandler(errorCode) {1875var handlerResult = adsEvalHandler(adsParamsLocal.ads_handler, errorCode);1876if (errorCode <= 0 && handlerResult !== true) {1877try { console.log('VK: ad_unit_id = ' + adsParams.ads_ad_unit_id, ', errorCode = ', errorCode); } catch (e) {}1878adsInsertHtmlHandler(adsParamsLocal.ads_handler_empty_html, adsParamsLocal.ads_ad_unit_width, adsParamsLocal.ads_ad_unit_height);1879}1880}1881function adsEvalHandler(handler) {1882var result = false;1883try {1884if (!handler) {1885return false;1886}1887var func = false;1888if (isFunction(handler)) {1889func = handler;1890} else if (isString(handler)) {1891var handlerFuncs = handler.split('.');1892func = window;1893for (var i = 0, len = handlerFuncs.length; i < len; i++) {1894func = func[handlerFuncs[i]];1895if (!func) {1896break;1897}1898}1899if (!func) {1900if (handler.substr(0, 8) === 'function') {1901handler = 'return ' + handler + ';';1902}1903var handlerResult = (new Function(handler))();1904if (isFunction(handlerResult)) {1905func = handlerResult;1906} else {1907result = handlerResult;1908}1909}1910}1911if (func) {1912var args = Array.prototype.slice.call(arguments, 1);1913result = func.apply(func, args);1914}1915} catch (e) {1916try {1917console.error(e);1918} catch (e2) {}1919}1920
1921return result;1922
1923function isFunction(obj) {1924return Object.prototype.toString.call(obj) === '[object Function]';1925}1926function isString(obj) {1927return Object.prototype.toString.call(obj) === '[object String]';1928}1929}1930function adsInsertHtmlHandler(handlerHtml, width, height) {1931if (!handlerHtml) {1932return;1933}1934if (!obj) {1935return;1936}1937
1938width = (width ? width + 'px' : '');1939height = (height ? height + 'px' : '');1940
1941var iframeHandlerHtml = '<html><head></head><body style="padding: 0; margin: 0;"><div>' + handlerHtml + '</div></body></html>';1942
1943var iframeHandler = document.createElement('iframe');1944iframeHandler.onload = fixIframeHeight;1945iframeHandler.id = (iframe ? iframe.id : ('vkwidget-' + Math.round(Math.random() * 1000000))) + '_ads_html_handler';1946iframeHandler.src = 'about:blank';1947iframeHandler.width = '100%';1948iframeHandler.height = '100%';1949iframeHandler.scrolling = 'no';1950iframeHandler.frameBorder = '0';1951iframeHandler.allowTransparency = true;1952iframeHandler.style.overflow = 'hidden';1953iframeHandler.style.width = width;1954iframeHandler.style.height = height;1955
1956obj.style.width = width;1957obj.style.height = height;1958
1959obj.appendChild(iframeHandler);1960
1961iframeHandler.contentWindow.vk_ads_html_handler = iframeHandlerHtml;1962iframeHandler.src = 'javascript:window["vk_ads_html_handler"]';1963
1964function fixIframeHeight() {1965if (height) {1966return;1967}1968try {1969var rect = iframeHandler.contentWindow.document.body.firstChild.getBoundingClientRect();1970var heightFix = Math.ceil(rect.bottom - rect.top);1971if (heightFix) {1972iframeHandler.style.height = heightFix;1973obj.style.height = heightFix;1974}1975} catch (e) {}1976}1977}1978function indexOf(arr, value, from) {1979for (var i = from || 0, l = (arr || []).length; i < l; i++) {1980if (arr[i] == value) return i;1981}1982return -1;1983}1984function inArray(value, arr) {1985return indexOf(arr, value) != -1;1986}1987function onDone(o, i, r) {1988obj = o;1989iframe = i;1990rpc = r;1991}1992};1993
1994VK.Widgets.AllowMessagesFromCommunity = function (objId, options, groupId) {1995groupId = parseInt(groupId, 10);1996
1997if (!options) options = {};1998if (!groupId || groupId < 0) throw Error('No group id passed');1999
2000var params = {2001height: ({22: 22, 24: 24, 30: 30})[parseInt(options.height, 10) || 24],2002key: options.key ? options.key.substr(0, 256) : '',2003group_id: groupId2004}, rpc;2005
2006return VK.Widgets._constructor('widget_allow_messages_from_community.php', objId, options, params, {}, {2007startHeight: params.height,2008height: params.height2009}, function(o, i, r) {2010rpc = r;2011});2012};2013
2014VK.Widgets.CommunityMessages = (function(CommunityMessages) {2015if (CommunityMessages) return CommunityMessages;2016
2017var instances = {}, wCur = {};2018var BUTTONS_CONF = {2019no_button: {width: 0, height: 0},2020blue_circle: {2021width: 50,2022height: 50,2023margin: {2024bottom: 202025}2026}2027}, DEFAULT_BUTTON_TYPE = 'blue_circle',2028BUTTON_POSITIONS = {2029left: {2030bottom: 0,2031left: 202032},2033right: {2034bottom: 0,2035right: 202036}2037}, DEFAULT_BUTTON_POSITION = 'right';2038
2039/* options2040- welcomeScreen
2041- expandTimeout
2042- shown || expended
2043- widgetPosition
2044- buttonType
2045- disableButtonTooltip
2046- tooltipButtonText
2047- disableNewMessagesSound
2048- disableExpandChatSound
2049- disableTitleChange
2050*/
2051CommunityMessages = function(objId, gid, options) {2052options = options || {};2053
2054options.width = 300;2055options.height = 399;2056
2057if (!options.base_domain) {2058options.base_domain = options.base_domain || VK._protocol + '//vk.com';2059}2060
2061options.expandTimeout = parseInt(options.expandTimeout) || 0;2062
2063var params = {2064gid: gid2065};2066
2067options.expanded = parseInt(options.expanded) || 0;2068
2069if (!options.from_dev && lsGet('expanded') != null || options.expanded) {2070options.shown = 1;2071}2072
2073if (options.shown) {2074params.shown = 1;2075}2076
2077if (!options.welcomeScreen) {2078params.disable_welcome_screen = 1;2079}2080
2081var buttonType = options.buttonType;2082if (Object.keys(BUTTONS_CONF).indexOf(buttonType) == -1) {2083buttonType = DEFAULT_BUTTON_TYPE;2084}2085
2086if (buttonType == 'no_button') {2087options.disableButtonTooltip = 1;2088}2089
2090if (options.disableButtonTooltip) {2091params.disable_tooltip = 1;2092}2093if (options.tooltipButtonText) {2094params.tooltip_text = options.tooltipButtonText;2095}2096
2097if (options.disableNewMessagesSound) {2098params.disable_new_messages_sound = 1;2099}2100
2101if (instances[objId]) {2102CommunityMessages.destroy(objId);2103}2104
2105params.domain = document.domain;2106
2107options.no_loading = 1;2108
2109var curBox = false, expanded = 0;2110var ttSize = [0, 0], widgetPosition;2111
2112changeWidgetPosition(options.widgetPosition);2113params.button_position = options.widgetPosition;2114
2115var chatRpc, chatIfr;2116var inited = 0, timers = {};2117instances[objId] = VK.Widgets._constructor('widget_community_messages.php', objId, options, params, {2118onStartLoading: function() {2119var obj = document.getElementById(objId);2120obj.style.position = 'fixed';2121obj.style['z-index'] = 10000;2122updateWidgetPosition();2123},2124onReady: function () {2125inited = 1;2126if (options.expandTimeout > 0 && !options.shown) {2127timers.showTimer = setTimeout(function () {2128expandChat({2129playSong: !options.disableExpandChatSound,2130noSaveState: 12131});2132}, options.expandTimeout);2133}2134},2135showBox: function(url) {2136if (curBox) {2137try {2138curBox.hide();2139try {2140curBox.iframe.src = 'about: blank;';2141} catch (e) {}2142curBox.iframe.parentNode.removeChild(curBox.iframe);2143} catch(e) { }2144}2145curBox = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], {2146proxy: function() {2147rpc.callMethod.apply(rpc, arguments);2148}2149});2150curBox.show();2151},2152setTooltipSize: function (size) {2153ttSize = size;2154if (!expanded) {2155minimize();2156}2157},2158expand: function(opts) {2159opts = opts || {};2160expanded = 1;2161expand();2162
2163if (!opts.noSaveState) {2164lsSet('expanded', 1);2165}2166},2167minimize: function() {2168setTimeout(function() {2169expanded = 0;2170minimize(objId);2171lsRemove('expanded');2172}, 120);2173},2174canNotWrite: function(type) {2175options.onCanNotWrite && options.onCanNotWrite(type);2176},2177destroy: function() {2178chatRpc.destroy();2179try {chatIfr.src = 'about: blank;';} catch (e) {}2180try {2181chatIfr.parentNode.removeChild(chatIfr);2182} catch(e) { }2183},2184fatalError: function(error_code, public_id) {2185
2186var query = {2187code: error_code,2188widget: 2,2189public_id: public_id,2190};2191
2192if (error_code == 1903) {2193query.referrer_domain = document.domain;2194}2195
2196var query_str = [];2197for(var i in query) {2198query_str.push(i+'='+query[i]);2199}2200
2201CommunityMessages.destroy(objId);2202var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, 'blank.php?'+query_str.join('&')));2203box.show();2204},2205setPageTitle: function (title) {2206if (options.disableTitleChange) {2207return;2208}2209stopTitleAnimation();2210wCur.oldTitle = document.title || null;2211wCur.title = title;2212wCur.changeTitleMode = 0;2213startTitleNotify(1);2214},2215resetPageTitle: function () {2216stopTitleAnimation();2217},2218newMessage: function () {2219if (document.hasFocus && !document.hasFocus() && !options.disableNewMessagesSound) {2220callRpcMethod('playNewMsgSong');2221}2222}2223}, {}, function(o, i, r) {2224chatRpc = r;2225chatIfr = i;2226if (!options.shown) {2227minimize();2228} else {2229expand();2230}2231});2232
2233function startTitleNotify(fast) {2234clearTimeout(wCur.titleTimer);2235wCur.titleTimer = setTimeout(function () {2236if (wCur.changeTitleMode == 1) {2237document.title = wCur.oldTitle || '';2238} else {2239document.title = wCur.title;2240}2241wCur.changeTitleMode = wCur.changeTitleMode == 1 ? 0 : 1;2242startTitleNotify();2243}, fast ? 0 : 1500);2244}2245
2246function stopTitleAnimation() {2247if (options.disableTitleChange) {2248return;2249}2250clearTimeout(wCur.titleTimer);2251if (wCur.oldTitle) {2252document.title = wCur.oldTitle;2253} else if (wCur.oldTitle === null) {2254document.title = '';2255}2256wCur.title = '';2257}2258
2259function expand() {2260var obj = document.getElementById(objId), frame = obj.getElementsByTagName('iframe')[0];2261
2262obj.style.width = frame.width = '372px';2263obj.style.height = frame.height = '399px';2264obj.style.margin = '0px 0px 0px 0px';2265//frame.style.boxShadow = '0 0 0 1px rgba(0, 20, 51, .12), 0 20px 40px 0 rgba(0, 0, 0, 0.3)';2266//frame.style.borderRadius = '6px';2267}2268
2269function minimize() {2270var obj = document.getElementById(objId), frame = obj.getElementsByTagName('iframe')[0];2271
2272var btnConf = BUTTONS_CONF[buttonType];2273
2274var w = btnConf.width + ttSize[0];2275var h = Math.max(btnConf.height, ttSize[1]);2276
2277obj.style.width = w + 'px';2278obj.style.height = h + 'px';2279frame.style.boxShadow = 'none';2280
2281var margin = btnConf.margin ? btnConf.margin : {};2282obj.style.margin = '0px ' + (margin.right || 0) + 'px ' + (margin.bottom || 0) + 'px 0px';2283
2284if (frame) {2285frame.width = w;2286frame.height = h;2287}2288}2289
2290function changeWidgetPosition(position) {2291widgetPosition = position;2292if (Object.keys(BUTTON_POSITIONS).indexOf(widgetPosition) == -1) {2293widgetPosition = DEFAULT_BUTTON_POSITION;2294}2295updateWidgetPosition();2296callRpcMethod('changeButtonPosition', widgetPosition);2297}2298
2299function updateWidgetPosition() {2300var obj = document.getElementById(objId);2301
2302if (!obj) {2303return;2304}2305
2306var props = ['left', 'right', 'top', 'bottom'];2307for(var i in props) {2308obj.style[props[i]] = '';2309}2310
2311var conf = BUTTON_POSITIONS[widgetPosition];2312for(var i in conf) {2313obj.style[i] = conf[i] + 'px';2314}2315
2316if (!inited) {2317return;2318}2319
2320if (expanded) {2321expand();2322} else {2323minimize();2324}2325}2326
2327function callRpcMethod() {2328chatRpc && chatRpc.callMethod.apply(chatRpc, arguments);2329}2330
2331/* opts2332- welcomeScreen
2333*/
2334function expandChat(opts) {2335if (!opts || Object.prototype.toString.call(opts) !== '[object Object]') {2336opts = {};2337}2338
2339if (opts.welcomeScreen == undefined) {2340opts.welcomeScreen = options.welcomeScreen;2341}2342
2343clearTimeout(timers.showTimer);2344callRpcMethod('expand', opts);2345}2346
2347function minimizeChat() {2348callRpcMethod('minimize');2349}2350
2351function destroyChat() {2352stopTitleAnimation();2353CommunityMessages.destroy(objId);2354}2355
2356return {2357expand: expandChat,2358minimize: minimizeChat,2359destroy: destroyChat,2360changeButtonPosition: changeWidgetPosition,2361stopTitleAnimation: stopTitleAnimation,2362};2363};2364
2365function lsGet(key) {2366if (!window.localStorage) {2367return null;2368}2369return localStorage.getItem('vk_community_widget_' + key);2370}2371
2372function lsSet(key, value) {2373window.localStorage && localStorage.setItem('vk_community_widget_' + key, value);2374}2375
2376function lsRemove(key) {2377window.localStorage && localStorage.removeItem('vk_community_widget_' + key);2378}2379
2380CommunityMessages.destroy = function(objId) {2381if (!instances[objId]) {2382return;2383}2384
2385var xdm = VK.Widgets.RPC[instances[objId]];2386xdm && xdm.methods.destroy();2387
2388delete instances[objId];2389};2390
2391CommunityMessages.expand = function (objId) {2392console.log(instances[objId]);2393};2394
2395return CommunityMessages;2396})(VK.Widgets.CommunityMessages);2397
2398VK.Widgets._constructor = function(widgetUrl, objId, options, params, funcs, defaults, onDone, widgetId, iter) {2399var obj = document.getElementById(objId);2400widgetId = widgetId || (++VK.Widgets.count);2401
2402if (!obj) {2403iter = iter || 0;2404if (iter > 10) {2405throw Error('VK.Widgets: object #' + objId + ' not found.');2406}2407setTimeout(function() {2408VK.Widgets._constructor(widgetUrl, objId, options, params, funcs, defaults, onDone, widgetId, iter + 1);2409}, 500);2410return widgetId;2411}2412
2413options = options || {};2414defaults = defaults || {};2415funcs = funcs || {};2416
2417if (options.preview) {2418params.preview = 1;2419delete options['preview'];2420}2421
2422var ifr, url, urlQueryString, encodedParam, rpc, iframe, i,2423base_domain = options.base_domain || VK._protocol + '//vk.com',2424width = options.width === 'auto' ? (obj.clientWidth || obj.offsetWidth || defaults.minWidth) | 0 : parseInt(options.width || 0, 10);2425width = width ? (Math.max(defaults.minWidth || 200, Math.min(defaults.maxWidth || 10000, width)) + 'px') : '100%';2426obj.style.width = width;2427
2428if (options.height) {2429params.height = options.height;2430obj.style.height = options.height + 'px';2431} else {2432obj.style.height = (defaults.startHeight || 200) + 'px';2433}2434
2435if (width === '100%') params.startWidth = (obj.clientWidth || obj.offsetWidth) | 0;2436if (!params.url) params.url = options.pageUrl || location.href.replace(/#.*$/, '');2437
2438url = base_domain + '/' + widgetUrl;2439urlQueryString = '';2440if (!options.noDefaultParams) {2441urlQueryString += '&app=' + (VK._apiId || '0') + '&width=' + encodeURIComponent(width)2442}2443urlQueryString += '&_ver=' + VK.version2444if (VK._iframeAppWidget) {2445params.iframe_app = 1;2446}2447var pData = VK.Util.getPageData();2448params.url = params.url || pData.url || "";2449params.referrer = params.referrer || document.referrer || "";2450params.title = params.title || pData.title || document.title || "";2451for (i in params) {2452if (i == 'title' && params[i].length > 80) params[i] = params[i].substr(0, 80)+'...';2453if (i == 'description' && params[i].length > 160) params[i] = params[i].substr(0, 160)+'...';2454if (typeof(params[i]) == 'number') {2455encodedParam = params[i];2456} else {2457try {2458encodedParam = encodeURIComponent(params[i]);2459} catch (e) {2460encodedParam = '';2461}2462}2463urlQueryString += '&' + i + '=' + encodedParam;2464}2465urlQueryString += '&' + (+new Date()).toString(16);2466url += '?' + urlQueryString.substr(1);2467
2468funcs.onStartLoading && funcs.onStartLoading();2469if (!options.no_loading) {2470VK.Widgets.loading(obj, true);2471}2472
2473funcs.showLoader = function(enable) {2474VK.Util.Loader(enable);2475};2476funcs.publish = function() {2477var args = Array.prototype.slice.call(arguments);2478args.push(widgetId);2479VK.Observer.publish.apply(VK.Observer, args);2480};2481funcs.onInit = function() {2482VK.Widgets.loading(obj, false);2483if (funcs.onReady) funcs.onReady();2484if (options.onReady) options.onReady();2485};2486funcs.resize = function(e, cb) {2487obj.style.height = e + 'px';2488var el = document.getElementById('vkwidget' + widgetId);2489if (el) {2490el.style.height = e + 'px';2491}2492};2493funcs.resizeWidget = function(newWidth, newHeight) {2494newWidth = parseInt(newWidth);2495newHeight = parseInt(newHeight);2496var widgetElem = document.getElementById('vkwidget' + widgetId);2497if (isFinite(newWidth)) {2498obj.style.width = newWidth + 'px';2499if (widgetElem) {2500widgetElem.style.width = newWidth + 'px';2501}2502}2503if (isFinite(newHeight)) {2504obj.style.height = newHeight + 'px';2505if (widgetElem) {2506widgetElem.style.height = newHeight + 'px';2507}2508}2509if (options.onResizeWidget) options.onResizeWidget();2510};2511funcs.updateVersion = function(ver) {2512if (ver > 1) {2513VK.Api.attachScript('//vk.com/js/api/openapi_update.js?'+parseInt(ver));2514}2515};2516rpc = VK.Widgets.RPC[widgetId] = new fastXDM.Server(funcs, function(origin) {2517if (!origin) return true;2518origin = origin.toLowerCase();2519return (origin.match(/(\.|\/)vk\.com($|\/|\?)/));2520}, {safe: true});2521iframe = VK.Widgets.RPC[widgetId].append(obj, {2522src: url,2523width: (width.indexOf('%') != -1) ? width : (parseInt(width) || width),2524height: defaults.startHeight || '100%',2525scrolling: 'no',2526id: 'vkwidget' + widgetId,2527allowTransparency: options.allowTransparency || false,2528style: {2529overflow: 'hidden'2530}2531});2532onDone && setTimeout(function() {onDone(obj, iframe || obj.firstChild, rpc);}, 10);2533return widgetId;2534};2535}
2536
2537if (!VK.Util) {2538VK.Util = {2539getPageData: function() {2540if (!VK._pData) {2541var metas = document.getElementsByTagName('meta'), pData = {}, keys = ['description', 'title', 'url', 'image', 'app_id'], metaName;2542for (var i in metas) {2543if (!metas[i].getAttribute) continue;2544if (metas[i].getAttribute && ((metaName = metas[i].getAttribute('name')) || (metaName = metas[i].getAttribute('property')))) {2545for (var j in keys) {2546if (metaName == keys[j] || metaName == 'og:'+keys[j] || metaName == 'vk:'+keys[j]) {2547pData[keys[j]] = metas[i].content;2548}2549}2550}2551}2552if (pData.app_id && !VK._apiId) {2553VK._apiId = pData.app_id;2554}2555pData.title = pData.title || document.title || '';2556pData.description = pData.description || '';2557pData.image = pData.image || '';2558if (!pData.url && VK._iframeAppWidget && VK._apiId) {2559pData.url = '/app' + VK._apiId;2560if (VK._browserHash) {2561pData.url += VK._browserHash2562}2563}2564var loc = location.href.replace(/#.*$/, '');2565if (!pData.url || !pData.url.indexOf(loc)) {2566pData.url = loc;2567}2568VK._pData = pData;2569}2570return VK._pData;2571},2572getStyle: function(elem, name) {2573var ret, defaultView = document.defaultView || window;2574if (defaultView.getComputedStyle) {2575name = name.replace(/([A-Z])/g, '-$1').toLowerCase();2576var computedStyle = defaultView.getComputedStyle(elem, null);2577if (computedStyle) {2578ret = computedStyle.getPropertyValue(name);2579}2580} else if (elem.currentStyle) {2581var camelCase = name.replace(/\-(\w)/g, function(all, letter){2582return letter.toUpperCase();2583});2584ret = elem.currentStyle[name] || elem.currentStyle[camelCase];2585}2586
2587return ret;2588},2589
2590getXY: function(obj, fixed) {2591if (!obj || obj === undefined) return;2592
2593var left = 0, top = 0;2594if (obj.getBoundingClientRect !== undefined) {2595var rect = obj.getBoundingClientRect();2596left = rect.left;2597top = rect.top;2598fixed = true;2599} else if (obj.offsetParent) {2600do {2601left += obj.offsetLeft;2602top += obj.offsetTop;2603if (fixed) {2604left -= obj.scrollLeft;2605top -= obj.scrollTop;2606}2607} while (obj = obj.offsetParent);2608}2609if (fixed) {2610top += window.pageYOffset || window.scrollNode && scrollNode.scrollTop || document.documentElement.scrollTop;2611left += window.pageXOffset || window.scrollNode && scrollNode.scrollLeft || document.documentElement.scrollLeft;2612}2613
2614return [left, top];2615},2616
2617Loader: function self(enable) {2618if (!self.loader) {2619self.loader = document.createElement('DIV');2620self.loader.innerHTML = '<style type="text/css">\2621@-webkit-keyframes VKWidgetsLoaderKeyframes {0%{opacity: 0.2;}30%{opacity: 1;}100%{opacity: 0.2;}}\
2622@keyframes VKWidgetsLoaderKeyframes {0%{opacity: 0.2;}30%{opacity: 1;}100%{opacity: 0.2;}}\
2623.VKWidgetsLoader div {width: 7px;height: 7px;-webkit-border-radius: 50%;-khtml-border-radius: 50%;-moz-border-radius: 50%;border-radius: 50%;background: #fff;top: 21px;position: absolute;z-index: 2;-o-transition: opacity 350ms linear; transition: opacity 350ms linear;opacity: 0.2;-webkit-animation-duration: 750ms;-o-animation-duration: 750ms;animation-duration: 750ms;-webkit-animation-name: VKWidgetsLoaderKeyframes;-o-animation-name: VKWidgetsLoaderKeyframes;animation-name: VKWidgetsLoaderKeyframes;-webkit-animation-iteration-count: infinite;-o-animation-iteration-count: infinite;animation-iteration-count: infinite;-webkit-transform: translateZ(0);transform: translateZ(0);}</style><div class="VKWidgetsLoader" style="position: fixed;left: 50%;top: 50%;margin: -25px -50px;z-index: 1002;height: 50px;width: 100px;"><div style="left: 36px;-webkit-animation-delay: 0ms;-o-animation-delay: 0ms;animation-delay: 0ms;"></div><div style="left: 47px;-webkit-animation-delay: 180ms;-o-animation-delay: 180ms;animation-delay: 180ms;"></div><div style="left: 58px;-webkit-animation-delay: 360ms;-o-animation-delay: 360ms;animation-delay: 360ms;"></div><span style="display: block;background-color: #000;-webkit-border-radius: 4px;-khtml-border-radius: 4px;-moz-border-radius: 4px;border-radius: 4px;-webkit-box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.35);-moz-box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.35);box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.35);position: absolute;left: 0;top: 0;bottom: 0; right: 0;z-index: 1;opacity: 0.7;"></span></div>';2624document.body.insertBefore(self.loader, document.body.firstChild);2625}2626self.loader.style.display = enable ? 'block' : 'none';2627},2628
2629Box: function(src, sizes, fnc, options) {2630fnc = fnc || {};2631var overflowB = document.body.style.overflow;2632VK.Util.Loader(true);2633var is_vk = /(^|\.)(vk\.com|vkontakte\.ru)$/.test(location.hostname);2634var rpc = new fastXDM.Server(VK.extend(fnc, {2635onInit: function() {2636iframe.style.background = 'transparent';2637iframe.style.visibility = 'visible';2638document.body.style.overflow = 'hidden';2639iframe.setAttribute('allowfullscreen', 1);2640if (is_vk) document.body.className += ' layers_shown';2641VK.Util.Loader();2642},2643hide: function() {2644iframe.style.display = 'none';2645},2646tempHide: function() {2647iframe.style.left = '-10000px';2648iframe.style.top = '-10000px';2649iframe.style.width = '10px';2650iframe.style.height = '10px';2651if (is_vk) document.body.className = document.body.className.replace(/\b\s*?layers_shown\s*\b/, ' ');2652document.body.style.overflow = overflowB;2653},2654destroy: function() {2655try {2656iframe.src = 'about: blank;';2657} catch (e) {}2658iframe.parentNode.removeChild(iframe);2659if (is_vk) document.body.className = document.body.className.replace(/\b\s*?layers_shown\s*\b/, ' ');2660document.body.style.overflow = overflowB;2661},2662resize: function(w, h) {2663}2664}, true), false, {safe: true}),2665iframe = rpc.append(document.body, {2666src: src.replace(/&/g, '&'),2667scrolling: 'no',2668allowTransparency: true,2669style: {position: 'fixed', left: 0, top: 0, zIndex: 1002, background: VK._protocol + '//vk.com/images/upload.gif center center no-repeat transparent', padding: '0', border: '0', width: '100%', height: '100%', overflow: 'hidden', visibility: 'hidden'}2670});2671return {2672show: function(scrollTop, height) {2673iframe.style.display = 'block';2674document.body.style.overflow = 'hidden';2675},2676hide: function() {2677iframe.style.display = 'none';2678document.body.style.overflow = overflowB;2679},2680iframe: iframe,2681rpc: rpc2682}2683},2684
2685addEvent: function(type, func) {2686if (window.document.addEventListener) {2687window.document.addEventListener(type, func, false);2688} else if (window.document.attachEvent) {2689window.document.attachEvent('on'+type, func);2690}2691},2692
2693removeEvent: function(type, func) {2694if (window.document.removeEventListener) {2695window.document.removeEventListener(type, func, false);2696} else if (window.document.detachEvent) {2697window.document.detachEvent('on'+type, func);2698}2699},2700
2701ss: function(el, styles) {VK.extend(el.style, styles, true);}2702};2703}
2704
2705if (!VK.Retargeting) {2706VK.Retargeting = {2707pixelCode: null,2708Init: function (pixelCode) {2709this.pixelCode = pixelCode;2710},2711Event: function (event) {2712if (!this.pixelCode) {2713return;2714}2715
2716(window.Image ? (new Image()) : document.createElement('img')).src = 'https://vk.com/rtrg?p=' + this.pixelCode + (event ? ('&event=' + encodeURIComponent(event)) : '');2717},2718Hit: function () {2719this.Event();2720},2721Add: function (audienceID) {2722if (!this.pixelCode || !audienceID) {2723return;2724}2725
2726(window.Image ? (new Image()) : document.createElement('img')).src = 'https://vk.com/rtrg?p=' + this.pixelCode + '&audience=' + encodeURIComponent(audienceID);2727},2728ProductEvent: function (priceListID, event, params, opts) {2729if (!this.pixelCode || !event || !priceListID) {2730return;2731}2732
2733opts = opts || {};2734
2735var canShowErrors = true;2736if (typeof opts.show_errors !== 'undefined') {2737canShowErrors = opts.show_errors ? true : false;2738}2739var errorsIgnore = '0';2740if (typeof opts.errors_ignore !== 'undefined') {2741errorsIgnore = opts.errors_ignore ? '1' : '0';2742}2743
2744var url = 'https://vk.com/rtrg';2745var productParams = params ? JSON.stringify(params) : '';2746var requestParams = {2747'p': this.pixelCode,2748'products_event': event,2749'price_list_id': priceListID,2750'e': '1',2751'i': errorsIgnore2752};2753if (productParams) {2754requestParams.products_params = productParams;2755}2756
2757var query = Object.keys(requestParams).map(function(key) {2758var segment = encodeURIComponent(key) + '=' + encodeURIComponent(requestParams[key]);2759return segment;2760}).join('&');2761
2762var requestUrl = url + '?' + query;2763
2764VK.Api.makeRequest(requestUrl, this.onDone.bind(this, canShowErrors));2765},2766onDone: function(canShowErrors, response) {2767if (!response || !canShowErrors) {2768return;2769}2770
2771var resp;2772try {2773resp = JSON.parse(response);2774} catch (e) {2775return;2776}2777
2778if (!resp || !resp.errors) {2779return;2780}2781this.showErrors(resp.errors);2782},2783showErrors: function(errors) {2784if (!errors && !errors.length) {2785return;2786}2787
2788var errorBegin = 'VK Pixel Error (' + this.pixelCode + '): ';2789
2790if (typeof errors === 'string') {2791console.error(errorBegin + errors);2792return;2793}2794
2795var errorsLength = errors.length;2796
2797if (!errorsLength) {2798return;2799}2800
2801for (var i = 0; i < errorsLength; i++) {2802console.error(errorBegin + errors[i]);2803}2804}2805};2806}
2807
2808// Init asynchronous library loading
2809window.vkAsyncInit && setTimeout(vkAsyncInit, 0);2810
2811if (window.vkAsyncInitCallbacks && vkAsyncInitCallbacks.length) {2812setTimeout(function() {2813var callback;2814while (callback = vkAsyncInitCallbacks.pop()) {2815try {2816callback();2817} catch(e) {2818try {2819console.error(e);2820} catch (e2) {}2821}2822}2823}, 0);2824}
2825
2826try{stManager.done('api/openapi.js');}catch(e){}2827