Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - photos_add.js (Старый размер - 33457 | Новый - 0):
- 0. - var PhotosAdd = {
- 1. - checkChanges: function(showBox) {
- 2. - if (cur.leaving) return;
- 3. - if (cur.album && cur.uploadStarted) {
- 4. - var msg = getLang('photos_uploading_warning');
- 5. - if (showBox === 1) {
- 6. - var box = showFastBox(getLang('global_warning'), msg, getLang('photos_stop_uploading'), function () {
- 7. - cur.leaving = true;
- 8. - box.hide();
- 9. - if (cur.onContinueCb) {
- 10. - cur.onContinueCb();
- 11. - }
- 12. - }, getLang('global_cancel'));
- 13. - return true;
- 14. - } else {
- 15. - return winToUtf(msg);
- 16. - }
- 17. - } else {
- 18. - if (showBox) return false;
- 19. - }
- 20. - },
- 21. - go: function(el, ev) {
- 22. - if (PhotosAdd.checkChanges(1)) {
- 23. - cur.onContinueCb = nav.go.pbind(el, ev);
- 24. - return true;
- 25. - }
- 26. - return nav.go(el, ev);
- 27. - },
- 28. - initBeforeUnload: function () {
- 29. - if (cur.unloadInited) return;
- 30. - cur.unloadInited = true;
- 31. - cur.nav.push(function (changed, old, n, opts) {
- 32. - if (PhotosAdd.checkChanges(1)) {
- 33. - cur.onContinueCb = nav.go.pbind(n);
- 34. - return false;
- 35. - } else if (cur.album == vk.id + '_-7' && cur.savedPhotos && cur.savedPhotos.length && !cur.savingPhotos) {
- 36. - cur.savingPhotos = true;
- 37. - ajax.post('/al_photos.php', {act: 'publish_photos', hash: cur.post_hash, photos: cur.savedPhotos.join(',')}, {
- 38. - onDone: nav.go.pbind(n)
- 39. - });
- 40. - return false;
- 41. - }
- 42. - });
- 43. - addEvent(window, 'DOMMouseScroll mousewheel', PhotosAdd.wheelHandler);
- 44. - addEvent(document, 'DOMMouseScroll', PhotosAdd.wheelHandler);
- 45. - cur.prevBefUnload = window.onbeforeunload;
- 46. - window.onbeforeunload = PhotosAdd.checkChanges;
- 47. - cur.destroy.push(function () {
- 48. - window.onbeforeunload = cur.prevBefUnload;
- 49. - removeEvent(window, 'DOMMouseScroll mousewheel', PhotosAdd.wheelHandler);
- 50. - removeEvent(document, 'DOMMouseScroll', PhotosAdd.wheelHandler);
- 51. - });
- 52. - },
- 53. - genFile: function(i, oncancel, cancel) {
- 54. - return ce('div', {innerHTML: '\
- 55. - <a class="photo_file_cancel" id="photo_cancel' + i + '" onclick="' + oncancel + '">' + cancel + '</a>\
- 56. - <div class="photo_file_button">\
- 57. - <div class="file_button_gray">\
- 58. - <div class="file_button" id="photo_file_button' + i + '">' + getLang('photos_choose_file') + '</div>\
- 59. - </div>\
- 60. - </div>\
- 61. - '});
- 62. - },
- 63. - initFile: function(i) {
- 64. - FileButton.init('photo_file_button' + i, {
- 65. - name: 'photo',
- 66. - id: 'photo_file' + i,
- 67. - accept: 'image/jpeg,image/png,image/gif',
- 68. - onchange: PhotosAdd.fileSelected
- 69. - });
- 70. - },
- 71. - addFile: function() {
- 72. - var i = cur.files.length, el = PhotosAdd.genFile(i, 'PhotosAdd.fileCancel(' + i + ')', getLang('global_cancel'));
- 73. - extend(el, {className: 'photo_upload_file', id: 'photo_upload_row' + i});
- 74. - ge('photo_upload_files').appendChild(el);
- 75. - PhotosAdd.initFile(i);
- 76. - cur.files.push({});
- 77. - },
- 78. - filesLoad: function() { // for opera mini
- 79. - var i = 0, j = 0;
- 80. - for (; i < cur.files.length; ++i) {
- 81. - var val = ge('photo_file' + i).value;
- 82. - if (val) break;
- 83. - }
- 84. - if (i == cur.files.length) return;
- 85. -
- 86. - cur.allcont = utilsNode.appendChild(ce('div', {innerHTML: '\
- 87. - <iframe name="photo_frame_all"></iframe>\
- 88. - <form target="photo_frame_all" id="photo_form_all" method="POST" action="' + cur.url + '" enctype="multipart/form-data"></form>\
- 89. - '})), form = ge('photo_form_all');
- 90. - var fields = extend(cur.fields, {
- 91. - act: 'do_add',
- 92. - al: 1,
- 93. - from_host: locHost,
- 94. - ondone: 'PhotosAdd.filesDone',
- 95. - onfail: 'PhotosAdd.filesFail'
- 96. - });
- 97. - for (j in fields) {
- 98. - form.appendChild(ce('input', {name: j, value: fields[j]}));
- 99. - }
- 100. - for (i = 0, j = 0; i < cur.files.length; ++i) {
- 101. - var f = ge('photo_file' + i);
- 102. - if (f.value) {
- 103. - f.name = 'file' + j;
- 104. - form.appendChild(f);
- 105. - ++j;
- 106. - }
- 107. - }
- 108. - form.submit();
- 109. - },
- 110. - fileSelected: function() {
- 111. - var i = intval(this.id.replace('photo_file', ''));
- 112. - if (!cur.files[i].deleting && (cur.files[i].cont || cur.files[i].id)) return;
- 113. -
- 114. - cur['fileDone' + i] = PhotosAdd.fileDone.pbind(i);
- 115. - cur['fileFail' + i] = PhotosAdd.fileFail.pbind(i);
- 116. -
- 117. - cur.files[i].cont = utilsNode.appendChild(ce('div', {innerHTML: '\
- 118. - <iframe name="photo_frame' + i + '"></iframe>\
- 119. - <form target="photo_frame' + i + '" id="photo_form' + i + '" method="POST" action="' + cur.url + '" enctype="multipart/form-data"></form>\
- 120. - '})), form = ge('photo_form' + i);
- 121. - var fields = extend(cur.fields, {
- 122. - act: 'do_add',
- 123. - al: 1,
- 124. - from_host: locHost,
- 125. - ondone: 'cur.fileDone' + i,
- 126. - onfail: 'cur.fileFail' + i
- 127. - });
- 128. - for (var j in fields) {
- 129. - form.appendChild(ce('input', {name: j, value: fields[j]}));
- 130. - }
- 131. - form.appendChild(this);
- 132. - form.submit();
- 133. -
- 134. - var btn = ge('photo_file_button' + i);
- 135. - lockButton(btn);
- 136. - setTimeout(function() {
- 137. - btn.innerHTML = btn.innerHTML; // opera hack for redraw
- 138. - }, 0);
- 139. - show('photo_cancel' + i);
- 140. - ge('photo_cancel' + i).innerHTML = getLang('global_cancel');
- 141. - if (i == cur.files.length - 1) PhotosAdd.addFile();
- 142. - },
- 143. - fileDone: function(i, res) {
- 144. - hide('photo_cancel' + i);
- 145. - var before = '';
- 146. - for (var j = i + 1; j < cur.files.length; ++j) {
- 147. - if (cur.files[j].id && !cur.files[j].deleting) {
- 148. - before = cur.files[j].id;
- 149. - break;
- 150. - }
- 151. - }
- 152. - var obj;
- 153. - try {
- 154. - obj = eval('(' + res + ')');
- 155. - } catch(e) {
- 156. - obj = q2ajx(res);
- 157. - }
- 158. - PhotosAdd.fetchGeo(obj);
- 159. - setTimeout(ajax.post.pbind('al_photos.php', extend({
- 160. - act: 'done_add',
- 161. - before: before,
- 162. - context: 1,
- 163. - geo: 1
- 164. - }, obj), {
- 165. - onDone: function(id, html) {
- 166. - if (!id) return PhotosAdd.fileFail(i, 0);
- 167. -
- 168. - cur.files[i].cont.innerHTML = '';
- 169. - utilsNode.removeChild(cur.files[i].cont);
- 170. - extend(cur.files[i], {
- 171. - id: id,
- 172. - deleting: false,
- 173. - cont: false
- 174. - });
- 175. -
- 176. - ge('photo_upload_row' + i).innerHTML = html;
- 177. - autosizeSetup('photo_caption' + id, {minHeight: 30});
- 178. - show('photo_delete' + id);
- 179. - },
- 180. - onFail: function(text) {
- 181. - if (text) {
- 182. - setTimeout(showFastBox(getLang('global_error'), text).hide, 3000);
- 183. - PhotosAdd.fileCancel(i);
- 184. - return true;
- 185. - }
- 186. - }
- 187. - }), 0);
- 188. - },
- 189. - fileCancel: function(i, cleaning) {
- 190. - if (cur.files[i].cont) {
- 191. - cur.files[i].cont.innerHTML = '';
- 192. - utilsNode.removeChild(cur.files[i].cont);
- 193. - }
- 194. - if (cleaning) return;
- 195. -
- 196. - var btn = ge('photo_file_button' + i);
- 197. - unlockButton(btn);
- 198. - btn.innerHTML = getLang('photos_choose_file');
- 199. - cur.files[i] = {};
- 200. - PhotosAdd.initFile(i);
- 201. - hide('photo_cancel' + i);
- 202. - },
- 203. - fileFail: function(i, code) {
- 204. - PhotosAdd.fileCancel(i);
- 205. - },
- 206. - fileDelete: function(id, hash) {
- 207. - var i = 0;
- 208. - for (; i < cur.files.length && cur.files[i].id != id;) {
- 209. - ++i;
- 210. - }
- 211. - if (i == cur.files.length || cur.files[i].deleting) return;
- 212. - cur.files[i].deleting = true;
- 213. - ajax.post('al_photos.php', {act: 'delete_photo', photo: id, hash: hash, edit: 2}, {onFail: function() {
- 214. - cur.files[i].deleting = false;
- 215. - }});
- 216. - var er = ge('photo_edit_row' + id);
- 217. - er.parentNode.insertBefore(PhotosAdd.genFile(i, 'PhotosAdd.fileRestore(\'' + id + '\', \'' + hash + '\')', getLang('global_restore')), er);
- 218. - hide(er);
- 219. - PhotosAdd.initFile(i);
- 220. - show('photo_cancel' + i);
- 221. - },
- 222. - fileRestore: function(id, hash) {
- 223. - var i = 0, before = '';
- 224. - for (; i < cur.files.length && cur.files[i].id != id;) {
- 225. - ++i;
- 226. - }
- 227. - if (i == cur.files.length || !cur.files[i].deleting || cur.files[i].deleting === -1) return;
- 228. - if (cur.files[i].cont) {
- 229. - return PhotosAdd.fileCancel(i);
- 230. - }
- 231. - for (var j = i + 1; j < cur.files.length; ++j) {
- 232. - if (cur.files[j].id && !cur.files[j].deleting) {
- 233. - before = cur.files[j].id;
- 234. - break;
- 235. - }
- 236. - }
- 237. - cur.files[i].deleting = -1;
- 238. - ajax.post('al_photos.php', {act: 'restore_photo', photo: id, hash: hash, before: before, edit: 2}, {onDone: function() {
- 239. - cur.files[i].deleting = false;
- 240. - }});
- 241. - var er = ge('photo_edit_row' + id);
- 242. - show(er);
- 243. - re(er.previousSibling);
- 244. - },
- 245. - filesDone: function(res) {
- 246. - var obj = q2ajx(res);
- 247. - PhotosAdd.fetchGeo(obj);
- 248. - setTimeout(ajax.post.pbind('al_photos.php', extend({act: 'done_add', context: 2, geo: 1}, obj)), 0);
- 249. - },
- 250. - filesFail: function() {
- 251. - for (var i = 0; i < cur.files.length; ++i) {
- 252. - PhotosAdd.fileCancel(i);
- 253. - }
- 254. - cur.allcont.innerHTML = '';
- 255. - utilsNode.removeChild(cur.allcont);
- 256. - cur.allcont = false;
- 257. - },
- 258. -
- 259. - chooseFlash: function() {
- 260. - if (browser.flash < 10) {
- 261. - return animate(ge('photo_flash_needed'), {backgroundColor: '#FFEFE8', borderBottomColor: '#E89B88', borderLeftColor: '#E89B88', borderRightColor: '#E89B88', borderTopColor: '#E89B88'}, 100, function() {
- 262. - animate(ge('photo_flash_needed'), {backgroundColor: '#FFFFFF', borderBottomColor: '#CCCCCC', borderLeftColor: '#CCCCCC', borderRightColor: '#CCCCCC', borderTopColor: '#CCCCCC'}, 500);
- 263. - });
- 264. - }
- 265. - show('photo_flash_upload');
- 266. - hide('photo_default_upload');
- 267. - },
- 268. - chooseDefault: function() {
- 269. - show('photo_default_upload');
- 270. - hide('photo_flash_upload');
- 271. - },
- 272. - flashWidth: function() {
- 273. - if (_ua.indexOf('Mac') != -1 && (_ua.indexOf('Opera') != -1 || _ua.indexOf('Firefox') != -1)) return '601';
- 274. - return '600';
- 275. - },
- 276. -
- 277. - backupDesc: function(photo) {
- 278. - if (!cur.descs) cur.descs = {};
- 279. - cur.descs[photo] = trim(ge('photo_caption' + photo).value);
- 280. - },
- 281. - saveDesc: function(photo, hash) {
- 282. - var dsc = ge('photo_caption' + photo).value, old = (cur.descs || {})[photo];
- 283. - delete (cur.descs || {})[photo];
- 284. - if (trim(dsc) == old) return;
- 285. -
- 286. - ajax.post('al_photos.php', {act: 'save_desc', photo: photo, hash: hash, text: dsc, edit: 1}, {onDone: function(text) {
- 287. - ge('photo_save_result' + photo).innerHTML = text;
- 288. - }, onFail: function(text) {
- 289. - ge('photo_save_result' + photo).innerHTML = '<div class="photo_save_error">' + text + '</div>';
- 290. - return true;
- 291. - }, showProgress: function() {
- 292. - ge('photo_save_result' + photo).innerHTML = getLang('photos_privacy_description');
- 293. - show('photo_save_progress' + photo);
- 294. - }, hideProgress: function() {
- 295. - hide('photo_save_progress' + photo);
- 296. - }});
- 297. - },
- 298. -
- 299. - multiSel: function(ev) {
- 300. - alert(ev.target.files.length);
- 301. - },
- 302. -
- 303. - activeTab: function(el) {
- 304. - var p = domPN(domPN(el));
- 305. - for (var i = domFC(p); i; i = domNS(i)) {
- 306. - removeClass(i, 'active_link');
- 307. - }
- 308. - addClass(domPN(el), 'active_link');
- 309. - var addTab = domFC(ge('photo_add_tab'));
- 310. - if (addTab !== el) re('photo_add_tab');
- 311. - },
- 312. -
- 313. - initHtml5: function() {
- 314. - var scrollNode = browser.msie6 ? pageNode : window;
- 315. - addEvent(scrollNode, 'scroll', PhotosAdd.scrollHandler);
- 316. - cur.destroy.push(function() {
- 317. - removeEvent(scrollNode, 'scroll', PhotosAdd.scrollHandler);
- 318. - });
- 319. -
- 320. - if (!cur.noSortPhotos && !browser.mobile) {
- 321. - sorter.init('photos_add_list', {onReorder: PhotosAdd.reorderPhoto, dh: 0});
- 322. - }
- 323. -
- 324. - cur.photoAddUpdate = function(el) {
- 325. - if (!cur.noSortPhotos && !browser.mobile) {
- 326. - setTimeout(sorter.update.pbind(el), 0);
- 327. - }
- 328. - }
- 329. - cur.deleteAllToggle = function(obj) {
- 330. - cur.photoAddUpdate(obj.parentNode);
- 331. - }
- 332. - },
- 333. -
- 334. - reorderPhoto: function(el, before, after) {
- 335. - var list = ge('photos_add_list');
- 336. - var first = list.firstChild;
- 337. - while(first && !hasClass(first, 'photos_add_upl_row')) {
- 338. - first = first.nextSibling;
- 339. - }
- 340. - if (!hasClass(first, 'photos_add_first_child')) {
- 341. - var last = geByClass('photos_add_first_child', list)[0];
- 342. - removeClass(last, 'photos_add_first_child');
- 343. - addClass(first, 'photos_add_first_child');
- 344. - }
- 345. -
- 346. - ajax.post('al_photos.php', {
- 347. - act: 'reorder_photos',
- 348. - photo: el.id.substr(14),
- 349. - before: (before) ? before.id.substr(14) : '',
- 350. - after: (after) ? after.id.substr(14) : ''
- 351. - });
- 352. - },
- 353. -
- 354. - wheelHandler: function(ev) {
- 355. - if (cur.album && !cur.scrollFixed) cur.scrollFixed = true;
- 356. - },
- 357. -
- 358. - scrollHandler: function(ev) {
- 359. - if (cur.uplSelected) {
- 360. - if (ge('photos_add_bar')) {
- 361. - var y = scrollGetY();
- 362. - if (!cur.scrollBarFixedY) {
- 363. - cur.scrollBarFixedY = getXY(ge('photos_add_bar').parentNode)[1];
- 364. - }
- 365. - var bar = ge('photos_add_bar');
- 366. - if (y > cur.scrollBarFixedY && !cur.scrollBarFixed) {
- 367. - bar.className = 'photos_add_bar1';
- 368. - cur.scrollBarFixed = true;
- 369. - if (cur.introTooltipHide) {
- 370. - cur.introTooltipHide();
- 371. - }
- 372. - }
- 373. - if (y < cur.scrollBarFixedY && cur.scrollBarFixed) {
- 374. - bar.className = 'photos_add_bar0';
- 375. - cur.scrollBarFixed = false;
- 376. - if (cur.introTooltipShow) {
- 377. - cur.introTooltipShow();
- 378. - }
- 379. - }
- 380. - }
- 381. - if (isVisible('photos_go_to_album')) {
- 382. - var w = window, de = document.documentElement, ft = ge('photos_go_to_album');
- 383. - if (!w.pageNode) return;
- 384. - var xy = getXY(ft.parentNode), sz = getSize(ft),
- 385. - dheight = Math.max(intval(w.innerHeight), intval(de.clientHeight));
- 386. - if (y < xy[1] + sz[1] - dheight && !cur.scrollFooterFixed) {
- 387. - addClass(ft, 'fixed');
- 388. - cur.scrollFooterFixed = true;
- 389. - }
- 390. - if (y > xy[1] + sz[1] - dheight && cur.scrollFooterFixed) {
- 391. - removeClass(ft, 'fixed');
- 392. - cur.scrollFooterFixed = false;
- 393. - }
- 394. - }
- 395. - }
- 396. - },
- 397. -
- 398. - setThumb: function(obj, control) {
- 399. - var img = geByClass1('photos_add_img', obj);
- 400. - var imgSize = getSize(img);
- 401. - control.mtop = 0;
- 402. - if (Math.abs(img.rotate) % 180 == 90 && this.transformAvailable()) {
- 403. - imgSize.reverse();
- 404. - if (imgSize[1] < imgSize[0]) {
- 405. - control.mtop = Math.floor((imgSize[1] - imgSize[0]) / 2);
- 406. - }
- 407. - }
- 408. - if (browser.opera) control.mtop = control.mtop - 2;
- 409. - setStyle(control, {
- 410. - width: imgSize[0],
- 411. - marginLeft: Math.floor((132 - imgSize[0]) / 2)
- 412. - });
- 413. - },
- 414. -
- 415. - thumbOver: function(obj, photo) {
- 416. - var control = geByClass('photos_add_controls', obj)[0];
- 417. - if (!control) { // create controls
- 418. - control = ce('div', {
- 419. - id: 'photos_add_controls'+photo,
- 420. - className: 'photos_add_controls',
- 421. - innerHTML: '<div class="photos_add_c_bar"><a class="photos_add_rl" onclick="PhotosAdd.rotateAngle(\''+photo+'\', 90);"></a><a class="photos_add_rr" onclick="PhotosAdd.rotateAngle(\''+photo+'\', -90);"></a></div>'
- 422. - });
- 423. - obj.appendChild(control);
- 424. - }
- 425. -
- 426. - PhotosAdd.setThumb(obj, control);
- 427. - show(control);
- 428. -
- 429. - animate(control, {height: 24, marginTop: control.mtop-24}, {duration: 200, transition: Fx.Transitions.easeOutCirc});
- 430. - },
- 431. -
- 432. - thumbOut: function(obj) {
- 433. - var control = geByClass('photos_add_controls', obj)[0];
- 434. - if (!control) {
- 435. - return;
- 436. - }
- 437. - animate(control, {height: 0, marginTop: control.mtop}, 200, function() {
- 438. - //hide(control);
- 439. - });
- 440. - },
- 441. -
- 442. - transformAvailable: function() {
- 443. - return false;
- 444. - if (cur.transformAvailable !== undefined) return cur.transformAvailable;
- 445. - var prefixes = 'Webkit Moz ms'.split(' '),
- 446. - prefix,
- 447. - div = ce('div'),i=0,
- 448. - prop = 'transform',
- 449. - support = div.style[prop] != undefined;
- 450. -
- 451. - prop = prop.charAt(0).toUpperCase() + prop.slice(1)
- 452. - while( !support && (prefix=prefixes[i++]) ){
- 453. - support = div.style[prefix+prop] != undefined;
- 454. - }
- 455. - cur.transformAvailable = support;
- 456. - return support;
- 457. - },
- 458. -
- 459. - rotateAngle: function(photo, angle) {
- 460. - var obj = ge('photos_add_img'+photo);
- 461. - var control = ge('photos_add_controls'+photo);
- 462. - if (control.blocked) return;
- 463. -
- 464. - var rotate = obj.rotate || 0;
- 465. - rotate += angle;
- 466. - obj.rotate = rotate;
- 467. -
- 468. - var imgSize = getSize(obj);
- 469. -
- 470. - var row = ge('photo_edit_row'+photo);
- 471. - var onUpdate = function() {
- 472. - if (!cur.noSortPhotos) sorter.update(row);
- 473. - clearInterval(updInt);
- 474. - if (Math.abs(rotate) % 180 != 90 && (imgSize[0] - imgSize[1] > 15)) {
- 475. - PhotosAdd.thumbOut(ge('photos_add_thumb'+photo));
- 476. - }
- 477. - };
- 478. -
- 479. - if (imgSize[0] > imgSize[1] && this.transformAvailable()) {
- 480. - if (!cur.noSortPhotos) {
- 481. - var updInt = setInterval(sorter.update.pbind(row), 10);
- 482. - }
- 483. - if (Math.abs(rotate) % 180 == 90) {
- 484. - animate(obj.parentNode, {
- 485. - marginTop: ((imgSize[0] - imgSize[1]) / 2),
- 486. - marginBottom: ((imgSize[0] - imgSize[1]) / 2)
- 487. - }, 200, onUpdate);
- 488. - } else {
- 489. - animate(obj.parentNode, {
- 490. - marginTop: 0,
- 491. - marginBottom: 0
- 492. - }, 200, onUpdate);
- 493. - }
- 494. - }
- 495. - if (!cur.noSortPhotos) {
- 496. - sorter.update(row);
- 497. - }
- 498. - if (this.transformAvailable()) {
- 499. - obj.style.webkitTransform = 'rotate('+rotate+'deg)';
- 500. - obj.style.MozTransform = 'rotate('+rotate+'deg)';
- 501. - obj.style.msTransform = 'rotate('+rotate+'deg)';
- 502. - PhotosAdd.setThumb(ge('photos_add_thumb'+photo), control);
- 503. - animate(control, {marginTop: control.mtop - 24}, 200);
- 504. - } else {
- 505. - var imgDiv = obj.parentNode.parentNode, xy = getXY(imgDiv), sz = getSize(imgDiv), w = 46, h = 16, l = Math.floor((sz[0] - w) / 2), t = Math.floor((sz[1] - h) / 2);
- 506. - setStyle(imgDiv, {position: 'relative'});
- 507. - var el = ce('div', {innerHTML: '<div id="rotating_image'+photo+'" class="progress_inv_img" style="display: block; position: absolute; width: '+w+'px; height: '+h+'px; left: '+l+'px; top: '+t+'px;">'}).firstChild;
- 508. - obj.parentNode.insertBefore(el, obj);
- 509. - }
- 510. - control.blocked = true;
- 511. - cur.rotateTimers = cur.rotateTimers || {};
- 512. - cur.rotateTimers[photo] = setTimeout(PhotosAdd.rotateFailed.pbind(photo), 5000);
- 513. -
- 514. - var ph = cur.photoData[photo];
- 515. - form = ge('photo_rotate_form'+photo);
- 516. - form.innerHTML = '';
- 517. - form.action = ph.rotate[0];
- 518. - var data = extend({
- 519. - act: 'do_rotate',
- 520. - to: (angle == 90) ? 1 : -1,
- 521. - fid: photo
- 522. - }, ph.rotate);
- 523. - if (data.act == 'rotate_photo') {
- 524. - data.angle = (data.angle + data.to + 4) % 4;
- 525. - }
- 526. - var to = (data.to + 4) % 4;
- 527. - if (data['rot'+to]) {
- 528. - data.act = 'done_rotate';
- 529. - data.complete = 1;
- 530. - ajax.post('/al_photos.php', data, {
- 531. - onDone: PhotosAdd.rotateDone,
- 532. - onFail: function() {
- 533. - PhotosAdd.rotateDone();
- 534. - }
- 535. - });
- 536. - return;
- 537. - }
- 538. - for (var i in data) {
- 539. - if (i != 0) {
- 540. - form.appendChild(ce('input', {type: 'hidden', name: i, value: data[i]}));
- 541. - }
- 542. - }
- 543. - form.submit();
- 544. -
- 545. - obj.parentNode.onclick = function() {
- 546. - cur.photoData[photo].onRotateShow = true;
- 547. - return false;
- 548. - }
- 549. -
- 550. - ajaxCache = {};
- 551. - delete cur.pvList;
- 552. - delete cur.pvData;
- 553. - },
- 554. -
- 555. - rotateDone: function(data) {
- 556. - if (!data) {
- 557. - return;
- 558. - }
- 559. - var photo = data['photo_raw'];
- 560. - var obj = ge('photos_add_img'+photo);
- 561. - var control = ge('photos_add_controls'+photo);
- 562. - delete control.blocked;
- 563. - if (!PhotosAdd.transformAvailable()) {
- 564. - re('rotating_image'+photo);
- 565. - obj.src = data.o_src || data.m_src;
- 566. - obj.onload = function() {
- 567. - PhotosAdd.setThumb(ge('photos_add_thumb'+photo), control);
- 568. - if (!cur.noSortPhotos) {
- 569. - sorter.update(ge('photo_edit_row'+photo));
- 570. - }
- 571. - };
- 572. - cur.rotateTimers = cur.rotateTimers || {};
- 573. - clearTimeout(cur.rotateTimers[photo]);
- 574. - }
- 575. - delete data.m_;
- 576. - delete data.o_;
- 577. -
- 578. - var ph = cur.photoData[photo];
- 579. -
- 580. - extend(ph.rotate, {photo: data.photo, hash: data.hash, rhash: data.rhash, angle: data.angle, rot1: data.rot1, rot3: data.rot3});
- 581. -
- 582. - ajaxCache = {};
- 583. - delete cur.pvList;
- 584. - delete cur.pvData;
- 585. -
- 586. - obj.parentNode.onclick = function(ev) {
- 587. - return showPhoto(photo, 'album' + ph['album'], {temp: {base: data['base'], x_: data['x_'], y_: data['y_'], z_: data['z_']}, dark: 1}, ev);
- 588. - }
- 589. -
- 590. - if (cur.photoData[photo].onRotateShow) {
- 591. - obj.parentNode.onclick();
- 592. - }
- 593. - cur.photoData[photo].onRotateShow = false;
- 594. - },
- 595. -
- 596. - rotateFailed: function(photo) {
- 597. - if (!PhotosAdd.transformAvailable()) {
- 598. - re('rotating_image'+photo);
- 599. - }
- 600. - var control = ge('photos_add_controls'+photo);
- 601. - delete control.blocked;
- 602. - },
- 603. -
- 604. - deleteAddPhoto: function(i) {
- 605. - var obj = qsorter.remove(cur.uplBox, ge('photos_add_item'+i));
- 606. - cur.uploadPhotoCount -= 1;
- 607. - if (obj) {
- 608. - PhotosAdd.thumbOver(obj.id.substr(19), geByClass('photos_add_img', obj)[0]);
- 609. - }
- 610. - PhotosAdd.updateCount();
- 611. - },
- 612. -
- 613. - correctThumb: function(i, rotate, obj) {
- 614. - if (Math.abs(rotate) % 180 == 90) {
- 615. - var w = Math.min(obj.firstChild.width, 98);
- 616. - setStyle(obj, {
- 617. - width: w,
- 618. - marginLeft: Math.ceil((130 - w) / 2)
- 619. - })
- 620. - } else {
- 621. - var w = obj.firstChild.width;
- 622. - setStyle(obj, {
- 623. - width: w,
- 624. - marginLeft: Math.ceil((130 - w) / 2)
- 625. - })
- 626. - }
- 627. -
- 628. - var control = ge('photos_add_controls'+i);
- 629. - hide(control);
- 630. - setStyle(control, {
- 631. - height: 0,
- 632. - marginTop: '0px'
- 633. - });
- 634. - setTimeout(function() {
- 635. - var fileItem = Upload.fileList[cur.uplId][i];
- 636. - fileItem.animating = false;
- 637. - PhotosAdd.thumbOver(i, obj);
- 638. - }, 600);
- 639. - },
- 640. -
- 641. - updateCount: function() {
- 642. - var save = ge('photos_add_save');
- 643. - save.innerHTML = langNumeric(cur.qsrt.count, cur.uploaderLang['photos_save_X_photos']);
- 644. - if (cur.qsrt.count == 0) {
- 645. - show('photos_add_empty');
- 646. - hide('photos_add_box');
- 647. - hide(ge('photos_add_bar').parentNode);
- 648. - Upload.fileList[cur.uplId] = false;
- 649. - }
- 650. - },
- 651. -
- 652. - saveHtml5: function() {
- 653. - Upload.uploadPhotos(cur.uplId);
- 654. - },
- 655. -
- 656. - scrollToBottom: function(el) {
- 657. - if (cur.scrollFixed) return;
- 658. - var w = window, de = document.documentElement;
- 659. - if (!el) el = cur.lastPhotoRow;
- 660. - if (!w.pageNode || !el) return;
- 661. - var xy = getXY(el), sz = getSize(el),
- 662. - dheight = Math.max(intval(w.innerHeight), intval(de.clientHeight));
- 663. - if (xy[1] <= 0) xy = getXY(el.parentNode);
- 664. - var scrollY = xy[1] + sz[1] - dheight;
- 665. - if (scrollY > 0) scrollToY(scrollY, 400);
- 666. - },
- 667. -
- 668. - onUploadStart: function(info, res) {
- 669. - PhotosAdd.initBeforeUnload();
- 670. - if (cur.onPhotoAddStart) {
- 671. - cur.onPhotoAddStart();
- 672. - }
- 673. - if (cur.flash_lite && info.num === undefined) {
- 674. - info = res;
- 675. - }
- 676. - if (info.num == 0) {
- 677. - cur.errorCount = 0;
- 678. - if (!ge('photos_add_wrap')) {
- 679. - cur.count = 0;
- 680. - var pc = ge('photos_container') || ge('photos_albums_container'), pa = ge('photos_upload_area'), tab = ge('photo_add_tab');
- 681. - pc.parentNode.insertBefore(ce('div', {innerHTML: cur.photosAddWrap}).firstChild, pc);
- 682. - pa.parentNode.insertBefore(ce('div', {innerHTML: cur.photosAddBar}).firstChild, pa);
- 683. - setStyle(ge('lite_photo_uploader'), {width: '1px', height: '1px'});
- 684. - hide(pc, pa, 'add_album_link');
- 685. - re(pa);
- 686. - re('photos_container');
- 687. - re('photos_albums_container');
- 688. - re('albums_load_more');
- 689. - re('photos_load_more');
- 690. - re(geByClass1('summary_wrap', ge('photos_upload_area_wrap').parentNode));
- 691. - re(geByClass1('photos_summary', ge('photos_upload_area_wrap').parentNode));
- 692. - show(tab);
- 693. - var w = 180;
- 694. - while (tab.previousSibling && getXY(tab)[1] > getXY(tab.previousSibling)[1] && w > 100) {
- 695. - w -= 10;
- 696. - var tabW = geByClass1('tab_word', tab.previousSibling);
- 697. - if (!tabW) break;
- 698. - setStyle(tabW, {maxWidth: w});
- 699. - }
- 700. - PhotosAdd.activeTab(tab.firstChild);
- 701. - PhotosAdd.initHtml5();
- 702. - if (cur.albums) {
- 703. - cur.movedd = new Dropdown(ge('photos_move_dd'), cur.albums, {
- 704. - width: 200,
- 705. - multiselect: false,
- 706. - autocomplete: (cur.albums.length > 7),
- 707. - onChange: photos.movePhoto
- 708. - });
- 709. - cur.moveddc = ge('photos_movedd_container').firstChild;
- 710. - }
- 711. - }
- 712. - hide('photos_add_empty', 'photos_go_to_album');
- 713. - show('photos_add_box');
- 714. - addClass(ge('photos_add_wrap'), 'photos_add_selected');
- 715. - show(ge('photos_add_bar').parentNode);
- 716. - if (browser.msie) {
- 717. - setStyle(ge('photos_add_bar_form'), {position: 'absolute', top: '-5000px'});
- 718. - } else {
- 719. - setStyle(ge('photos_add_bar_form'), {visibility: 'hidden'});
- 720. - }
- 721. - if (browser.mozilla && ge('lite_photo_uploader')) {
- 722. - setStyle(ge('lite_photo_uploader'), {visibility: 'hidden'});
- 723. - }
- 724. - show('photos_add_bar_progress');
- 725. - if (info.totalCount > 1) {
- 726. - var txt = (cur.uploaderLang['photos_add_uploading_X'] || '').replace('%s', info.totalCount);
- 727. - } else {
- 728. - var txt = cur.uploaderLang['photos_add_uploading'];
- 729. - }
- 730. - ge('photos_add_p_text').innerHTML = txt;
- 731. - cur.scrollBarFixedY = false;
- 732. - cur.uploadStarted = true;
- 733. - setStyle(ge('photos_add_p_inner'), {width: '0px'});
- 734. - hide('photos_add_error');
- 735. - } else {
- 736. - var lng = langNumeric(info.num, cur.uploaderLang['photos_add_uploaded_X'])
- 737. - ge('photos_add_p_text').innerHTML = lng.replace('{count}', info.totalCount);
- 738. - }
- 739. - var classAdd = '';
- 740. -
- 741. - if (!cur.photosAddFirst) {
- 742. - cur.photosAddFirst = true;
- 743. - classAdd = ' photos_add_first_child';
- 744. - }
- 745. - info.prepareCont = ce('div', {
- 746. - className: 'photos_add_upl_row'+classAdd,
- 747. - innerHTML: '<div class="photos_add_s_loading"></div>'
- 748. - });
- 749. - if (cur.flash_lite) {
- 750. - cur.flashPrepareCont = cur.flashPrepareCont || {};
- 751. - cur.flashPrepareCont[info.num] = cur.flashPrepareCont[info.num] || {};
- 752. - cur.flashPrepareCont[info.num][info.filename] = info.prepareCont;
- 753. - }
- 754. - var addList = ge('photos_add_list');
- 755. - addList.appendChild(info.prepareCont);
- 756. - cur.lastPhotoRow = info.prepareCont;
- 757. - PhotosAdd.makeTask(function() {
- 758. - show(info.prepareCont);
- 759. - PhotosAdd.scrollToBottom();
- 760. - return true; // need to flush
- 761. - });
- 762. - cur.uplSelected = true;
- 763. -
- 764. - setStyle(ge('photos_add_p_inner'), {width: (info.loadedSize / info.totalSize * 175)+'px'});
- 765. - ajax.post('al_photos.php', {act: 'start_add', hash: cur.statsPhotoAddHash});
- 766. - },
- 767. -
- 768. - onUploadProgress: function(info, start, all) {
- 769. - if (cur.flash_lite) {
- 770. - info = {loadedSize: start, totalSize: all};
- 771. - start = 0;
- 772. - }
- 773. -
- 774. - var allProgress = (info.loadedSize + start) / info.totalSize;
- 775. - var newWidth = allProgress * 175;
- 776. - var oldWidth = intval(ge('photos_add_p_inner').style.width);
- 777. - if (newWidth > oldWidth) {
- 778. - animate(ge('photos_add_p_inner'), {width: newWidth}, 200);
- 779. - }
- 780. - },
- 781. -
- 782. - onUploadComplete: function(info, res) {
- 783. - if (cur.flash_lite) {
- 784. - info.prepareCont = cur.flashPrepareCont[info.num][info.filename];
- 785. - }
- 786. - var obj;
- 787. - try {
- 788. - obj = eval('(' + res + ')');
- 789. - } catch(e) {
- 790. - obj = q2ajx(res);
- 791. - }
- 792. - if (!obj.photos) {
- 793. - cur.errorCount++;
- 794. - re(info.prepareCont);
- 795. - if (info.prepareCont && info.prepareCont.helper) re(info.prepareCont.helper);
- 796. - ge('photos_add_error').innerHTML = cur.uploaderLang['photos_add_error'];
- 797. - show('photos_add_error');
- 798. - scrollToTop(200);
- 799. - PhotosAdd.makeTask();
- 800. - return;
- 801. - }
- 802. - if (obj.code) {
- 803. - Upload.onUploadError(cur.UplId, obj.code);
- 804. - return;
- 805. - }
- 806. - PhotosAdd.fetchGeo(obj);
- 807. - var params = extend({act: 'done_add', from: 'html5', context: 1, geo: 1}, obj);
- 808. - cur.lastPhotoRow = info.prepareCont;
- 809. - cur.photoSaveQ = cur.photoSaveQ || [];
- 810. - cur.photoSaveQ.push(function() {
- 811. - ajax.post('al_photos.php', params, {
- 812. - onDone: function(html, js, photoRaw) {
- 813. - cur.count++;
- 814. - info.prepareCont.innerHTML = html;
- 815. - eval(js);
- 816. - cur.savedPhotos = cur.savedPhotos || [];
- 817. - cur.savedPhotos.push(photoRaw);
- 818. - if (!cur.movedd) hide('photos_move_link'+photoRaw);
- 819. - show(info.prepareCont);
- 820. - info.prepareCont.id = 'photo_edit_row'+photoRaw;
- 821. - PhotosAdd.makeTask();
- 822. - setTimeout(function() {
- 823. - if (!cur.noSortPhotos) {
- 824. - sorter.added(info.prepareCont.parentNode);
- 825. - }
- 826. - setTimeout(PhotosAdd.scrollToBottom, 100);
- 827. - }, 0);
- 828. - cur.photoSaveQ.shift();
- 829. - if (cur.photoSaveQ[0]) cur.photoSaveQ[0]();
- 830. - if (cur.onPhotoFirstUploaded) cur.onPhotoFirstUploaded();
- 831. - },
- 832. - onFail: function(text) {
- 833. - if (text) {
- 834. - ge('photos_add_error').innerHTML = text;
- 835. - show('photos_add_error');
- 836. - scrollToTop(200);
- 837. - }
- 838. - cur.errorUpload = true;
- 839. - if (hasClass(info.prepareCont, 'photos_add_first_child')) {
- 840. - var next = info.prepareCont.nextSibling;
- 841. - while(next) {
- 842. - if (hasClass(next, 'photos_add_upl_row')) {
- 843. - addClass(next, 'photos_add_first_child');
- 844. - break;
- 845. - }
- 846. - next = next.nextSibling;
- 847. - }
- 848. - if (!next) {
- 849. - cur.photosAddFirst = false;
- 850. - }
- 851. - }
- 852. - re(info.prepareCont);
- 853. - cur.photoSaveQ.shift();
- 854. - if (cur.photoSaveQ[0]) cur.photoSaveQ[0]();
- 855. - PhotosAdd.makeTask();
- 856. - return true;
- 857. - }
- 858. - });
- 859. - });
- 860. - if (cur.photoSaveQ.length == 1) {
- 861. - cur.photoSaveQ[0]();
- 862. - }
- 863. - },
- 864. -
- 865. - updateSorterRow: function(photo) {
- 866. - if (!cur.noSortPhotos) {
- 867. - setTimeout(function() {
- 868. - sorter.update(ge('photo_edit_row'+photo));
- 869. - }, 0)
- 870. - }
- 871. - },
- 872. -
- 873. - onUploadCompleteAll: function(info, res) {
- 874. - cur.uploadStartProgress = 0;
- 875. - delete cur.uploadStarted;
- 876. - window.onbeforeunload = cur.prevBefUnload;
- 877. - delete cur.unloadInited;
- 878. - this.onUploadProgress({loadedSize: 100, totalSize: 100}, cur.flash_lite ? 100 : 0, 100);
- 879. - PhotosAdd.makeTask(function() {
- 880. - var infoCont = ge('photo_upload_area_label'), infoText = infoCont.innerHTML;
- 881. - hide('photos_add_more_info');
- 882. - if (!cur.errorUpload) {
- 883. - infoCont.innerHTML = langNumeric((info.totalCount || res.totalCount) - (cur.errorCount || 0), cur.uploaderLang['photos_successfully_added']);
- 884. - } else {
- 885. - infoCont.innerHTML = cur.uploaderLang['photos_add_error'];
- 886. - cur.errorUpload = false;
- 887. - }
- 888. - toggleClass(infoCont, "photos_upload_area_img", false);
- 889. - fadeIn(infoCont, 500, function() {
- 890. - setTimeout(function() {
- 891. - fadeOut(infoCont,300, function() {
- 892. - if ((cur.savedPhotos || []).length >= (cur.maxFiles || 200)) {
- 893. - slideUp('photos_upload_area_wrap', 200, function() {re('photos_upload_area_wrap')});
- 894. - } else {
- 895. - if (cur.flash_lite) {
- 896. - re('lite_photo_uploader');
- 897. - var par = ge('photos_upload_area'),
- 898. - el = ce('div', {innerHTML: '<div id="lite_photo_uploader" style="position: absolute; height: 100%; width: 100%; z-index: 9999; cursor: pointer;"></div>'}).firstChild;
- 899. - par.parentNode.insertBefore(el, par);
- 900. - cur.initFlashLite();
- 901. - } else if (cur.html5AddLink){
- 902. - var par = ge('photos_upload_area'), el = ce('div', {innerHTML: cur.html5AddLink}).firstChild;
- 903. - par.id = 'remove_in_process';
- 904. - par.parentNode.insertBefore(el, par);
- 905. - re(par);
- 906. - infoCont = ge('photo_upload_area_label');
- 907. - }
- 908. - toggleClass(infoCont, "photos_upload_area_img", true);
- 909. - infoCont.innerHTML = infoText;
- 910. - fadeIn(infoCont, 300);
- 911. - }
- 912. - })
- 913. - }, 2000);
- 914. - })
- 915. - show('photos_go_to_album');
- 916. - cur.lastPhotoRow = ge('photos_go_to_album');
- 917. - PhotosAdd.scrollToBottom();
- 918. - if (cur.flash_lite) {
- 919. - re('lite_photo_uploader');
- 920. - }
- 921. - fadeOut('photos_add_bar_progress', 500);
- 922. - if (browser.msie) {
- 923. - setStyle(ge('photos_add_bar_form'), {position: 'relative', top: '0px', display: 'none'});
- 924. - } else {
- 925. - setStyle(ge('photos_add_bar_form'), {visibility: 'visible', display: 'none'});
- 926. - }
- 927. - fadeIn('photos_add_bar_form', 500);
- 928. - });
- 929. - },
- 930. -
- 931. - makeTask: function(task) {
- 932. - cur.photoAddQ = cur.photoAddQ || [];
- 933. - if (task) {
- 934. - cur.photoAddQ.push(task);
- 935. - } else {
- 936. - cur.photoAddSt = false;
- 937. - }
- 938. - if (!cur.photoAddSt) {
- 939. - var newTask = cur.photoAddQ.shift();
- 940. - if (newTask) {
- 941. - cur.photoAddSt = newTask();
- 942. - }
- 943. - }
- 944. - },
- 945. -
- 946. - fetchGeo: function(obj) {
- 947. - if (!obj.photos) {
- 948. - return false;
- 949. - }
- 950. - var photos = parseJSON(obj.photos);
- 951. -
- 952. - if (!photos) {
- 953. - return false;
- 954. - }
- 955. - var coords = {};
- 956. - var len = 0;
- 957. - for (var i in photos) {
- 958. - var lat = photos[i].latitude;
- 959. - var long = photos[i].longitude;
- 960. - if (lat && long) {
- 961. - coords[lat+','+long] = 1;
- 962. - len += 1;
- 963. - }
- 964. - }
- 965. - if (!len) {
- 966. - return false;
- 967. - }
- 968. - stManager.add(['maps.js'], function() {
- 969. - cur.placeMap = new vkMaps.VKMap(false, 'google');
- 970. - if (cur.placeMap.isLoaded('google')) {
- 971. - PhotosAdd.setGeo(coords);
- 972. - } else {
- 973. - cur.placeMap.load.addHandler(PhotosAdd.setGeo.pbind(coords));
- 974. - }
- 975. - });
- 976. - },
- 977. -
- 978. - setGeo: function(coords) {
- 979. - var lngcode = cur.uploaderLang.geolang || 'en';
- 980. - for (var coord in coords) {
- 981. - coord = coord.split(',');
- 982. - var lat = coord[0];
- 983. - var long = coord[1];
- 984. - new vkMaps.Geocoder('google', function(place) {
- 985. - ajax.post('al_photos.php', {
- 986. - act: 'a_set_geo',
- 987. - lat: coord[0],
- 988. - long: coord[1],
- 989. - geo_country: place.country,
- 990. - geo_locality: place.locality,
- 991. - geo_region: place.region,
- 992. - geo_street: place.street,
- 993. - geo_place: place.place,
- 994. - geo_lang: lngcode,
- 995. - geo_code: place.countryCode
- 996. - });
- 997. - }).geocode({location: new google.maps.LatLng(lat, long), language: lngcode})
- 998. - }
- 999. - }
- 1000. -
- 1001. - }
- 1002. -
- 1003. - try{stManager.done('photos_add.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment