Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - aes_light.js (Старый размер - 37534 | Новый - 0):
- 0. - (function() {
- 1. -
- 2. - var AdsLight = {};
- 3. -
- 4. - var isVkDomain = (document.domain === 'vk.com');
- 5. -
- 6. - var uaLight = navigator.userAgent.toLowerCase();
- 7. - var browserLight = {
- 8. - msie6: (/msie 6/i.test(uaLight) && !/opera/i.test(uaLight)),
- 9. - msie7: (/msie 7/i.test(uaLight) && !/opera/i.test(uaLight)),
- 10. - msie8: (/msie 8/i.test(uaLight) && !/opera/i.test(uaLight))
- 11. - };
- 12. -
- 13. - if (isVkDomain) {
- 14. - if (!('__adsLoaded' in window)) window.__adsLoaded = vkNow();
- 15. - window.AdsLight = AdsLight;
- 16. - }
- 17. -
- 18. - AdsLight.init = function() {
- 19. - if (window.vk__adsLight) {
- 20. - return;
- 21. - }
- 22. -
- 23. - window.vk__adsLight = {};
- 24. -
- 25. - AdsLight.initUserHandlers();
- 26. -
- 27. - vk__adsLight.widgetsIds = {};
- 28. - vk__adsLight.observersInited = false;
- 29. - vk__adsLight.publishTimers = {};
- 30. -
- 31. - vk__adsLight.windowId = Math.round(Math.random() * 1000000000 + 1);
- 32. - vk__adsLight.activeTab = 0;
- 33. - vk__adsLight.userEventTime = 0;
- 34. - vk__adsLight.wrapVisible = false;
- 35. - vk__adsLight.imagesTimer = false;
- 36. - vk__adsLight.reloadTimer = false;
- 37. - vk__adsLight.updateBlockTimer = false;
- 38. -
- 39. - vk__adsLight.adsCanShow = 1;
- 40. - vk__adsLight.adsSection = false;
- 41. - vk__adsLight.adsShowed = '';
- 42. - vk__adsLight.adsShowedHash = +new Date;
- 43. - vk__adsLight.adsParams = false;
- 44. -
- 45. - vk__adsLight.updateProgress = 0;
- 46. - vk__adsLight.adsShowedAll = {};
- 47. -
- 48. - vk__adsLight.loadComplete = false;
- 49. - vk__adsLight.loaderParams = false;
- 50. -
- 51. - vk__adsLight.adsIdsApplyNeeded = {};
- 52. - vk__adsLight.adsIdsApplyProcess = [];
- 53. - vk__adsLight.adsIdsApplyTimer = false;
- 54. - vk__adsLight.adsIdsApplyLocked = false;
- 55. -
- 56. - if ('onfocusin' in window) { // IE
- 57. - if (window.addEventListener) { // IE >= 9
- 58. - window.addEventListener('focusin', vk__adsLight.userHandlers.onFocusWindow, false);
- 59. - window.addEventListener('focusout', vk__adsLight.userHandlers.onBlurWindow, false);
- 60. - } else {
- 61. - if (window.attachEvent) { // IE < 9
- 62. - window.attachEvent('onfocusin', vk__adsLight.userHandlers.onFocusWindow);
- 63. - window.attachEvent('onfocusout', vk__adsLight.userHandlers.onBlurWindow);
- 64. - }
- 65. - }
- 66. - } else {
- 67. - if (window.addEventListener) { // Firefox, Opera, Google Chrome and Safari
- 68. - window.addEventListener('focus', vk__adsLight.userHandlers.onFocusWindow, true);
- 69. - window.addEventListener('blur', vk__adsLight.userHandlers.onBlurWindow, true);
- 70. - }
- 71. - }
- 72. - if (document.addEventListener) {
- 73. - window.addEventListener('scroll', vk__adsLight.userHandlers.onScrollWindow, true);
- 74. - document.addEventListener('mousedown', vk__adsLight.userHandlers.onMouseDownDocument, true);
- 75. - } else if (document.attachEvent) {
- 76. - window.attachEvent('onscroll', vk__adsLight.userHandlers.onScrollWindow);
- 77. - document.attachEvent('onmousedown', vk__adsLight.userHandlers.onMouseDownDocument);
- 78. - }
- 79. -
- 80. - if (!isVkDomain && window.VK && VK.addCallback) {
- 81. - VK.addCallback('adsPublish', AdsLight.handleEvent);
- 82. - }
- 83. -
- 84. - vk__adsLight.userHandlers.onInit(true);
- 85. - }
- 86. -
- 87. - AdsLight.initUserHandlers = function() {
- 88. -
- 89. - vk__adsLight.userHandlers = {
- 90. - onInit: onInit,
- 91. - onHasFocus: onHasFocus,
- 92. - onFocusWindow: onFocusWindow,
- 93. - onBlurWindow: onBlurWindow,
- 94. - onScrollWindow: onScrollWindow,
- 95. - onMouseDownDocument: onMouseDownDocument,
- 96. - onMouseDownDocumentAction: onMouseDownDocumentAction,
- 97. - onActiveTab: onActiveTab
- 98. - };
- 99. -
- 100. - var needBlur = false;
- 101. - var afterClickLink = false;
- 102. - var focusTime = false;
- 103. - var updateTimer = false;
- 104. - var scrollTimer = false;
- 105. -
- 106. - function onInit(eventStub) {
- 107. - AdsLight.initObservers();
- 108. -
- 109. - if (eventStub) {
- 110. - AdsLight.handleEvent('ads.onEvent', 'onInit', 0);
- 111. - }
- 112. -
- 113. - if (!eventStub) {
- 114. - AdsLight.loadAds();
- 115. - }
- 116. -
- 117. - if (document.hasFocus && document.hasFocus()) {
- 118. - onHasFocus(true);
- 119. - }
- 120. - }
- 121. - function onHasFocus(eventStub) {
- 122. - if (eventStub) {
- 123. - AdsLight.handleEvent('ads.onEvent', 'onHasFocus', 0);
- 124. - }
- 125. -
- 126. - onActiveTab();
- 127. - }
- 128. - function onFocusWindow(event) {
- 129. - if (event) {
- 130. - AdsLight.handleEvent('ads.onEvent', 'onFocusWindow', 0);
- 131. - }
- 132. -
- 133. - // Opera fix
- 134. - // May be obsolete
- 135. - if (needBlur) {
- 136. - return;
- 137. - }
- 138. - needBlur = true;
- 139. -
- 140. - focusTime = (window.vkNow && vkNow() || 0);
- 141. -
- 142. - vk__adsLight.userEventTime = (window.vkNow && vkNow() || 0);
- 143. -
- 144. - onActiveTab();
- 145. - }
- 146. - function onBlurWindow(event) {
- 147. -
- 148. - needBlur = false;
- 149. -
- 150. - if (window.vkNow && vkNow() - focusTime < 1000) {
- 151. - return;
- 152. - }
- 153. -
- 154. - if (event) {
- 155. - AdsLight.handleEvent('ads.onEvent', 'onBlurWindow', 0);
- 156. - }
- 157. -
- 158. - vk__adsLight.activeTab = (window.vkNow && -vkNow() || 0);
- 159. - }
- 160. - function onScrollWindow(event, delayed) {
- 161. - if (event && !delayed) {
- 162. - clearTimeout(scrollTimer);
- 163. - scrollTimer = setTimeout(function() {
- 164. - onScrollWindow(event, true);
- 165. - }, 100);
- 166. - return;
- 167. - }
- 168. -
- 169. - if (event) {
- 170. - AdsLight.handleEvent('ads.onEvent', 'onScrollWindow', 0);
- 171. - }
- 172. -
- 173. - vk__adsLight.userEventTime = (window.vkNow && vkNow() || 0);
- 174. -
- 175. - onActiveTab();
- 176. -
- 177. - if (isVkDomain && window.vkNow && window.vk && vk.ads_rotate_interval && isTimeToUpdate()) {
- 178. - clearTimeout(updateTimer);
- 179. - updateTimer = setTimeout(function() {
- 180. - if (isTimeToUpdate()) {
- 181. - __adsLoaded = 0;
- 182. - AdsLight.updateBlock();
- 183. - }
- 184. - }, 10);
- 185. - }
- 186. -
- 187. - if (isVkDomain) {
- 188. - AdsLight.applyAds();
- 189. - }
- 190. -
- 191. - function isTimeToUpdate() {
- 192. - return vk__adsLight.adsSection === 'web' && vkNow() - __adsLoaded >= vk.ads_rotate_interval || vkNow() - __adsLoaded >= vk.ads_rotate_interval * 5;
- 193. - }
- 194. - }
- 195. - function onMouseDownDocument(event) {
- 196. - if (event) {
- 197. - AdsLight.handleEvent('ads.onEvent', 'onMouseDownDocument', 0);
- 198. - }
- 199. -
- 200. - vk__adsLight.userEventTime = (window.vkNow && vkNow() || 0);
- 201. -
- 202. - onActiveTab();
- 203. -
- 204. - if (!event) {
- 205. - return;
- 206. - }
- 207. - var elem = event.target;
- 208. - while (elem) {
- 209. - if (elem.tagName == 'A') {
- 210. - break;
- 211. - }
- 212. - if (elem.onclick) {
- 213. - break;
- 214. - }
- 215. - elem = elem.parentNode;
- 216. - }
- 217. - if (!elem) {
- 218. - return;
- 219. - }
- 220. -
- 221. - onMouseDownDocumentAction(true);
- 222. - }
- 223. - function onMouseDownDocumentAction(eventStub) {
- 224. - if (eventStub) {
- 225. - AdsLight.handleEvent('ads.onEvent', 'onMouseDownDocumentAction', 0);
- 226. - }
- 227. -
- 228. - clearTimeout(updateTimer);
- 229. -
- 230. - afterClickLink = true;
- 231. - setTimeout(function() {
- 232. - afterClickLink = false;
- 233. - }, 10);
- 234. - }
- 235. - function onActiveTab(eventStub) {
- 236. - if (isVkDomain && window.vkNow && window.vk && vk.ads_rotate_interval && !afterClickLink && vk__adsLight.activeTab < 0 && vkNow() + vk__adsLight.activeTab >= 15000 && isTimeToUpdate()) {
- 237. - clearTimeout(updateTimer);
- 238. - updateTimer = setTimeout(function() {
- 239. - if (isTimeToUpdate()) {
- 240. - __adsLoaded = 0;
- 241. - AdsLight.updateBlock();
- 242. - }
- 243. - }, 10);
- 244. - }
- 245. - vk__adsLight.activeTab = 1;
- 246. -
- 247. - function isTimeToUpdate() {
- 248. - return vkNow() - __adsLoaded >= vk.ads_rotate_interval;
- 249. - }
- 250. - }
- 251. - }
- 252. -
- 253. - AdsLight.initWeb = function(adsSection, loaderParams, adsScriptVersion, adsParamsExport) {
- 254. - vk__adsLight.adsSection = adsSection;
- 255. -
- 256. - if (top === window) {
- 257. - return;
- 258. - }
- 259. -
- 260. - var rpcMethods = {
- 261. - adsPublish: function() {
- 262. - AdsLight.handleEvent.apply(AdsLight, arguments);
- 263. - },
- 264. - onAdsAttached: function() {
- 265. - vk__adsLight.rpc.callMethod('publish', 'ads.subscribeEvents');
- 266. - },
- 267. - onInit: function() {
- 268. - vk__adsLight.rpc.callMethod('publish', 'ads.subscribeEvents');
- 269. - }
- 270. - };
- 271. - try {
- 272. - vk__adsLight.rpc = new fastXDM.Client(rpcMethods);
- 273. - vk__adsLight.rpc.callMethod('adsOnInitLoader', adsScriptVersion);
- 274. - vk__adsLight.loaderParams = loaderParams;
- 275. - vk__adsLight.adsParamsExport = adsParamsExport;
- 276. - } catch (e) {
- 277. - debugLog(e);
- 278. - }
- 279. - }
- 280. -
- 281. - AdsLight.initObservers = function() {
- 282. - if (!window.VK || !VK.Observer || !VK.Observer.subscribe) {
- 283. - return;
- 284. - }
- 285. - if (vk__adsLight.observersInited) {
- 286. - return;
- 287. - }
- 288. - vk__adsLight.observersInited = true;
- 289. -
- 290. - VK.Observer.subscribe('ads.isVisibleBlockWrap', getHandler('ads.isVisibleBlockWrap'));
- 291. - VK.Observer.subscribe('ads.subscribeEvents', getHandler('ads.subscribeEvents'));
- 292. - VK.Observer.subscribe('ads.onEvent', getHandler('ads.onEvent'));
- 293. - VK.Observer.subscribe('ads.onAdsShowed', getHandler('ads.onAdsShowed'));
- 294. -
- 295. - for (var widgetId in VK.Widgets.RPC) {
- 296. - if (VK.Widgets.RPC[widgetId].methods.adsOnInit) {
- 297. - VK.Widgets.RPC[widgetId].callMethod('onAdsAttached');
- 298. - }
- 299. - }
- 300. -
- 301. - function getHandler(publishEventName) {
- 302. - return function() {
- 303. - var args = Array.prototype.slice.call(arguments);
- 304. - args.unshift(publishEventName);
- 305. - AdsLight.handleEvent.apply(AdsLight, args);
- 306. - };
- 307. - }
- 308. - }
- 309. -
- 310. - AdsLight.handleEvent = function() {
- 311. - var args = Array.prototype.slice.call(arguments);
- 312. - var publishEventName = args.shift();
- 313. - switch (publishEventName) {
- 314. - case 'ads.isVisibleBlockWrap':
- 315. - AdsLight.isVisibleBlockWrapRpc.apply(AdsLight, args);
- 316. - break;
- 317. - case 'ads.subscribeEvents':
- 318. - var widgetId = args[0];
- 319. - if (widgetId && !vk__adsLight.widgetsIds[widgetId]) {
- 320. - vk__adsLight.widgetsIds[widgetId] = true;
- 321. - }
- 322. - vk__adsLight.userHandlers.onInit(true);
- 323. - break;
- 324. - case 'ads.onEvent':
- 325. - AdsLight.onEvent.apply(AdsLight, args);
- 326. - break;
- 327. - case 'ads.onAdsShowed':
- 328. - AdsLight.onAdsShowed.apply(AdsLight, args);
- 329. - break;
- 330. - }
- 331. - }
- 332. -
- 333. - AdsLight.onEvent = function(eventName, windowsIds) {
- 334. - if (windowsIds === 0) {
- 335. - windowsIds = [];
- 336. - //windowsIds.push(Math.round(Math.random() * -1000)); // For debug
- 337. - } else {
- 338. - var isWindowCur = false;
- 339. - for (var i in windowsIds) {
- 340. - if (windowsIds[i] == vk__adsLight.windowId) {
- 341. - isWindowCur = true;
- 342. - break;
- 343. - }
- 344. - }
- 345. - if (isWindowCur) {
- 346. - return;
- 347. - }
- 348. - if (vk__adsLight.userHandlers[eventName]) {
- 349. - vk__adsLight.userHandlers[eventName](false);
- 350. - }
- 351. - }
- 352. - windowsIds.push(vk__adsLight.windowId);
- 353. -
- 354. - AdsLight.publish(false, 'ads.onEvent', eventName, windowsIds);
- 355. - }
- 356. -
- 357. - AdsLight.onAdsShowed = function(adsShowedAll) {
- 358. - if (adsShowedAll === 0) {
- 359. - adsShowedAll = {};
- 360. - }
- 361. -
- 362. - // Sort windows ids to correct compare received messages
- 363. - {
- 364. - var windowsIds = [];
- 365. - for (var windowId in adsShowedAll) {
- 366. - windowsIds.push(parseInt(windowId));
- 367. - }
- 368. - windowsIds.sort();
- 369. - }
- 370. -
- 371. - // Check for identical message was send
- 372. - {
- 373. - var publishHash = [];
- 374. - for (var i = 0, len = windowsIds.length; i < len; i++) {
- 375. - var windowId = windowsIds[i];
- 376. - publishHash.push(adsShowedAll[windowId].ads_showed_hash);
- 377. - }
- 378. - publishHash = publishHash.join('_');
- 379. -
- 380. - var noPublish = (publishHash && adsShowedAll[vk__adsLight.windowId] && publishHash === adsShowedAll[vk__adsLight.windowId].publish_hash);
- 381. - }
- 382. -
- 383. - // Add known showed ads to message
- 384. - {
- 385. - var nowTime = +new Date;
- 386. -
- 387. - if (!adsShowedAll[vk__adsLight.windowId]) {
- 388. - adsShowedAll[vk__adsLight.windowId] = {};
- 389. - windowsIds.push(vk__adsLight.windowId);
- 390. - windowsIds.sort();
- 391. - }
- 392. - adsShowedAll[vk__adsLight.windowId].ads_showed = vk__adsLight.adsShowed;
- 393. - adsShowedAll[vk__adsLight.windowId].ads_showed_hash = vk__adsLight.adsShowedHash;
- 394. - adsShowedAll[vk__adsLight.windowId].update_progress = vk__adsLight.updateProgress;
- 395. -
- 396. - for (var windowId in vk__adsLight.adsShowedAll) {
- 397. - if ((!adsShowedAll[windowId] || vk__adsLight.adsShowedAll[windowId].publish_time > adsShowedAll[windowId].publish_time) && nowTime - vk__adsLight.adsShowedAll[windowId].publish_time < 10000) {
- 398. - adsShowedAll[windowId] = vk__adsLight.adsShowedAll[windowId];
- 399. - }
- 400. - }
- 401. -
- 402. - var publishHash = [];
- 403. - for (var i = 0, len = windowsIds.length; i < len; i++) {
- 404. - var windowId = windowsIds[i];
- 405. - publishHash.push(adsShowedAll[windowId].ads_showed_hash);
- 406. - }
- 407. - publishHash = publishHash.join('_');
- 408. -
- 409. - adsShowedAll[vk__adsLight.windowId].publish_time = nowTime;
- 410. - adsShowedAll[vk__adsLight.windowId].publish_hash = publishHash;
- 411. - }
- 412. -
- 413. - // Update all showed ads
- 414. - for (var windowId in adsShowedAll) {
- 415. - vk__adsLight.adsShowedAll[windowId] = adsShowedAll[windowId];
- 416. - }
- 417. -
- 418. - if (!noPublish) {
- 419. - AdsLight.publish(true, 'ads.onAdsShowed', adsShowedAll);
- 420. - }
- 421. - }
- 422. -
- 423. - AdsLight.publish = function(delayBigPublish, publishEventName) {
- 424. -
- 425. - var args = Array.prototype.slice.call(arguments, 1);
- 426. - var args1 = args.slice();
- 427. - var args2 = args.slice();
- 428. - var args3 = args.slice();
- 429. - var args4 = args.slice();
- 430. - args1.unshift('adsPublish');
- 431. - args2.unshift('adsPublish');
- 432. - args3.unshift('adsPublish');
- 433. - args4.unshift('publish');
- 434. -
- 435. - var func;
- 436. - var funcs = [];
- 437. - if (window.VK && VK.Widgets && VK.Widgets.RPC) {
- 438. - for (var widgetId in vk__adsLight.widgetsIds) {
- 439. - if (VK.Widgets.RPC[widgetId] && VK.Widgets.RPC[widgetId].callMethod) {
- 440. - func = (function() {
- 441. - var widgetIdCur = widgetId;
- 442. - return function() {
- 443. - VK.Widgets.RPC[widgetIdCur].callMethod.apply(VK.Widgets.RPC[widgetIdCur], args1);
- 444. - }
- 445. - })();
- 446. - funcs.push(func);
- 447. - }
- 448. - }
- 449. - }
- 450. - if (!isVkDomain && window.VK && VK.callMethod) {
- 451. - func = function() {
- 452. - VK.callMethod.apply(VK, args2);
- 453. - }
- 454. - funcs.push(func);
- 455. - }
- 456. - if (isVkDomain && vk__adsLight.adsSection !== 'web' && window.cur && cur.app && cur.app.runCallback) {
- 457. - func = function() {
- 458. - cur.app.runCallback.apply(cur.app, args3);
- 459. - }
- 460. - funcs.push(func);
- 461. - }
- 462. - if (isVkDomain && vk__adsLight.adsSection === 'web' && vk__adsLight.rpc && vk__adsLight.rpc.callMethod) {
- 463. - func = function() {
- 464. - vk__adsLight.rpc.callMethod.apply(vk__adsLight.rpc, args4);
- 465. - }
- 466. - funcs.push(func);
- 467. - }
- 468. -
- 469. - clearTimeout(vk__adsLight.publishTimers[publishEventName]);
- 470. - if (funcs.length > 1 && delayBigPublish) {
- 471. - vk__adsLight.publishTimers[publishEventName] = setTimeout(publishAll, 50);
- 472. - } else {
- 473. - publishAll();
- 474. - }
- 475. -
- 476. - function publishAll() {
- 477. - for (var i = 0, len = funcs.length; i < len; i++) {
- 478. - funcs[i]();
- 479. - }
- 480. - }
- 481. - }
- 482. -
- 483. - AdsLight.canUpdate = function(forAjax) {
- 484. -
- 485. - var containerElem = ge('left_ads');
- 486. -
- 487. - var initialAjax = (forAjax && __adsLoaded === false);
- 488. -
- 489. - var result = true;
- 490. -
- 491. - // Is visible
- 492. - result = (result && containerElem && isVisible(containerElem) && (vk__adsLight.activeTab > 0 && AdsLight.isVisibleBlockWrap() || initialAjax));
- 493. - // Is reasonable
- 494. - result = (result && vk.id && (vk__adsLight.adsCanShow >= 1 || vkNow() + vk__adsLight.adsCanShow > 3600000)); // hour
- 495. -
- 496. - if (vk__adsLight.adsSection === 'web') {
- 497. - // Is reasonable
- 498. - result = (result && vk__adsLight.loadComplete === 2);
- 499. - } else {
- 500. - // Is visible
- 501. - result = (result && isVisible('side_bar') && !layers.visible && !isVisible('left_friends'));
- 502. - // Is reasonable
- 503. - result = (result && !vk.no_ads && (vk.loaded || initialAjax));
- 504. - }
- 505. -
- 506. - return result;
- 507. - }
- 508. -
- 509. - AdsLight.getAjaxParams = function(ajaxParams, ajaxOptions) {
- 510. - var ajaxParamsNew = {};
- 511. - var canUpdateBlock = AdsLight.canUpdate(true);
- 512. - if (ajaxOptions.noAds) {
- 513. - ajaxParamsNew.al_ad = 0;
- 514. - } else if (canUpdateBlock || ajaxOptions.ads) {
- 515. - if (ajaxOptions.ads || window.vkNow && window.vk && vk.ads_rotate_interval && vk__adsLight.adsSection !== 'web' && vkNow() - __adsLoaded >= vk.ads_rotate_interval) {
- 516. - __adsLoaded = vkNow();
- 517. - ajaxParamsNew.al_ad = 1;
- 518. - }
- 519. - if (ajaxParams.al_ad || ajaxParamsNew.al_ad) {
- 520. - ajaxParamsNew.ads_section = vk__adsLight.adsSection;
- 521. - ajaxParamsNew.ads_showed = AdsLight.getAdsShowed();
- 522. - }
- 523. - } else {
- 524. - ajaxParamsNew.al_ad = null;
- 525. - }
- 526. - return ajaxParamsNew;
- 527. - }
- 528. -
- 529. - AdsLight.doRequest = function(requestFunc, delayed) {
- 530. -
- 531. - var isWebLoad = (vk__adsLight.adsSection === 'web' && vk__adsLight.loadComplete === 1);
- 532. -
- 533. - if (!delayed) {
- 534. - vk__adsLight.updateProgress = 1;
- 535. - AdsLight.onAdsShowed(0);
- 536. - setTimeout(AdsLight.doRequest.pbind(requestFunc, true), 300);
- 537. - return;
- 538. - }
- 539. -
- 540. - var lastRequestWindowId = 0;
- 541. - var lastRequestWindowsIds = {};
- 542. - var intervalTimer;
- 543. - var timeoutTimer;
- 544. -
- 545. - checkRequest();
- 546. -
- 547. - function checkRequest(force) {
- 548. - var nowTime = +new Date;
- 549. - var currentRequestWindowId = 0;
- 550. - for (var windowId in vk__adsLight.adsShowedAll) {
- 551. - var windowAdsShowed = vk__adsLight.adsShowedAll[windowId];
- 552. - if (nowTime - windowAdsShowed.publish_time >= 30000) {
- 553. - delete vk__adsLight.adsShowedAll[windowId];
- 554. - } else if (!isWebLoad || !lastRequestWindowsIds[windowId]) {
- 555. - if (windowAdsShowed.update_progress == 2) {
- 556. - currentRequestWindowId = windowId;
- 557. - break;
- 558. - } else if (windowAdsShowed.update_progress == 1 && (!currentRequestWindowId || windowId < currentRequestWindowId)) {
- 559. - currentRequestWindowId = windowId;
- 560. - }
- 561. - }
- 562. - }
- 563. -
- 564. - if (force || !currentRequestWindowId || currentRequestWindowId == vk__adsLight.windowId) {
- 565. - clearInterval(intervalTimer);
- 566. - clearTimeout(timeoutTimer);
- 567. - vk__adsLight.updateProgress = 2;
- 568. - AdsLight.onAdsShowed(0);
- 569. - requestFunc();
- 570. - } else if (currentRequestWindowId != lastRequestWindowId) {
- 571. - lastRequestWindowId = currentRequestWindowId;
- 572. - clearInterval(intervalTimer);
- 573. - clearTimeout(timeoutTimer);
- 574. - intervalTimer = setInterval(checkRequest, isWebLoad ? 100 : 200);
- 575. - timeoutTimer = setTimeout(checkRequest.pbind(true), 5000 + 50);
- 576. - }
- 577. -
- 578. - lastRequestWindowsIds[currentRequestWindowId] = (lastRequestWindowsIds[currentRequestWindowId] ? lastRequestWindowsIds[currentRequestWindowId] + 1 : 1);
- 579. - }
- 580. - }
- 581. -
- 582. - AdsLight.getAdsShowed = function() {
- 583. - var adsShowed = [];
- 584. - for (var windowId in vk__adsLight.adsShowedAll) {
- 585. - var windowAdsShowed = vk__adsLight.adsShowedAll[windowId];
- 586. - if (windowAdsShowed.ads_showed) {
- 587. - adsShowed.push(windowAdsShowed.ads_showed);
- 588. - }
- 589. - }
- 590. - adsShowed = adsShowed.join(',');
- 591. - return adsShowed;
- 592. - }
- 593. -
- 594. - AdsLight.updateBlock = function(force, delayed) {
- 595. -
- 596. - if (force === 'very_lazy') {
- 597. - __adsLoaded = 0;
- 598. - return;
- 599. - }
- 600. - if (force === 'lazy') {
- 601. - if (__adsLoaded) {
- 602. - __adsLoaded = 0;
- 603. - return;
- 604. - } else {
- 605. - __adsLoaded = 0; // if __adsLoaded === false
- 606. - }
- 607. - }
- 608. - if (force === 'force') {
- 609. - __adsLoaded = 0;
- 610. - }
- 611. - if (force === 'already') {
- 612. - __adsLoaded = vkNow();
- 613. - return;
- 614. - }
- 615. -
- 616. - if (__adsLoaded || __adsLoaded === false) {
- 617. - return;
- 618. - }
- 619. -
- 620. - if (!delayed) {
- 621. - clearTimeout(vk__adsLight.updateBlockTimer);
- 622. - vk__adsLight.updateBlockTimer = setTimeout(AdsLight.updateBlock.pbind(false, 1), 1000);
- 623. - return;
- 624. - }
- 625. -
- 626. - var canUpdateBlock = AdsLight.canUpdate();
- 627. -
- 628. - if (delayed == 1) {
- 629. - setTimeout(AdsLight.updateBlock.pbind(false, 2), 500); // Period must be greater than in isVisibleBlockWrapCoords
- 630. - return;
- 631. - }
- 632. -
- 633. - if (!canUpdateBlock) {
- 634. - return;
- 635. - }
- 636. -
- 637. - __adsLoaded = vkNow();
- 638. -
- 639. - var ajaxParams = {};
- 640. - for (var i in vk__adsLight.adsParams) {
- 641. - ajaxParams[i] = vk__adsLight.adsParams[i];
- 642. - }
- 643. -
- 644. - AdsLight.doRequest(function(){
- 645. - ajaxParams.ads_showed = AdsLight.getAdsShowed();
- 646. - ajax.post('/ads_rotate.php?act=al_update_ad', ajaxParams, {ads: 1, onDone: onComplete, onFail: onComplete});
- 647. - });
- 648. -
- 649. - function onComplete() {
- 650. - vk__adsLight.updateProgress = 3;
- 651. - }
- 652. - }
- 653. -
- 654. - AdsLight.setNewBlock = function(adsHtml, adsSection, adsCanShow, adsShowed, adsParams) {
- 655. - if (typeof(adsSection) === 'string') {
- 656. - vk__adsLight.adsSection = adsSection;
- 657. - }
- 658. - vk__adsLight.adsCanShow = ((adsCanShow || adsCanShow === '0') ? 1 : -vkNow());
- 659. - vk__adsLight.adsShowed = adsShowed;
- 660. - vk__adsLight.adsShowedHash = +new Date;
- 661. - if (adsParams) {
- 662. - vk__adsLight.adsParams = adsParams;
- 663. - }
- 664. -
- 665. - if (!adsHtml) {
- 666. - if (vk.no_ads) {
- 667. - adsHtml = '';
- 668. - } else if (vk__adsLight.adsSection === 'im' && __seenAds == 0) {
- 669. - adsHtml = '';
- 670. - } else {
- 671. - AdsLight.resizeBlockWrap([0,0], false, false, true);
- 672. - return;
- 673. - }
- 674. - }
- 675. -
- 676. - __adsLoaded = vkNow();
- 677. -
- 678. - var containerElem = ge('left_ads');
- 679. - var isContainerVisible = (containerElem && isVisible(containerElem) || vk.ad_preview);
- 680. - if (!containerElem) {
- 681. - var sideBarElem = ge('side_bar');
- 682. - if (!sideBarElem) {
- 683. - AdsLight.resizeBlockWrap([0,0], false, false, true);
- 684. - return;
- 685. - }
- 686. - containerElem = sideBarElem.appendChild(ce('div', {id: 'left_ads'}, {display: isContainerVisible ? 'block' : 'none'}));
- 687. - }
- 688. -
- 689. - AdsLight.showNewBlock(containerElem, adsHtml, isContainerVisible);
- 690. -
- 691. - if (window.vk && vk.ads_rotate_interval && vk__adsLight.adsSection === 'web') {
- 692. - clearInterval(vk__adsLight.reloadTimer);
- 693. - vk__adsLight.reloadTimer = setInterval(function(){
- 694. - if (vkNow() - __adsLoaded >= vk.ads_rotate_interval && vkNow() - vk__adsLight.userEventTime <= vk.ads_rotate_interval * 3 / 4) { // Check part of ads_rotate_interval for user actions to prevent side effects when rotating ads cause window to scroll
- 695. - __adsLoaded = 0;
- 696. - AdsLight.updateBlock();
- 697. - }
- 698. - }, vk.ads_rotate_interval);
- 699. - }
- 700. -
- 701. - setTimeout(function() {
- 702. - vk__adsLight.updateProgress = 3;
- 703. - AdsLight.onAdsShowed(0);
- 704. - }, 100);
- 705. - }
- 706. -
- 707. - AdsLight.showNewBlock = function(containerElem, adsHtml, isContainerVisible) {
- 708. - if (!isContainerVisible || browserLight.msie6 || browserLight.msie7) {
- 709. - if (!isContainerVisible) {
- 710. - debugLog('Ads container is hidden');
- 711. - }
- 712. - containerElem.innerHTML = adsHtml;
- 713. - var newSize = AdsLight.getBlockSize(containerElem);
- 714. - AdsLight.resizeBlockWrap(newSize, false, false, true);
- 715. - AdsLight.updateExternalStats(containerElem);
- 716. - return;
- 717. - }
- 718. -
- 719. - var isNewBlockEmpty = !adsHtml;
- 720. - var speed = (isNewBlockEmpty ? 0 : 200);
- 721. - var oldSize = AdsLight.getBlockSize(containerElem);
- 722. - var lastSize = [0, 0];
- 723. - var newBlockElem = containerElem.appendChild(ce('div', {innerHTML: adsHtml}, {display: 'none'}));
- 724. - var newBlockSizeElem = (geByClass1('ads_ads_box3', newBlockElem) || newBlockElem);
- 725. -
- 726. - var imagesElems = geByTag('img', newBlockElem);
- 727. - var imagesObjects = [];
- 728. - for (var i = 0, len = imagesElems.length; i < len; i++) {
- 729. - var imageObject = vkImage();
- 730. - imageObject.onload = delayedResizeBlockWrap;
- 731. - imageObject.onerror = delayedResizeBlockWrap;
- 732. - imageObject.src = imagesElems[i].src;
- 733. - imagesObjects.push(imageObject);
- 734. - }
- 735. -
- 736. - // Wait images then show ads
- 737. - clearInterval(vk__adsLight.imagesTimer);
- 738. - vk__adsLight.imagesTimer = setInterval(waitIamges.pbind({count: 40}), 50); // 2 seconds
- 739. -
- 740. - function waitIamges(context) {
- 741. - if (--context.count > 0) {
- 742. - for (var i in imagesObjects) {
- 743. - if (!imagesObjects[i].width || !imagesObjects[i].height) {
- 744. - return;
- 745. - }
- 746. - }
- 747. - }
- 748. - clearInterval(vk__adsLight.imagesTimer);
- 749. - startShowing();
- 750. - }
- 751. - function delayedResizeBlockWrap() {
- 752. - if (isVisible(newBlockElem)) {
- 753. - var newSize = AdsLight.getBlockSize(newBlockSizeElem);
- 754. - newSize = AdsLight.resizeBlockWrap(newSize, oldSize, lastSize);
- 755. - }
- 756. - }
- 757. - function startShowing() {
- 758. - setStyle(containerElem, {overflow: 'hidden'});
- 759. - // zIndex: 10 - To be upper then previous block and hiders after closing ads
- 760. - // width: '100%' - For correct horizontal centering.
- 761. - setStyle(newBlockElem, {display: 'block', position: 'absolute', left: 0, top: 0, opacity: 0, zIndex: 10, width: '100%'});
- 762. -
- 763. - var newSize = AdsLight.getBlockSize(newBlockSizeElem);
- 764. - newSize = AdsLight.resizeBlockWrap(newSize, oldSize, lastSize);
- 765. -
- 766. - // Resize container
- 767. - animate(containerElem, {width: newSize[0], height: newSize[1]}, speed, showNewBlock.pbind());
- 768. - }
- 769. - function showNewBlock() {
- 770. - cleanElems(containerElem);
- 771. -
- 772. - var newSize = AdsLight.getBlockSize(newBlockSizeElem)
- 773. - newSize = AdsLight.resizeBlockWrap(newSize, false, lastSize, true);
- 774. -
- 775. - animate(newBlockElem, {opacity: 1}, speed, removeOldBlock);
- 776. - }
- 777. - function removeOldBlock() {
- 778. - cleanElems(newBlockElem);
- 779. -
- 780. - while (newBlockElem.previousSibling) {
- 781. - re(newBlockElem.previousSibling);
- 782. - }
- 783. - setStyle(newBlockElem, {position: 'static', zIndex: '', width: ''});
- 784. - setStyle(containerElem, {width: '', height: '', overflow: 'visible'});
- 785. -
- 786. - // Update site layout
- 787. - if (window.updSideTopLink) updSideTopLink();
- 788. -
- 789. - AdsLight.updateExternalStats(containerElem);
- 790. - }
- 791. - }
- 792. -
- 793. - AdsLight.updateExternalStats = function(containerElem) {
- 794. - var elems = geByClass('ads_ad_external_stats', containerElem);
- 795. - for (var i = 0, elem; elem = elems[i]; i++) {
- 796. - if (elem.getAttribute('external_stats_complete')) {
- 797. - continue;
- 798. - }
- 799. - elem.setAttribute('external_stats_complete', 1);
- 800. - vkImage().src = elem.getAttribute('external_stats_src');
- 801. - }
- 802. - }
- 803. -
- 804. - AdsLight.addAdsToApply = function(adsIdsApply) {
- 805. - for (var elemId in adsIdsApply) {
- 806. - vk__adsLight.adsIdsApplyNeeded[elemId] = adsIdsApply[elemId];
- 807. - }
- 808. - AdsLight.applyAds();
- 809. - }
- 810. -
- 811. - AdsLight.applyAds = function(delayed) {
- 812. - if (isEmpty(vk__adsLight.adsIdsApplyNeeded)) {
- 813. - return;
- 814. - }
- 815. - if (!delayed) {
- 816. - clearTimeout(vk__adsLight.adsIdsApplyTimer);
- 817. - vk__adsLight.adsIdsApplyTimer = setTimeout(AdsLight.applyAds.pbind(true), 100);
- 818. - return;
- 819. - }
- 820. -
- 821. - check();
- 822. -
- 823. - function check() {
- 824. - for (var elemId in vk__adsLight.adsIdsApplyNeeded) {
- 825. - var elem = ge(elemId);
- 826. - if (!elem) {
- 827. - delete vk__adsLight.adsIdsApplyNeeded[elemId];
- 828. - continue;
- 829. - }
- 830. - elemRect = elem.getBoundingClientRect();
- 831. - if (elemRect.bottom > 0 && elemRect.top < lastWindowHeight) {
- 832. - vk__adsLight.adsIdsApplyProcess.push(vk__adsLight.adsIdsApplyNeeded[elemId][0]);
- 833. - delete vk__adsLight.adsIdsApplyNeeded[elemId];
- 834. - } else if (vk__adsLight.adsIdsApplyNeeded[elemId][1] && (vkNow() - vk.started) / 1000 > vk__adsLight.adsIdsApplyNeeded[elemId][1]) {
- 835. - re(elem);
- 836. - delete vk__adsLight.adsIdsApplyNeeded[elemId];
- 837. - }
- 838. - }
- 839. - request();
- 840. - }
- 841. - function request(delayed) {
- 842. - if (vk__adsLight.adsIdsApplyProcess.length == 0) {
- 843. - return;
- 844. - }
- 845. - if (vk__adsLight.adsIdsApplyLocked) {
- 846. - return;
- 847. - }
- 848. - if (!delayed) {
- 849. - clearTimeout(vk__adsLight.adsIdsApplyTimer);
- 850. - vk__adsLight.adsIdsApplyTimer = setTimeout(request.pbind(true), 100);
- 851. - return;
- 852. - }
- 853. -
- 854. - vk__adsLight.adsIdsApplyLocked = true;
- 855. -
- 856. - var ajaxParams = {};
- 857. - ajaxParams.ads_ids_apply = vk__adsLight.adsIdsApplyProcess.join(';');
- 858. -
- 859. - vk__adsLight.adsIdsApplyProcess = [];
- 860. -
- 861. - ajax.post('/ads_light.php?act=apply_views', ajaxParams, {onDone: onComplete, onFail: onComplete})
- 862. - }
- 863. - function onComplete(response) {
- 864. - vk__adsLight.adsIdsApplyLocked = false;
- 865. - if (!response || !isObject(response)) {
- 866. - return;
- 867. - }
- 868. - for (var blockIdSuffix in response) {
- 869. - var elem = ge('ads_ad_box2_' + blockIdSuffix);
- 870. - if (!elem) {
- 871. - continue;
- 872. - }
- 873. - for (var key in response[blockIdSuffix]) {
- 874. - elem.setAttribute(key, response[blockIdSuffix][key]);
- 875. - }
- 876. - }
- 877. -
- 878. - AdsLight.applyAds();
- 879. - }
- 880. - }
- 881. -
- 882. - AdsLight.isVisibleBlockWrap = function(forceLocal) {
- 883. - var containerElem = ge('left_ads');
- 884. - var containerRect = containerElem.getBoundingClientRect();
- 885. - var coords = [];
- 886. - if (containerRect.right && containerRect.bottom) {
- 887. - coords.push([containerRect.left + (containerRect.right - containerRect.left) * 1 / 5, containerRect.top + (containerRect.bottom - containerRect.top) * 1 / 5]);
- 888. - coords.push([containerRect.left + (containerRect.right - containerRect.left) * 4 / 5, containerRect.top + (containerRect.bottom - containerRect.top) * 4 / 5]);
- 889. - }
- 890. -
- 891. - AdsLight.isVisibleBlockWrapCoords(coords, containerElem, onComplete, forceLocal);
- 892. -
- 893. - return vk__adsLight.wrapVisible;
- 894. -
- 895. - function onComplete(isVisibleWrap) {
- 896. - vk__adsLight.wrapVisible = isVisibleWrap;
- 897. - }
- 898. - }
- 899. -
- 900. - AdsLight.isVisibleBlockWrapCoords = function(coords, containerElem, onComplete, forceLocal) {
- 901. -
- 902. - var isVisibleWrap = false;
- 903. - var coordsNew = [];
- 904. - for (var i = 0, len = coords.length; i < len; i++) {
- 905. - var elem = document.elementFromPoint(coords[i][0], coords[i][1]);
- 906. - var isVisibleElem = (elem && (elem === containerElem || isAncestor(elem, containerElem)));
- 907. - var isVisibleWrap = (isVisibleWrap || isVisibleElem);
- 908. - if (isVisibleElem) {
- 909. - coordsNew.push(coords[i]);
- 910. - }
- 911. - }
- 912. - isVisibleWrap = !!isVisibleWrap;
- 913. -
- 914. - var completeTimer;
- 915. - var onCompleteCurrent = function(isVisibleWrapNew) {
- 916. - clearTimeout(completeTimer);
- 917. - onComplete((isVisibleWrapNew !== undefined) ? isVisibleWrapNew : isVisibleWrap);
- 918. - }
- 919. -
- 920. - if (!forceLocal && coordsNew.length && window != parent && isVkDomain && vk__adsLight.adsSection === 'web' && vk__adsLight.rpc && vk__adsLight.rpc.callMethod) {
- 921. - vk__adsLight.rpc.callMethod('publish', 'ads.isVisibleBlockWrap', coordsNew, onCompleteCurrent);
- 922. - completeTimer = setTimeout(onCompleteCurrent, 300); // Period must be lower than in updateBlock
- 923. - } else if (!forceLocal && coordsNew.length && window != parent && !isVkDomain && window.VK && VK.callMethod) {
- 924. - VK.callMethod('adsPublish', 'ads.isVisibleBlockWrap', coordsNew, onCompleteCurrent);
- 925. - completeTimer = setTimeout(onCompleteCurrent, 300); // Period must be lower than in updateBlock
- 926. - } else {
- 927. - onCompleteCurrent();
- 928. - }
- 929. -
- 930. - function isAncestor(elem, ancestor) {
- 931. - if (!elem || !ancestor) {
- 932. - return false;
- 933. - }
- 934. - while (elem = elem.parentNode) {
- 935. - if (elem === ancestor) {
- 936. - return true;
- 937. - }
- 938. - }
- 939. - return false;
- 940. - }
- 941. - }
- 942. -
- 943. - AdsLight.isVisibleBlockWrapRpc = function(coords, onComplete, widgetId) {
- 944. - var containerElem;
- 945. - if (widgetId) {
- 946. - containerElem = VK.Widgets.RPC[widgetId].frame;
- 947. - } else {
- 948. - containerElem = cur.app.frame;
- 949. - }
- 950. -
- 951. - var contanerRect = containerElem.getBoundingClientRect();
- 952. -
- 953. - var coordsNew = [];
- 954. - for (var i = 0, len = coords.length; i < len; i++) {
- 955. - var newX = coords[i][0] + contanerRect.left;
- 956. - var newY = coords[i][1] + contanerRect.top;
- 957. - coordsNew.push([newX, newY]);
- 958. - }
- 959. -
- 960. - AdsLight.isVisibleBlockWrapCoords(coordsNew, containerElem, onComplete);
- 961. - }
- 962. -
- 963. - AdsLight.getBlockSize = function(blockElem) {
- 964. - var adBoxes1 = geByClass('ads_ad_box', blockElem);
- 965. - var adBoxes5 = geByClass('ads_ad_box5', blockElem);
- 966. -
- 967. - each(adBoxes5, function(index, elem) { addClass(elem, 'max_size'); });
- 968. -
- 969. - if (browserLight.msie8) {
- 970. - each(adBoxes1, function(index, elem) {
- 971. - var width = Math.ceil(floatval(getStyle(elem, 'width')));
- 972. - var widthMax = Math.ceil(floatval(getStyle(elem, 'max-width')));
- 973. - if (widthMax && widthMax > 200 && width >= widthMax) {
- 974. - elem.style.width = widthMax + 'px';
- 975. - }
- 976. - });
- 977. - }
- 978. -
- 979. - var blockWidth = Math.ceil(floatval(getStyle(blockElem, 'width')));
- 980. - var blockHeight = Math.ceil(floatval(getStyle(blockElem, 'height')));
- 981. - var blockSize = [blockWidth, blockHeight];
- 982. -
- 983. - each(adBoxes5, function(index, elem) { removeClass(elem, 'max_size'); });
- 984. -
- 985. - return blockSize;
- 986. - }
- 987. -
- 988. - AdsLight.resizeBlockWrap = function(newSize, oldSize, lastSize, forceResize) {
- 989. - if (!newSize) {
- 990. - return [0, 0];
- 991. - }
- 992. -
- 993. - var newWidth = newSize[0];
- 994. - var newHeight = newSize[1];
- 995. - if (newWidth && vk__adsLight.adsParams && vk__adsLight.adsParams.ads_ad_unit_width_real > newWidth) {
- 996. - newWidth = vk__adsLight.adsParams.ads_ad_unit_width_real;
- 997. - }
- 998. - if (newHeight && vk__adsLight.adsParams && vk__adsLight.adsParams.ads_ad_unit_height_real > newHeight) {
- 999. - newHeight = vk__adsLight.adsParams.ads_ad_unit_height_real;
- 1000. - }
- 1001. - var isResizeWidth = !!(forceResize || oldSize && newWidth > oldSize[0] || lastSize && lastSize[0] && newWidth > lastSize[0]);
- 1002. - var isResizeHeight = !!(forceResize || oldSize && newHeight > oldSize[1] || lastSize && lastSize[1] && newHeight > lastSize[1]);
- 1003. - if (!isResizeWidth && !isResizeHeight) {
- 1004. - return [newWidth, newHeight];
- 1005. - }
- 1006. - if (lastSize) {
- 1007. - if (isResizeWidth) {
- 1008. - lastSize[0] = newWidth;
- 1009. - }
- 1010. - if (isResizeHeight) {
- 1011. - lastSize[1] = newHeight;
- 1012. - }
- 1013. - }
- 1014. -
- 1015. - if (isVkDomain && vk__adsLight.adsSection === 'web' && vk__adsLight.rpc && vk__adsLight.rpc.callMethod) {
- 1016. - vk__adsLight.rpc.callMethod('resizeWidget', isResizeWidth && newWidth, isResizeHeight && newHeight);
- 1017. - }
- 1018. -
- 1019. - return [newWidth, newHeight];
- 1020. - }
- 1021. -
- 1022. - AdsLight.loadAds = function() {
- 1023. - if (!isVkDomain || !vk__adsLight.loaderParams || vk__adsLight.loadComplete) {
- 1024. - return;
- 1025. - }
- 1026. - vk__adsLight.loadComplete = 1;
- 1027. -
- 1028. - var adsParamsExport = vk__adsLight.adsParamsExport;
- 1029. - delete vk__adsLight.adsParamsExport;
- 1030. -
- 1031. - var ajaxParams = {};
- 1032. -
- 1033. - for (var i in vk__adsLight.loaderParams) {
- 1034. - ajaxParams[i] = vk__adsLight.loaderParams[i];
- 1035. - }
- 1036. -
- 1037. - ajaxParams.url = document.referrer;
- 1038. - try { ajaxParams.url_top = top.location.toString(); } catch (e) {}
- 1039. -
- 1040. - var isVisibleWeb = AdsLight.isVisibleBlockWrap(true);
- 1041. - if (!isVisibleWeb) {
- 1042. - ajaxParams.web_invisible = 1;
- 1043. - }
- 1044. -
- 1045. - if (document.documentMode) {
- 1046. - ajaxParams.ie_document_mode = document.documentMode;
- 1047. - }
- 1048. -
- 1049. - AdsLight.doRequest(function(){
- 1050. - ajaxParams.ads_showed = AdsLight.getAdsShowed();
- 1051. - ajax.post('/ads_rotate.php?act=ads_web', ajaxParams, {onDone: onComplete, onFail: onComplete});
- 1052. - });
- 1053. -
- 1054. - function onComplete(response, nothing, js) {
- 1055. - vk__adsLight.updateProgress = 3;
- 1056. -
- 1057. - if (response && isObject(response) && 'ads_html' in response) {
- 1058. - var styleElemOld = ge('ads_style_web_loader');
- 1059. - var sheetOld = (styleElemOld.sheet ? styleElemOld.sheet : styleElemOld.styleSheet);
- 1060. - var deleteFunc = (sheetOld.deleteRule ? 'deleteRule' : 'removeRule');
- 1061. - sheetOld[deleteFunc](0);
- 1062. -
- 1063. - var styleElemNew = ce('style', {type: 'text/css'})
- 1064. - if (styleElemNew.styleSheet) {
- 1065. - styleElemNew.styleSheet.cssText = response.css;
- 1066. - } else {
- 1067. - styleElemNew.appendChild(document.createTextNode(response.css));
- 1068. - }
- 1069. - headNode.appendChild(styleElemNew);
- 1070. -
- 1071. - AdsLight.setNewBlock(response.ads_html, response.ads_section, response.ads_can_show, response.ads_showed, response.ads_params);
- 1072. - vk__adsLight.rpc.callMethod('adsOnInit', response.ads_count, response.ads_params_export);
- 1073. -
- 1074. - vk__adsLight.loadComplete = 2;
- 1075. - } else {
- 1076. - if (typeof(js) === 'string') {
- 1077. - try {
- 1078. - eval(js);
- 1079. - } catch (e) {
- 1080. - debugLog(e);
- 1081. - }
- 1082. - }
- 1083. - AdsLight.loadAdsFailed(-3001, adsParamsExport);
- 1084. - }
- 1085. - }
- 1086. - }
- 1087. -
- 1088. - AdsLight.loadAdsFailed = function(errorCode, adsParamsExport) {
- 1089. - if (!vk__adsLight.rpc) {
- 1090. - return false;
- 1091. - }
- 1092. - if (vk__adsLight.loadComplete === -1) {
- 1093. - return true;
- 1094. - }
- 1095. - vk__adsLight.loadComplete = -1;
- 1096. -
- 1097. - vk__adsLight.rpc.callMethod('resizeWidget', 0, 0);
- 1098. - vk__adsLight.rpc.callMethod('adsOnInit', errorCode, adsParamsExport);
- 1099. -
- 1100. - return true;
- 1101. - }
- 1102. -
- 1103. - AdsLight.handleAllAds = function(box, adsIdsMore, adsIdsApply, adsHeightMore) {
- 1104. -
- 1105. - var moreLocked = false;
- 1106. - var needAdsHeight = false;
- 1107. -
- 1108. - boxLayerWrap.scrollTop = 0;
- 1109. -
- 1110. - var boxOptions = {};
- 1111. - boxOptions.onClean = deinit;
- 1112. - box.setOptions(boxOptions);
- 1113. -
- 1114. - if (adsIdsMore) {
- 1115. - addEvent(boxLayerWrap, 'scroll', onScroll);
- 1116. - }
- 1117. - allowApply();
- 1118. - onScroll();
- 1119. -
- 1120. - function deinit() {
- 1121. - removeEvent(boxLayerWrap, 'scroll', onScroll);
- 1122. - hide('ads_ads_all_ads_more');
- 1123. - }
- 1124. - function checkDeinit() {
- 1125. - if (!adsIdsMore && isEmpty(vk__adsLight.adsIdsApplyNeeded)) {
- 1126. - deinit();
- 1127. - }
- 1128. - }
- 1129. - function allowApply(delayed) {
- 1130. - if (!delayed) {
- 1131. - setTimeout(allowApply.pbind(true), 500);
- 1132. - return;
- 1133. - }
- 1134. - AdsLight.addAdsToApply(adsIdsApply);
- 1135. - onScroll();
- 1136. - }
- 1137. - function onScroll() {
- 1138. - var moreElem = ge('ads_ads_all_ads_more');
- 1139. - if (!moreElem) {
- 1140. - return;
- 1141. - }
- 1142. - var moreRect = moreElem.getBoundingClientRect()
- 1143. - if (moreRect.top < lastWindowHeight + adsHeightMore) {
- 1144. - needAdsHeight = Math.round(Math.max(needAdsHeight, lastWindowHeight - moreRect.top + adsHeightMore));
- 1145. - moreAds();
- 1146. - }
- 1147. -
- 1148. - AdsLight.applyAds();
- 1149. -
- 1150. - checkDeinit();
- 1151. - }
- 1152. - function moreAds(delayed) {
- 1153. - if (!delayed) {
- 1154. - setTimeout(moreAds.pbind(true), 100);
- 1155. - return;
- 1156. - }
- 1157. - if (!adsIdsMore) {
- 1158. - return;
- 1159. - }
- 1160. - if (!needAdsHeight) {
- 1161. - return;
- 1162. - }
- 1163. - if (moreLocked) {
- 1164. - return;
- 1165. - }
- 1166. - moreLocked = true;
- 1167. -
- 1168. - var ajaxParams = {};
- 1169. - ajaxParams.ads_ids_more = adsIdsMore;
- 1170. - ajaxParams.ads_height = needAdsHeight;
- 1171. -
- 1172. - ajax.post('/ads_light.php?act=all_ads_more', ajaxParams, {onDone: onDoneMoreAds, onFail: onFailMoreAds})
- 1173. - }
- 1174. - function onDoneMoreAds(response) {
- 1175. - moreLocked = false;
- 1176. - if (!response) {
- 1177. - onFailMoreAds();
- 1178. - return;
- 1179. - }
- 1180. - adsIdsMore = response.ads_ids_more;
- 1181. - AdsLight.addAdsToApply(response.ads_ids_apply);
- 1182. - if (response.ads_html) {
- 1183. - var adsElem = ge('ads_ads_all_ads_rows');
- 1184. - var moreElem = ge('ads_ads_all_ads_more');
- 1185. - if (adsElem) {
- 1186. - adsElem.innerHTML += response.ads_html;
- 1187. - needAdsHeight = false;
- 1188. - onScroll();
- 1189. - }
- 1190. - if (moreElem) {
- 1191. - moreElem.height = response.ads_more_height;
- 1192. - }
- 1193. - }
- 1194. - checkDeinit();
- 1195. - }
- 1196. - function onFailMoreAds() {
- 1197. - moreLocked = false;
- 1198. - return true;
- 1199. - }
- 1200. - }
- 1201. -
- 1202. - AdsLight.blockOverOut = function(event, elemCur, targetClass) {
- 1203. - var isOver = (event.type === 'mouseover');
- 1204. - var elemTarget;
- 1205. - var opacity = false;
- 1206. - if (hasClass(elemCur, targetClass)) {
- 1207. - elemTarget = elemCur;
- 1208. - toggleClass(elemTarget, 'over', isOver);
- 1209. - opacity = (isOver ? 1 : 0.3);
- 1210. - } else {
- 1211. - elemTarget = geByClass1(targetClass, elemTarget);
- 1212. - elemTarget.over = 1;
- 1213. - if (!hasClass(elemTarget, 'over')) {
- 1214. - opacity = (isOver ? 0.3 : 0);
- 1215. - }
- 1216. - }
- 1217. - if (opacity !== false) {
- 1218. - animate(elemTarget, {opacity: opacity}, 200);
- 1219. - }
- 1220. - if (isOver && elemCur == elemTarget) {
- 1221. - var tooltipTextElem = geByClass1('tooltip_text', elemTarget);
- 1222. - if (tooltipTextElem) {
- 1223. - showTooltip(elemTarget, {text: tooltipTextElem.innerHTML, showdt: 0, black: 1, shift: [14, 3, 3]});
- 1224. - }
- 1225. - }
- 1226. - }
- 1227. -
- 1228. - AdsLight.closeNewsBlock = function(elem, hash) {
- 1229. - while (!hasClass(elem, 'feed_row')) elem = elem.parentNode;
- 1230. - slideUp(elem, 200);
- 1231. - ajax.post('/ads_light.php?act=close_news', {hash: hash}, {onDone: onComplete, onFail: onComplete});
- 1232. - function onComplete() {
- 1233. - return true;
- 1234. - }
- 1235. - }
- 1236. -
- 1237. - AdsLight.init();
- 1238. -
- 1239. - })();
- 1240. -
- 1241. - try{stManager.done('aes_light.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment