1(function(w) { 2 if (w.fastXDM) return; 3 4 var handlers = {}; 5 var onEnvLoad = []; 6 var env = {}; 7 8 // Key generation 9 function genKey() { 10 var key = ''; 11 for (var i = 0; i < 5; i++) { 12 key += Math.ceil(Math.random() * 15).toString(16); 13 } 14 return key; 15 } 16 17 function waitFor(obj, prop, func, self, count) { 18 if (obj[prop]) { 19 func.apply(self); 20 } else { 21 count = count || 0; 22 if (count < 1000) { 23 setTimeout(function() { 24 waitFor(obj, prop, func, self, count + 1); 25 }, 0); 26 } 27 } 28 } 29 30 function attachScript(url) { 31 setTimeout(function() { 32 var newScript = document.createElement('script'); 33 newScript.type = 'text/javascript'; 34 newScript.src = url || w.fastXDM.helperUrl; 35 waitFor(document, 'body', function() { 36 document.getElementsByTagName('HEAD')[0].appendChild(newScript); 37 }); 38 }, 0); 39 } 40 41 function walkVar(value, clean) { 42 var newValue; 43 44 switch (typeof value) { 45 case 'string': 46 if (clean) { 47 newValue = value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); 48 } else { 49 newValue = value.replace(/'/g, '\'').replace(/"/g, '"').replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&'); 50 } 51 break; 52 case 'object': 53 if (Object.prototype.toString.apply(value) === '[object Array]') { 54 newValue = []; 55 for (var i = 0, len = value.length; i < len; i++) { 56 newValue[i] = walkVar(value[i], clean); 57 } 58 } else { 59 newValue = {}; 60 for (var k in value) { 61 if (Object.hasOwnProperty.call(value, k)) { 62 newValue[k] = walkVar(value[k], clean); 63 } 64 } 65 } 66 break; 67 default: 68 newValue = value; 69 break; 70 } 71 72 return newValue; 73 } 74 75 // Env functions 76 function getEnv(callback, self) { 77 if (env.loaded) { 78 callback.apply(self, [env]); 79 } else { 80 onEnvLoad.push([self, callback]); 81 } 82 } 83 84 function envLoaded() { 85 env.loaded = true; 86 87 for (var i = 0, len = onEnvLoad.length; i < len; i++) { 88 onEnvLoad[i][1].apply(onEnvLoad[i][0], [env]); 89 } 90 } 91 92 function applyMethod(strData, self) { 93 getEnv(function(env) { 94 var data = env.json.parse(strData); 95 if (data[0]) { 96 if (!data[1]) data[1] = []; 97 98 for (var i = 0, len = data[1].length; i < len; i++) { 99 if (data[1][i] && data[1][i]._func) { 100 var funcNum = data[1][i]._func; 101 data[1][i] = function() { 102 var args = Array.prototype.slice.call(arguments); 103 args.unshift('_func' + funcNum); 104 self.callMethod.apply(self, args); 105 } 106 } else if (self.options.safe) { 107 data[1][i] = walkVar(data[1][i], true); 108 } 109 } 110 111 setTimeout(function() { 112 if (!self.methods[data[0]]) { 113 throw Error('fastXDM: Method ' + data[0] + ' is undefined'); 114 } 115 self.methods[data[0]].apply(self, data[1]); 116 }, 0); 117 } 118 }); 119 } 120 121 function extend(obj1, obj2) { 122 for (var i in obj2) { 123 if (obj1[i] && typeof(obj1[i]) === 'object') { 124 extend(obj1[i], obj2[i]) 125 } else { 126 obj1[i] = obj2[i]; 127 } 128 } 129 } 130 131 // XDM object 132 w.fastXDM = { 133 _id: 0, 134 helperUrl: 'https://vk.com/js/api/xdmHelper.js', 135 136 Server: function(methods, filter, options) { 137 this.methods = methods || {}; 138 this.filter = filter; 139 this.options = options || {}; 140 this.id = w.fastXDM._id++; 141 this.key = genKey(); 142 this.frameName = 'fXD' + this.key; 143 this.server = true; 144 145 this.methods['%init%'] = this.methods.__fxdm_i = function() { 146 w.fastXDM.run(this.id); 147 if (this.methods.onInit) { 148 this.methods.onInit(); 149 } 150 }; 151 152 handlers[this.key] = [applyMethod, this]; 153 }, 154 155 Client: function(methods, options) { 156 this.methods = methods || {}; 157 this.options = options || {}; 158 this.id = w.fastXDM._id++; 159 this.client = true; 160 161 w.fastXDM.run(this.id); 162 163 if (window.name.indexOf('fXD') === 0) { 164 this.key = window.name.substr(3); 165 } else { 166 throw Error('Wrong window.name property.'); 167 } 168 169 this.caller = window.parent; 170 171 handlers[this.key] = [applyMethod, this]; 172 173 w.fastXDM.on('helper', function() { 174 w.fastXDM.onClientStart(this); 175 }, this); 176 177 getEnv(function(env) { 178 env.send(this, env.json.stringify(['%init%'])); 179 180 var methods = this.methods; 181 setTimeout(function() { 182 if (methods.onInit) { 183 methods.onInit(); 184 } 185 }, 0); 186 }, this); 187 }, 188 189 onMessage: function(e) { 190 var data = e.data; 191 if (!data) { 192 return false;
193 } 194 if (typeof data !== 'string' && !(data instanceof String)) { 195 return false; 196 } 197 198 var key = data.substr(0, 5); 199 if (handlers[key]) { 200 var self = handlers[key][1]; 201 if (self && (!self.filter || self.filter(e.origin))) { 202 handlers[key][0](data.substr(6), self); 203 } 204 } 205 }, 206 207 setJSON: function(json) { 208 env.json = json; 209 }, 210 211 getJSON: function(callback) { 212 if (!callback) { 213 return env.json; 214 } 215 216 getEnv(function(env) { 217 callback(env.json); 218 }); 219 }, 220 221 setEnv: function(exEnv) { 222 for (var i in exEnv) { 223 env[i] = exEnv[i]; 224 } 225 226 envLoaded(); 227 }, 228 229 _q: {}, 230 231 on: function(key, act, self) { 232 if (!this._q[key]) this._q[key] = []; 233 234 if (this._q[key] == -1) { 235 act.apply(self); 236 } else { 237 this._q[key].push([act, self]); 238 } 239 }, 240 241 run: function(key) { 242 var len = (this._q[key] || []).length; 243 for (var i = 0; i < len; i++) { 244 this._q[key][i][0].apply(this._q[key][i][1]); 245 } 246 247 this._q[key] = -1; 248 }, 249 250 waitFor: waitFor 251 } 252 253 w.fastXDM.Server.prototype.start = function(obj, count) { 254 if (obj.contentWindow) { 255 this.caller = obj.contentWindow; 256 this.frame = obj; 257 258 w.fastXDM.on('helper', function() { 259 w.fastXDM.onServerStart(this); 260 }, this); 261 } else { // Opera old versions 262 var self = this; 263 count = count || 0; 264 if (count < 50) { 265 setTimeout(function() { 266 self.start.apply(self, [obj, count + 1]); 267 }, 100); 268 } 269 } 270 } 271 272 w.fastXDM.Server.prototype.destroy = function() { 273 delete handlers[this.key]; 274 } 275 276 w.fastXDM.Server.prototype.append = function(obj, options, attrs) { 277 var div = document.createElement('DIV'); 278 div.innerHTML = '<iframe name="' + this.frameName + '" ' + (attrs || '') + '></iframe>'; 279 var frame = div.firstChild; 280 var self = this; 281 282 setTimeout(function() { 283 frame.frameBorder = '0'; 284 if (options) extend(frame, options); 285 obj.insertBefore(frame, obj.firstChild); 286 self.start(frame); 287 }, 0); 288 289 return frame; 290 } 291 292 w.fastXDM.Client.prototype.callMethod = w.fastXDM.Server.prototype.callMethod = function() { 293 var args = Array.prototype.slice.call(arguments); 294 var method = args.shift(); 295 296 for (var i = 0, len = args.length; i < len; i++) { 297 if (typeof(args[i]) === 'function') { 298 this.funcsCount = (this.funcsCount || 0) + 1; 299 var func = args[i]; 300 var funcName = '_func' + this.funcsCount; 301 302 this.methods[funcName] = function() { 303 func.apply(this, arguments); 304 delete this.methods[funcName]; 305 } 306 307 args[i] = {_func: this.funcsCount}; 308 } else if (this.options.safe) { 309 args[i] = walkVar(args[i], false); 310 } 311 } 312 313 waitFor(this, 'caller', function() { 314 w.fastXDM.on(this.id, function() { 315 getEnv(function(env) { 316 env.send(this, env.json.stringify([method, args])); 317 }, this); 318 }, this); 319 }, this); 320 } 321 322 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]}') { 323 env.json = {parse: w.JSON.parse, stringify: w.JSON.stringify}; 324 } else { 325 w.fastXDM._needJSON = true; 326 } 327 328 // PostMessage cover 329 if (w.postMessage) { 330 env.protocol = 'p'; 331 env.send = function(xdm, strData) { 332 var win = (xdm.frame ? xdm.frame.contentWindow : xdm.caller); 333 if (win) { 334 try { 335 win.postMessage(xdm.key + ':' + strData, "*"); 336 } catch(e) { 337 window.postMessage.call(win, xdm.key + ':' + strData, "*"); 338 } 339 } 340 } 341 342 if (w.addEventListener) { 343 w.addEventListener("message", w.fastXDM.onMessage, false); 344 } else { 345 w.attachEvent("onmessage", w.fastXDM.onMessage); 346 } 347 348 if (w.fastXDM._needJSON) { 349 w.fastXDM._onlyJSON = true; 350 attachScript(); 351 } else { 352 envLoaded(); 353 } 354 } else { 355 attachScript(); 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);
367v=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) { 375 for (var key in source) { 376 if (overwrite || typeof target[key] === 'undefined') { 377 target[key] = source[key]; 378 } 379 } 380 return target; 381}; 382 383VK._protocol = 'https:'; 384 385if (!VK.xdConnectionCallbacks) { 386 387 VK.extend(VK, { 388 version: 1, 389 _apiId: null, 390 _session: null, 391 _userStatus: 'unknown', 392 _domain: { 393 main: 'https://oauth.vk.com/', 394 api: 'https://api.vk.com/' 395 }, 396 _path: { 397 login: 'authorize', 398 proxy: 'fxdm_oauth_proxy.html' 399 }, 400 _rootId: 'vk_api_transport', 401 _nameTransportPath: '', 402 xdReady: false, 403 access: { 404 FRIENDS: 0x2, 405 PHOTOS: 0x4, 406 AUDIO: 0x8, 407 VIDEO: 0x10, 408 MATCHES: 0x20, 409 QUESTIONS: 0x40, 410 WIKI: 0x80 411 } 412 }); 413 414 VK.init = function(options) { 415 var body, root; 416 417 VK._apiId = null; 418 if (!options.apiId) { 419 throw Error('VK.init() called without an apiId'); 420 } 421 VK._apiId = options.apiId; 422 423 if (options.onlyWidgets) return true; 424
425 if (options.nameTransportPath && options.nameTransportPath !== '') { 426 VK._nameTransportPath = options.nameTransportPath; 427 } 428 429 root = document.getElementById(VK._rootId); 430 if (!root) { 431 root = document.createElement('div'); 432 root.id = VK._rootId; 433 body = document.getElementsByTagName('body')[0]; 434 body.insertBefore(root, body.childNodes[0]); 435 } 436 root.style.position = 'absolute'; 437 root.style.top = '-10000px'; 438 439 var session = VK.Cookie.load(); 440 if (session) { 441 VK.Auth._loadState = 'loaded'; 442 VK.Auth.setSession(session, session ? 'connected' : 'unknown'); 443 } 444 }; 445 446 if (!VK.Cookie) { 447 VK.Cookie = { 448 _domain: null, 449 load: function() { 450 var cookie = document.cookie.match('\\bvk_app_' + VK._apiId + '=([^;]*)\\b') 451 var session; 452 453 if (cookie) { 454 session = this.decode(cookie[1]); 455 if (session.secret != 'oauth') { 456 return false; 457 } 458 session.expire = parseInt(session.expire, 10); 459 VK.Cookie._domain = '.' + window.location.hostname;//session.base_domain; 460 } 461 462 return session; 463 }, 464 setRaw: function(val, ts, domain, time) { 465 var rawCookie; 466 rawCookie = 'vk_app_' + VK._apiId + '=' + val + ''; 467 var exp = time ? (new Date().getTime() + time * 1000) : ts * 1000; 468 rawCookie += (val && ts === 0 ? '' : '; expires=' + new Date(exp).toGMTString()); 469 rawCookie += '; path=/'; 470 rawCookie += (domain ? '; domain=.' + domain : ''); 471 document.cookie = rawCookie; 472 473 this._domain = domain; 474 }, 475 set: function(session, resp) { 476 if (session) { 477 this.setRaw(this.encode(session), session.expire, window.location.hostname, (resp || {}).time); 478 } else { 479 this.clear(); 480 } 481 }, 482 clear: function() {
483 this.setRaw('', 0, this._domain, 0); 484 }, 485 encode: function(params) { 486 var 487 pairs = [], 488 key; 489 490 for (key in params) { 491 if (key != 'user') pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key])); 492 } 493 pairs.sort(); 494 495 return pairs.join('&'); 496 }, 497 decode: function(str) { 498 var 499 params = {}, 500 parts = str.split('&'), 501 i, 502 pair; 503 504 for (i=0; i < parts.length; i++) { 505 pair = parts[i].split('=', 2); 506 if (pair && pair[0]) { 507 params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); 508 } 509 } 510 511 return params; 512 } 513 }; 514 } 515 516 if (!VK.Api) { 517 VK.Api = { 518 _headId: null, 519 _callbacks: {}, 520 521 ie6_7: function() { 522 if (!VK.Api.ieTested) { 523 VK.Api.isIE6_7 = navigator.userAgent.match(/MSIE [6|7]/i); 524 VK.Api.ieTested = true; 525 } 526 return VK.Api.isIE6_7; 527 }, 528 529 supportCORS: function() { 530 var xhr = new XMLHttpRequest(); 531 if ("withCredentials" in xhr) { 532 return true; 533 } 534 535 if (typeof XDomainRequest != "undefined") { 536 return true; 537 } 538 539 return false; 540 }, 541 542 makeRequest: function(url, cb) { 543 var xhr = VK.Api.createRequest('GET', url); 544 if (!xhr) { 545 return false; 546 } 547 548 xhr.onload = function() { 549 var text = xhr.responseText; 550 if (xhr.status === 200) { 551 cb(text); 552 } else { 553 try { 554 console.error('Open api access error', xhr.response); 555 } catch(e) { 556 //nop 557 } 558 } 559 }; 560 561 xhr.onerror = function() { 562 try { 563 console.error('Open api access error'); 564 } catch(e) { 565 //nop 566 } 567 }; 568 569 xhr.send(); 570 return true; 571 }, 572 573 createRequest: function(method, url) { 574 var xhr = new XMLHttpRequest(); 575 576 if ("withCredentials" in xhr) { 577 // XHR for Chrome/Firefox/Opera/Safari. 578 xhr.open(method, url, true); 579 xhr.withCredentials = true; 580 } else if (typeof XDomainRequest != "undefined") { 581 // XDomainRequest for IE. 582 xhr = new XDomainRequest(); 583 xhr.open(method, url); 584 xhr.withCredentials = true; 585 } else { 586 // CORS not supported. 587 xhr = null; 588 } 589 590 return xhr; 591 }, 592 593 attachScript: function(url) { 594 if (!VK.Api._headId) VK.Api._headId = document.getElementsByTagName("head")[0]; 595 var newScript = document.createElement('script'); 596 newScript.type = 'text/javascript'; 597 newScript.setAttribute('encoding', 'UTF-8'); 598 newScript.src = url; 599 VK.Api._headId.appendChild(newScript); 600 }, 601 602 checkMethod: function(method, params, cb, queryTry) { 603 var m = method.toLowerCase(); 604 if (m == 'wall.post' || m == 'activity.set') { 605 var text = (m == 'activity.set') ? params.text : params.message; 606 if (!text) { 607 text = ''; 608 } 609 var query = VK._protocol + 'http://vk.com/al_apps.php?act=wall_post_box&widget=4&method='+m+'&aid=' + parseInt(VK._apiId, 10) + '&text=' + encodeURIComponent(text); 610 if (m == 'wall.post') { 611 query += '&owner_id=' + parseInt(params.owner_id || 0, 10) + '&attachments=' + (params.attachments || params.attachment || '') + '&publish_date=' + (params.publish_date || ''); 612 } 613 var method_access = '_'+(Math.random()).toString(16).substr(2); 614 query += '&method_access='+method_access; 615 var popup = VK.UI.popup({ 616 url: query, 617 width: 560, 618 height: 304 619 }); 620 var timer = setInterval(function() { 621 if (VK.UI.active.closed) { 622 clearInterval(timer); 623 params.method_access = method_access; 624 VK.Api.call(method, params, cb, queryTry); 625 } 626 }, 500); 627 return false;
628 } 629 630 if (m == 'messages.allowmessagesfromgroup') { 631 var method_access = '_' + (Math.random()).toString(16).substr(2); 632 var query = VK._protocol + 'http://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=' + method_access; 633 634 VK.UI.popup({ 635 url: query, 636 width: 560, 637 height: 304 638 }); 639 640 var timer = setInterval(function () { 641 if (VK.UI.active.closed) { 642 clearInterval(timer); 643 params.method_access = method_access; 644 VK.Api.call(method, params, cb, queryTry); 645 } 646 }, 500); 647 648 return false; 649 } 650 651 return true; 652 }, 653 654 call: function(method, params, cb, queryTry) { 655 var 656 query = params || {}, 657 qs, 658 responseCb; 659 660 if (typeof query != 'object' || typeof cb != 'function') { 661 return false; 662 } 663 if (!params.method_access && !params.method_force && !VK.Api.checkMethod(method, params, cb, queryTry)) { 664 return; 665 } 666 667 if (!queryTry) queryTry = 0; 668 669 if (VK.Auth._loadState != 'loaded') { 670 var authFunc = function(result) { 671 if (result && result.session) { 672 VK.Observer.unsubscribe('auth.loginStatus', authFunc); 673 VK.Api.call(method, params, cb); 674 } 675 }; 676 VK.Observer.subscribe('auth.loginStatus', authFunc); 677 VK.Auth.getLoginStatus(); 678 return; 679 } 680 681 if (VK.Api.queryLength(query) < 1500 && !VK.Api.ie6_7()) { 682 var useXDM = false; 683 var rnd = parseInt(Math.random() * 10000000, 10); 684 while (VK.Api._callbacks[rnd]) { 685 rnd = parseInt(Math.random() * 10000000, 10) 686 } 687 query.callback = 'VK.Api._callbacks['+rnd+']'; 688 } else { 689 var useXDM = true; 690 } 691 692 if (VK._session && VK._session.sid) { 693 query.access_token = VK._session.sid; 694 } 695 696 qs = VK.Cookie.encode(query); 697 698 responseCb = function(response) { 699 if (response.error && (response.error.error_code == 3 || response.error.error_code == 4 || response.error.error_code == 5)) { 700 if (queryTry > 3) return false; 701 var repeatCall = function(resp) { 702 VK.Observer.unsubscribe('auth.sessionChange', repeatCall); 703 delete params.access_token; 704 if (resp.session) VK.Api.call(method, params, cb, queryTry + 1); 705 } 706 VK.Observer.subscribe('auth.sessionChange', repeatCall); 707 VK.Auth.getLoginStatus(); 708 } else { 709 cb(response); 710 } 711 if (!useXDM) delete VK.Api._callbacks[rnd]; 712 }; 713 714 if (useXDM) { 715 if (VK.xdReady) { 716 VK.XDM.remote.callMethod('apiCall', method, qs, responseCb); 717 } else { 718 VK.Observer.subscribe('xdm.init', function() { 719 VK.XDM.remote.callMethod('apiCall', method, qs, responseCb); 720 }); 721 VK.XDM.init(); 722 } 723 } else { 724 VK.Api._callbacks[rnd] = responseCb; 725 VK.Api.attachScript(VK._domain.api + 'method/' + method +'?' + qs); 726 } 727 }, 728 729 queryLength: function(query) { 730 var len = 100, i; // sid + sig 731 for (i in query) { 732 len += i.length + encodeURIComponent(query[i]).length + 1; 733 } 734 return len; 735 } 736 }; 737 738// Alias 739 VK.api = function(method, params, cb) {VK.Api.call(method, params, cb);} 740 }; 741 742 if (!VK.Auth) { 743 VK.Auth = { 744 popup: null, 745 lsCb: {}, 746 747 setSession: function(session, status, settings, resp) { 748 var 749 login = !VK._session && session, 750 logout = VK._session && !session, 751 both = VK._session && session && VK._session.mid != session.mid, 752 sessionChange = login || logout || (VK._session && session && VK._session.sid != session.sid), 753 statusChange = status != VK._userStatus, 754 response = { 755 'session': session, 756 'status': status, 757 'settings': settings 758 }; 759 760 VK._session = session; 761 762 VK._userStatus = status; 763 764 VK.Cookie.set(session, resp); 765 766 if (sessionChange || statusChange || both) { 767 setTimeout(function() { 768 if (statusChange) { 769 VK.Observer.publish('auth.statusChange', response); 770 } 771 772 if (logout || both) { 773 VK.Observer.publish('auth.logout', response); 774 } 775 776 if (login || both) { 777 VK.Observer.publish('auth.login', response); 778 } 779 780 if (sessionChange) { 781 VK.Observer.publish('auth.sessionChange', response); 782 } 783 }, 0); 784 } 785 786 return response; 787 }, 788 789 // Public VK.Auth methods 790 login: function(cb, settings) { 791 if (!VK._apiId) { 792 return false;
793 } 794 795 var url = VK._domain.main + VK._path.login + '?client_id='+VK._apiId+'&display=popup&redirect_uri=close.html&response_type=token'; 796 if (settings && parseInt(settings, 10) > 0) { 797 url += '&scope=' + settings; 798 } 799 800 VK.Observer.unsubscribe('auth.onLogin'); 801 VK.Observer.subscribe('auth.onLogin', cb); 802 803 VK.UI.popup({ 804 width: 665, 805 height: 370, 806 url: url 807 }); 808 809 var authCallback = function() { 810 VK.Auth.getLoginStatus(function(resp) { 811 VK.Observer.publish('auth.onLogin', resp); 812 VK.Observer.unsubscribe('auth.onLogin'); 813 }, true); 814 } 815 816 VK.UI.popupOpened = true; 817 var popupCheck = function() { 818 if (!VK.UI.popupOpened) { 819 return false; 820 } 821 822 try { 823 if (!VK.UI.active.top || VK.UI.active.closed) { 824 VK.UI.popupOpened = false; 825 authCallback(); 826 return true; 827 } 828 } catch(e) { 829 VK.UI.popupOpened = false; 830 authCallback(); 831 return true; 832 } 833 setTimeout(popupCheck, 100); 834 }; 835 836 setTimeout(popupCheck, 100); 837 }, 838 839 // Logout user from app, vk.com & login.vk.com 840 logout: function(cb) { 841 VK.Auth.revokeGrants(cb); 842 }, 843 844 revokeGrants: function(cb) { 845 var onLogout = function(resp) { 846 VK.Observer.unsubscribe('auth.statusChange', onLogout); 847 if (cb) { 848 cb(resp); 849 } 850 } 851 852 VK.Observer.subscribe('auth.statusChange', onLogout); 853 if (VK._session && VK._session.sid) { 854 var url = 'https://login.vk.com/?act=openapi&oauth=1&aid=' + parseInt(VK._apiId, 10) + '&location=' + encodeURIComponent(window.location.hostname) + '&do_logout=1&token='
854+ VK._session.sid; 855 if (VK.Api.supportCORS()) { 856 var logoutCallback = function() { 857 VK.Auth.setSession(null, 'unknown'); 858 }; 859 860 VK.Api.makeRequest(url + '&new=1', logoutCallback); 861 } else { 862 VK.Api.attachScript(url); 863 } 864 } 865 866 VK.Cookie.clear(); 867 }, 868 869 // Get current login status from session (sync) (not use on load time) 870 getSession: function() { 871 return VK._session; 872 }, 873 874 // Get current login status from vk.com (async) 875 getLoginStatus: function(cb, force) { 876 if (!VK._apiId) { 877 return; 878 } 879 880 if (cb) { 881 if (!force && VK.Auth._loadState == 'loaded') { 882 cb({status: VK._userStatus, session: VK._session}); 883 return; 884 } else { 885 VK.Observer.subscribe('auth.loginStatus', cb); 886 } 887 } 888 889 if (!force && VK.Auth._loadState == 'loading') { 890 return; 891 } 892 893 VK.Auth._loadState = 'loading'; 894 895 var url = 'https://login.vk.com/?act=openapi&oauth=1&aid=' + parseInt(VK._apiId, 10) + '&location=' + encodeURIComponent(window.location.hostname); 896 if (VK.Api.supportCORS()) { 897 var loginCallback = function(response) { 898 if (!this.JSON) { 899 this.JSON = {}; 900 } 901 902 if (typeof JSON.parse !== 'function') { 903 //IE6 and IE7 904 response = eval(response); 905 } else { 906 response = JSON.parse(response); 907 } 908 909 VK.Auth._loadState = 'loaded'; 910 if (response && response.auth) { 911 var session = { 912 mid: response.user.id, 913 sid: response.access_token, 914 sig: response.sig, 915 secret: response.secret, 916 expire: response.expire 917 }; 918 919 if (force) { 920 session.user = response.user; 921 } 922 923 var status = 'connected'; 924 } else { 925 var session = null; 926 var status = response.user ? 'not_authorized' : 'unknown'; 927 VK.Cookie.clear(); 928 } 929 930 VK.Auth.setSession(session, status, false, response); 931 VK.Observer.publish('auth.loginStatus', {session: session, status: status}); 932 VK.Observer.unsubscribe('auth.loginStatus'); 933 }; 934 935 VK.Api.makeRequest(url + '&new=1', loginCallback); 936 } else { 937 var rnd = parseInt(Math.random() * 10000000, 10); 938 while (VK.Auth.lsCb[rnd]) { 939 rnd = parseInt(Math.random() * 10000000, 10); 940 } 941 942 VK.Auth.lsCb[rnd] = function(response) { 943 delete VK.Auth.lsCb[rnd]; 944 VK.Auth._loadState = 'loaded'; 945 if (response && response.auth) { 946 var session = { 947 mid: response.user.id, 948 sid: response.access_token, 949 sig: response.sig, 950 secret: response.secret, 951 expire: response.expire 952 }; 953 if (force) session.user = response.user; 954 var status = 'connected'; 955 } else { 956 var session = null; 957 var status = response.user ? 'not_authorized' : 'unknown'; 958 VK.Cookie.clear(); 959 } 960 VK.Auth.setSession(session, status, false, response); 961 VK.Observer.publish('auth.loginStatus', {session: session, status: status}); 962 VK.Observer.unsubscribe('auth.loginStatus'); 963 }; 964 965 // AttachScript here 966 VK.Api.attachScript(url+'&rnd='+rnd); 967 } 968 } 969 }; 970 } 971 972} else { // if VK.xdConnectionCallbacks 973 setTimeout(function() { 974 var callback; 975 while (callback = VK.xdConnectionCallbacks.pop()) { 976 callback(); 977 } 978 }, 0); 979 if (VK.Widgets && !VK.Widgets._constructor) { 980 VK.Widgets = false; 981 } 982} 983 984if (!VK.UI) { 985 VK.UI = { 986 active: null, 987 _buttons: [], 988 popup: function(options) { 989 var 990 screenX = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft, 991 screenY = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop, 992 outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth, 993 outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22), 994 width = options.width, 995 height = options.height, 996 left = parseInt(screenX + ((outerWidth - width) / 2), 10), 997 top = parseInt(screenY + ((outerHeight - height) / 2.5), 10), 998 features = ( 999 'width=' + width + 1000 ',height=' + height + 1001 ',left=' + left + 1002 ',top=' + top 1003 ); 1004 this.active = window.open(options.url, 'vk_openapi', features); 1005 }, 1006 button: function(el, handler) { 1007 var html = ''; 1008 1009 if (typeof el == 'string') { 1010 el = document.getElementById(el); 1011 } 1012 1013 1014 this._buttons.push(el); 1015 index = this._buttons.length - 1; 1016 1017 html = ( 1018 '<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">' + 1019 '<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>' + 1020 '<td><div style="background: url(' + VK._protocol + 'http://vk.com/images/btns.png) 0px -42px no-repeat; width: 21px; height: 21px"></div></td>' + 1021 '<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>' + 1022 '</tr></table>' 1023 ); 1024 el.innerHTML = html; 1025 el.style.width = el.childNodes[0].offsetWidth + 'px'; 1026 }, 1027 _change: function(state, index) {
1028 var row = document.getElementById('openapi_UI_' + index).rows[0]; 1029 var elems = [row.cells[0].firstChild.firstChild, row.cells[2].firstChild.firstChild]; 1030 for (var i = 0; i < 2; ++i) { 1031 var elem = elems[i]; 1032 if (state === 0) { 1033 elem.style.backgroundColor = '#6D8DB1'; 1034 elem.style.borderTopColor = '#7E9CBC'; 1035 elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#5C82AB'; 1036 } else if (state == 1) { 1037 elem.style.backgroundColor = '#7693B6'; 1038 elem.style.borderTopColor = '#88A4C4'; 1039 elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderBottomColor = '#6088B4'; 1040 } else if (state == 2) { 1041 elem.style.backgroundColor = '#6688AD'; 1042 elem.style.borderBottomColor = '#7495B8'; 1043 elem.style.borderLeftColor = elem.style.borderRightColor = elem.style.borderTopColor = '#51779F'; 1044 } 1045 } 1046 if (state === 0 || state == 2) { 1047 row.cells[2].firstChild.style.backgroundPosition = '0px -42px'; 1048 } else if (state == 1) { 1049 row.cells[2].firstChild.style.backgroundPosition = '0px -63px'; 1050 } 1051 } 1052 }; 1053} 1054 1055if (!VK.XDM) { 1056 VK.XDM = { 1057 remote: null, 1058 init: function() { 1059 if (this.remote) return false; 1060 var url = VK._domain.api + VK._path.proxy; 1061 this.remote = new fastXDM.Server({ 1062 onInit: function() { 1063 VK.xdReady = true; 1064 VK.Observer.publish('xdm.init'); 1065 } 1066 }); 1067 1068 this.remote.append(document.getElementById(VK._rootId), { 1069 src: url 1070 }); 1071 }, 1072 xdHandler: function(code) { 1073 try { 1074 eval('VK.' + code); 1075 } catch(e) {} 1076 } 1077 }; 1078} 1079 1080if (!VK.Observer) { 1081 VK.Observer = { 1082 _subscribers: function() { 1083 if (!this._subscribersMap) { 1084 this._subscribersMap = {}; 1085 } 1086 return this._subscribersMap; 1087 }, 1088 publish: function(eventName) { 1089 var 1090 args = Array.prototype.slice.call(arguments), 1091 eventName = args.shift(), 1092 subscribers = this._subscribers()[eventName], 1093 i, j; 1094 1095 if (!subscribers) return; 1096 1097 for (i = 0, j = subscribers.length; i < j; i++) { 1098 if (subscribers[i] != null) { 1099 subscribers[i].apply(this, args); 1100 } 1101 } 1102 }, 1103 subscribe: function(eventName, handler) { 1104 var 1105 subscribers = this._subscribers(); 1106 1107 if (typeof handler != 'function') return false; 1108 1109 if (!subscribers[eventName]) { 1110 subscribers[eventName] = [handler]; 1111 } else { 1112 subscribers[eventName].push(handler); 1113 } 1114 }, 1115 unsubscribe: function(eventName, handler) { 1116 var 1117 subscribers = this._subscribers()[eventName], 1118 i, j; 1119 1120 if (!subscribers) return false; 1121 if (typeof handler == 'function') { 1122 for (i = 0, j = subscribers.length; i < j; i++) { 1123 if (subscribers[i] == handler) { 1124 subscribers[i] = null; 1125 } 1126 } 1127 } else { 1128 delete this._subscribers()[eventName]; 1129 } 1130 } 1131 }; 1132} 1133 1134if (!VK.Widgets) { 1135 VK.Widgets = {}; 1136 1137 VK.Widgets.count = 0; 1138 VK.Widgets.RPC = {}; 1139 1140 VK.Widgets.showBoxUrl = function(domain, url) { 1141 domain = (domain || VK._protocol + 'http://vk.com').replace(/\/?\s*$/, ''); 1142 url = url.replace(/^\s*\/?/, ''); 1143 return domain + '/' + url; 1144 }; 1145 1146 VK.Widgets.loading = function(obj, enabled) { 1147 obj.style.background = enabled ? 'url("' + VK._protocol + 'http://vk.com/images/upload.gif") center center no-repeat transparent' : 'none'; 1148 }; 1149 1150 VK.Widgets.Comments = function(objId, options, page) { 1151 var pData = VK.Util.getPageData(); 1152 if (!VK._apiId) throw Error('VK not initialized. Please use VK.init'); 1153 options = options || {}; 1154 var params = { 1155 limit: options.limit || 10, 1156 height: options.height || 0, 1157 mini: options.mini === undefined ? 'auto' : options.mini, 1158 norealtime: options.norealtime ? 1 : 0 1159 }, mouseup = function() { 1160 rpc.callMethod('mouseUp'); 1161 return false; 1162 }, move = function(event) { 1163 rpc.callMethod('mouseMove', {screenY: event.screenY}); 1164 }, iframe, rpc; 1165 1166 if (options.browse) { // browse all comments 1167 params.browse = 1; 1168 params.replies = options.replies || 0; 1169 } else { // page 1170 var url = options.pageUrl || pData.url; 1171 if (url.substr(0, 1) == '/') { 1172 url = (location.protocol + '//' + location.host) + url; 1173 } 1174 VK.extend(params, { 1175 page: page || 0, 1176 status_publish: options.autoPublish === undefined ? 1 : options.autoPublish, 1177 attach: options.attach === undefined ? '*' : (options.attach ? options.attach : ''), 1178 url: url, 1179 title: options.pageTitle || pData.title, 1180 description: options.pageDescription || pData.description, 1181 image: options.pageImage || pData.image 1182 }); 1183 } 1184 if (options.onChange) { // DEPRECATED 1185 VK.Observer.subscribe('widgets.comments.new_comment', options.onChange); 1186 VK.Observer.subscribe('widgets.comments.delete_comment', options.onChange); 1187 } 1188 1189 return VK.Widgets._constructor('widget_comments.php', objId, options, params, { 1190 showBox: function(url, props) { 1191 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], { 1192 proxy: function() { 1193 rpc.callMethod.apply(rpc, arguments); 1194 } 1195 }); 1196 box.show(); 1197 }, 1198 startDrag: function() { 1199 cursorBack = window.document.body.style.cursor; 1200 window.document.body.style.cursor = 'pointer'; 1201 VK.Util.addEvent('mousemove', move); 1202 VK.Util.addEvent('mouseup', mouseup); 1203 }, 1204 stopDrag: function() {
1205 window.document.body.style.cursor = cursorBack; 1206 VK.Util.removeEvent('mousemove', move); 1207 VK.Util.removeEvent('mouseup', mouseup); 1208 } 1209 }, { 1210 startHeight: 133, 1211 minWidth: 300, 1212 width: '100%' 1213 }, function(o, i, r) {iframe = i; rpc = r;}); 1214 }; 1215 1216 VK.Widgets.CommentsBrowse = function(objId, options) { 1217 options = options || {}; 1218 options.browse = 1; 1219 return VK.Widgets.Comments(objId, options); 1220 }; 1221 1222 VK.Widgets.Recommended = function(objId, options) { 1223 var pData = VK.Util.getPageData(); 1224 if (!VK._apiId) throw Error('VK not initialized. Please use VK.init'); 1225 options = options || {}; 1226 var params = { 1227 limit: options.limit || 5, 1228 max: options.max || 0, 1229 sort: options.sort || 'friend_likes', 1230 verb: options.verb || 0, 1231 period: options.period || 'week', 1232 target: options.target || 'parent' 1233 }; 1234 return VK.Widgets._constructor('widget_recommended.php', objId, options, params, {}, { 1235 startHeight: (116 + params.limit * 47 - 15), 1236 minWidth: 150, 1237 width: '100%' 1238 }); 1239 }; 1240 1241 VK.Widgets.Post = function(objId, ownerId, postId, hash, options) { 1242 options = options || {}; 1243 var obj = document.getElementById(objId), 1244 params = { 1245 owner_id: ownerId, 1246 post_id: postId, 1247 hash: hash || '', 1248 width: options.width || (obj && obj.offsetWidth > 0 ? obj.offsetWidth : 500) 1249 }, iframe, rpc, cursorBack; 1250 if (options.preview) { 1251 params.preview = 1; 1252 delete options['preview']; 1253 } 1254 return VK.Widgets._constructor('widget_post.php', objId, options, params, { 1255 showBox: function(url, props) { 1256 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], { 1257 proxy: function() { 1258 rpc.callMethod.apply(rpc, arguments); 1259 } 1260 }); 1261 box.show(); 1262 }, 1263 startDrag: function() { 1264 cursorBack = window.document.body.style.cursor; 1265 window.document.body.style.cursor = 'pointer'; 1266 }, 1267 stopDrag: function() { 1268 window.document.body.style.cursor = cursorBack; 1269 } 1270 }, { 1271 startHeight: 90, 1272 minWidth: 250, 1273 width: '100%' 1274 }, function(o, i, r) {iframe = i; rpc = r;}); 1275 }; 1276 1277 VK.Widgets.Like = (function(Like) { 1278 if (Like) return Like; 1279 1280 var instances = []; 1281 1282 Like = function(objId, options, page) { 1283 var pData = VK.Util.getPageData(); 1284 if (!VK._apiId) throw Error('VK not initialized. Please use VK.init'); 1285 options = VK.extend(options || {}, {allowTransparency: true}); 1286 var verticalBtnHeightWidth = { 1287 18: 43, 1288 20: 47, 1289 22: 51, 1290 24: 55, 1291 30: 67, 1292 }, 1293 type = (options.type == 'full' || options.type == 'button' || options.type == 'vertical' || options.type == 'mini') ? options.type : 'full', 1294 autoWidth = options.width === 'auto' && (type == 'button' || type == 'mini'), 1295 btnHeight = parseInt(options.height, 10) || 22, 1296 size = btnHeight && verticalBtnHeightWidth[btnHeight] ? btnHeight : 22, 1297 width = autoWidth ? 153 : (type == 'full' ? Math.max(200, options.width || 350) : (type == 'button' ? 180 : (type == 'mini' ? 115 : verticalBtnHeightWidth[size]))), 1298 height = type == 'vertical' ? (2 * btnHeight + 7) : btnHeight, 1299 params = { 1300 page: page || 0, 1301 url: options.pageUrl || pData.url, 1302 type: type, 1303 verb: options.verb == 1 ? 1 : 0, 1304 color: options.color || '', 1305 title: options.pageTitle || pData.title, 1306 description: options.pageDescription || pData.description, 1307 image: options.pageImage || pData.image, 1308 text: (options.text || '').substr(0, 140), 1309 h: btnHeight 1310 }, 1311 ttHere = options.ttHere || false, 1312 isOver = false, 1313 hideTimeout = null, 1314 obj, buttonIfr, buttonRpc, tooltipIfr, tooltipRpc, checkTO, statsBox; 1315 if (type == 'vertical' || type == 'button' || type == 'mini') delete options.width; 1316 if (autoWidth) params.auto_width = 1; 1317 function showTooltip(force) { 1318 if ((!isOver && !force) || !tooltipRpc) return; 1319 if (!tooltipIfr || !tooltipRpc || tooltipIfr.style.display != 'none' && tooltipIfr.getAttribute('vkhidden') != 'yes') return; 1320 hideTimeout && clearTimeout(hideTimeout); 1321 checkTO && clearTimeout(checkTO); 1322 var scrollTop = options.getScrollTop ? options.getScrollTop() : (document.body.scrollTop || document.documentElement.scrollTop || 0); 1323 var objPos = VK.Util.getXY(obj, options.fixed); 1324 var startY = ttHere ? 0 : objPos[1]; 1325 if (scrollTop > objPos[1] - 120 && options.tooltipPos != 'top' || type == 'vertical' || options.tooltipPos == 'bottom') { 1326 tooltipIfr.style.top = (startY + height + 2) + 'px';
1327 tooltipRpc.callMethod('show', false, type+'_'+size); 1328 } else { 1329 tooltipIfr.style.top = (startY - 128) + 'px'; 1330 tooltipRpc.callMethod('show', true, type+'_'+size); 1331 } 1332 VK.Util.ss(tooltipIfr, {left: (ttHere ? 0 : objPos[0]) - (type == 'full' || type == 'button' ? 32 : 2) + 'px', display: 'block', opacity: 1, filter: 'none'}); 1333 tooltipIfr.setAttribute('vkhidden', 'no'); 1334 isOver = true; 1335 } 1336 1337 function hideTooltip(force) { 1338 if ((isOver && !force) || !tooltipRpc) return; 1339 tooltipRpc.callMethod('hide'); 1340 buttonRpc.callMethod('hide'); 1341 hideTimeout = setTimeout(function() { 1342 tooltipIfr.style.display = 'none' 1343 }, 400); 1344 } 1345 1346 function handleStatsBox(act) { 1347 hideTooltip(true); 1348 statsBox = VK.Util.Box(buttonIfr.src + '&act=a_stats_box&widget_width=638&from=wlike'); 1349 statsBox.show(); 1350 } 1351 1352 var widgetId = VK.Widgets._constructor('widget_like.php', objId, options, params, { 1353 initTooltip: function(counter) { 1354 tooltipRpc = new fastXDM.Server({ 1355 onInit: counter ? function() { 1356 showTooltip(); 1357 } : function() {}, 1358 proxy: function() { 1359 buttonRpc.callMethod.apply(buttonRpc, arguments); 1360 }, 1361 showBox: function(url, props) { 1362 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [props.width, props.height], { 1363 proxy: function() { 1364 tooltipRpc.callMethod.apply(tooltipRpc, arguments); 1365 } 1366 }); 1367 box.show(); 1368 }, 1369 statsBox: handleStatsBox 1370 }, false, {safe: true}); 1371 tooltipIfr = tooltipRpc.append(ttHere ? obj : document.body, { 1372 src: buttonIfr.src + '&act=a_like_tooltip', 1373 scrolling: 'no', 1374 allowTransparency: true, 1375 id: buttonIfr.id + '_tt', 1376 style: {position: 'absolute', padding: 0, display: 'block', opacity: 0.01, filter: 'alpha(opacity=1)', border: '0', width: '274px', height: '130px', zIndex: 5000, overflow: 'hidden'} 1377 }); 1378 tooltipIfr.setAttribute('vkhidden', 'yes'); 1379 1380 tooltipIfr.onmouseover = function() { 1381 clearTimeout(checkTO); 1382 isOver = true; 1383 }; 1384 tooltipIfr.onmouseout = function() { 1385 clearTimeout(checkTO); 1386 isOver = false; 1387 checkTO = setTimeout(function() {hideTooltip(); }, 200); 1388 }; 1389 }, 1390 statsBox: handleStatsBox, 1391 showTooltip: showTooltip, 1392 hideTooltip: hideTooltip, 1393 destroy: function() { 1394 buttonRpc.destroy(); 1395 try {buttonIfr.src = 'about: blank;';} catch (e) {} 1396 buttonIfr.parentNode.removeChild(buttonIfr); 1397 if (tooltipIfr) { 1398 try {tooltipIfr.src = 'about: blank;';} catch (e) {} 1399 tooltipIfr.parentNode.removeChild(tooltipIfr); 1400 } 1401 tooltipRpc && tooltipRpc.destroy(); 1402 if (statsBox) { 1403 if (statsBox.iframe) { 1404 try {statsBox.iframe.src = 'about: blank;';} catch (e) {} 1405 statsBox.iframe.parentNode.removeChild(statsBox.iframe); 1406 } 1407 statsBox.rpc && statsBox.rpc.destroy(); 1408 } 1409 }, 1410 showBox: function(url, props) { 1411 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], { 1412 proxy: function() { 1413 buttonRpc.callMethod.apply(buttonRpc, arguments); 1414 } 1415 }); 1416 box.show(); 1417 }, 1418 proxy: function() {if (tooltipRpc) tooltipRpc.callMethod.apply(tooltipRpc, arguments);} 1419 }, { 1420 startHeight: height, 1421 minWidth: width 1422 }, function(o, i, r) { 1423 buttonRpc = r; 1424 VK.Util.ss(obj = o, {height: height + 'px', width: width + 'px', position: 'relative', clear: 'both'}); 1425 VK.Util.ss(buttonIfr = i, {height: height + 'px', width: width + 'px', overflow: 'hidden', zIndex: 150}); 1426 obj.onmouseover = function() { 1427 clearTimeout(checkTO); 1428 isOver = true; 1429 }; 1430 obj.onmouseout = function() { 1431 clearTimeout(checkTO); 1432 isOver = false;
1433 checkTO = setTimeout(function() {hideTooltip(); }, 200); 1434 }; 1435 }); 1436 1437 instances.push(widgetId); 1438 return widgetId; 1439 }; 1440 1441 Like.destroyAll = function() { 1442 var xdm = null; 1443 while (instances[0]) { 1444 xdm = VK.Widgets.RPC[instances.pop()]; 1445 xdm && xdm.methods.destroy(); 1446 } 1447 } 1448 1449 return Like; 1450 })(VK.Widgets.Like); 1451 1452 VK.Widgets.Poll = function(objId, options, pollId) { 1453 var pData = VK.Util.getPageData(); 1454 if (!pollId) throw Error('No poll id passed'); 1455 options = options || {}; 1456 var params = { 1457 poll_id: pollId, 1458 url: options.pageUrl || pData.url || location.href, 1459 title: options.pageTitle || pData.title, 1460 description: options.pageDescription || pData.description 1461 }; 1462 return VK.Widgets._constructor('al_widget_poll.php', objId, options, params, {}, { 1463 startHeight: 144, 1464 minWidth: 300, 1465 width: '100%' 1466 }); 1467 }; 1468 1469 VK.Widgets.Community = VK.Widgets.Group = function(objId, options, gid) { 1470 gid = parseInt(gid, 10); 1471 if (!gid) { 1472 throw Error('No group_id passed'); 1473 } 1474 options.mode = parseInt(options.mode, 10).toString(); 1475 var params = { 1476 gid: gid, 1477 mode: (options.mode) ? options.mode : '0' 1478 }, 1479 startHeight = options.mode == 3 ? 185 : (options.mode == 1 ? 141 : options.height|0 || 290), 1480 rpc; 1481 if (options.wall) params.wall = options.wall; 1482 params.color1 = options.color1 || ''; 1483 params.color2 = options.color2 || ''; 1484 params.color3 = options.color3 || ''; 1485 params.class_name = options.class_name || ''; 1486 if (options.no_head) params.no_head = 1; 1487 if (options.wide) { 1488 params.wide = 1; 1489 if (!options.width || options.width < 300) { 1490 options.width = 300; 1491 } 1492 } 1493 if (!options.width|0) options.width = 200; 1494 1495 var cursorBack; 1496 1497 function mouseup() { 1498 rpc.callMethod('mouseUp'); 1499 return false; 1500 } 1501 1502 function move(event) { 1503 rpc.callMethod('mouseMove', {screenY: event.screenY}); 1504 return false; 1505 } 1506 1507 return VK.Widgets._constructor('widget_community.php', objId, options, params, { 1508 showBox: function(url, props) { 1509 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], { 1510 proxy: function() { 1511 rpc.callMethod.apply(rpc, arguments); 1512 } 1513 }); 1514 box.show(); 1515 }, 1516 startDrag: function() { 1517 cursorBack = window.document.body.style.cursor; 1518 window.document.body.style.cursor = 'pointer'; 1519 VK.Util.addEvent('mousemove', move); 1520 VK.Util.addEvent('mouseup', mouseup); 1521 }, 1522 stopDrag: function() { 1523 window.document.body.style.cursor = cursorBack; 1524 VK.Util.removeEvent('mousemove', move); 1525 VK.Util.removeEvent('mouseup', mouseup); 1526 }, 1527 auth: function() { 1528 VK.Auth.login(null, 1); 1529 } 1530 }, { 1531 minWidth: 120, 1532 startHeight: startHeight 1533 }, function(o, i, r) { 1534 rpc = r; 1535 }); 1536 }; 1537 1538 VK.Widgets.Auth = function(objId, options) { 1539 var pData = VK.Util.getPageData(); 1540 if (!VK._apiId) throw Error('VK not initialized. Please use VK.init'); 1541 if (!options.width) { 1542 options.width = 200; 1543 } 1544 if (options.type) { 1545 type = 1; 1546 } else { 1547 type = 0; 1548 } 1549 return VK.Widgets._constructor('widget_auth.php', objId, options, {}, {makeAuth: function(data) { 1550 if (data.session) { 1551 VK.Auth._loadState = 'loaded'; 1552 VK.Auth.setSession(data.session, 'connected'); 1553 VK.Observer.publish('auth.loginStatus', {session: data.session, status: 'connected'}); 1554 VK.Observer.unsubscribe('auth.loginStatus'); 1555 } 1556 if (options.onAuth) { 1557 options.onAuth(data); 1558 } else { 1559 if (options.authUrl) { 1560 var href = options.authUrl; 1561 } else { 1562 var href = window.location.href; 1563 } 1564 if (href.indexOf('?') == -1) { 1565 href+='?'; 1566 } else { 1567 href+='&'; 1568 } 1569 var vars = []; 1570 1571 for (var i in data) { 1572 if (i != 'session') vars.push(i+'='+decodeURIComponent(data[i]).replace(/&/g, '%26').replace(/\?/, '%3F')); 1573 } 1574 window.location.href = href + vars.join('&'); 1575 } 1576 }}, {startHeight: 134}); 1577 }; 1578 1579 VK.Widgets.Subscribe = function(objId, options, oid) { 1580 oid = parseInt(oid, 10); 1581 if (!oid) { 1582 throw Error('No owner_id passed'); 1583 } 1584 var params = { 1585 oid: oid 1586 }, rpc; 1587 if (options.mode) { 1588 params.mode = options.mode; 1589 } 1590 if (options.soft) { 1591 params.soft = options.soft; 1592 } 1593 1594 return VK.Widgets._constructor('widget_subscribe.php', objId, options, params, { 1595 showBox: function(url, props) { 1596 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], { 1597 proxy: function() { 1598 rpc.callMethod.apply(rpc, arguments); 1599 } 1600 }); 1601 box.show(); 1602 }, 1603 auth: function() { 1604 VK.Auth.login(null, 1); 1605 } 1606 }, {
1607 minWidth: 220, 1608 startHeight: 22, 1609 height: options.height || 22 1610 }, function(o, i, r) { 1611 rpc = r; 1612 }); 1613 }; 1614 1615 VK.Widgets.ContactUs = function(objId, options, oid) { 1616 oid = parseInt(oid, 10); 1617 1618 if (!options) options = {}; 1619 if (!oid) throw Error('No group or user id passed'); 1620 1621 var params = { 1622 oid: oid, 1623 height: ({18: 18, 20: 20, 22: 22, 24: 24, 30: 30})[parseInt(options.height, 10) || 24], 1624 text: (options.text || '').substr(0, 140) 1625 }, rpc; 1626 1627 return VK.Widgets._constructor('widget_contactus.php', objId, options, params, {}, { 1628 startHeight: params.height, 1629 height: params.height 1630 }, function(o, i, r) { 1631 rpc = r; 1632 }); 1633 }; 1634 1635 VK.Widgets.Ads = function(objId, options, paramsExtra) { 1636 options = options || {}; 1637 paramsExtra = paramsExtra || {}; 1638 var params = {}; 1639 var defaults = {}; 1640 var funcs = {}; 1641 var obj = document.getElementById(objId); 1642 var iframe; 1643 var rpc; 1644 1645 var adsParams = {}; 1646 var adsParamsLocal = {}; 1647 var adsParamsDefault = {}; 1648 for (var key in paramsExtra) { 1649 var keyFix = (inArray(key, ['hash']) ? key : 'ads_' + key); 1650 adsParams[keyFix] = paramsExtra[key]; 1651 } 1652 1653 if (obj && obj.getBoundingClientRect) { 1654 obj.style.width = '100%'; 1655 obj.style.height = '100%'; 1656 var rect = obj.getBoundingClientRect(); 1657 obj.style.width = ''; 1658 obj.style.height = ''; 1659 adsParams.ads_ad_unit_width_auto = Math.floor(rect.right - rect.left); 1660 adsParams.ads_ad_unit_height_auto = Math.floor(rect.bottom - rect.top); 1661 } 1662 1663 adsParamsDefault.ads_ad_unit_width = 100; 1664 adsParamsDefault.ads_ad_unit_height = 100; 1665 1666 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); 1667 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); 1668 if (adsParams.ads_handler) { 1669 adsParamsLocal.ads_handler = adsParams.ads_handler; 1670 } 1671 if (adsParams.ads_handler_empty_html) { 1672 adsParamsLocal.ads_handler_empty_html = adsParams.ads_handler_empty_html; 1673 } 1674 1675 delete adsParams.ads_handler; 1676 delete adsParams.ads_handler_empty_html; 1677 1678 params.act = 'ads_web'; 1679 params.url = location.href; 1680 VK.extend(params, adsParams); 1681 1682 options.noDefaultParams = true; 1683 options.width = adsParamsLocal.ads_ad_unit_width; 1684 options.allowTransparency = true; 1685 defaults.startHeight = adsParamsLocal.ads_ad_unit_height; 1686 defaults.minWidth = adsParamsLocal.ads_ad_unit_width; 1687 funcs.adsOnInitLoader = adsOnInitLoader; 1688 funcs.adsOnInit = adsOnInit; 1689 1690 return VK.Widgets._constructor('ads_rotate.php', objId, options, params, funcs, defaults, onDone); 1691 1692 function adsOnInitLoader(adsScriptVersion) { 1693 VK.Widgets.loading(obj, true); 1694 adsAttachScript(adsScriptVersion); 1695 } 1696 function adsOnInit(errorCode, adsParamsExport) { 1697 VK.Widgets.loading(obj, false); 1698 adsProcessParams(adsParamsExport); 1699 if (options.onAdsReady) options.onAdsReady.apply(options.onAdsReady, Array.prototype.slice.call(arguments)); 1700 adsProcessHandler(errorCode); 1701 } 1702 function adsAttachScript(adsScriptVersion) { 1703 if (!('vk__adsLight' in window)) { 1704 window.vk__adsLight = false; 1705 adsScriptVersion = parseInt(adsScriptVersion); 1706 var attachScriptFunc = (VK.Api && VK.Api.attachScript || VK.addScript); 1707 var base_domain = (options.base_domain || VK._protocol + 'http://vk.com'); 1708 attachScriptFunc(base_domain + '/js/al/aes_light.js?' + adsScriptVersion); 1709 } else if (window.vk__adsLight && vk__adsLight.userHandlers && vk__adsLight.userHandlers.onInit) { 1710 vk__adsLight.userHandlers.onInit(false); // false - do not publish initial onInit 1711 } 1712 } 1713 function adsProcessParams(adsParamsExport) { 1714 if (!adsParamsExport) { 1715 return; 1716 } 1717 for (var paramName in adsParamsExport) { 1718 var paramValue = adsParamsExport[paramName]; 1719 if (paramName === 'ads_ad_unit_width' || paramName === 'ads_ad_unit_height') { 1720 if (!(paramName in adsParams)) { 1721 adsParamsLocal[paramName] = (parseInt(paramValue) || paramValue === 'auto' && adsParams[paramName + '_auto'] || adsParamsDefault[paramName]); 1722 } 1723 } else { 1724 if (!(paramName in adsParamsLocal)) { 1725 adsParamsLocal[paramName] = paramValue; 1726 } 1727 } 1728 } 1729 } 1730 function adsProcessHandler(errorCode) { 1731 var handlerResult = adsEvalHandler(adsParamsLocal.ads_handler, errorCode); 1732 if (errorCode <= 0 && handlerResult !== true) { 1733 try { console.log('VK: ad_unit_id = ' + adsParams.ads_ad_unit_id, ', errorCode = ', errorCode); } catch (e) {} 1734 adsInsertHtmlHandler(adsParamsLocal.ads_handler_empty_html, adsParamsLocal.ads_ad_unit_width, adsParamsLocal.ads_ad_unit_height); 1735 } 1736 } 1737 function adsEvalHandler(handler) { 1738 var result = false;
1739 try { 1740 if (!handler) { 1741 return false; 1742 } 1743 var func = false; 1744 if (isFunction(handler)) { 1745 func = handler; 1746 } else if (isString(handler)) { 1747 var handlerFuncs = handler.split('.'); 1748 func = window; 1749 for (var i = 0, len = handlerFuncs.length; i < len; i++) { 1750 func = func[handlerFuncs[i]]; 1751 if (!func) { 1752 break; 1753 } 1754 } 1755 if (!func) { 1756 if (handler.substr(0, 8) === 'function') { 1757 handler = 'return ' + handler + ';'; 1758 } 1759 var handlerResult = (new Function(handler))(); 1760 if (isFunction(handlerResult)) { 1761 func = handlerResult; 1762 } else { 1763 result = handlerResult; 1764 } 1765 } 1766 } 1767 if (func) { 1768 var args = Array.prototype.slice.call(arguments, 1); 1769 result = func.apply(func, args); 1770 } 1771 } catch (e) { 1772 try { 1773 console.error(e); 1774 } catch (e2) {} 1775 } 1776 1777 return result; 1778 1779 function isFunction(obj) { 1780 return Object.prototype.toString.call(obj) === '[object Function]'; 1781 } 1782 function isString(obj) { 1783 return Object.prototype.toString.call(obj) === '[object String]'; 1784 } 1785 } 1786 function adsInsertHtmlHandler(handlerHtml, width, height) { 1787 if (!handlerHtml) { 1788 return; 1789 } 1790 if (!obj) { 1791 return; 1792 } 1793 1794 width = (width ? width + 'px' : ''); 1795 height = (height ? height + 'px' : ''); 1796 1797 var iframeHandlerHtml = '<html><head></head><body style="padding: 0; margin: 0;"><div>' + handlerHtml + '</div></body></html>'; 1798 1799 var iframeHandler = document.createElement('iframe'); 1800 iframeHandler.onload = fixIframeHeight; 1801 iframeHandler.id = (iframe ? iframe.id : ('vkwidget-' + Math.round(Math.random() * 1000000))) + '_ads_html_handler'; 1802 iframeHandler.src = 'about:blank'; 1803 iframeHandler.width = '100%'; 1804 iframeHandler.height = '100%'; 1805 iframeHandler.scrolling = 'no'; 1806 iframeHandler.frameBorder = '0'; 1807 iframeHandler.allowTransparency = true; 1808 iframeHandler.style.overflow = 'hidden'; 1809 iframeHandler.style.width = width; 1810 iframeHandler.style.height = height; 1811 1812 obj.style.width = width; 1813 obj.style.height = height; 1814 1815 obj.appendChild(iframeHandler); 1816 1817 iframeHandler.contentWindow.vk_ads_html_handler = iframeHandlerHtml; 1818 iframeHandler.src = 'javascript:window["vk_ads_html_handler"]'; 1819 1820 function fixIframeHeight() { 1821 if (height) { 1822 return; 1823 } 1824 try { 1825 var rect = iframeHandler.contentWindow.document.body.firstChild.getBoundingClientRect(); 1826 var heightFix = Math.ceil(rect.bottom - rect.top); 1827 if (heightFix) { 1828 iframeHandler.style.height = heightFix; 1829 obj.style.height = heightFix; 1830 } 1831 } catch (e) {} 1832 } 1833 } 1834 function indexOf(arr, value, from) { 1835 for (var i = from || 0, l = (arr || []).length; i < l; i++) { 1836 if (arr[i] == value) return i; 1837 } 1838 return -1; 1839 } 1840 function inArray(value, arr) { 1841 return indexOf(arr, value) != -1; 1842 } 1843 function onDone(o, i, r) { 1844 obj = o; 1845 iframe = i; 1846 rpc = r; 1847 } 1848 }; 1849 1850 VK.Widgets.AllowMessagesFromCommunity = function (objId, options, groupId) { 1851 groupId = parseInt(groupId, 10); 1852 1853 if (!options) options = {}; 1854 if (!groupId || groupId < 0) throw Error('No group id passed'); 1855 1856 var params = { 1857 height: ({22: 22, 24: 24, 30: 30})[parseInt(options.height, 10) || 24], 1858 key: options.key ? options.key.substr(0, 256) : '', 1859 group_id: groupId 1860 }, rpc; 1861 1862 return VK.Widgets._constructor('widget_allow_messages_from_community.php', objId, options, params, {}, { 1863 startHeight: params.height, 1864 height: params.height 1865 }, function(o, i, r) { 1866 rpc = r; 1867 }); 1868 }; 1869 1870 VK.Widgets.CommunityMessages = (function(CommunityMessages) { 1871 if (CommunityMessages) return CommunityMessages; 1872 1873 var instances = {}; 1874 1875 CommunityMessages = function(objId, gid, options) { 1876 options = options || {}; 1877 1878 options.width = 300; 1879 options.height = 399; 1880 1881 if (!options.base_domain) { 1882 options.base_domain = options.base_domain || VK._protocol + 'http://vk.com'; 1883 } 1884 1885 var rpcSrv = null; 1886 var params = { 1887 gid: gid, 1888 }; 1889 if (options.shown) { 1890 params.shown = 1; 1891 } 1892 1893 if (instances[objId]) { 1894 CommunityMessages.destroy(objId); 1895 } 1896 1897 var curBox = false;
1898 1899 var chatRpc, chatIfr; 1900 instances[objId] = VK.Widgets._constructor('widget_community_messages.php', objId, options, params, { 1901 onStartLoading: function() { 1902 var obj = document.getElementById(objId); 1903 obj.style.position = 'fixed'; 1904 obj.style['z-index'] = 10000; 1905 obj.style.right = '20px'; 1906 obj.style.bottom = '0px'; 1907 minimize(objId); 1908 }, 1909 showBox: function(url, props) { 1910 if (curBox) { 1911 try { 1912 curBox.hide(); 1913 try { 1914 curBox.iframe.src = 'about: blank;'; 1915 } catch (e) {} 1916 curBox.iframe.parentNode.removeChild(curBox.iframe); 1917 } catch(e) { } 1918 } 1919 curBox = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, url), [], { 1920 proxy: function() { 1921 rpc.callMethod.apply(rpc, arguments); 1922 } 1923 }); 1924 curBox.show(); 1925 }, 1926 expand: function() { 1927 expand(objId); 1928 }, 1929 minimize: function() { 1930 setTimeout(function() { 1931 minimize(objId); 1932 }, 120); 1933 }, 1934 canNotWrite: function() { 1935 options.onCanNotWrite && options.onCanNotWrite(); 1936 }, 1937 destroy: function() { 1938 chatRpc.destroy(); 1939 try {chatIfr.src = 'about: blank;';} catch (e) {} 1940 try { 1941 chatIfr.parentNode.removeChild(chatIfr); 1942 } catch(e) { } 1943 }, 1944 fatalError: function(error_code, public_id) { 1945 1946 var query = { 1947 code: error_code, 1948 widget: 2, 1949 public_id: public_id, 1950 }; 1951 1952 if (error_code == 1903) { 1953 query.referrer_domain = document.domain; 1954 } 1955 1956 var query_str = []; 1957 for(var i in query) { 1958 query_str.push(i+'='+query[i]); 1959 } 1960 1961 CommunityMessages.destroy(objId); 1962 var box = VK.Util.Box(VK.Widgets.showBoxUrl(options.base_domain, 'blank.php?'+query_str.join('&'))); 1963 box.show(); 1964 }, 1965 }, {}, function(o, i, r) { 1966 chatRpc = r; 1967 chatIfr = i; 1968 if (!options.shown) { 1969 minimize(objId); 1970 } else { 1971 expand(objId); 1972 } 1973 }); 1974 return instances[objId]; 1975 }; 1976 1977 function expand(objId) { 1978 var obj = document.getElementById(objId), frame = obj.getElementsByTagName('iframe')[0]; 1979 1980 var size = 50; 1981 obj.style.width = frame.width = '300px'; 1982 obj.style.height = frame.height = '399px'; 1983 } 1984 1985 function minimize(objId) { 1986 var obj = document.getElementById(objId), frame = obj.getElementsByTagName('iframe')[0]; 1987 1988 obj.style.width = '60px'; 1989 obj.style.height = '80px'; 1990 1991 if (frame) { 1992 frame.width = 60; 1993 frame.height = 80; 1994 } 1995 } 1996 1997 CommunityMessages.destroy = function(objId) { 1998 if (!instances[objId]) { 1999 return; 2000 } 2001 2002 var xdm = VK.Widgets.RPC[instances[objId]]; 2003 xdm && xdm.methods.destroy(); 2004 2005 delete instances[objId]; 2006 }; 2007 2008 return CommunityMessages; 2009 })(VK.Widgets.CommunityMessages); 2010 2011 VK.Widgets._constructor = function(widgetUrl, objId, options, params, funcs, defaults, onDone, widgetId, iter) { 2012 var obj = document.getElementById(objId); 2013 widgetId = widgetId || (++VK.Widgets.count); 2014 2015 if (!obj) { 2016 iter = iter || 0; 2017 if (iter > 10) { 2018 throw Error('VK.Widgets: object #' + objId + ' not found.'); 2019 } 2020 setTimeout(function() { 2021 VK.Widgets._constructor(widgetUrl, objId, options, params, funcs, defaults, onDone, widgetId, iter + 1); 2022 }, 500); 2023 return widgetId; 2024 } 2025 2026 var ifr, base_domain, width, url, urlQueryString, encodedParam, rpc, iframe, i; 2027 options = options || {}; 2028 defaults = defaults || {}; 2029 funcs = funcs || {}; 2030 base_domain = options.base_domain || VK._protocol + 'http://vk.com'; 2031 width = (options.width == 'auto') ? obj.clientWidth || '100%' : parseInt(options.width, 10); 2032 2033 if (options.height) { 2034 params.height = options.height; 2035 obj.style.height = options.height + 'px'; 2036 } else { 2037 obj.style.height = (defaults.startHeight || 200) + 'px'; 2038 } 2039 2040 width = width ? (Math.max(defaults.minWidth || 200, Math.min(10000, width)) + 'px') : '100%'; 2041 2042 if (!params.url) { 2043 params.url = options.pageUrl || location.href.replace(/#.*$/, ''); 2044 } 2045 url = base_domain + '/' + widgetUrl; 2046 urlQueryString = ''; 2047 if (!options.noDefaultParams) { 2048 urlQueryString += '&app=' + (VK._apiId || '0') + '&width=' + width 2049 } 2050 urlQueryString += '&_ver=' + VK.version 2051 if (VK._iframeAppWidget) { 2052 params.iframe_app = 1; 2053 } 2054 var pData = VK.Util.getPageData(); 2055 params.url = params.url || pData.url || ""; 2056 params.referrer = params.referrer || document.referrer || ""; 2057 params.title = params.title || pData.title || document.title || ""; 2058 for (i in params) { 2059 if (i == 'title' && params[i].length > 80) params[i] = params[i].substr(0, 80)+'...'; 2060 if (i == 'description' && params[i].length > 160) params[i] = params[i].substr(0, 160)+'...'; 2061 if (typeof(params[i]) == 'number') { 2062 encodedParam = params[i]; 2063 } else { 2064 try { 2065 encodedParam = encodeURIComponent(params[i]); 2066 } catch (e) { 2067 encodedParam = ''; 2068 } 2069 } 2070 urlQueryString += '&' + i + '=' + encodedParam; 2071 } 2072 urlQueryString += '&' + (+new Date()).toString(16); 2073 url += '?' + urlQueryString.substr(1); 2074 2075 obj.style.width = width; 2076 funcs.onStartLoading && funcs.onStartLoading(); 2077 VK.Widgets.loading(obj, true); 2078 2079 funcs.showLoader = function(enable) { 2080 VK.Util.Loader(enable); 2081 }; 2082 funcs.publish = function() { 2083 var args = Array.prototype.slice.call(arguments); 2084 args.push(widgetId); 2085 VK.Observer.publish.apply(VK.Observer, args); 2086 }; 2087 funcs.onInit = function() { 2088 VK.Widgets.loading(obj, false); 2089 if (funcs.onReady) funcs.onReady(); 2090 if (options.onReady) options.onReady(); 2091 };
2092 funcs.resize = function(e, cb) { 2093 obj.style.height = e + 'px'; 2094 var el = document.getElementById('vkwidget' + widgetId); 2095 if (el) { 2096 el.style.height = e + 'px'; 2097 } 2098 }; 2099 funcs.resizeWidget = function(newWidth, newHeight) { 2100 newWidth = parseInt(newWidth); 2101 newHeight = parseInt(newHeight); 2102 var widgetElem = document.getElementById('vkwidget' + widgetId); 2103 if (isFinite(newWidth)) { 2104 obj.style.width = newWidth + 'px'; 2105 if (widgetElem) { 2106 widgetElem.style.width = newWidth + 'px'; 2107 } 2108 } 2109 if (isFinite(newHeight)) { 2110 obj.style.height = newHeight + 'px'; 2111 if (widgetElem) { 2112 widgetElem.style.height = newHeight + 'px'; 2113 } 2114 } 2115 if (options.onResizeWidget) options.onResizeWidget(); 2116 }; 2117 funcs.updateVersion = function(ver) { 2118 if (ver > 1) { 2119 VK.Api.attachScript('http://vk.com/js/api/openapi_update.js?'+parseInt(ver)); 2120 } 2121 }; 2122 rpc = VK.Widgets.RPC[widgetId] = new fastXDM.Server(funcs, function(origin) { 2123 if (!origin) return true; 2124 origin = origin.toLowerCase(); 2125 return (origin.match(/(\.|\/)vk\.com($|\/|\?)/)); 2126 }, {safe: true}); 2127 iframe = VK.Widgets.RPC[widgetId].append(obj, { 2128 src: url, 2129 width: (width.indexOf('%') != -1) ? width : (parseInt(width) || width), 2130 height: defaults.startHeight || '100%', 2131 scrolling: 'no', 2132 id: 'vkwidget' + widgetId, 2133 allowTransparency: options.allowTransparency || false, 2134 style: { 2135 overflow: 'hidden' 2136 } 2137 }); 2138 onDone && setTimeout(function() {onDone(obj, iframe || obj.firstChild, rpc);}, 10); 2139 return widgetId; 2140 }; 2141} 2142 2143if (!VK.Util) { 2144 VK.Util = { 2145 getPageData: function() { 2146 if (!VK._pData) { 2147 var metas = document.getElementsByTagName('meta'), pData = {}, keys = ['description', 'title', 'url', 'image', 'app_id'], metaName; 2148 for (var i in metas) { 2149 if (!metas[i].getAttribute) continue; 2150 if (metas[i].getAttribute && ((metaName = metas[i].getAttribute('name')) || (metaName = metas[i].getAttribute('property')))) { 2151 for (var j in keys) { 2152 if (metaName == keys[j] || metaName == 'og:'+keys[j] || metaName == 'vk:'+keys[j]) { 2153 pData[keys[j]] = metas[i].content; 2154 } 2155 } 2156 } 2157 } 2158 if (pData.app_id && !VK._apiId) { 2159 VK._apiId = pData.app_id; 2160 } 2161 pData.title = pData.title || document.title || ''; 2162 pData.description = pData.description || ''; 2163 pData.image = pData.image || ''; 2164 if (!pData.url && VK._iframeAppWidget && VK._apiId) { 2165 pData.url = '/app' + VK._apiId; 2166 if (VK._browserHash) { 2167 pData.url += VK._browserHash 2168 } 2169 } 2170 var loc = location.href.replace(/#.*$/, ''); 2171 if (!pData.url || !pData.url.indexOf(loc)) { 2172 pData.url = loc; 2173 } 2174 VK._pData = pData; 2175 } 2176 return VK._pData; 2177 }, 2178 getStyle: function(elem, name) { 2179 var ret, defaultView = document.defaultView || window; 2180 if (defaultView.getComputedStyle) { 2181 name = name.replace(/([A-Z])/g, '-$1').toLowerCase(); 2182 var computedStyle = defaultView.getComputedStyle(elem, null); 2183 if (computedStyle) { 2184 ret = computedStyle.getPropertyValue(name); 2185 } 2186 } else if (elem.currentStyle) { 2187 var camelCase = name.replace(/\-(\w)/g, function(all, letter){ 2188 return letter.toUpperCase(); 2189 }); 2190 ret = elem.currentStyle[name] || elem.currentStyle[camelCase]; 2191 } 2192 2193 return ret; 2194 }, 2195 2196 getXY: function(obj, fixed) { 2197 if (!obj || obj === undefined) return; 2198 2199 var left = 0, top = 0; 2200 if (obj.getBoundingClientRect !== undefined) { 2201 var rect = obj.getBoundingClientRect(); 2202 left = rect.left; 2203 top = rect.top; 2204 fixed = true; 2205 } else if (obj.offsetParent) { 2206 do { 2207 left += obj.offsetLeft; 2208 top += obj.offsetTop; 2209 if (fixed) { 2210 left -= obj.scrollLeft; 2211 top -= obj.scrollTop; 2212 } 2213 } while (obj = obj.offsetParent); 2214 } 2215 if (fixed) { 2216 top += window.pageYOffset || window.scrollNode && scrollNode.scrollTop || document.documentElement.scrollTop; 2217 left += window.pageXOffset || window.scrollNode && scrollNode.scrollLeft || document.documentElement.scrollLeft; 2218 } 2219 2220 return [left, top]; 2221 }, 2222 2223 Loader: function self(enable) { 2224 if (!self.loader) { 2225 self.loader = document.createElement('DIV'); 2226 self.loader.innerHTML = '<style type="text/css">\ 2227 @-webkit-keyframes VKWidgetsLoaderKeyframes {0%{opacity: 0.2;}30%{opacity: 1;}100%{opacity: 0.2;}}\ 2228 @keyframes VKWidgetsLoaderKeyframes {0%{opacity: 0.2;}30%{opacity: 1;}100%{opacity: 0.2;}}\ 2229 .VKWidgetsLoader div {width: 7px;height: 7px;
2229-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>'; 2230 document.body.insertBefore(self.loader, document.body.firstChild); 2231 } 2232 self.loader.style.display = enable ? 'block' : 'none'; 2233 }, 2234 2235 Box: function(src, sizes, fnc, options) { 2236 fnc = fnc || {}; 2237 var overflowB = document.body.style.overflow; 2238 VK.Util.Loader(true); 2239 var is_vk = /(^|\.)(vk\.com|vkontakte\.ru)$/.test(location.hostname); 2240 var rpc = new fastXDM.Server(VK.extend(fnc, { 2241 onInit: function() { 2242 iframe.style.background = 'transparent'; 2243 iframe.style.visibility = 'visible'; 2244 document.body.style.overflow = 'hidden'; 2245 iframe.setAttribute('allowfullscreen', 1); 2246 if (is_vk) document.body.className += ' layers_shown'; 2247 VK.Util.Loader(); 2248 }, 2249 hide: function() { 2250 iframe.style.display = 'none'; 2251 }, 2252 tempHide: function() { 2253 iframe.style.left = '-10000px'; 2254 iframe.style.top = '-10000px'; 2255 iframe.style.width = '10px'; 2256 iframe.style.height = '10px'; 2257 if (is_vk) document.body.className = document.body.className.replace(/\b\s*?layers_shown\s*\b/, ' '); 2258 document.body.style.overflow = overflowB; 2259 }, 2260 destroy: function() { 2261 try { 2262 iframe.src = 'about: blank;'; 2263 } catch (e) {} 2264 iframe.parentNode.removeChild(iframe); 2265 if (is_vk) document.body.className = document.body.className.replace(/\b\s*?layers_shown\s*\b/, ' '); 2266 document.body.style.overflow = overflowB; 2267 }, 2268 resize: function(w, h) { 2269 } 2270 }, true), false, {safe: true}), 2271 iframe = rpc.append(document.body, { 2272 src: src.replace(/&/g, '&'), 2273 scrolling: 'no', 2274 allowTransparency: true, 2275 style: {position: 'fixed', left: 0, top: 0, zIndex: 1002, background: VK._protocol + 'http://vk.com/images/upload.gif center center no-repeat transparent', padding: '0', border: '0', width: '100%', height: '100%', overflow: 'hidden', visibility: 'hidden'} 2276 }); 2277 return { 2278 show: function(scrollTop, height) { 2279 iframe.style.display = 'block'; 2280 document.body.style.overflow = 'hidden'; 2281 }, 2282 hide: function() { 2283 iframe.style.display = 'none'; 2284 document.body.style.overflow = overflowB; 2285 }, 2286 iframe: iframe, 2287 rpc: rpc 2288 } 2289 }, 2290 2291 addEvent: function(type, func) { 2292 if (window.document.addEventListener) { 2293 window.document.addEventListener(type, func, false); 2294 } else if (window.document.attachEvent) { 2295 window.document.attachEvent('on'+type, func); 2296 } 2297 }, 2298 2299 removeEvent: function(type, func) { 2300 if (window.document.removeEventListener) { 2301 window.document.removeEventListener(type, func, false); 2302 } else if (window.document.detachEvent) { 2303 window.document.detachEvent('on'+type, func); 2304 } 2305 }, 2306 2307 ss: function(el, styles) {VK.extend(el.style, styles, true);} 2308 }; 2309} 2310 2311// Init asynchronous library loading 2312window.vkAsyncInit && setTimeout(vkAsyncInit, 0); 2313 2314if (window.vkAsyncInitCallbacks && vkAsyncInitCallbacks.length) { 2315 setTimeout(function() { 2316 var callback; 2317 while (callback = vkAsyncInitCallbacks.pop()) {
2318 try { 2319 callback(); 2320 } catch(e) { 2321 try { 2322 console.error(e); 2323 } catch (e2) {} 2324 } 2325 } 2326 }, 0); 2327} 2328 2329try{stManager.done('api/openapi.js');}catch(e){}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.