Hormold

VK Change (#1391105705)

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