My static website generator using poole https://www.xythobuz.de
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

flickr.source.js 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*!
  2. * Yox Flickr plugin
  3. * http://yoxigen.com/yoxview/
  4. *
  5. * Copyright (c) 2010 Yossi Kolesnicov
  6. *
  7. * Licensed under the MIT license.
  8. * http://www.opensource.org/licenses/mit-license.php
  9. *
  10. * Date: 17th July, 2010
  11. * Version : 1.6
  12. */
  13. function yox_flickr()
  14. {
  15. var $ = jQuery,
  16. flickrUrl = "http://www.flickr.com/",
  17. flickrApiUrl = "http://api.flickr.com/services/rest/",
  18. yoxviewFlickrApikey = "cd6c91f9721f34ead20e6ebe03dd5871",
  19. flickrUserIdRegex = /\d+@N\d+/,
  20. flickrUrlRegex = /http:\/\/(?:www\.)?flickr\.com\/(\w+)\/(?:([^\/]+)\/(?:(\w+)\/?(?:([^\/]+)\/?)?)?)?(?:\?(.*))?/,
  21. self = this,
  22. fixedOptions = {
  23. api_key: yoxviewFlickrApikey,
  24. format: 'json'
  25. };
  26. this.getImagesData = function(options, callback)
  27. {
  28. var defaults = {
  29. imageSize: "medium", // medium/large/original, for large, your images in Flickr must be 1280 in width or more. For original, you must allow originals to be downloaded
  30. thumbsize: "smallSquare",
  31. setThumbnail: true,
  32. setSinglePhotosetThumbnails: true,
  33. setTitle: true,
  34. method: 'flickr.photosets.getList',
  35. extras: 'description'
  36. };
  37. var requireLookup = true;
  38. var lookupData = {
  39. method: "flickr.urls.lookupUser",
  40. onData: function(data)
  41. {
  42. return {
  43. user_id: data.user.id,
  44. username: data.user.username._content
  45. };
  46. }
  47. };
  48. var fromDataUrl = {};
  49. if (options.dataUrl)
  50. {
  51. var urlMatch = options.dataUrl.match(flickrUrlRegex);
  52. var queryData;
  53. if (urlMatch[5])
  54. {
  55. queryData = Yox.queryToJson(urlMatch[5]);
  56. $.extend(fromDataUrl, queryData);
  57. }
  58. if (urlMatch && urlMatch.length > 1)
  59. {
  60. if (urlMatch[1] == "search")
  61. {
  62. fromDataUrl.method = "flickr.photos.search";
  63. fromDataUrl.text = queryData.q;
  64. if (queryData.w)
  65. {
  66. queryData.w = queryData.w.replace("%40", "@");
  67. if (queryData.w.match(flickrUserIdRegex))
  68. fromDataUrl.user_id = queryData.w;
  69. }
  70. if (!queryData || !queryData.sort)
  71. fromDataUrl.sort = "relevance";
  72. requireLookup = false;
  73. }
  74. else
  75. {
  76. switch(urlMatch[3])
  77. {
  78. case undefined:
  79. fromDataUrl.method = "flickr.people.getPublicPhotos";
  80. break;
  81. case "sets":
  82. $.extend(fromDataUrl, {
  83. method: urlMatch[4] || options.dataSourceOptions.photoset_id ? "flickr.photosets.getPhotos" : "flickr.photosets.getList",
  84. photoset_id: urlMatch[4]
  85. });
  86. break;
  87. case "galleries":
  88. $.extend(fromDataUrl, {
  89. method: urlMatch[4] ? "flickr.galleries.getPhotos" : "flickr.galleries.getList",
  90. gallery_id: urlMatch[4]
  91. });
  92. if (urlMatch[4])
  93. {
  94. requireLookup = true;
  95. lookupData = {
  96. method: "flickr.urls.lookupGallery",
  97. onData: function(data)
  98. {
  99. return {
  100. gallery_id: data.gallery.id,
  101. title: data.gallery.title
  102. };
  103. }
  104. };
  105. }
  106. break;
  107. case "collections":
  108. $.extend(fromDataUrl, {
  109. method: "flickr.collections.getTree",
  110. collection_id: urlMatch[4]
  111. });
  112. break;
  113. default:
  114. fromDataUrl.method = "flickr.photos.search";
  115. break;
  116. }
  117. $.extend(fromDataUrl, {
  118. username: urlMatch[2],
  119. type: urlMatch[3]
  120. });
  121. }
  122. }
  123. }
  124. var datasourceOptions = jQuery.extend({}, defaults, fromDataUrl, options.dataSourceOptions, fixedOptions);
  125. datasourceOptions.media = "photos";
  126. if (datasourceOptions.user && datasourceOptions.photoset_id)
  127. datasourceOptions.method = "flickr.photosets.getPhotos";
  128. var screenSize = screen.width > screen.height ? screen.width : screen.height;
  129. // Save resources for smaller screens:
  130. if (!datasourceOptions.imageSize || (screenSize.width <= 800 && datasourceOptions.imageSize != "medium"))
  131. datasourceOptions.imageSize = "medium";
  132. if (requireLookup)
  133. {
  134. $.jsonp({
  135. url: flickrApiUrl,
  136. async: false,
  137. dataType: 'jsonp',
  138. data: $.extend({ url: options.dataUrl, method: lookupData.method }, fixedOptions),
  139. callbackParameter: "jsoncallback",
  140. success: function(data)
  141. {
  142. $.extend(datasourceOptions, lookupData.onData(data));
  143. getData();
  144. }
  145. });
  146. }
  147. else
  148. getData();
  149. function getData()
  150. {
  151. var returnData = {};
  152. if (options.onLoadBegin)
  153. options.onLoadBegin();
  154. $.jsonp({
  155. url: flickrApiUrl,
  156. async: false,
  157. dataType: 'jsonp',
  158. data: datasourceOptions,
  159. callbackParameter: "jsoncallback",
  160. success: function(data)
  161. {console.log(data);
  162. returnData.images = self.getImagesDataFromJson(data, datasourceOptions);
  163. if (data.photosets || data.collections)
  164. $.extend(returnData, {
  165. createGroups: true
  166. });
  167. if (returnData.images.length > 0 && ((datasourceOptions.setThumbnail && !datasourceOptions.setSinglePhotosetThumbnails) || options.isSingleLink))
  168. {
  169. $.extend(returnData, {
  170. isGroup: true,
  171. link: getPhotosetUrl(data.photoset.owner, data.photoset.id),
  172. thumbnailSrc: options.isSingleLink ? undefined : getImageUrl(data.photoset.photo[0], flickrImageSizes[datasourceOptions.thumbsize]),
  173. title: "None"
  174. });
  175. }
  176. if (callback)
  177. callback(returnData);
  178. if (options.onLoadComplete)
  179. options.onLoadComplete();
  180. },
  181. error : function(xOptions, textStatus){
  182. if (options.onLoadError)
  183. options.onLoadError("Flickr plugin encountered an error while retrieving data");
  184. }
  185. });
  186. }
  187. }
  188. var flickrImageSizes = {
  189. smallSquare : "_s", // 75x75
  190. thumbnail : "_t", // 100px
  191. small : "_m", // 240px
  192. medium : "", // 500px
  193. large : "_b", // 1024px
  194. original : "_o"
  195. };
  196. function getImageUrl(photoData, size)
  197. {
  198. return "http://farm" + photoData.farm + ".static.flickr.com/" + photoData.server + "/" + (photoData.primary || photoData.id) + "_" + photoData.secret + size + ".jpg";
  199. }
  200. function getPhotosetUrl(userid, photosetId)
  201. {
  202. return prepareUrl(flickrUrl + "photos/" + userid + "/sets/" + photosetId + "/");
  203. }
  204. // makes sure a string can be used as a Flickr url
  205. function prepareUrl(url)
  206. {
  207. return url.replace(/\s/g, "_");
  208. }
  209. this.getImagesDataFromJson = function(data, datasourceOptions)
  210. {
  211. var isPhotos = data.photoset || data.photos;
  212. var photos;
  213. if (isPhotos)
  214. photos = data.photoset ? data.photoset.photo : data.photos.photo;
  215. else if (data.photosets)
  216. photos = data.photosets.photoset;
  217. else if (data.collections)
  218. photos = data.collections.collection[0].set;
  219. var imagesData = [];
  220. var inSet = data.photoset ? "/in/set-" + data.photoset.id : "";
  221. // Photos:
  222. if (photos)
  223. {
  224. var thumbSuffix = flickrImageSizes[datasourceOptions.thumbsize];
  225. var imageSuffix = flickrImageSizes[datasourceOptions.imageSize];
  226. jQuery.each(photos, function(i, photo){
  227. var imageData = {
  228. thumbnailSrc : getImageUrl(photo, thumbSuffix),
  229. link: prepareUrl(flickrUrl + "photos/" + (photo.owner || datasourceOptions.user_id) + "/" + photo.id + inSet),
  230. media: {
  231. src: getImageUrl(photo, imageSuffix),
  232. title: isPhotos ? photo.title : photo.title._content + (!isPhotos ? " (" + photo.photos + " images)" : ""),
  233. alt: photo.title._content || photo.title,
  234. description: photo.description ? photo.description._content : undefined
  235. }
  236. };
  237. if (!isPhotos)
  238. imageData.data = { photoset_id: photo.id };
  239. imagesData.push(imageData);
  240. });
  241. }
  242. return imagesData;
  243. }
  244. }