Stig's Flickr Fixr

Show photographer's albums on photostream-pages, Increase display-size and quality of "old" photos, Display photo-notes, Photographer's other photos by tag-links, Links to album-map and album-comments on album headers, A fix to actually show a geotagged photo on the from photo linked map - And more to come?...

当前为 2015-12-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Stig's Flickr Fixr
  3. // @namespace dk.rockland.userscript.flickr.fixr
  4. // @description Show photographer's albums on photostream-pages, Increase display-size and quality of "old" photos, Display photo-notes, Photographer's other photos by tag-links, Links to album-map and album-comments on album headers, A fix to actually show a geotagged photo on the from photo linked map - And more to come?...
  5. // @author Stig Nygaard, http://www.rockland.dk, https://www.flickr.com/photos/stignygaard/
  6. // @homepageURL http://www.rockland.dk/userscript/flickr/fixr/
  7. // @supportURL http://www.rockland.dk/userscript/flickr/fixr/
  8. // @icon http://www.rockland.dk/img/fixr32.png
  9. // @icon64 http://www.rockland.dk/img/fixr64.png
  10. // @include https://www.flickr.com/*
  11. // @include https://flickr.com/*
  12. // @match https://*.flickr.com/*
  13. // @version 2015.12.03.2
  14. // @grant none
  15. // @run-at document-start
  16. // ==/UserScript==
  17.  
  18. // CHANGELOG - The most important updates/versions:
  19. var changelog = [
  20. {version: '2015.12.03.2', description: 'Quick basic "beta" support for the good old photo-notes (read-only, public and safe photos only, no formatting/links, not working in Lightbox mode)'},
  21. {version: '2015.11.30.1', description: 'Better icon for the new album-map links'},
  22. {version: '2015.11.28.1', description: 'New feature: Album-headers are now updated with links to album-map and album-comments'},
  23. {version: '2015.08.27.3', description: 'Fixing an error when using the Chrome browser'},
  24. {version: '2015.08.26.4', description: 'Initial release version'}
  25. ];
  26.  
  27. var DEBUG = false;
  28. function log(s) {
  29. if (DEBUG && window.console) {
  30. window.console.log(s);
  31. }
  32. }
  33. if (DEBUG) {
  34. if ('loading' === document.readyState) {
  35. log("This userscript is running at document-start time.");
  36. } else {
  37. log("This userscript is running with document.readyState: " + document.readyState);
  38. }
  39. window.addEventListener('DOMContentLoaded', function(){log('(onDOMContentLoaded)');}, false);
  40. window.addEventListener('focus', function(){log('(onfocus)');}, false);
  41. window.addEventListener('load', function(){log('(onload)');}, false);
  42. window.addEventListener('pageshow', function(){log('(onpageshow)');}, false);
  43. window.addEventListener('resize', function(){log('(onresize)');}, false);
  44. window.addEventListener('hashchange', function(){log('(onhashchange)');}, false);
  45. }
  46.  
  47. // FIXR page-tracker
  48. var fixr = {
  49. context: {
  50. pageType: '',
  51. userId: '',
  52. photographerId: '', // value might be delayed (If uninitialized, try call initPhotographerId())
  53. photographerIcon: '',
  54. photographerAlias: '', // (pathalias) bonus-info sometimes initialized (from url) when initializing photoId or albumId
  55. photographerName: '',
  56. photoId: '',
  57. albumId: '',
  58. groupId: '',
  59. galleryId: ''
  60. },
  61. content: null,
  62. pageactionsCount: 0,
  63. timerResizeActionDelayed: 0,
  64. onPageHandlers: [],
  65. onResizeHandlers: [],
  66. initPhotographerId: function () { // photographer/attribution id
  67. var elem;
  68. if (document.querySelector('div.photostream-page-view')) {
  69. // photostream
  70. elem = document.querySelector('div.photostream-page-view div.fluid-photostream-coverphoto-view div.avatar.person');
  71. } else if (document.querySelector('div.photo-page-scrappy-view')) {
  72. // photopage
  73. elem = document.querySelector('div.photo-page-scrappy-view div.sub-photo-view div.avatar.person');
  74. } else if (document.querySelector('div.photo-page-lightbox-scrappy-view')) {
  75. // photopage lightbox
  76. elem = document.querySelector('div.photo-page-lightbox-scrappy-view div.photo-well-view div.photo-attribution div.avatar.person');
  77. } else if (document.querySelector('div.album-page-view')) {
  78. // album page
  79. elem = document.querySelector('div.album-page-view div.album-container div.album-header-view div.album-attribution div.avatar.person');
  80. } else {
  81. log('we do not look for photographerId on this page');
  82. return true;
  83. }
  84. // album oversigt
  85. // etc...
  86. // men minus f.eks. favorites oversigt!
  87. if (!elem) {
  88. log('fixr.initPhotographerId() - Attribution elem NOT found - returning false');
  89. return false;
  90. } // re-run a little later???
  91. log('fixr.initPhotographerId() - Attribution elem found');
  92. // (div.avatar.person).style.backgroundImage=url(https://s.yimg.com/pw/images/buddyicon07_r.png#44504567@N00)
  93. // .style.backgroundImage=url(//c4.staticflickr.com/8/7355/buddyicons/10259776@N00_r.jpg?1372021232#10259776@N00)
  94. if (elem.style.backgroundImage) {
  95. log('fixr.initPhotographerId() - elem has style.backgroundImage "' + elem.style.backgroundImage + '", now looking for the attribution id...');
  96. var pattern = /url[^#\?]+(\/\/[^#\?]+\.com\/[^#\?]+\/buddyicon[^\?\#]+)[^#]*#(\d+\@N\d{2})/i;
  97. // var pattern = /\/buddyicons\/(\d+\@N\d{2})\D+/i;
  98. var result = elem.style.backgroundImage.match(pattern);
  99. if (result) {
  100. log('fixr.initPhotographerId() - Attribution pattern match found: ' + result[0]);
  101. log('fixr.initPhotographerId() - the attribution icon is ' + result[1]);
  102. log('fixr.initPhotographerId() - the attribution id is ' + result[2]);
  103. fixr.context.photographerIcon = result[1];
  104. fixr.context.photographerId = result[2];
  105. } else {
  106. log('fixr.initPhotographerId() - attribution pattern match not found');
  107. return false;
  108. }
  109. } else {
  110. log('fixr.initPhotographerId() - elem.style.backgroundImage not found');
  111. return false;
  112. }
  113. log('fixr.initPhotographerId() - returning true...');
  114. return true;
  115. },
  116. initPhotoId: function () { // Photo Id
  117. // *flickr.com/photos/user/PId/*
  118. var pattern = /^\/photos\/([^\/]+)\/([\d]{2,})/i;
  119. var result = window.location.pathname.match(pattern);
  120. if (result) {
  121. log('url match med photoId=' + result[2]);
  122. log('url match med photographerAlias=' + result[1]);
  123. fixr.context.photoId = result[2];
  124. fixr.context.photographerAlias = result[1];
  125. return true;
  126. }
  127. return false;
  128. },
  129. initAlbumId: function () {
  130. // *flickr.com/photos/user/albums/AId/*
  131. // *flickr.com/photos/user/sets/AId/*
  132. var pattern = /^\/photos\/([^\/]+)\/albums\/([\d]{2,})/i;
  133. var result = window.location.pathname.match(pattern);
  134. if (!result) {
  135. pattern = /^\/photos\/([^\/]+)\/sets\/([\d]{2,})/i;
  136. result = window.location.pathname.match(pattern);
  137. }
  138. if (result) {
  139. log('url match med albumId=' + result[2]);
  140. log('url match med photographerAlias=' + result[1]);
  141. fixr.context.albumId = result[2];
  142. fixr.context.photographerAlias = result[1];
  143. return true;
  144. }
  145. return false;
  146. },
  147. pageActions: function () {
  148. if (fixr.content) {
  149. log('fixr.pageActions() has started with fixr.content defined');
  150. } else {
  151. log('fixr.pageActions() was called, but fixr.content NOT defined');
  152. return;
  153. }
  154. fixr.pageactionsCount++;
  155. for (var p in fixr.context) { // reset context on new page
  156. fixr.context[p] = ''; // filter ?
  157. }
  158. if (fixr.content.querySelector('div.photostream-page-view')) {
  159. if (fixr.content.querySelector('div.slideshow-view')) {
  160. fixr.context.pageType = 'PHOTOSTREAM SLIDESHOW';
  161. } else {
  162. fixr.context.pageType = 'PHOTOSTREAM';
  163. }
  164. } else if (fixr.content.querySelector('div.photo-page-scrappy-view')) {
  165. fixr.context.pageType = 'PHOTOPAGE';
  166. } else if (fixr.content.querySelector('div.photo-page-lightbox-scrappy-view')) {
  167. fixr.context.pageType = 'PHOTOPAGE LIGHTBOX';
  168. } else if (fixr.content.querySelector('div.albums-list-page-view')) {
  169. fixr.context.pageType = 'ALBUMSLIST';
  170. } else if (fixr.content.querySelector('div.album-page-view')) {
  171. if (fixr.content.querySelector('div.slideshow-view')) {
  172. fixr.context.pageType = 'ALBUM SLIDESHOW';
  173. } else {
  174. fixr.context.pageType = 'ALBUM';
  175. }
  176. } else if (fixr.content.querySelector('div.cameraroll-page-view')) {
  177. fixr.context.pageType = 'CAMERAROLL';
  178. } else if (fixr.content.querySelector('div.explore-page-view')) {
  179. fixr.context.pageType = 'EXPLORE';
  180. } else if (fixr.content.querySelector('div.favorites-page-view')) {
  181. if (fixr.content.querySelector('div.slideshow-view')) {
  182. fixr.context.pageType = 'FAVORITES SLIDESHOW';
  183. } else {
  184. fixr.context.pageType = 'FAVORITES';
  185. }
  186. } else if (fixr.content.querySelector('div.groups-list-view')) {
  187. fixr.context.pageType = 'GROUPSLIST'; // personal grouplist
  188. } else if (fixr.content.querySelector('div#activityFeed')) { // id=main i stedet for id=fixr.content
  189. fixr.context.pageType = 'ACTIVITYFEED'; // aka. front page
  190. } else {
  191. // fixr.context.pageType = ''; // unknown
  192. }
  193.  
  194. log('fixr.context.pageType = ' + fixr.context.pageType);
  195. if (fixr.initPhotographerId()) {
  196. log('fixr.initPhotographerId() returned true');
  197. } else {
  198. log('fixr.initPhotographerId() returned false - re-running delayed...');
  199. setTimeout(fixr.initPhotographerId, 2000);
  200. }
  201. if (fixr.initPhotoId()) {
  202. log('fixr.initPhotoId() returned true');
  203. } else {
  204. log('fixr.initPhotoId() returned false');
  205. }
  206. if (fixr.initAlbumId()) {
  207. log('fixr.initAlbumId() returned true');
  208. }
  209. if (fixr.content.querySelector('a.owner-name')) {
  210. fixr.context.photographerName = fixr.content.querySelector('a.owner-name').textContent;
  211. }
  212.  
  213. // Now run the page handlers....
  214. if (fixr.onPageHandlers && fixr.onPageHandlers !== null && fixr.onPageHandlers.length) {
  215. log('We have ' + fixr.onPageHandlers.length + ' onPage handlers starting now...');
  216. for (var f = 0; f < fixr.onPageHandlers.length; f++) {
  217. fixr.onPageHandlers[f]();
  218. }
  219. }
  220. },
  221. setupContent: function () {
  222. if (document.getElementById('content')) {
  223. fixr.content = document.getElementById('content');
  224. } else if (document.getElementById('main')) {
  225. fixr.content = document.getElementById('main'); // frontpage
  226. }
  227. if (fixr.content && fixr.content.id) {
  228. log('fixr.content.id = ' + fixr.content.id);
  229. } else {
  230. log('content or main element NOT found!');
  231. }
  232. },
  233. runPageActionsIfMissed: function () {
  234. if (fixr.pageactionsCount === 0) {
  235. log('Vi kører fixr.pageActions() på bagkant via onload...');
  236. fixr.setupContent();
  237. if (fixr.content === null) {
  238. log('Vi kan IKKE køre fixr.pageActions() på bagkant, da fixr.content ikke er defineret');
  239. return;
  240. }
  241. fixr.pageActions();
  242. } else {
  243. log('ej nødvendigt at køre fixr.pageActions() på bagkant i dette tilfælde...');
  244. }
  245. },
  246. runDelayedPageActionsIfMissed: function () {
  247. setTimeout(fixr.runPageActionsIfMissed, 2000);
  248. },
  249. resizeActions: function () {
  250. if (fixr.onResizeHandlers && fixr.onResizeHandlers !== null && fixr.onResizeHandlers.length) {
  251. for (var f = 0; f < fixr.onResizeHandlers.length; f++) {
  252. fixr.onResizeHandlers[f]();
  253. }
  254. }
  255. },
  256. resizeActionsDelayed: function () { // or "preburner"
  257. clearTimeout(fixr.timerResizeActionDelayed);
  258. fixr.timerResizeActionDelayed = setTimeout(fixr.resizeActions, 250);
  259. },
  260. setupObserver: function () {
  261. log('fixr.setupObserve INITIALIZATION START');
  262. fixr.setupContent();
  263. if (fixr.content === null) {
  264. log('Init fails because content not defined');
  265. return;
  266. }
  267. // create an observer instance
  268. var observer = new MutationObserver(function (mutations) {
  269. log('NEW PAGE MUTATION!');
  270. //mutations.forEach(function(mutation) {
  271. // log('MO: '+mutation.type); // might check for specific type of "mutations" (MutationRecord)
  272. //});
  273. fixr.pageActions();
  274. }); // MutationObserver end
  275. // configuration of the observer:
  276. var config = {attributes: false, childList: true, subtree: false, characterData: false};
  277. observer.observe(fixr.content, config);
  278. log('fixr.setupObserve INITIALIZATION DONE');
  279. },
  280. init: function (onPageHandlerArray, onResizeHandlerArray) {
  281. // General page-change observer setup:
  282. window.addEventListener('DOMContentLoaded', fixr.setupObserver, false); // Page on DOMContentLoaded
  283. window.addEventListener('load', fixr.runDelayedPageActionsIfMissed, false); // Page on load
  284. window.addEventListener('resize', fixr.resizeActionsDelayed, false); // også på resize
  285. if (onPageHandlerArray && onPageHandlerArray !== null && onPageHandlerArray.length) {
  286. fixr.onPageHandlers = onPageHandlerArray; // Replace by adding with a one-by-one by "helper" for flexibility?
  287. }
  288. if (onResizeHandlerArray && onResizeHandlerArray !== null && onResizeHandlerArray.length) {
  289. fixr.onResizeHandlers = onResizeHandlerArray; // Replace by adding with a one-by-one by "helper" for flexibility?
  290. }
  291. }
  292. };
  293. // FIXR page-tracker end
  294.  
  295.  
  296. var _timerMaplink = 0;
  297. function updateMapLink() {
  298. if (fixr.context.pageType !== 'PHOTOPAGE') {
  299. return; // exit if not photopage
  300. }
  301. log('updateMapLink() running at readystate=' + document.readyState + ' and with photoId=' + fixr.context.photoId);
  302. if (fixr.context.photoId) {
  303. var maplink = fixr.content.querySelector('a.static-maps');
  304. if (maplink) {
  305. if (maplink.getAttribute('href') && (maplink.getAttribute('href').indexOf('map/?') > 0) && (maplink.getAttribute('href').indexOf('&photo=') === -1)) {
  306. maplink.setAttribute('href', maplink.getAttribute('href') + '&photo=' + fixr.context.photoId);
  307. log('link is updated by updateMapLink() at readystate=' + document.readyState);
  308. } else {
  309. log('link NOT updated by updateMapLink(). Invalid element or already updated. readystate=' + document.readyState);
  310. }
  311. } else {
  312. log('NO maplink found at readystate=' + document.readyState + '. Re-try later?');
  313. }
  314. } else {
  315. log('NO photoId found at readystate=' + document.readyState);
  316. }
  317. }
  318. function updateMapLinkDelayed() {
  319. if (fixr.context.pageType !== 'PHOTOPAGE') {
  320. return;
  321. } // exit if not photopage
  322. log('updateMapLinkDelayed() running... with pageType=' + fixr.context.pageType);
  323. //clearTimeout(_timerMaplink);
  324. _timerMaplink = setTimeout(updateMapLink, 2000); // make maplink work better on photopage
  325. }
  326.  
  327. var album = { // cache to avoid repeating requests
  328. albumId: '',
  329. commentCount: 0
  330. };
  331. function updateAlbumCommentCount() {
  332. var _reqAlbumComments = null;
  333. if (window.XMLHttpRequest) {
  334. _reqAlbumComments = new XMLHttpRequest();
  335. if (typeof _reqAlbumComments.overrideMimeType !== 'undefined') {
  336. _reqAlbumComments.overrideMimeType('text/html');
  337. }
  338.  
  339. _reqAlbumComments.onreadystatechange = function () {
  340. if (_reqAlbumComments.readyState === 4 && _reqAlbumComments.status === 200) {
  341. log('_reqAlbumComments returned status=' + _reqAlbumComments.status);
  342. var doc = document.implementation.createHTMLDocument("sizeDoc");
  343. doc.documentElement.innerHTML = _reqAlbumComments.responseText;
  344. album.albumId = fixr.context.albumId;
  345. album.commentCount = -1;
  346. var e = doc.body.querySelectorAll('span.LinksNew b.Here');
  347. if (e && e.length === 1) {
  348. var n = parseInt(e[0].textContent, 10);
  349. if (isNaN(n)) {
  350. album.commentCount = 0;
  351. } else {
  352. album.commentCount = n;
  353. }
  354. } else {
  355. album.commentCount = -1;
  356. log('b.Here??? ');
  357. }
  358. if (document.getElementById('albumCommentCount')) {
  359. if (album.commentCount === -1) {
  360. document.getElementById('albumCommentCount').innerHTML = '?';
  361. } else {
  362. document.getElementById('albumCommentCount').innerHTML = '' + album.commentCount;
  363. }
  364. } else {
  365. log('albumCommentCount element not found');
  366. }
  367. } else {
  368. // wait for the call to complete
  369. }
  370. };
  371.  
  372. if (fixr.context.albumId === album.albumId && fixr.context.albumId !== '' && album.commentCount !== -1) {
  373. log('Usinging CACHED album count!...');
  374. document.getElementById('albumCommentCount').innerHTML = '' + album.commentCount;
  375. } else if (fixr.context.albumId !== '') {
  376. var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/' + fixr.context.albumId + '/comments/';
  377. _reqAlbumComments.open('GET', url, true);
  378. _reqAlbumComments.send(null);
  379. } else {
  380. log('albumId not initialized');
  381. }
  382. } else {
  383. log('understøtter ikke XMLHttpRequest');
  384. }
  385. }
  386.  
  387. var albums = { // cache albums to avoid repeating requests
  388. ownerId: '',
  389. html: '',
  390. count: 0
  391. };
  392. function getAlbumlist() {
  393. var _reqAlbumlist = null;
  394. if (window.XMLHttpRequest) {
  395. _reqAlbumlist = new XMLHttpRequest();
  396. if (typeof _reqAlbumlist.overrideMimeType !== 'undefined') {
  397. _reqAlbumlist.overrideMimeType('text/html');
  398. }
  399.  
  400. _reqAlbumlist.onreadystatechange = function () {
  401. if (_reqAlbumlist.readyState === 4 && _reqAlbumlist.status === 200) {
  402. log('_reqAlbumlist returned status=' + _reqAlbumlist.status); // + ', \ntext:\n' + _reqAlbumlist.responseText);
  403. var doc = document.implementation.createHTMLDocument("sizeDoc");
  404. doc.documentElement.innerHTML = _reqAlbumlist.responseText;
  405.  
  406. albums.ownerId = fixr.context.photographerId;
  407. albums.html = '';
  408. albums.count = 0;
  409. var e = doc.body.querySelectorAll('div.photo-list-album-view');
  410. var imgPattern = /url\([\'\"]*([^\)\'\"]+)(\.[jpgtifn]{3,4})[\'\"]*\)/i;
  411. if (e && e.length > 0) {
  412. albums.count = e.length;
  413. for (var i = 0; i < Math.min(10, e.length); i++) {
  414. var imgUrl = '';
  415. log(e[i].outerHTML);
  416. log('A7 (' + i + ') : ' + e[i].style.backgroundImage);
  417. // var result = e[i].style.backgroundImage.match(imgPattern); // strangely not working in Chrome
  418. var result = (e[i].outerHTML).match(imgPattern); // quick work-around for above (works for now)
  419. if (result) {
  420. imgUrl = result[1].replace(/_[a-z]$/, '') + '_s' + result[2];
  421. log('imgUrl=' + imgUrl);
  422. } else {
  423. log('No match on imgPattern');
  424. }
  425. var a = e[i].querySelector('a[href][title]'); // sub-element
  426. if (a && a !== null) {
  427. log('Album title: ' + a.title);
  428. log('Album url: ' + a.getAttribute('href'));
  429. albums.html += '<div><a href="//www.flickr.com' + a.getAttribute('href') + '"><img src="' + imgUrl + '" alt="" /><div style="margin:0 0 .8em 0">' + a.title + '</div></a></div>';
  430. } else {
  431. log('a element not found?');
  432. }
  433. }
  434. }
  435. if (document.getElementById('albumTeaser')) {
  436. document.getElementById('albumTeaser').innerHTML = '<div style="margin:0 0 .8em 0">Albums</div>' + albums.html + '<div><i><a href="/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/">' + (albums.count > 10 ? 'More albums...' : (albums.count == 0 ? 'No albums found...' : '')) + '</a></i></div>';
  437. } else {
  438. log('albumTeaser NOT FOUND!?!');
  439. }
  440. } else {
  441. // wait for the call to complete
  442. }
  443. };
  444.  
  445. if (fixr.context.photographerId === albums.ownerId && fixr.context.photographerId !== '') {
  446. log('Usinging CACHED albumlist!...');
  447. document.getElementById('albumTeaser').innerHTML = '<div style="margin:0 0 .8em 0">Albums</div>' + albums.html + '<div><i><a href="/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/">' + (albums.count > 10 ? 'More albums...' : (albums.count == 0 ? 'No albums found...' : '')) + '</a></i></div>';
  448. } else if (fixr.context.photographerId) {
  449. var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums';
  450. _reqAlbumlist.open('GET', url, true);
  451. _reqAlbumlist.send(null);
  452. } else {
  453. log('Attribution user (photographer) not found');
  454. }
  455. } else {
  456. log('understøtter ikke XMLHttpRequest');
  457. }
  458. }
  459. function albumTeaser() {
  460. if (fixr.context.pageType !== 'PHOTOSTREAM') {
  461. return; // exit if not photostream
  462. }
  463. log('albumTeaser() running');
  464. var dpc = document.querySelector('div.photolist-container');
  465. if (!dpc) {
  466. return;
  467. }
  468. // to-do: check om personlig photostream?
  469. // to-do: check padding-right er mindst 130px?
  470. log('AlbumTeaser found div.photolist-container');
  471. if (!document.getElementById('albumTeaser')) {
  472. dpc.style.position = "relative";
  473. dpc.insertAdjacentHTML('afterbegin', '<div id="albumTeaser" style="border:none;margin:0;padding:0;position:absolute;top:0;right:10px;width:100px"></div>');
  474. }
  475. if (document.getElementById('albumTeaser')) {
  476. getAlbumlist(); // også check på fixr.context.photographerId ?
  477. }
  478. }
  479. var _timerAlbumTeaserDelayed;
  480. function albumTeaserDelayed() {
  481. if (fixr.context.pageType !== 'PHOTOSTREAM') {
  482. return; // exit if not photostream
  483. }
  484. log('albumTeaserDelayed() running...');
  485. clearTimeout(_timerAlbumTeaserDelayed);
  486. _timerAlbumTeaserDelayed = setTimeout(albumTeaser, 1500);
  487. }
  488.  
  489. function getUserId() { // Id of logged-in user
  490. return null; // to-do
  491. }
  492.  
  493. var scaler = {
  494. photoId: '',
  495. mf: null, // document.querySelector('img.main-photo') for (re-)re-scale
  496. lrf: null, // document.querySelector('img.low-res-photo') for (re-)re-scale
  497. maxSizeUrl: '',
  498. hasOriginal: false,
  499. scaleToWidth: 0,
  500. scaleToHeight: 0,
  501. postAction: function() {
  502. log('scaler.postAction');
  503. },
  504. run: function () {
  505. if (fixr.context.pageType !== 'PHOTOPAGE' && fixr.context.pageType !== 'PHOTOPAGE LIGHTBOX') {
  506. return; // exit if not photopage or lightbox
  507. }
  508. log('scaler.run() running...');
  509. // var that = this;
  510. var scale = function () { // Do the actual scaling
  511. if (fixr.context.pageType !== 'PHOTOPAGE' && fixr.context.pageType !== 'PHOTOPAGE LIGHTBOX') {
  512. return;
  513. } // exit if not photopage or lightbox
  514. log('scaler.scale() running... (scale to:' + scaler.scaleToWidth + 'x' + scaler.scaleToHeight + ')');
  515. scaler.mf = document.querySelector('img.main-photo'); // for en sikkerheds skyld
  516. scaler.lrf = document.querySelector('img.low-res-photo'); // for en sikkerheds skyld
  517. if (scaler.mf && scaler.mf !== null && scaler.lrf && scaler.lrf !== null && scaler.scaleToWidth > 0 && scaler.scaleToHeight > 0) {
  518. log('[scaler] do scaling WORK. Height from ' + scaler.mf.height + ' to ' + scaler.scaleToHeight);
  519. scaler.mf.height = scaler.scaleToHeight;
  520. log('[scaler] do scaling WORK. Width from ' + scaler.mf.width + ' to ' + scaler.scaleToWidth);
  521. scaler.mf.width = scaler.scaleToWidth;
  522. scaler.lrf.height = scaler.mf.height;
  523. scaler.lrf.width = scaler.mf.width;
  524. }
  525. scaler.postAction('notes on scaled photo');
  526. };
  527. var replace = function () { // and (re-)scale?
  528. if (fixr.context.pageType !== 'PHOTOPAGE' && fixr.context.pageType !== 'PHOTOPAGE LIGHTBOX') {
  529. return; // exit if not photopage or lightbox
  530. }
  531. log('scaler.run.replace() running...');
  532. scaler.mf = document.querySelector('img.main-photo'); // for en sikkerheds skyld
  533. if (scaler.mf && scaler.mf !== null) {
  534. scaler.mf.src = scaler.maxSizeUrl; // only if original
  535. scale();
  536. }
  537. };
  538. var getSizes = function () {
  539. log('scaler.run.getSizes() running...');
  540. var _reqAllSizes = null;
  541. if (window.XMLHttpRequest) {
  542. _reqAllSizes = new XMLHttpRequest();
  543. if (typeof _reqAllSizes.overrideMimeType !== 'undefined') {
  544. _reqAllSizes.overrideMimeType('text/html');
  545. }
  546. _reqAllSizes.onreadystatechange = function () {
  547. if (_reqAllSizes.readyState === 4 && _reqAllSizes.status === 200) {
  548. log('[scaler] _reqAllSizes returned status=' + _reqAllSizes.status); // + ', \ntext:\n' + _reqAllSizes.responseText);
  549. var doc = document.implementation.createHTMLDocument("sizeDoc");
  550. doc.documentElement.innerHTML = _reqAllSizes.responseText;
  551. if (doc.body.querySelector('div#allsizes-photo>img')) {
  552. scaler.maxSizeUrl = doc.body.querySelector('div#allsizes-photo>img').src;
  553. log('[scaler] Largest image size: ' + scaler.maxSizeUrl);
  554. }
  555. var e = doc.body.querySelectorAll('ol.sizes-list li ol li');
  556. if (e && e.length > 0) {
  557. var s = e[e.length - 1].textContent.replace(/\s{2,}/g, ' ');
  558. if (s.indexOf('Original') > -1) {
  559. scaler.hasOriginal = true;
  560. log('[scaler] ' + s);
  561. replace();
  562. } else {
  563. log('[scaler] Bruger tillader ikke adgang til original');
  564. }
  565. // udtræk evt sizes fra s?
  566. }
  567. } else {
  568. // wait for the call to complete
  569. }
  570. };
  571. var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/' + fixr.context.photoId + '/sizes/o';
  572. _reqAllSizes.open('GET', url, true);
  573. _reqAllSizes.send(null);
  574. } else {
  575. log('[scaler] understøtter ikke XMLHttpRequest');
  576. }
  577. };
  578. if (scaler.photoId === '') {
  579. scaler.photoId = fixr.context.photoId;
  580. } else if (scaler.photoId !== fixr.context.photoId) {
  581. scaler.photoId = fixr.context.photoId;
  582. scaler.mf = null;
  583. scaler.lrf = null;
  584. scaler.maxSizeUrl = '';
  585. scaler.hasOriginal = false;
  586. scaler.scaleToWidth = 0;
  587. scaler.scaleToHeight = 0;
  588. }
  589. var roomHeight = 0;
  590. var roomWidth = 0;
  591. var roomPaddingHeight = 0;
  592. var roomPaddingWidth = 0;
  593.  
  594. // Fortsæt kun hvis PhotoId!!!?
  595.  
  596. var dpev = document.querySelector('div.photo-engagement-view');
  597. var pwv = document.querySelector('div.photo-well-view');
  598. if (pwv) {
  599. log('[scaler] height-controller: height=' + pwv.clientHeight + ' (padding=70?), width=' + pwv.clientWidth + ' (padding=80?).'); // hc.style.padding: 20px 40px 50px
  600. if (roomHeight === 0) {
  601. roomHeight = pwv.clientHeight;
  602. }
  603. if (roomWidth === 0) {
  604. roomWidth = pwv.clientWidth;
  605. }
  606. roomPaddingHeight += (parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-top'), 10) + parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-bottom'), 10));
  607. roomPaddingWidth += (parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-left'), 10) + parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-right'), 10));
  608. }
  609. var hc = document.querySelector('div.height-controller');
  610. if (hc) {
  611. log('[scaler] height-controller: height=' + hc.clientHeight + ' (padding=70?), width=' + hc.clientWidth + ' (padding=80?).'); // hc.style.padding: 20px 40px 50px
  612. if (roomHeight === 0) {
  613. roomHeight = hc.clientHeight;
  614. }
  615. if (roomWidth === 0) {
  616. roomWidth = hc.clientWidth;
  617. }
  618. roomPaddingHeight += (parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-top'), 10) + parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-bottom'), 10));
  619. roomPaddingWidth += (parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-left'), 10) + parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-right'), 10));
  620. }
  621. var pwmsv = document.querySelector('div.photo-well-media-scrappy-view');
  622. if (pwmsv) {
  623. log('[scaler] div.photo-well-media-scrappy-view: height=' + pwmsv.clientHeight + ' (padding=70?), width=' + pwmsv.clientWidth + ' (padding=80?).'); // pwmsv.style.padding: 20px 40px 50px
  624. if (roomHeight === 0) {
  625. roomHeight = pwmsv.clientHeight;
  626. }
  627. if (roomWidth === 0) {
  628. roomWidth = pwmsv.clientWidth;
  629. }
  630. roomPaddingHeight += (parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-top'), 10) + parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-bottom'), 10));
  631. roomPaddingWidth += (parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-left'), 10) + parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-right'), 10));
  632. }
  633. scaler.mf = document.querySelector('img.main-photo');
  634. scaler.lrf = document.querySelector('img.low-res-photo');
  635. // var zl = document.querySelector('img.zoom-large'); // currently not used
  636. // var zs = document.querySelector('img.zoom-small'); // currently not used
  637. if (scaler.mf) {
  638. log('[scaler] main-photo: h=' + scaler.mf.height + ', w=' + scaler.mf.width + '. - Room: (h=' + (roomHeight - roomPaddingHeight) + ',w=' + (roomWidth - roomPaddingWidth) + ')');
  639. if (roomPaddingWidth === 0) { // hack
  640. roomPaddingWidth = 120;
  641. log('[scaler] roomPaddingWidth=120 hack used');
  642. }
  643. if (((roomHeight - roomPaddingHeight) > scaler.mf.height + 5) && ((roomWidth - roomPaddingWidth) > scaler.mf.width + 5)) {
  644. log('[scaler] ALLRIGHT - WE ARE READY FOR SCALING!...');
  645. if (((roomHeight - roomPaddingHeight) / scaler.mf.height) < ((roomWidth - roomPaddingWidth) / scaler.mf.width)) {
  646. scaler.scaleToWidth = Math.floor(scaler.mf.width * ((roomHeight - roomPaddingHeight) / scaler.mf.height));
  647. scaler.scaleToHeight = roomHeight - roomPaddingHeight;
  648. } else {
  649. scaler.scaleToHeight = Math.floor(scaler.mf.height * ((roomWidth - roomPaddingWidth) / scaler.mf.width));
  650. scaler.scaleToWidth = roomWidth - roomPaddingWidth;
  651. }
  652. log('[scaler] now calling scale()... [' + scaler.scaleToWidth + ', ' + scaler.scaleToWidth + ']');
  653. scale();
  654. log('[scaler] ...AND CONTINUE LOOKING FOR ORIGINAL...');
  655. if (dpev) { // if (document.querySelector('ul.sizes'))
  656. var org = document.querySelector('ul.sizes li.Original a.download-image-size');
  657. if (org) { // når vi bladrer?
  658. scaler.hasOriginal = true; // ??? kun hvis original
  659. scaler.maxSizeUrl = (org.href).replace(/^https\:/i, '').replace(/_d\./i, '.');
  660. replace();
  661. } else {
  662. // vi kan finde original "inline"
  663. var target = document.querySelector('div.photo-engagement-view');
  664. // if(!target) return; ???
  665. if (target) {
  666. var observer = new MutationObserver(function (mutations) {
  667. mutations.forEach(function (mutation) {
  668. log('[scaler] MO size: ' + mutation.type); // might check for specific "mutations"?
  669. });
  670. var org = document.querySelector('ul.sizes li.Original a.download-image-size');
  671. if (org) {
  672. scaler.hasOriginal = true; // ??? kun hvis original
  673. scaler.maxSizeUrl = (org.href).replace(/^https\:/i, '').replace(/_d\./i, '.');
  674. replace();
  675. } else {
  676. scale(); // ???
  677. log('Original photo not available for download on this photographer');
  678. }
  679. observer.disconnect();
  680. });
  681. // configuration of the observer:
  682. var config = {attributes: false, childList: true, subtree: false, characterData: false};
  683. observer.observe(target, config);
  684. }
  685. }
  686. } else {
  687. getSizes(); // resize (& replace) from/when size-list
  688. }
  689. }
  690. }
  691. scaler.postAction('notes on unscaled photo'); // look for notes (not (yet?) scaled)
  692. }
  693. };
  694.  
  695. function insertStyle() {
  696. if (!document.getElementById('fixrStyle')) {
  697. var style = document.createElement('style');
  698. style.type = 'text/css';
  699. style.id = 'fixrStyle';
  700. style.innerHTML = 'ul.tags-list>li.tag>a.fixrTag,ul.tags-list>li.autotag>a.fixrTag{display:none;} ul.tags-list>li.tag:hover>a.fixrTag,ul.tags-list>li.autotag:hover>a.fixrTag{display:inline;} .album-map-icon{background:url("https://c2.staticflickr.com/6/5654/23426346485_334afa6e8f_o_d.png") no-repeat;height:21px;width:24px;top:6px;left:3px} .album-comments-icon{background:url("https://s.yimg.com/uy/build/images/icons-1x-s2fb29ad15b.png") -32px -460px no-repeat;height:21px;width:24px;top:6px;left:3px} .notebrd1{position:absolute;border:1px solid #000;color:#FFF;z-index:1000;margin:0;padding:0;display:none;} .notebrd2{border:1px solid #FFF;z-index:1000;margin:0;padding:0;display:none;} .shownotes .notebrd1{display:block;} .shownotes .notebrd2{display:block;} .photo-well-media-scrappy-view:hover .notebrd1{display:block;} .photo-well-media-scrappy-view:hover .notebrd2{display:block;} .notebrd2:hover{border:1px solid #FF0;}';
  701. // style.innerHTML = 'ul.tags-list>li.tag>a.fixrTag,ul.tags-list>li.autotag>a.fixrTag{display:none;} ul.tags-list>li.tag:hover>a.fixrTag,ul.tags-list>li.autotag:hover>a.fixrTag{display:inline;} .album-map-icon{background:url("https://c2.staticflickr.com/6/5654/23426346485_334afa6e8f_o_d.png") no-repeat;height:21px;width:24px;top:6px;left:3px} .album-comments-icon{background:url("https://s.yimg.com/uy/build/images/icons-1x-s2fb29ad15b.png") -32px -460px no-repeat;height:21px;width:24px;top:6px;left:3px}';
  702. document.getElementsByTagName('head')[0].appendChild(style);
  703. log('fixrStyle has been ADDED');
  704. } else {
  705. log('fixrStyle was already present');
  706. }
  707. }
  708. function albumExtras() { // links to album's map and comments
  709. if (fixr.context.pageType !== 'ALBUM') {
  710. return; // exit if not albumpage
  711. }
  712. if (fixr.context.albumId) {
  713. log('albumsExtra() med album=' + fixr.context.albumId);
  714. } else {
  715. log('Exit albumsExtra(). Mangler albumId');
  716. return;
  717. }
  718. var elist = document.querySelector('div.album-engagement-view');
  719. if (elist) {
  720. // map-link:
  721. var mapdiv = document.createElement('div');
  722. mapdiv.className = 'create-book-container';
  723. mapdiv.title = 'Album on map';
  724. mapdiv.style.textAlign = 'center';
  725. mapdiv.innerHTML = '<a href="/photos/' + fixr.context.photographerAlias + '/albums/' + fixr.context.albumId + '/map/" style="font-size:14px;color:#FFF;"><span title="Album on map" class="album-map-icon"></span></a>';
  726. elist.appendChild(mapdiv);
  727. // comments-link:
  728. var comurl = '/photos/' + fixr.context.photographerAlias + '/albums/' + fixr.context.albumId + '/comments/';
  729. var cmdiv = document.createElement('div');
  730. cmdiv.className = 'create-book-container';
  731. cmdiv.title = 'Comments';
  732. cmdiv.style.textAlign = 'center';
  733. cmdiv.innerHTML = '<a href="' + comurl + '" style="font-size:14px;color:#FFF;"><span title="Album comments" class="album-comments-icon" id="albumCommentCount"></span></a>';
  734. elist.appendChild(cmdiv);
  735. updateAlbumCommentCount();
  736. }
  737. }
  738. function updateTags() {
  739. if (fixr.context.pageType !== 'PHOTOPAGE') {
  740. return; // exit if not photopage
  741. }
  742. log('updateTags()');
  743. if (document.querySelector('ul.tags-list')) {
  744. var tags = document.querySelectorAll('ul.tags-list>li');
  745. if (tags && tags !== null && tags.length > 0) {
  746. for (var i = 0; i < tags.length; i++) {
  747. var atag = tags[i].querySelector('a[title][href*="?tags="],a[title][href*="?q="]');
  748. if (atag) {
  749. var realtag = (atag.href.match(/\?(tags|q)\=([\S]+)$/i))[2];
  750. if (!(tags[i].querySelector('a.fixrTag'))) {
  751. //log('updateTags() '+i+' fixr.context.photographerIcon: '+fixr.context.photographerIcon);
  752. var icon = fixr.context.photographerIcon.match(/^([^_]+)(_\w)?\.[jpgntif]{3,4}$/)[1] + '' + fixr.context.photographerIcon.match(/^[^_]+(_\w)?(\.[jpgntif]{3,4})$/)[2]; // do we know for sure it is square?
  753. //log('updateTags() '+i+' icon: '+icon); //
  754. tags[i].insertAdjacentHTML('afterbegin', '<a class="fixrTag" href="/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/tags/' + realtag + '/" title="' + atag.title + ' by ' + fixr.context.photographerName + '"><img src="' + icon + '" style="width:1em;height:1em;margin:0;padding:0;position:relative;top:3px" alt="*" /></a>');
  755. }
  756. }
  757. }
  758. } else {
  759. log('no tags defined (yet?)');
  760. }
  761. } else {
  762. log('taglist container not found');
  763. }
  764. }
  765. function updateTagsDelayed() {
  766. if (fixr.context.pageType !== 'PHOTOPAGE') {
  767. return; // exit if not photopage
  768. }
  769. log('updateTagsDelayed() running... with pageType=' + fixr.context.pageType);
  770. //clearTimeout(_timerMaplink);
  771. if (fixr.context.pageType === 'PHOTOPAGE') {
  772. setTimeout(updateTags, 2500);
  773. }
  774. }
  775.  
  776. function showNotes() {
  777. var container = document.querySelector('div.photo-well-media-scrappy-view');
  778. if (container && container.classList) {
  779. container.classList.add('shownotes');
  780. }
  781. }
  782.  
  783. function hideNotes() {
  784. var container = document.querySelector('div.photo-well-media-scrappy-view');
  785. if (container && container.classList) {
  786. container.classList.remove('shownotes');
  787. }
  788. }
  789.  
  790. var photoInfo = { // cache albums to avoid repeating requests
  791. photoId: '',
  792. notes: [],
  793. json: ''
  794. };
  795. function renderNotes(notes) {
  796. var scalefactor = 1;
  797. if (parseInt(document.querySelector('img.main-photo').getAttribute('width'),10)>=parseInt(document.querySelector('img.main-photo').getAttribute('height'),10)) {
  798. scalefactor = parseInt(document.querySelector('img.main-photo').getAttribute('width'),10)/500;
  799. } else {
  800. scalefactor = parseInt(document.querySelector('img.main-photo').getAttribute('height'),10)/500;
  801. }
  802.  
  803. // Slet alle eksisterende noter først (kan blive genereret multiple gange ved skalering)
  804. var oldnode = document.querySelector('div.notebrd1');
  805. while (oldnode && oldnode.parentNode) {
  806. oldnode.parentNode.removeChild(oldnode);
  807. oldnode = document.querySelector('div.notebrd1');
  808. }
  809.  
  810. // log(''+parseInt(document.querySelector('img.main-photo').getAttribute('width'),10)+'px wide photo has scalefactor='+scalefactor);
  811. for (var i=0; i<photoInfo.notes.length; i++) // notes=obj.photo.notes.note
  812. {
  813. var n = photoInfo.notes[i];
  814. // log('Note: id=' + n.id + ', author=' + n.author + ', authorname=' + n.authorname + ', x=' + n.x + ', y=' + n.y + ', w=' + n.w + ', h=' + n.h + ', _content=' + n._content + '.');
  815. // log('You might see note at: http://dh.elsewhere.org/mbedr/?p=' + photoId + '&fmt=Medium&v');
  816. // test:
  817. // document.querySelector('div.photo-well-media-scrappy-view').style.position="relative"; // 50px padding tilføjes til top px:
  818. var div = document.createElement('div');
  819. div.innerHTML = n._content;
  820. document.querySelector('div.photo-well-media-scrappy-view').insertAdjacentHTML('afterbegin', '<div class="notebrd1" style="width:' + Math.floor(parseInt(n.w, 10) * scalefactor) + 'px;height:' + Math.floor(parseInt(n.h, 10) * scalefactor) + 'px;top:' + (50 + Math.floor(parseInt(n.y, 10) * scalefactor)) + 'px;left:' + Math.floor(parseInt(n.x, 10) * scalefactor) + 'px;" title="' + div.textContent + '\n - ' + n.authorname + '"><div class="notebrd2" style="height:' + (Math.floor(parseInt(n.h, 10) * scalefactor)-2) + 'px;width:' + (Math.floor(parseInt(n.w, 10) * scalefactor)-2) + 'px;"></div></div>');
  821. // document.querySelector('div.photo-well-media-scrappy-view').insertAdjacentHTML('afterbegin', '<div style="position:absolute;width:' + Math.floor(parseInt(n.w, 10) * scalefactor) + 'px;height:' + Math.floor(parseInt(n.h, 10) * scalefactor) + 'px;border:1px solid #000;top:' + (50 + Math.floor(parseInt(n.y, 10) * scalefactor)) + 'px;left:' + Math.floor(parseInt(n.x, 10) * scalefactor) + 'px;color:#FFF;z-index:1000;margin:0;padding:0" title="' + div.textContent + ' - ' + n.authorname + '"><div style="border:1px solid #FFF;z-index:1000;margin:0;padding:0;height:' + (Math.floor(parseInt(n.h, 10) * scalefactor)-2) + 'px;width:' + (Math.floor(parseInt(n.w, 10) * scalefactor)-2) + 'px;"></div></div>');
  822. }
  823. showNotes();
  824. setTimeout(hideNotes, 800);
  825. }
  826. // Call Flickr REST API to get photo info incl. eventual photo-notes:
  827. var _wsGetPhotoInfoLock = 0; // Date.now();
  828. function wsGetPhotoInfo() {
  829. var diff = 0+Date.now()-_wsGetPhotoInfoLock;
  830. if ((_wsGetPhotoInfoLock>0) && (diff<100)) {
  831. log('Skipping wsGetPhotoInfo() because already running?: '+diff);
  832. return;
  833. }
  834.  
  835. var _reqGetPhotoInfo = null;
  836. if (window.XMLHttpRequest) {
  837. _reqGetPhotoInfo = new XMLHttpRequest();
  838. if (typeof _reqGetPhotoInfo.overrideMimeType !== 'undefined') {
  839. _reqGetPhotoInfo.overrideMimeType('application/json');
  840. }
  841. _reqGetPhotoInfo.onreadystatechange = function () {
  842. if (_reqGetPhotoInfo.readyState === 4 && _reqGetPhotoInfo.status === 200) {
  843. // do something with the results
  844. log('webservice photos.getInfo returned status=' + _reqGetPhotoInfo.status);
  845. // log('webservice photos.getInfo returned status=' + _reqGetPhotoInfo.status + ', text: ' + _reqGetPhotoInfo.responseText);
  846.  
  847. photoInfo.photoId = fixr.context.photoId;
  848. photoInfo.json = _reqGetPhotoInfo.responseText;
  849. photoInfo.notes = [];
  850.  
  851. var obj = JSON.parse(_reqGetPhotoInfo.responseText);
  852. if (obj.stat === "ok") {
  853. log("ok");
  854. if (obj.photo && obj.photo.notes && obj.photo.notes && obj.photo.notes.note && obj.photo.notes.note.length > 0) {
  855. log("looks like there are " + obj.photo.notes.note.length + " notes on this photo");
  856.  
  857. photoInfo.notes = obj.photo.notes.note;
  858. renderNotes();
  859.  
  860. } else {
  861. log('No notes or not accessible');
  862. }
  863. }
  864. _wsGetPhotoInfoLock = 0;
  865. } else {
  866. // wait for the call to complete
  867. }
  868. };
  869.  
  870. _wsGetPhotoInfoLock = Date.now();
  871. _reqGetPhotoInfo.open('GET', 'https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=9b8140dc97b93a5c80751a9dad552bd4&photo_id=' + fixr.context.photoId + '&format=json&nojsoncallback=1', true);
  872. _reqGetPhotoInfo.send(null);
  873.  
  874. } else {
  875. log('understøtter ikke XMLHttpRequest');
  876. }
  877. }
  878. function getNotes(logtext) {
  879. if (fixr.context.pageType === 'PHOTOPAGE') {
  880. log("getNotes(): " + fixr.context.photoId + ( logtext ? ': ' + logtext : '' ));
  881. if (fixr.context.photoId) {
  882. if (fixr.context.photoId === photoInfo.photoId) {
  883. log('render cached notes');
  884. renderNotes();
  885. } else {
  886. log('render notes via flickr.photos.getInfo');
  887. wsGetPhotoInfo(); // wsGetPhotoInfo also calls renderNotes()
  888. }
  889. }
  890. }
  891. }
  892.  
  893.  
  894. scaler.postAction = getNotes; // look for notes after scaling
  895. // FIXR fixr.init(onPageHandlers, onResizeHandlers)
  896. fixr.init([scaler.run, insertStyle, albumExtras, albumTeaserDelayed, updateMapLinkDelayed, updateTagsDelayed], [scaler.run]);
  897.  
  898.  
  899. /* OLD STUFF... CURRENTLY NOT USED: */
  900.  
  901.  
  902. /*
  903. // Call Flickr REST API to get available photo sizes - Method currently NOT USED:
  904. function wsGetSizes(photoId) {
  905. var _reqGetSizes = null;
  906. if (window.XMLHttpRequest) {
  907. _reqGetSizes = new XMLHttpRequest();
  908. if (typeof _reqGetSizes.overrideMimeType !== 'undefined') {
  909. _reqGetSizes.overrideMimeType('application/json');
  910. }
  911. _reqGetSizes.onreadystatechange = function () {
  912. if (_reqGetSizes.readyState === 4 && _reqGetSizes.status === 200) {
  913. // do something with the results
  914. // var myObj = eval ( _reqGetSizes.responseText );
  915. log('webservice photos.getSizes returned status=' + _reqGetSizes.status + ', text: ' + _reqGetSizes.responseText);
  916. var obj = JSON.parse(_reqGetSizes.responseText);
  917. if (obj.stat === "ok") {
  918. log("ok");
  919. if (obj.sizes.candownload == 1) {
  920. log("can download");
  921. var array = obj.sizes.size;
  922. if (array && array.length > 0) {
  923. log("array length=" + array.length);
  924. var elem = array[array.length - 1];
  925. if (elem) {
  926. log("last elem is: " + elem.label + " with source=" + elem.source);
  927. if (elem.label === "Original" && elem.source && elem.source.length > 0) {
  928. // make sure photoId matches source
  929. photoOrg(elem.source);
  930. log("Original from webservice was used");
  931. }
  932. }
  933. }
  934. } else {
  935. log('Originals not available on user');
  936. }
  937. }
  938. // Hvis sizeList && original tilgængelig
  939. // photoOrg(url); // Update image now!!!
  940. // ellers hvis sizelist
  941. // log('Originals not available on user');
  942. // ellers hvis sizelist
  943. // log('Error fetching original');
  944. } else {
  945. // wait for the call to complete
  946. }
  947. };
  948.  
  949. _reqGetSizes.open('GET', 'https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=9b8140dc97b93a5c80751a9dad552bd4&photo_id=' + photoId + '&format=json&nojsoncallback=1', true);
  950. _reqGetSizes.send(null);
  951.  
  952. } else {
  953. log('understøtter ikke XMLHttpRequest');
  954. }
  955. }
  956.  
  957. // Call Flickr REST API to get albums - Method currently NOT USED:
  958. function wsGetAlbums() {
  959. var _reqGetAlbums = null;
  960. if (window.XMLHttpRequest) {
  961. _reqGetAlbums = new XMLHttpRequest();
  962. if (typeof _reqGetAlbums.overrideMimeType != 'undefined') {
  963. _reqGetAlbums.overrideMimeType('application/json');
  964. }
  965. _reqGetAlbums.onreadystatechange = function () {
  966. if (_reqGetAlbums.readyState == 4 && _reqGetAlbums.status == 200) {
  967. log('Webservice photosets.getList returned status=' + _reqGetAlbums.status + _reqGetAlbums.responseText);
  968. var obj = JSON.parse(_reqGetAlbums.responseText);
  969. if (obj && obj.stat == "ok") {
  970. log("ok");
  971. albums.ownerId = fixr.context.photographerId;
  972. albums.set = [];
  973. albums.html = '';
  974. albums.pathalias = '';
  975. if (obj.photosets) {
  976. if (parseInt(obj.photosets.total, 10) === 0) {
  977. // keep empty
  978. } else if (obj.photosets.photoset) {
  979. albums.set = obj.photosets.photoset;
  980. var elem;
  981. for (var i = 0; i < obj.photosets.photoset.length; i++) {
  982. elem = obj.photosets.photoset[i]; // should loop through multiple
  983. log("elem is: " + elem.id + " with title=" + elem.title._content);
  984. if (elem.primary_photo_extras && elem.primary_photo_extras.url_sq && elem.primary_photo_extras.url_sq.length > 0) {
  985. log('photoset ikon url = ' + elem.primary_photo_extras.url_sq);
  986. albums.html += '<div><a href="//www.flickr.com/photos/' + elem.primary_photo_extras.pathalias + '/sets/' + elem.id + '"><img src="' + elem.primary_photo_extras.url_sq + '" alt="" /><div style="margin:0 0 .8em 0">' + elem.title._content + '</div></a></div>';
  987. }
  988. }
  989. albums.pathalias = elem.primary_photo_extras.pathalias;
  990. } else {
  991. log('why are we here?');
  992. }
  993. }
  994. } else {
  995. // error parse
  996. }
  997. document.getElementById('albumTeaser').innerHTML = '<div style="margin:0 0 .8em 0">Albums</div>' + albums.html + '<div><i><a href="/photos/' + albums.pathalias + '/albums/">More albums...</a></i></div>';
  998. } else {
  999. // wait for the call to complete
  1000. }
  1001. };
  1002. if (fixr.context.photographerId === albums.ownerId && fixr.context.photographerId != '') {
  1003. // use cached
  1004. document.getElementById('albumTeaser').innerHTML = '<div style="margin:0 0 .8em 0">Albums</div>' + albums.html + '<div><i><a href="/photos/' + albums.pathalias + '/albums/">More albums...</a></i></div>';
  1005. log('Using CACHED albumlist!');
  1006. } else if (fixr.context.photographerId) {
  1007. _reqGetAlbums.open('GET', 'https://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=9b8140dc97b93a5c80751a9dad552bd4&user_id=' + fixr.context.photographerId + '&page=1&per_page=10&primary_photo_extras=geo%2C+path_alias%2C+url_sq&format=json&nojsoncallback=1', true);
  1008. _reqGetAlbums.send(null);
  1009. } else {
  1010. log('Attribution user (photographer) not found');
  1011. }
  1012. } else {
  1013. log('Understøtter ikke XMLHttpRequest');
  1014. }
  1015. }
  1016. */