Hormold

VK Change (#1378293304)

Sep 4th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 31.94 KB | None | 0 0
  1. Файл - places.js (Старый размер - 25773 | Новый - 0):
  2. 0.  - var Places = {
  3. 1.  -
  4. 2.  - initPhotoMap: function(opts) {
  5. 3.  -   var map, isMapbox, isGoogle, CustomMarker, createMarker;
  6. 4.  -   if (!cur.iconLastNum) {
  7. 5.  -     cur.iconLastNum = 0;
  8. 6.  -   }
  9. 7.  -   if (opts.provider == 'mapbox') {
  10. 8.  -     isMapbox = 1;
  11. 9.  -     if (!window.L || !window.L.mapbox) {
  12. 10.  -       var stat = ['mapbox.css', 'mapbox.js'];
  13. 11.  -       if (browser.msie && browser.version < 8) {
  14. 12.  -         stat.push('mapbox_ie.css');
  15. 13.  -       }
  16. 14.  -       stManager.add(stat, function() {
  17. 15.  -         Places.initPhotoMap(opts);
  18. 16.  -       });
  19. 17.  -       return false;
  20. 18.  -     }
  21. 19.  -   } else {
  22. 20.  -     isGoogle = 1;
  23. 21.  -     if (!window.google || !google.maps.OverlayView) {
  24. 22.  -       if (!opts.googleAttaced) {
  25. 23.  -         headNode.appendChild(ce('script', {
  26. 24.  -           type: 'text/javascript',
  27. 25.  -           src: (window.locProtocol || 'http:') + '//maps.google.com/maps/api/js?sensor=false&callback=gMapsInit&language='+(cur.vkLngCode || 'en')
  28. 26.  -         }));
  29. 27.  -       }
  30. 28.  -       window.gMapsInit = function() {
  31. 29.  -         Places.initPhotoMap(opts);
  32. 30.  -         delete window.gMapsInit;
  33. 31.  -       }
  34. 32.  -       return false;
  35. 33.  -     }
  36. 34.  -   }
  37. 35.  -   cur.photoMapOpts = opts;
  38. 36.  -
  39. 37.  -   function unexpandPoint(point, sub) {
  40. 38.  -     if (!point.expanded) {
  41. 39.  -       return false;
  42. 40.  -     }
  43. 41.  -     if (!sub) {
  44. 42.  -       if (isMapbox) {
  45. 43.  -         map.addLayer(point.overlay);
  46. 44.  -       } else {
  47. 45.  -         point.overlay.setMap(map);
  48. 46.  -       }
  49. 47.  -     }
  50. 48.  -     point.expanded = false;
  51. 49.  -     var p = point.points;
  52. 50.  -     if (p) {
  53. 51.  -       for (i in p) {
  54. 52.  -         var subPoint = p[i];
  55. 53.  -         if (subPoint.overlay) {
  56. 54.  -           if (isMapbox) {
  57. 55.  -             map.removeLayer(subPoint.overlay);
  58. 56.  -           } else {
  59. 57.  -             subPoint.overlay.setMap(null);
  60. 58.  -           }
  61. 59.  -           unexpandPoint(subPoint, true)
  62. 60.  -         }
  63. 61.  -       }
  64. 62.  -     }
  65. 63.  -   }
  66. 64.  -
  67. 65.  -   function expandPoint(point, possive) {
  68. 66.  -     if (point.diff && point.diff < 0.00002) {
  69. 67.  -       return false;
  70. 68.  -     }
  71. 69.  -     if (point.diff && point.diff <= (point.count + 1) * 0.000001) {
  72. 70.  -       return false;
  73. 71.  -     }
  74. 72.  -     var p = point.points;
  75. 73.  -     if (p) {
  76. 74.  -       if (point.expanded || possive) {
  77. 75.  -         return false;
  78. 76.  -       }
  79. 77.  -       var len = p.length;
  80. 78.  -       while (len--) {
  81. 79.  -         var subPoint = p[len];
  82. 80.  -         if (subPoint.overlay) {
  83. 81.  -           if (isMapbox) {
  84. 82.  -             map.addLayer(subPoint.overlay);
  85. 83.  -           } else {
  86. 84.  -             subPoint.overlay.setMap(map);
  87. 85.  -           }
  88. 86.  -         } else {
  89. 87.  -           if (isMapbox) {
  90. 88.  -             var pt = new L.LatLng(subPoint.lat, subPoint.lng);
  91. 89.  -             subPoint.overlay = createMarker(pt, map, subPoint.src, subPoint.count, subPoint.diff);
  92. 90.  -             subPoint.overlay.on('click', (pointClick).pbind(subPoint));
  93. 91.  -           } else {
  94. 92.  -             var pt = new google.maps.LatLng(subPoint.lat, subPoint.lng);
  95. 93.  -             subPoint.overlay = new CustomMarker(pt, map, subPoint.src, subPoint.count, subPoint.diff);
  96. 94.  -             google.maps.event.addListener(subPoint.overlay, 'click', (pointClick).pbind(subPoint));
  97. 95.  -           }
  98. 96.  -         }
  99. 97.  -       }
  100. 98.  -       if (isMapbox) {
  101. 99.  -         map.removeLayer(point.overlay);
  102. 100.  -       } else {
  103. 101.  -         point.overlay.setMap(null);
  104. 102.  -       }
  105. 103.  -       point.expanded = true;
  106. 104.  -     } else if (!point.loading) {
  107. 105.  -       point.loading = true;
  108. 106.  -       ajax.post('al_places.php', {
  109. 107.  -         act: 'a_get_points',
  110. 108.  -         diff: point.diff || opts.diffZone,
  111. 109.  -         lat: point.lat,
  112. 110.  -         lng: point.lng,
  113. 111.  -         uid: opts.uid
  114. 112.  -       }, {
  115. 113.  -         onDone: function(points) {
  116. 114.  -           point.points = points;
  117. 115.  -           expandPoint(point, possive);
  118. 116.  -         },
  119. 117.  -         onFail: function() {
  120. 118.  -           point.loading = false;
  121. 119.  -         }
  122. 120.  -       })
  123. 121.  -     }
  124. 122.  -   }
  125. 123.  -
  126. 124.  -   function checkPointsReq(points, mapBounds) {
  127. 125.  -     if (!points) {
  128. 126.  -       return false;
  129. 127.  -     }
  130. 128.  -     for (i in points) {
  131. 129.  -       var point = points[i];
  132. 130.  -       if (point.count <= 1) {
  133. 131.  -         continue;
  134. 132.  -       }
  135. 133.  -       var diff = (point.diff * 15) || opts.diffZone;
  136. 134.  -       var inside = (point.lat + diff > mapBounds.neLat && point.lat - diff < mapBounds.swLat && point.lng + diff > mapBounds.neLng && point.lng - diff < mapBounds.swLng);
  137. 135.  -
  138. 136.  -       if (!inside) {
  139. 137.  -         if (point.expanded) {
  140. 138.  -           unexpandPoint(point);
  141. 139.  -         }
  142. 140.  -         continue;
  143. 141.  -       }
  144. 142.  -       if (point.expanded) {
  145. 143.  -         checkPointsReq(point.points, mapBounds);
  146. 144.  -       } else if (inside) {
  147. 145.  -         expandPoint(point);
  148. 146.  -       } else if (point.expanded) {
  149. 147.  -         unexpandPoint(point);
  150. 148.  -       }
  151. 149.  -     }
  152. 150.  -   }
  153. 151.  -
  154. 152.  -   function updateMapPoints() {
  155. 153.  -     checkPointsReq(opts.points, getMapBounds());
  156. 154.  -   }
  157. 155.  -
  158. 156.  -   function zoomToPoint(point) {
  159. 157.  -     var mapBounds = map.getBounds();
  160. 158.  -     var ne = mapBounds.getNorthEast();
  161. 159.  -     var sw = mapBounds.getSouthWest();
  162. 160.  -     var zoom =  map.getZoom();
  163. 161.  -     if (point.diff) {
  164. 162.  -       var needZoom = ((ne.lat() - sw.lat()) * 0.9) > point.diff * 2;
  165. 163.  -     } else {
  166. 164.  -       var needZoom = zoom < 17;
  167. 165.  -     }
  168. 166.  -     if (needZoom) {
  169. 167.  -       map.setZoom(zoom + 1)
  170. 168.  -       //zoomToPoint(point);
  171. 169.  -       setTimeout(zoomToPoint.pbind(point), 0)
  172. 170.  -     } else {
  173. 171.  -       updateMapPoints();
  174. 172.  -     }
  175. 173.  -   }
  176. 174.  -
  177. 175.  -   function pointClick(point) {
  178. 176.  -     if (!opts.box) {
  179. 177.  -       showBox('al_places.php', {
  180. 178.  -         act: 'photos_box',
  181. 179.  -         lat: point.lat,
  182. 180.  -         lng: point.lng,
  183. 181.  -         diff: opts.diffZone,
  184. 182.  -         uid: opts.uid
  185. 183.  -       }, {
  186. 184.  -         stat: ['maps.js', 'places.js', 'places.css', 'ui_controls.js', 'ui_controls.css']
  187. 185.  -       });
  188. 186.  -       return false;
  189. 187.  -     }
  190. 188.  -     if (point.count == 1/* || point.diff < 0.0001*/ || true) {
  191. 189.  -       var photo = point.photo.split('_');
  192. 190.  -       if (point.overlay) {
  193. 191.  -         var elCont = ge('profile_map_icon_'+point.overlay.iconNum);
  194. 192.  -         var el = geByClass1('profile_map_first', elCont) || elCont;
  195. 193.  -         var cnt = geByClass1('profile_map_photo_count', el);
  196. 194.  -         if (cnt) {
  197. 195.  -           hide(cnt);
  198. 196.  -         }
  199. 197.  -         re('profile_map_photo_loader');
  200. 198.  -         var loader = ce('div', {id: 'profile_map_photo_loader'});
  201. 199.  -         el.appendChild(loader);
  202. 200.  -       }
  203. 201.  -       var diff = (point.diff || 0.000001);
  204. 202.  -       var list = 'map'+opts.uid+'_'+(point.lat - diff)+'_'+(point.lng - diff)+'_'+(point.lat + diff)+'_'+(point.lng + diff);
  205. 203.  -       return opts.showPlacePhoto(point.photo, list, {});
  206. 204.  -     }/* else if (opts.box) {
  207. 205.  -       map.panTo(new google.maps.LatLng(point.lat, point.lng));
  208. 206.  -       zoomToPoint(point);
  209. 207.  -       expandPoint(point, true);
  210. 208.  -     }*/
  211. 209.  -     return false;
  212. 210.  -   }
  213. 211.  -
  214. 212.  -   function getMapBounds() {
  215. 213.  -     var mapBounds = map.getBounds();
  216. 214.  -     var ne = mapBounds.getNorthEast();
  217. 215.  -     var sw = mapBounds.getSouthWest();
  218. 216.  -     var zoom = map.getZoom();
  219. 217.  -     if (zoom < 3) {
  220. 218.  -       var res = {
  221. 219.  -         swLat: -90,
  222. 220.  -         swLng: -90,
  223. 221.  -         neLat: 90,
  224. 222.  -         neLng: 90
  225. 223.  -       };
  226. 224.  -     } else {
  227. 225.  -       if (isMapbox) {
  228. 226.  -         var res = {
  229. 227.  -           swLat: sw.lat,
  230. 228.  -           swLng: sw.lng,
  231. 229.  -           neLat: ne.lat,
  232. 230.  -           neLng: ne.lng
  233. 231.  -         };
  234. 232.  -       } else {
  235. 233.  -         var res = {
  236. 234.  -           swLat: sw.lat(),
  237. 235.  -           swLng: sw.lng(),
  238. 236.  -           neLat: ne.lat(),
  239. 237.  -           neLng: ne.lng()
  240. 238.  -         };
  241. 239.  -       }
  242. 240.  -     }
  243. 241.  -     return res;
  244. 242.  -   }
  245. 243.  -
  246. 244.  -   function updatePhotosList() {
  247. 245.  -     var mapBounds = getMapBounds();
  248. 246.  -     ajax.post('al_places.php', {
  249. 247.  -       act: 'update_photos_list',
  250. 248.  -       uid: opts.uid,
  251. 249.  -       sw_lat: mapBounds.swLat,
  252. 250.  -       sw_lng: mapBounds.swLng,
  253. 251.  -       ne_lat: mapBounds.neLat,
  254. 252.  -       ne_lng: mapBounds.neLng
  255. 253.  -     }, {
  256. 254.  -       onDone: function(html) {
  257. 255.  -         ge('place_map_other').innerHTML = html;
  258. 256.  -       }
  259. 257.  -     })
  260. 258.  -     checkPointsReq(opts.points, mapBounds);
  261. 259.  -   }
  262. 260.  -
  263. 261.  -   function setMapOpts(map) {
  264. 262.  -     if (opts.box) {
  265. 263.  -       cur.placeBoxMap = map;
  266. 264.  -       cur.placeBoxOpts = opts;
  267. 265.  -     } else {
  268. 266.  -       cur.placesPhotoMap = map;
  269. 267.  -       cur.placesPhotoOpts = opts;
  270. 268.  -     }
  271. 269.  -   }
  272. 270.  -
  273. 271.  -   function onBoundsChanged(fast) {
  274. 272.  -     if (cur.editPhotosPlace) {
  275. 273.  -       fadeOut(ge('places_photo_hint_cont'), 200);
  276. 274.  -     }
  277. 275.  -     if (cur.mapMoveTimeout) {
  278. 276.  -       clearTimeout(cur.mapMoveTimeout);
  279. 277.  -     }
  280. 278.  -     cur.mapMoveTimeout = setTimeout(updateMapPoints, fast ? 0 : 200)
  281. 279.  -     if (firstTimeout) {
  282. 280.  -       firstTimeout = false;
  283. 281.  -       return false;
  284. 282.  -     }
  285. 283.  -     if (opts.box) {
  286. 284.  -       if (cur.mapMoveServerTimeout) {
  287. 285.  -         clearTimeout(cur.mapMoveServerTimeout);
  288. 286.  -       }
  289. 287.  -       cur.mapMoveServerTimeout = setTimeout(updatePhotosList, 500)
  290. 288.  -     }
  291. 289.  -   }
  292. 290.  -
  293. 291.  -   function getIconHtml(imgSrc, cnt, diff, iconNum) {
  294. 292.  -     var html = '';
  295. 293.  -     if (cnt > 1 && diff) {
  296. 294.  -       html = '<span class="profile_map_photo_count">'+(cnt > 99 ? '99+' : cnt)+'</span>';
  297. 295.  -     }
  298. 296.  -     var len = Math.min(cnt - 1, 3);
  299. 297.  -     html = '<div'+(len ? '' : ' id="profile_map_icon_'+iconNum+'"')+' class="profile_map_photo profile_map_first" style="background: url('+imgSrc+') center center no-repeat;'+(len ? ' margin-left: -2px; margin-top: -4px;' : '')+'">'+html+'</div>';
  300. 298.  -     while(len--) {
  301. 299.  -       html = '<div'+(len ? '' : ' id="profile_map_icon_'+iconNum+'"')+' class="profile_map_photo"'+(len ? ' style="margin-left: -2px; margin-top: -4px;"' : '')+'>'+html+'</div>';
  302. 300.  -     }
  303. 301.  -     return html;
  304. 302.  -   }
  305. 303.  -
  306. 304.  -   cur.editPhotosPlace = false;
  307. 305.  -
  308. 306.  -   var firstTimeout = true;
  309. 307.  -   if (isMapbox) {
  310. 308.  -     createMarker = function(latlng, addToMap, src, count, diff) {
  311. 309.  -       var icon = new L.HtmlIcon({
  312. 310.  -          html: getIconHtml(src, count, diff, cur.iconLastNum)
  313. 311.  -       });
  314. 312.  -       cur.icon = icon;
  315. 313.  -       var m = new L.Marker(latlng, {
  316. 314.  -         draggable: false,
  317. 315.  -         icon: icon
  318. 316.  -       });
  319. 317.  -       if (addToMap) {
  320. 318.  -         map.addLayer(m);
  321. 319.  -       } else {
  322. 320.  -         map.removeLayer(m);
  323. 321.  -       }
  324. 322.  -       m.iconNum = cur.iconLastNum++;
  325. 323.  -       return m;
  326. 324.  -     }
  327. 325.  -     var mapboxApiId = 'vkmaps.map-an1xcr4f';
  328. 326.  -     var mapboxApiId_2x = 'vkmaps.map-40lc3e3w';
  329. 327.  -     map = opts.map || L.mapbox.map(opts.cont, mapboxApiId, {zoomControl: false, scrollWheelZoom: false, touchZoom: false, detectRetina: true, retinaVersion: mapboxApiId_2x});
  330. 328.  -     setMapOpts(map);
  331. 329.  -
  332. 330.  -     if (opts.bounds) {
  333. 331.  -       map.fitBounds([[opts.bounds.swlat, opts.bounds.swlng], [opts.bounds.nelat, opts.bounds.nelng]]);
  334. 332.  -     } else {
  335. 333.  -       if (!opts.lat && !opts.lng) {
  336. 334.  -         opts.lat = 30;
  337. 335.  -       }
  338. 336.  -       map.setView([opts.lat, opts.lng], 1)
  339. 337.  -     }
  340. 338.  -     if (!opts.nowheel) {
  341. 339.  -       map.on('moveend', onBoundsChanged.pbind(true));
  342. 340.  -       map.on('zoomend', onBoundsChanged.pbind(true));
  343. 341.  -     }
  344. 342.  -
  345. 343.  -     if (opts.points) {
  346. 344.  -       var len = opts.points.length;
  347. 345.  -       while(len--) {
  348. 346.  -         var point = opts.points[len];
  349. 347.  -         var p = new L.LatLng(point.lat, point.lng);
  350. 348.  -         point.overlay = createMarker(p, point.points ? false : true, point.src, point.count, point.diff);
  351. 349.  -         point.overlay.on('click', (pointClick).pbind(point));
  352. 350.  -         if (point.points) {
  353. 351.  -           expandPoint(point);
  354. 352.  -         }
  355. 353.  -       }
  356. 354.  -     }
  357. 355.  -
  358. 356.  -     map.on('click', (function(point) {
  359. 357.  -       if (!opts.box) {
  360. 358.  -         Places.showProfileBox(opts.uid);
  361. 359.  -       }
  362. 360.  -     }).bind(this));
  363. 361.  -   } else {
  364. 362.  -     CustomMarker = function(latlng, map, src, count, diff) {
  365. 363.  -       this.latlng = latlng;
  366. 364.  -       this.photoSrc = src;
  367. 365.  -       this.photoCount = count;
  368. 366.  -       this.photoDiff = diff;
  369. 367.  -       this.setMap(map);
  370. 368.  -     }
  371. 369.  -
  372. 370.  -     CustomMarker.prototype = new google.maps.OverlayView();
  373. 371.  -
  374. 372.  -     CustomMarker.prototype.draw = function() {
  375. 373.  -       var div = this.photoDiv;
  376. 374.  -       if (!div) {
  377. 375.  -
  378. 376.  -         var div = se(getIconHtml(this.photoSrc, this.photoCount, this.photoDiff, cur.iconLastNum));
  379. 377.  -         this.photoDiv = div;
  380. 378.  -         this.iconNum = cur.iconLastNum++;
  381. 379.  -
  382. 380.  -         google.maps.event.addDomListener(div, 'click', (function(event) {
  383. 381.  -           google.maps.event.trigger(this, 'click');
  384. 382.  -           return cancelEvent(event);
  385. 383.  -         }).bind(this));
  386. 384.  -
  387. 385.  -         var panes = this.getPanes();
  388. 386.  -         panes.overlayImage.appendChild(div);
  389. 387.  -       }
  390. 388.  -
  391. 389.  -       var point = this.getProjection().fromLatLngToDivPixel(this.latlng);
  392. 390.  -       if (point) {
  393. 391.  -         div.style.left = point.x + 'px';
  394. 392.  -         div.style.top = point.y + 'px';
  395. 393.  -       }
  396. 394.  -     };
  397. 395.  -
  398. 396.  -     CustomMarker.prototype.remove = function() {
  399. 397.  -       if (this.photoDiv) {
  400. 398.  -         this.photoDiv.parentNode.removeChild(this.photoDiv);
  401. 399.  -         this.photoDiv = null;
  402. 400.  -       }
  403. 401.  -     };
  404. 402.  -
  405. 403.  -     CustomMarker.prototype.getPosition = function() {
  406. 404.  -      return this.latlng;
  407. 405.  -     };
  408. 406.  -
  409. 407.  -
  410. 408.  -     var mapOpts = {
  411. 409.  -       center: new google.maps.LatLng(opts.lat, opts.lng),
  412. 410.  -       mapTypeId: google.maps.MapTypeId.ROADMAP,
  413. 411.  -       disableDefaultUI: true
  414. 412.  -     }
  415. 413.  -     if (opts.nowheel) {
  416. 414.  -       mapOpts.scrollwheel = false;
  417. 415.  -       mapOpts.disableDoubleClickZoom = true;
  418. 416.  -     }
  419. 417.  -     if (opts.map) {
  420. 418.  -       map = opts.map;
  421. 419.  -     } else {
  422. 420.  -       map = new google.maps.Map(ge(opts.cont), mapOpts);
  423. 421.  -     }
  424. 422.  -     setMapOpts(map);
  425. 423.  -
  426. 424.  -     if (opts.bounds) {
  427. 425.  -       var sw = new google.maps.LatLng(opts.bounds.swlat, opts.bounds.swlng);
  428. 426.  -       var ne = new google.maps.LatLng(opts.bounds.nelat, opts.bounds.nelng);
  429. 427.  -       map.fitBounds(new google.maps.LatLngBounds(sw, ne));
  430. 428.  -     } else {
  431. 429.  -       if (!opts.lat && !opts.lng) {
  432. 430.  -         opts.lat = 30;
  433. 431.  -       }
  434. 432.  -       map.setCenter(new google.maps.LatLng(opts.lat, opts.lng));
  435. 433.  -       map.setZoom(1);
  436. 434.  -     }
  437. 435.  -
  438. 436.  -     if (!opts.nowheel) {
  439. 437.  -       google.maps.event.addListener(map, 'bounds_changed', onBoundsChanged.pbind(false));
  440. 438.  -     }
  441. 439.  -
  442. 440.  -     if (opts.points) {
  443. 441.  -       var len = opts.points.length;
  444. 442.  -       while(len--) {
  445. 443.  -         var point = opts.points[len];
  446. 444.  -         var p = new google.maps.LatLng(point.lat, point.lng);
  447. 445.  -         point.overlay = new CustomMarker(p, point.points ? null : map, point.src, point.count, point.diff);
  448. 446.  -         google.maps.event.addListener(point.overlay, 'click', (pointClick).pbind(point));
  449. 447.  -         if (point.points) {
  450. 448.  -           expandPoint(point);
  451. 449.  -         }
  452. 450.  -       }
  453. 451.  -     }
  454. 452.  -
  455. 453.  -     google.maps.event.addDomListener(map, 'click', (function(point) {
  456. 454.  -       if (!opts.box) {
  457. 455.  -         Places.showProfileBox(opts.uid);
  458. 456.  -       }
  459. 457.  -     }).bind(this));
  460. 458.  -   }
  461. 459.  - },
  462. 460.  -
  463. 461.  - showProfileBox: function(uid) {
  464. 462.  -   showBox('al_places.php', {
  465. 463.  -     act: 'photos_box',
  466. 464.  -     uid: uid
  467. 465.  -   }, {
  468. 466.  -     stat: ['maps.js', 'places.js', 'places.css', 'ui_controls.js', 'ui_controls.css']
  469. 467.  -   });
  470. 468.  -   return false;
  471. 469.  - },
  472. 470.  -
  473. 471.  - setMarker: function(map, point) {
  474. 472.  -   cur.placeMarker = new vkMaps.Marker(point);
  475. 473.  -   cur.placeMarker.mousedown.addHandler(function() {
  476. 474.  -   });
  477. 475.  -   cur.placeMarker.dragend.addHandler(function(type, marker) {
  478. 476.  -     marker.update();
  479. 477.  -     Places.setPlaceStr(marker.location);
  480. 478.  -   });
  481. 479.  -   map.addMarkerWithData(cur.placeMarker, {
  482. 480.  -     draggable: true,
  483. 481.  -     icon: '/images/map/move.png',
  484. 482.  -     icon2x: '/images/map/move_2x.png',
  485. 483.  -     iconSize: [33, 32],
  486. 484.  -     iconAnchor: [16, 32],
  487. 485.  -     infoBubble: ''
  488. 486.  -   });
  489. 487.  - },
  490. 488.  -
  491. 489.  - showMorePhotos: function(uid) {
  492. 490.  -   if (!cur.addPhotosOffset || cur.PlacesPhotosMoreBack) {
  493. 491.  -     return false;
  494. 492.  -   }
  495. 493.  -   var cont = ge('places_photo_more');
  496. 494.  -   cur.PlacesPhotosMoreBack = cont.innerHTML;
  497. 495.  -   ajax.post('al_places.php', {act: 'a_edit_photos', uid: uid, offset: cur.addPhotosOffset}, {
  498. 496.  -     onDone: function(html, offset, showmore) {
  499. 497.  -       cur.addPhotosOffset = offset;
  500. 498.  -       if (!showmore) {
  501. 499.  -         hide('places_photo_more');
  502. 500.  -       }
  503. 501.  -       var elsCont = ge('places_map_add_list');
  504. 502.  -       elsCont.appendChild(cf(html));
  505. 503.  -       cur.PlacesPhotosMoreBack = false;
  506. 504.  -     },
  507. 505.  -     showProgress: function() {
  508. 506.  -       cont.innerHTML = '<img src="/images/upload.gif">';
  509. 507.  -     },
  510. 508.  -     hideProgress: function() {
  511. 509.  -       cont.innerHTML = cur.PlacesPhotosMoreBack;
  512. 510.  -     }
  513. 511.  -   }, {stat: ['upload.js']})
  514. 512.  - },
  515. 513.  -
  516. 514.  - addPhotos: function(obj, uid) {
  517. 515.  -   ajax.post('al_places.php', {act: 'a_edit_photos', uid: uid}, {
  518. 516.  -     onDone: function(html, js, offset) {
  519. 517.  -       hide('places_edit_step_0');
  520. 518.  -       show('places_edit_step_1');
  521. 519.  -       hide('places_edit_step_2');
  522. 520.  -       hide('places_edit_step_3');
  523. 521.  -       hide('place_map_cont');
  524. 522.  -       cur.addPhotosOffset = offset;
  525. 523.  -       cur.editPhotosPlace = true;
  526. 524.  -       cur.placesFixedBottom = false;
  527. 525.  -       var editCont = ge('place_map_edit');
  528. 526.  -       editCont.innerHTML = html;
  529. 527.  -       show(editCont);
  530. 528.  -       hide('place_map_other');
  531. 529.  -
  532. 530.  -       /*var tt = ge('places_photo_hint_cont');
  533. 531.  -       if (tt) {
  534. 532.  -         fadeIn(tt, 100);
  535. 533.  -       } else {
  536. 534.  -         var mapCont = ge('place_map_cont');
  537. 535.  -         var tt = ce('div', {
  538. 536.  -           innerHTML: '<div class="places_photo_hint">'+getLang('places_select_position')+'</div><div id="places_photo_pointer"></div>',
  539. 537.  -           className: 'places_photo_hint_cont',
  540. 538.  -           id: 'places_photo_hint_cont'
  541. 539.  -         });
  542. 540.  -         mapCont.parentNode.insertBefore(tt, mapCont);
  543. 541.  -         var w = getSize(tt)[0];
  544. 542.  -         tt.style.marginLeft = intval((666 - w) / 2) + 'px';
  545. 543.  -         ge('places_photo_pointer').style.marginLeft = intval((w/2) - 10)+ 'px';
  546. 544.  -       }
  547. 545.  -       show('places_photos_save_panel');
  548. 546.  -       Places.setMarker(cur.vkmap.getCenter());*/
  549. 547.  -       cur.onPlaceScroll();
  550. 548.  -       if (js) {
  551. 549.  -         eval('(function() {'+js+'})();')
  552. 550.  -       }
  553. 551.  -     },
  554. 552.  -     showProgress: function() {
  555. 553.  -       lockButton(obj);
  556. 554.  -     },
  557. 555.  -     hideProgress: function() {
  558. 556.  -       unlockButton(obj);
  559. 557.  -     }
  560. 558.  -   })
  561. 559.  - },
  562. 560.  -
  563. 561.  - step2: function() {
  564. 562.  -   hide('places_edit_step_0');
  565. 563.  -   show('places_edit_step_1');
  566. 564.  -   hide('places_edit_step_2');
  567. 565.  -   hide('places_edit_step_3');
  568. 566.  -   hide('place_map_cont');
  569. 567.  -   show('place_map_edit');
  570. 568.  -   hide('place_map_point');
  571. 569.  -   hide('place_map_other');
  572. 570.  -   cur.vkmap.removeMarker(cur.placeMarker);
  573. 571.  - },
  574. 572.  -
  575. 573.  - cancelAdd: function() {
  576. 574.  -   cur.editPhotosPlace = false;
  577. 575.  -   show('places_edit_step_0');
  578. 576.  -   hide('places_edit_step_1');
  579. 577.  -   hide('places_edit_step_2');
  580. 578.  -   hide('places_edit_step_3');
  581. 579.  -   show('place_map_cont');
  582. 580.  -   hide('place_map_edit');
  583. 581.  -   hide('place_map_point');
  584. 582.  -   show('place_map_other');
  585. 583.  -   cur.vkmap.removeMarker(cur.placeMarker);
  586. 584.  - },
  587. 585.  -
  588. 586.  - selectPhoto: function(pids, photoSrc, lat, lng) {
  589. 587.  -   cur.mapPids = pids;
  590. 588.  -   hide('places_edit_step_0');
  591. 589.  -   hide('places_edit_step_1');
  592. 590.  -   show('places_edit_step_2');
  593. 591.  -   hide('places_edit_step_3');
  594. 592.  -   hide('place_map_edit');
  595. 593.  -   show('place_map_point');
  596. 594.  -   var mapChoose = new vkMaps.VKMap('place_map_point_cont', {
  597. 595.  -     provider: 'google',
  598. 596.  -     providerId: 2,
  599. 597.  -     lngcode: cur.vkLngCode,
  600. 598.  -   });
  601. 599.  -   cur.placesChooseMap = mapChoose;
  602. 600.  -   placeholderSetup(ge('place_map_point_search'), {back: true});
  603. 601.  -   var pCont = ge('place_map_point');
  604. 602.  -   var els = geByClass('places_map_preview', pCont);
  605. 603.  -   for (var i in els) {
  606. 604.  -     re(els[i]);
  607. 605.  -   }
  608. 606.  -   pCont.appendChild(ce('div', {
  609. 607.  -     innerHTML: '<div class="places_map_preview_cont"><img src="'+photoSrc+'" class="places_map_preview_img" align="center" /></div>',
  610. 608.  -     className: 'places_map_preview'
  611. 609.  -   }));
  612. 610.  -
  613. 611.  -   mapChoose.addMapTypeControls();
  614. 612.  -   mapChoose.addControls({zoom: 'large', pan: false});
  615. 613.  -   if (!cur.lastSelectLat && !cur.lastSelectLng) {
  616. 614.  -     var lastPos = ls.get('last_map_pos');
  617. 615.  -     if (lastPos) {
  618. 616.  -       cur.lastSelectLat = lastPos[0];
  619. 617.  -       cur.lastSelectLng = lastPos[1];
  620. 618.  -       cur.lastSelectZoom = lastPos[2];
  621. 619.  -     }
  622. 620.  -   }
  623. 621.  -
  624. 622.  -   var loc = cur.vkmap.getCenter();
  625. 623.  -   if (lat || lng) {
  626. 624.  -     var point = new vkMaps.LatLonPoint(lat, lng);
  627. 625.  -     mapChoose.setCenterAndZoom(point, 14);
  628. 626.  -     Places.setMarker(mapChoose, point);
  629. 627.  -     Places.setPlaceStr(point, true);
  630. 628.  -   } else {
  631. 629.  -     var point = new vkMaps.LatLonPoint(cur.lastSelectLat || loc.lat, cur.lastSelectLng || loc.lon);
  632. 630.  -     mapChoose.setCenterAndZoom(point, cur.lastSelectZoom || cur.vkmap.getZoom());
  633. 631.  -   }
  634. 632.  -
  635. 633.  -   mapChoose.click.addHandler((function(eventType, map, place) {
  636. 634.  -     mapChoose.removeMarker(cur.placeMarker);
  637. 635.  -     Places.setMarker(mapChoose, place.location);
  638. 636.  -     Places.setPlaceStr(place.location);
  639. 637.  -
  640. 638.  -       //fadeOut(ge('places_photo_hint_cont'), 200);
  641. 639.  -   }).bind(this));
  642. 640.  - },
  643. 641.  -
  644. 642.  - setPlaceStr: function(loc, noRemember) {
  645. 643.  -   if (!noRemember) {
  646. 644.  -     cur.lastSelectLat = loc.lat;
  647. 645.  -     cur.lastSelectLng = loc.lon;
  648. 646.  -     cur.lastSelectZoom = Math.min(16, cur.placesChooseMap.getZoom());
  649. 647.  -     ls.set('last_map_pos', [cur.lastSelectLat, cur.lastSelectLng, cur.lastSelectZoom]);
  650. 648.  -   }
  651. 649.  -   var geocoder = new vkMaps.Geocoder('google', function(place) {
  652. 650.  -     hide('places_edit_step_0');
  653. 651.  -     hide('places_edit_step_1');
  654. 652.  -     hide('places_edit_step_2');
  655. 653.  -     show('places_edit_step_3');
  656. 654.  -     cur.lastSelectedPlace = place;
  657. 655.  -     var placeInfo = [];
  658. 656.  -
  659. 657.  -     if (place.place) {
  660. 658.  -       placeInfo.push(place.place);
  661. 659.  -     } else if (place.street) {
  662. 660.  -       placeInfo.push(place.street);
  663. 661.  -     } else if (place.region) {
  664. 662.  -       placeInfo.push(place.region);
  665. 663.  -     }
  666. 664.  -     if (place.locality) {
  667. 665.  -       placeInfo.push(place.locality);
  668. 666.  -     } else if (place.country) {
  669. 667.  -       placeInfo.push(place.country);
  670. 668.  -     }
  671. 669.  -     for (var i in placeInfo) {
  672. 670.  -       if (placeInfo[i].length > 26) {
  673. 671.  -         placeInfo[i] = placeInfo[i].substr(0, 24)+'..';
  674. 672.  -       }
  675. 673.  -     }
  676. 674.  -     var str = placeInfo.join(', ');
  677. 675.  -     ge('place_map_edit_add').innerHTML = getLang('places_add_to_point').replace('%s', str);
  678. 676.  -   })
  679. 677.  -   geocoder.geocode({location: new google.maps.LatLng(loc.lat, loc.lon), language: cur.vkLngCode})
  680. 678.  - },
  681. 679.  -
  682. 680.  - searchPhotoPlace: function() {
  683. 681.  -   var str = val(ge('place_map_point_search'));
  684. 682.  -
  685. 683.  -   var geocoder = new vkMaps.Geocoder('google', function(place) {
  686. 684.  -     cur.placesChooseMap.setBounds(place.bounds)
  687. 685.  -     cur.placesChooseMap.removeMarker(cur.placeMarker);
  688. 686.  -     Places.setPlaceStr(place.point);
  689. 687.  -     Places.setMarker(cur.placesChooseMap, place.point);
  690. 688.  -   }, function() {
  691. 689.  -     notaBene('place_map_point_search');
  692. 690.  -   })
  693. 691.  -   geocoder.geocode({address: str, language: cur.vkLngCode})
  694. 692.  - },
  695. 693.  -
  696. 694.  - onEditScroll: function(resize) {
  697. 695.  -   var y = boxLayerWrap.scrollTop;
  698. 696.  -   var panel = ge('places_photos_save_buttons');
  699. 697.  -   if (!panel) return;
  700. 698.  -   var py = getXY(ge('places_photos_save_panel'), true)[1];
  701. 699.  -   if (!cur.boxPhotosBottomSize) {
  702. 700.  -     cur.boxPhotosBottomSize = getSize(panel);
  703. 701.  -   }
  704. 702.  -
  705. 703.  -   var ph = cur.boxPhotosBottomSize[1];
  706. 704.  -
  707. 705.  -   var wndHeight = window.innerHeight || document.documentElement.clientHeight;
  708. 706.  -
  709. 707.  -   if (resize && !cur.placesFixedBottom && wndHeight - ph < py + 20) {
  710. 708.  -     boxLayerWrap.scrollTop += py + 20 - (wndHeight - ph);
  711. 709.  -   } else if (wndHeight - ph < py) {
  712. 710.  -     if (!cur.placesFixedBottom || resize) {
  713. 711.  -       cur.placesFixedBottom = true;
  714. 712.  -       setStyle(panel, {
  715. 713.  -         position: 'fixed',
  716. 714.  -         top: (wndHeight - ph) + 'px'
  717. 715.  -       });
  718. 716.  -       addClass(panel, 'places_panel_fixed');
  719. 717.  -     }
  720. 718.  -   } else {
  721. 719.  -     if (cur.placesFixedBottom || resize) {
  722. 720.  -       cur.placesFixedBottom = false;
  723. 721.  -       setStyle(panel, {
  724. 722.  -         position: 'static',
  725. 723.  -         top: '0px'
  726. 724.  -       });
  727. 725.  -       removeClass(panel, 'places_panel_fixed');
  728. 726.  -     }
  729. 727.  -   }
  730. 728.  -
  731. 729.  -   if (resize && cur.placesFixedBottom) {
  732. 730.  -     setStyle(panel, {left: (getXY(curBox().bodyNode)[0] + 1)+'px'})
  733. 731.  -   }
  734. 732.  - },
  735. 733.  -
  736. 734.  - savePhotos: function(btn, hash) {
  737. 735.  -   var loc = cur.placeMarker.location;
  738. 736.  -   var params = {act: 'save_photos_places', pids: cur.mapPids, lat: loc.lat, lng: loc.lon, hash: hash};
  739. 737.  -   if (cur.lastSelectedPlace) {
  740. 738.  -     var place = cur.lastSelectedPlace;
  741. 739.  -     extend(params, {
  742. 740.  -       geo_country: place.country,
  743. 741.  -       geo_locality: place.locality,
  744. 742.  -       geo_region: place.region,
  745. 743.  -       geo_street: place.street,
  746. 744.  -       geo_place: place.place,
  747. 745.  -       geo_lang: cur.vkLngCode,
  748. 746.  -       geo_code: place.countryCode
  749. 747.  -     });
  750. 748.  -   }
  751. 749.  -   ajax.post('al_places.php', params, {
  752. 750.  -     onDone: function() {
  753. 751.  -       //Places.cancelAdd();
  754. 752.  -       Places.updateBox();
  755. 753.  -     },
  756. 754.  -     showProgress: function() {
  757. 755.  -       lockButton(btn);
  758. 756.  -     },
  759. 757.  -     hideProgress: function() {
  760. 758.  -       unlockButton(btn);
  761. 759.  -     }
  762. 760.  -   })
  763. 761.  - },
  764. 762.  -
  765. 763.  - updateBox: function() {
  766. 764.  -   var box = curBox();
  767. 765.  -   box.hide();
  768. 766.  -   showBox('al_places.php', {
  769. 767.  -     act: 'photos_box',
  770. 768.  -     add_more: '1',
  771. 769.  -     lat: cur.placeBoxOpts.lat,
  772. 770.  -     lng: cur.placeBoxOpts.lng,
  773. 771.  -     diff: cur.placeBoxOpts.diffZone,
  774. 772.  -     uid: cur.placeBoxOpts.uid
  775. 773.  -   });
  776. 774.  - },
  777. 775.  -
  778. 776.  - checkHtml5Uploader: function() {
  779. 777.  -   return (window.XMLHttpRequest || window.XDomainRequest) && (window.FormData || window.FileReader && (window.XMLHttpRequest && XMLHttpRequest.sendAsBinary ||  window.ArrayBuffer && window.Uint8Array && (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)));
  780. 778.  - },
  781. 779.  -
  782. 780.  - uploadPhotos: function(obj, ev) {
  783. 781.  -   if (ev && (ev.button == 2 || ev.ctrlKey)) {
  784. 782.  -     if (photos.checkHtml5Uploader()) {
  785. 783.  -       obj.href += '&html5=1';
  786. 784.  -     }
  787. 785.  -     return true;
  788. 786.  -   }
  789. 787.  -   if (cur.uplId !== undefined && window.Upload && Upload.checked && Upload.checked[cur.uplId] && Places.checkHtml5Uploader()) {
  790. 788.  -     ge('photos_upload_input').click();
  791. 789.  -     return false;
  792. 790.  -   }
  793. 791.  -   return true;
  794. 792.  - },
  795. 793.  -
  796. 794.  - onPhotoUploadStart: function(info, res) {
  797. 795.  -   var label = ge('places_photo_upload_area_label');
  798. 796.  -   setStyle(label, {background: 'none', paddingLeft: '0px'});
  799. 797.  -   label.innerHTML = '<div id="places_ph_add_progress"><div id="places_add_p_line"><div id="places_add_p_inner"></div></div><div id="places_add_p_str"></div></div>';
  800. 798.  -   if (info.num === undefined) {
  801. 799.  -     info = res;
  802. 800.  -   }
  803. 801.  -   if (info.totalCount > 1) {
  804. 802.  -     ge('places_add_p_str').innerHTML = langNumeric(info.num ? info.num + 1 : 1, cur.lang['photos_add_uploading_num_X']).replace('{count}', info.totalCount);
  805. 803.  -   } else {
  806. 804.  -     ge('places_add_p_str').innerHTML = getLang('photos_add_uploading');
  807. 805.  -   }
  808. 806.  - },
  809. 807.  -
  810. 808.  - onPhotoUploadProgress: function(ind, upl, need) {
  811. 809.  -   var inner = ge('places_add_p_inner');
  812. 810.  -   var w = (upl / need) * 175;
  813. 811.  -   var oldWidth = intval(inner.style.width);
  814. 812.  -   if (ind.totalCount > 1) {
  815. 813.  -     ge('places_add_p_str').innerHTML = langNumeric(ind.num + 1, cur.lang['photos_add_uploading_num_X']).replace('{count}', ind.totalCount);
  816. 814.  -   }
  817. 815.  -   if (w > oldWidth) {
  818. 816.  -     animate(inner, {width: w}, 200);
  819. 817.  -   }
  820. 818.  - },
  821. 819.  -
  822. 820.  - onPhotoUploadComplete: function(info, res) {
  823. 821.  -   var params, i = info.ind !== undefined ? info.ind : info;
  824. 822.  -   try {
  825. 823.  -     params = eval('(' + res + ')');
  826. 824.  -   } catch(e) {
  827. 825.  -     params = q2ajx(res);
  828. 826.  -   }
  829. 827.  -   cur.savedPhotos = cur.savedPhotos || {mid: params.mid, gid: params.gid, aid: params.aid, server: params.server};
  830. 828.  -   cur.savedPhotos.photos = cur.savedPhotos.photos || [];
  831. 829.  -   cur.savedPhotos.photos.push({photo: params.photos, hash: params.hash});
  832. 830.  -   return;
  833. 831.  - },
  834. 832.  -
  835. 833.  - onPhotoUploadCompleteAll: function(info) {
  836. 834.  -   var query = {act: 'done_add', context: 1, from: 'profile_map'}, k = 1;
  837. 835.  -
  838. 836.  -   if (!cur.savedPhotos.photos) {
  839. 837.  -     return;
  840. 838.  -   }
  841. 839.  -   for (var j in (cur.savedPhotos.photos || [])) {
  842. 840.  -     query['photo'+k] = cur.savedPhotos.photos[j].photo;
  843. 841.  -     query['hash'+k] = cur.savedPhotos.photos[j].hash;
  844. 842.  -     k++;
  845. 843.  -   }
  846. 844.  -   delete cur.savedPhotos.photos;
  847. 845.  -   query = extend(query, cur.savedPhotos);
  848. 846.  -   ajax.post('/al_photos.php', query, {
  849. 847.  -     onDone: function(photos, hash, oid, photoPreview) {
  850. 848.  -       Places.selectPhoto(photos, photoPreview);
  851. 849.  -     },
  852. 850.  -     onFail: function(text) {
  853. 851.  -       setTimeout(showFastBox(getLang('global_error'), text).hide, __debugMode ? 30000 : 3000);
  854. 852.  -     }
  855. 853.  -   })
  856. 854.  - },
  857. 855.  -
  858. 856.  - showPlaceTT: function(obj, text) {
  859. 857.  -   showTooltip(obj, {black: 1, text: text, center:1, shift:[0, 4, 0]});
  860. 858.  - },
  861. 859.  -
  862. 860.  - showPhotoPlace: function(lat, lng) {
  863. 861.  -   var map = cur.placeBoxMap;
  864. 862.  -   map.setCenter(new google.maps.LatLng(lat, lng));
  865. 863.  -   map.setZoom(16);
  866. 864.  -   animate(boxLayerWrap, {scrollTop: 0}, 200);
  867. 865.  - }
  868. 866.  -
  869. 867.  - }
  870. 868.  -
  871. 869.  - try{stManager.done('places.js');}catch(e){}
  872. ------
Advertisement
Add Comment
Please, Sign In to add comment