Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - aes_light.js (Старый размер - 38275 | Новый - 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 containerElemY = getXY(containerElem)[1];
- 720. - var scrollY = scrollGetY();
- 721. - var isNewBlockEmpty = !adsHtml;
- 722. - var speed = ((isNewBlockEmpty || containerElemY + 50 > scrollY + lastWindowHeight) ? 0 : 200);
- 723. - var oldSize = AdsLight.getBlockSize(containerElem);
- 724. - var lastSize = [0, 0];
- 725. - var newBlockElem = containerElem.appendChild(ce('div', {innerHTML: adsHtml}, {display: 'none'}));
- 726. - var newBlockSizeElem = (geByClass1('ads_ads_box3', newBlockElem) || newBlockElem);
- 727. -
- 728. - var imagesElems = geByTag('img', newBlockElem);
- 729. - var imagesObjects = [];
- 730. - for (var i = 0, len = imagesElems.length; i < len; i++) {
- 731. - var imageObject = vkImage();
- 732. - imageObject.onload = delayedResizeBlockWrap;
- 733. - imageObject.onerror = delayedResizeBlockWrap;
- 734. - imageObject.src = imagesElems[i].src;
- 735. - imagesObjects.push(imageObject);
- 736. - }
- 737. -
- 738. - // Wait images then show ads
- 739. - clearInterval(vk__adsLight.imagesTimer);
- 740. - vk__adsLight.imagesTimer = setInterval(waitIamges.pbind({count: 40}), 50); // 2 seconds
- 741. -
- 742. - function waitIamges(context) {
- 743. - if (--context.count > 0) {
- 744. - for (var i in imagesObjects) {
- 745. - if (!imagesObjects[i].width || !imagesObjects[i].height) {
- 746. - return;
- 747. - }
- 748. - }
- 749. - }
- 750. - clearInterval(vk__adsLight.imagesTimer);
- 751. - startShowing();
- 752. - }
- 753. - function delayedResizeBlockWrap() {
- 754. - if (isVisible(newBlockElem)) {
- 755. - var newSize = AdsLight.getBlockSize(newBlockSizeElem);
- 756. - newSize = AdsLight.resizeBlockWrap(newSize, oldSize, lastSize);
- 757. - }
- 758. - }
- 759. - function startShowing() {
- 760. - setStyle(containerElem, {overflow: 'hidden'});
- 761. - // zIndex: 10 - To be upper then previous block and hiders after closing ads
- 762. - // width: '100%' - For correct horizontal centering.
- 763. - setStyle(newBlockElem, {display: 'block', position: 'absolute', left: 0, top: 0, opacity: 0, zIndex: 10, width: '100%'});
- 764. -
- 765. - var newSize = AdsLight.getBlockSize(newBlockSizeElem);
- 766. - newSize = AdsLight.resizeBlockWrap(newSize, oldSize, lastSize);
- 767. -
- 768. - // Resize container
- 769. - animate(containerElem, {width: newSize[0], height: newSize[1]}, speed, showNewBlock.pbind());
- 770. - }
- 771. - function showNewBlock() {
- 772. - cleanElems(containerElem);
- 773. -
- 774. - var newSize = AdsLight.getBlockSize(newBlockSizeElem)
- 775. - newSize = AdsLight.resizeBlockWrap(newSize, false, lastSize, true);
- 776. -
- 777. - animate(newBlockElem, {opacity: 1}, speed, removeOldBlock);
- 778. - }
- 779. - function removeOldBlock() {
- 780. - cleanElems(newBlockElem);
- 781. -
- 782. - while (newBlockElem.previousSibling) {
- 783. - re(newBlockElem.previousSibling);
- 784. - }
- 785. - setStyle(newBlockElem, {position: 'static', zIndex: '', width: ''});
- 786. - setStyle(containerElem, {width: '', height: '', overflow: 'visible'});
- 787. -
- 788. - // Update site layout
- 789. - if (window.updSideTopLink) updSideTopLink();
- 790. -
- 791. - AdsLight.updateExternalStats(containerElem);
- 792. -
- 793. - if (!isNewBlockEmpty) {
- 794. - AdsLight.scrollToPreview();
- 795. - }
- 796. - }
- 797. - }
- 798. -
- 799. - AdsLight.updateExternalStats = function(containerElem) {
- 800. - var elems = geByClass('ads_ad_external_stats', containerElem);
- 801. - for (var i = 0, elem; elem = elems[i]; i++) {
- 802. - if (elem.getAttribute('external_stats_complete')) {
- 803. - continue;
- 804. - }
- 805. - elem.setAttribute('external_stats_complete', 1);
- 806. - vkImage().src = elem.getAttribute('external_stats_src');
- 807. - }
- 808. - }
- 809. -
- 810. - AdsLight.addAdsToApply = function(adsIdsApply) {
- 811. - for (var elemId in adsIdsApply) {
- 812. - vk__adsLight.adsIdsApplyNeeded[elemId] = adsIdsApply[elemId];
- 813. - }
- 814. - AdsLight.applyAds();
- 815. - }
- 816. -
- 817. - AdsLight.applyAds = function(delayed) {
- 818. - if (isEmpty(vk__adsLight.adsIdsApplyNeeded)) {
- 819. - return;
- 820. - }
- 821. - if (!delayed) {
- 822. - clearTimeout(vk__adsLight.adsIdsApplyTimer);
- 823. - vk__adsLight.adsIdsApplyTimer = setTimeout(AdsLight.applyAds.pbind(true), 100);
- 824. - return;
- 825. - }
- 826. -
- 827. - check();
- 828. -
- 829. - function check() {
- 830. - for (var elemId in vk__adsLight.adsIdsApplyNeeded) {
- 831. - var elem = ge(elemId);
- 832. - if (!elem) {
- 833. - delete vk__adsLight.adsIdsApplyNeeded[elemId];
- 834. - continue;
- 835. - }
- 836. - elemRect = elem.getBoundingClientRect();
- 837. - if (elemRect.bottom > 0 && elemRect.top < lastWindowHeight) {
- 838. - vk__adsLight.adsIdsApplyProcess.push(vk__adsLight.adsIdsApplyNeeded[elemId][0]);
- 839. - delete vk__adsLight.adsIdsApplyNeeded[elemId];
- 840. - } else if (vk__adsLight.adsIdsApplyNeeded[elemId][1] && (vkNow() - vk.started) / 1000 > vk__adsLight.adsIdsApplyNeeded[elemId][1]) {
- 841. - re(elem);
- 842. - delete vk__adsLight.adsIdsApplyNeeded[elemId];
- 843. - }
- 844. - }
- 845. - request();
- 846. - }
- 847. - function request(delayed) {
- 848. - if (vk__adsLight.adsIdsApplyProcess.length == 0) {
- 849. - return;
- 850. - }
- 851. - if (vk__adsLight.adsIdsApplyLocked) {
- 852. - return;
- 853. - }
- 854. - if (!delayed) {
- 855. - clearTimeout(vk__adsLight.adsIdsApplyTimer);
- 856. - vk__adsLight.adsIdsApplyTimer = setTimeout(request.pbind(true), 100);
- 857. - return;
- 858. - }
- 859. -
- 860. - vk__adsLight.adsIdsApplyLocked = true;
- 861. -
- 862. - var ajaxParams = {};
- 863. - ajaxParams.ads_ids_apply = vk__adsLight.adsIdsApplyProcess.join(';');
- 864. -
- 865. - vk__adsLight.adsIdsApplyProcess = [];
- 866. -
- 867. - ajax.post('/ads_light.php?act=apply_views', ajaxParams, {onDone: onComplete, onFail: onComplete})
- 868. - }
- 869. - function onComplete(response) {
- 870. - vk__adsLight.adsIdsApplyLocked = false;
- 871. - if (!response || !isObject(response)) {
- 872. - return;
- 873. - }
- 874. - for (var blockIdSuffix in response) {
- 875. - var elem = ge('ads_ad_box2_' + blockIdSuffix);
- 876. - if (!elem) {
- 877. - continue;
- 878. - }
- 879. - for (var key in response[blockIdSuffix]) {
- 880. - elem.setAttribute(key, response[blockIdSuffix][key]);
- 881. - }
- 882. - }
- 883. -
- 884. - AdsLight.applyAds();
- 885. - }
- 886. - }
- 887. -
- 888. - AdsLight.isVisibleBlockWrap = function(forceLocal) {
- 889. - var containerElem = ge('left_ads');
- 890. - var containerRect = containerElem.getBoundingClientRect();
- 891. - var coords = [];
- 892. - if (containerRect.right && containerRect.bottom) {
- 893. - coords.push([containerRect.left + (containerRect.right - containerRect.left) * 1 / 5, containerRect.top + (containerRect.bottom - containerRect.top) * 1 / 5]);
- 894. - coords.push([containerRect.left + (containerRect.right - containerRect.left) * 4 / 5, containerRect.top + (containerRect.bottom - containerRect.top) * 4 / 5]);
- 895. - }
- 896. -
- 897. - AdsLight.isVisibleBlockWrapCoords(coords, containerElem, onComplete, forceLocal);
- 898. -
- 899. - return vk__adsLight.wrapVisible;
- 900. -
- 901. - function onComplete(isVisibleWrap) {
- 902. - vk__adsLight.wrapVisible = isVisibleWrap;
- 903. - }
- 904. - }
- 905. -
- 906. - AdsLight.isVisibleBlockWrapCoords = function(coords, containerElem, onComplete, forceLocal) {
- 907. -
- 908. - var isVisibleWrap = false;
- 909. - var coordsNew = [];
- 910. - for (var i = 0, len = coords.length; i < len; i++) {
- 911. - var elem = document.elementFromPoint(coords[i][0], coords[i][1]);
- 912. - var isVisibleElem = (elem && (elem === containerElem || isAncestor(elem, containerElem)));
- 913. - var isVisibleWrap = (isVisibleWrap || isVisibleElem);
- 914. - if (isVisibleElem) {
- 915. - coordsNew.push(coords[i]);
- 916. - }
- 917. - }
- 918. - isVisibleWrap = !!isVisibleWrap;
- 919. -
- 920. - var completeTimer;
- 921. - var onCompleteCurrent = function(isVisibleWrapNew) {
- 922. - clearTimeout(completeTimer);
- 923. - onComplete((isVisibleWrapNew !== undefined) ? isVisibleWrapNew : isVisibleWrap);
- 924. - }
- 925. -
- 926. - if (!forceLocal && coordsNew.length && window != parent && isVkDomain && vk__adsLight.adsSection === 'web' && vk__adsLight.rpc && vk__adsLight.rpc.callMethod) {
- 927. - vk__adsLight.rpc.callMethod('publish', 'ads.isVisibleBlockWrap', coordsNew, onCompleteCurrent);
- 928. - completeTimer = setTimeout(onCompleteCurrent, 300); // Period must be lower than in updateBlock
- 929. - } else if (!forceLocal && coordsNew.length && window != parent && !isVkDomain && window.VK && VK.callMethod) {
- 930. - VK.callMethod('adsPublish', 'ads.isVisibleBlockWrap', coordsNew, onCompleteCurrent);
- 931. - completeTimer = setTimeout(onCompleteCurrent, 300); // Period must be lower than in updateBlock
- 932. - } else {
- 933. - onCompleteCurrent();
- 934. - }
- 935. -
- 936. - function isAncestor(elem, ancestor) {
- 937. - if (!elem || !ancestor) {
- 938. - return false;
- 939. - }
- 940. - while (elem = elem.parentNode) {
- 941. - if (elem === ancestor) {
- 942. - return true;
- 943. - }
- 944. - }
- 945. - return false;
- 946. - }
- 947. - }
- 948. -
- 949. - AdsLight.isVisibleBlockWrapRpc = function(coords, onComplete, widgetId) {
- 950. - var containerElem;
- 951. - if (widgetId) {
- 952. - containerElem = VK.Widgets.RPC[widgetId].frame;
- 953. - } else {
- 954. - containerElem = cur.app.frame;
- 955. - }
- 956. -
- 957. - var contanerRect = containerElem.getBoundingClientRect();
- 958. -
- 959. - var coordsNew = [];
- 960. - for (var i = 0, len = coords.length; i < len; i++) {
- 961. - var newX = coords[i][0] + contanerRect.left;
- 962. - var newY = coords[i][1] + contanerRect.top;
- 963. - coordsNew.push([newX, newY]);
- 964. - }
- 965. -
- 966. - AdsLight.isVisibleBlockWrapCoords(coordsNew, containerElem, onComplete);
- 967. - }
- 968. -
- 969. - AdsLight.getBlockSize = function(blockElem) {
- 970. - var adBoxes1 = geByClass('ads_ad_box', blockElem);
- 971. - var adBoxes5 = geByClass('ads_ad_box5', blockElem);
- 972. -
- 973. - each(adBoxes5, function(index, elem) { addClass(elem, 'max_size'); });
- 974. -
- 975. - if (browserLight.msie8) {
- 976. - each(adBoxes1, function(index, elem) {
- 977. - var width = Math.ceil(floatval(getStyle(elem, 'width')));
- 978. - var widthMax = Math.ceil(floatval(getStyle(elem, 'max-width')));
- 979. - if (widthMax && widthMax > 200 && width >= widthMax) {
- 980. - elem.style.width = widthMax + 'px';
- 981. - }
- 982. - });
- 983. - }
- 984. -
- 985. - var blockWidth = Math.ceil(floatval(getStyle(blockElem, 'width')));
- 986. - var blockHeight = Math.ceil(floatval(getStyle(blockElem, 'height')));
- 987. - var blockSize = [blockWidth, blockHeight];
- 988. -
- 989. - each(adBoxes5, function(index, elem) { removeClass(elem, 'max_size'); });
- 990. -
- 991. - return blockSize;
- 992. - }
- 993. -
- 994. - AdsLight.resizeBlockWrap = function(newSize, oldSize, lastSize, forceResize) {
- 995. - if (!newSize) {
- 996. - return [0, 0];
- 997. - }
- 998. -
- 999. - var newWidth = newSize[0];
- 1000. - var newHeight = newSize[1];
- 1001. - if (newWidth && vk__adsLight.adsParams && vk__adsLight.adsParams.ads_ad_unit_width_real > newWidth) {
- 1002. - newWidth = vk__adsLight.adsParams.ads_ad_unit_width_real;
- 1003. - }
- 1004. - if (newHeight && vk__adsLight.adsParams && vk__adsLight.adsParams.ads_ad_unit_height_real > newHeight) {
- 1005. - newHeight = vk__adsLight.adsParams.ads_ad_unit_height_real;
- 1006. - }
- 1007. - var isResizeWidth = !!(forceResize || oldSize && newWidth > oldSize[0] || lastSize && lastSize[0] && newWidth > lastSize[0]);
- 1008. - var isResizeHeight = !!(forceResize || oldSize && newHeight > oldSize[1] || lastSize && lastSize[1] && newHeight > lastSize[1]);
- 1009. - if (!isResizeWidth && !isResizeHeight) {
- 1010. - return [newWidth, newHeight];
- 1011. - }
- 1012. - if (lastSize) {
- 1013. - if (isResizeWidth) {
- 1014. - lastSize[0] = newWidth;
- 1015. - }
- 1016. - if (isResizeHeight) {
- 1017. - lastSize[1] = newHeight;
- 1018. - }
- 1019. - }
- 1020. -
- 1021. - if (isVkDomain && vk__adsLight.adsSection === 'web' && vk__adsLight.rpc && vk__adsLight.rpc.callMethod) {
- 1022. - vk__adsLight.rpc.callMethod('resizeWidget', isResizeWidth && newWidth, isResizeHeight && newHeight);
- 1023. - }
- 1024. -
- 1025. - return [newWidth, newHeight];
- 1026. - }
- 1027. -
- 1028. - AdsLight.loadAds = function() {
- 1029. - if (!isVkDomain || !vk__adsLight.loaderParams || vk__adsLight.loadComplete) {
- 1030. - return;
- 1031. - }
- 1032. - vk__adsLight.loadComplete = 1;
- 1033. -
- 1034. - var adsParamsExport = vk__adsLight.adsParamsExport;
- 1035. - delete vk__adsLight.adsParamsExport;
- 1036. -
- 1037. - var ajaxParams = {};
- 1038. -
- 1039. - for (var i in vk__adsLight.loaderParams) {
- 1040. - ajaxParams[i] = vk__adsLight.loaderParams[i];
- 1041. - }
- 1042. -
- 1043. - ajaxParams.url = document.referrer;
- 1044. - try { ajaxParams.url_top = top.location.toString(); } catch (e) {}
- 1045. -
- 1046. - var isVisibleWeb = AdsLight.isVisibleBlockWrap(true);
- 1047. - if (!isVisibleWeb) {
- 1048. - ajaxParams.web_invisible = 1;
- 1049. - }
- 1050. -
- 1051. - if (document.documentMode) {
- 1052. - ajaxParams.ie_document_mode = document.documentMode;
- 1053. - }
- 1054. -
- 1055. - AdsLight.doRequest(function(){
- 1056. - ajaxParams.ads_showed = AdsLight.getAdsShowed();
- 1057. - ajax.post('/ads_rotate.php?act=ads_web', ajaxParams, {onDone: onComplete, onFail: onComplete});
- 1058. - });
- 1059. -
- 1060. - function onComplete(response, nothing, js) {
- 1061. - vk__adsLight.updateProgress = 3;
- 1062. -
- 1063. - if (response && isObject(response) && 'ads_html' in response) {
- 1064. - var styleElemOld = ge('ads_style_web_loader');
- 1065. - var sheetOld = (styleElemOld.sheet ? styleElemOld.sheet : styleElemOld.styleSheet);
- 1066. - var deleteFunc = (sheetOld.deleteRule ? 'deleteRule' : 'removeRule');
- 1067. - sheetOld[deleteFunc](0);
- 1068. -
- 1069. - var styleElemNew = ce('style', {type: 'text/css'})
- 1070. - if (styleElemNew.styleSheet) {
- 1071. - styleElemNew.styleSheet.cssText = response.css;
- 1072. - } else {
- 1073. - styleElemNew.appendChild(document.createTextNode(response.css));
- 1074. - }
- 1075. - headNode.appendChild(styleElemNew);
- 1076. -
- 1077. - AdsLight.setNewBlock(response.ads_html, response.ads_section, response.ads_can_show, response.ads_showed, response.ads_params);
- 1078. - vk__adsLight.rpc.callMethod('adsOnInit', response.ads_count, response.ads_params_export);
- 1079. -
- 1080. - vk__adsLight.loadComplete = 2;
- 1081. - } else {
- 1082. - if (typeof(js) === 'string') {
- 1083. - try {
- 1084. - eval(js);
- 1085. - } catch (e) {
- 1086. - debugLog(e);
- 1087. - }
- 1088. - }
- 1089. - AdsLight.loadAdsFailed(-3001, adsParamsExport);
- 1090. - }
- 1091. - }
- 1092. - }
- 1093. -
- 1094. - AdsLight.loadAdsFailed = function(errorCode, adsParamsExport) {
- 1095. - if (!vk__adsLight.rpc) {
- 1096. - return false;
- 1097. - }
- 1098. - if (vk__adsLight.loadComplete === -1) {
- 1099. - return true;
- 1100. - }
- 1101. - vk__adsLight.loadComplete = -1;
- 1102. -
- 1103. - vk__adsLight.rpc.callMethod('resizeWidget', 0, 0);
- 1104. - vk__adsLight.rpc.callMethod('adsOnInit', errorCode, adsParamsExport);
- 1105. -
- 1106. - return true;
- 1107. - }
- 1108. -
- 1109. - AdsLight.handleAllAds = function(box, adsIdsMore, adsIdsApply, adsHeightMore) {
- 1110. -
- 1111. - var moreLocked = false;
- 1112. - var needAdsHeight = false;
- 1113. -
- 1114. - boxLayerWrap.scrollTop = 0;
- 1115. -
- 1116. - var boxOptions = {};
- 1117. - boxOptions.onClean = deinit;
- 1118. - box.setOptions(boxOptions);
- 1119. -
- 1120. - if (adsIdsMore) {
- 1121. - addEvent(boxLayerWrap, 'scroll', onScroll);
- 1122. - }
- 1123. - allowApply();
- 1124. - onScroll();
- 1125. -
- 1126. - function deinit() {
- 1127. - removeEvent(boxLayerWrap, 'scroll', onScroll);
- 1128. - hide('ads_ads_all_ads_more');
- 1129. - }
- 1130. - function checkDeinit() {
- 1131. - if (!adsIdsMore && isEmpty(vk__adsLight.adsIdsApplyNeeded)) {
- 1132. - deinit();
- 1133. - }
- 1134. - }
- 1135. - function allowApply(delayed) {
- 1136. - if (!delayed) {
- 1137. - setTimeout(allowApply.pbind(true), 500);
- 1138. - return;
- 1139. - }
- 1140. - AdsLight.addAdsToApply(adsIdsApply);
- 1141. - onScroll();
- 1142. - }
- 1143. - function onScroll() {
- 1144. - var moreElem = ge('ads_ads_all_ads_more');
- 1145. - if (!moreElem) {
- 1146. - return;
- 1147. - }
- 1148. - var moreRect = moreElem.getBoundingClientRect()
- 1149. - if (moreRect.top < lastWindowHeight + adsHeightMore) {
- 1150. - needAdsHeight = Math.round(Math.max(needAdsHeight, lastWindowHeight - moreRect.top + adsHeightMore));
- 1151. - moreAds();
- 1152. - }
- 1153. -
- 1154. - AdsLight.applyAds();
- 1155. -
- 1156. - checkDeinit();
- 1157. - }
- 1158. - function moreAds(delayed) {
- 1159. - if (!delayed) {
- 1160. - setTimeout(moreAds.pbind(true), 100);
- 1161. - return;
- 1162. - }
- 1163. - if (!adsIdsMore) {
- 1164. - return;
- 1165. - }
- 1166. - if (!needAdsHeight) {
- 1167. - return;
- 1168. - }
- 1169. - if (moreLocked) {
- 1170. - return;
- 1171. - }
- 1172. - moreLocked = true;
- 1173. -
- 1174. - var ajaxParams = {};
- 1175. - ajaxParams.ads_ids_more = adsIdsMore;
- 1176. - ajaxParams.ads_height = needAdsHeight;
- 1177. -
- 1178. - ajax.post('/ads_light.php?act=all_ads_more', ajaxParams, {onDone: onDoneMoreAds, onFail: onFailMoreAds})
- 1179. - }
- 1180. - function onDoneMoreAds(response) {
- 1181. - moreLocked = false;
- 1182. - if (!response) {
- 1183. - onFailMoreAds();
- 1184. - return;
- 1185. - }
- 1186. - adsIdsMore = response.ads_ids_more;
- 1187. - AdsLight.addAdsToApply(response.ads_ids_apply);
- 1188. - if (response.ads_html) {
- 1189. - var adsElem = ge('ads_ads_all_ads_rows');
- 1190. - var moreElem = ge('ads_ads_all_ads_more');
- 1191. - if (adsElem) {
- 1192. - adsElem.innerHTML += response.ads_html;
- 1193. - needAdsHeight = false;
- 1194. - onScroll();
- 1195. - }
- 1196. - if (moreElem) {
- 1197. - moreElem.height = response.ads_more_height;
- 1198. - }
- 1199. - }
- 1200. - checkDeinit();
- 1201. - }
- 1202. - function onFailMoreAds() {
- 1203. - moreLocked = false;
- 1204. - return true;
- 1205. - }
- 1206. - }
- 1207. -
- 1208. - AdsLight.blockOverOut = function(event, elemCur, targetClass) {
- 1209. - var isOver = (event.type === 'mouseover');
- 1210. - var elemTarget;
- 1211. - var opacity = false;
- 1212. - if (hasClass(elemCur, targetClass)) {
- 1213. - elemTarget = elemCur;
- 1214. - toggleClass(elemTarget, 'over', isOver);
- 1215. - opacity = (isOver ? 1 : 0.3);
- 1216. - } else {
- 1217. - elemTarget = geByClass1(targetClass, elemTarget);
- 1218. - elemTarget.over = 1;
- 1219. - if (!hasClass(elemTarget, 'over')) {
- 1220. - opacity = (isOver ? 0.3 : 0);
- 1221. - }
- 1222. - }
- 1223. - if (opacity !== false) {
- 1224. - animate(elemTarget, {opacity: opacity}, 200);
- 1225. - }
- 1226. - if (isOver && elemCur == elemTarget) {
- 1227. - var tooltipTextElem = geByClass1('tooltip_text', elemTarget);
- 1228. - if (tooltipTextElem) {
- 1229. - showTooltip(elemTarget, {text: tooltipTextElem.innerHTML, showdt: 0, black: 1, shift: [14, 3, 3]});
- 1230. - }
- 1231. - }
- 1232. - }
- 1233. -
- 1234. - AdsLight.closeNewsBlock = function(elem, hash) {
- 1235. - while (!hasClass(elem, 'feed_row')) elem = elem.parentNode;
- 1236. - slideUp(elem, 200);
- 1237. - ajax.post('/ads_light.php?act=close_news', {hash: hash}, {onDone: onComplete, onFail: onComplete});
- 1238. - function onComplete() {
- 1239. - return true;
- 1240. - }
- 1241. - }
- 1242. -
- 1243. - AdsLight.scrollToPreview = function(delayed) {
- 1244. - if (!delayed) {
- 1245. - setTimeout(AdsLight.scrollToPreview.pbind(true), 100);
- 1246. - return;
- 1247. - }
- 1248. - var elem = geByClass1('ads_ads_preview');
- 1249. - if (!elem || hasClass(elem, 'ads_ads_preview_viewed')) {
- 1250. - return;
- 1251. - }
- 1252. - addClass(elem, 'ads_ads_preview_viewed');
- 1253. - var scrollY = scrollGetY();
- 1254. - var elemY = getXY(elem)[1];
- 1255. - var elemHeight = getSize(elem)[1];
- 1256. - if (elemY + elemHeight > scrollY + lastWindowHeight) {
- 1257. - scrollToY(elemY - (lastWindowHeight - elemHeight) / 2, 500);
- 1258. - }
- 1259. - }
- 1260. -
- 1261. - AdsLight.init();
- 1262. -
- 1263. - })();
- 1264. -
- 1265. - try{stManager.done('aes_light.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment