My static website generator using poole https://www.xythobuz.de
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

picasa.source.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*!
  2. * Yox Picasa 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: 13th November, 2010
  11. * Version : 1.55
  12. */
  13. function yox_picasa()
  14. {
  15. var $ = jQuery;
  16. var picasaRegex = /http:\/\/picasaweb\.google\.\w+\/([^\/#\?]+)\/?([^\/#\?]+)?(\?([^#]*))?/
  17. var self = this;
  18. this.getImagesData = function(options, callback)
  19. {
  20. var defaults = {
  21. url: "http://picasaweb.google.com/data/feed/api/",
  22. setThumbnail: true,
  23. setSingleAlbumThumbnails: true,
  24. setTitle: true, // Whether to add a header with user and/or album name before thumbnails
  25. alt: 'json',
  26. thumbsize: 64
  27. },
  28. picasaThumbnailSizes = [32, 48, 64, 72, 104, 144, 150, 160],
  29. picasaImgMaxSizes = [94, 110, 128, 200, 220, 288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600],
  30. fromDataUrl = {};
  31. function getFeedUrl()
  32. {
  33. var feedUrl = datasourceOptions.url;
  34. if (datasourceOptions.user && datasourceOptions.user != "lh")
  35. {
  36. feedUrl += "user/" + datasourceOptions.user;
  37. if (datasourceOptions.album)
  38. feedUrl += "/album/" + datasourceOptions.album;
  39. }
  40. else
  41. feedUrl += "all";
  42. return feedUrl;
  43. }
  44. function picasa_getMaxSize(size, sizesArray, roundSizeUp)
  45. {
  46. size = parseInt(size);
  47. for(var i=sizesArray.length - 1; i >= 0; i--)
  48. {
  49. var pSize = sizesArray[i];
  50. if (size >= pSize)
  51. return roundSizeUp
  52. ? i < sizesArray.length - 1 ? sizesArray[i + 1] : pSize
  53. : pSize;
  54. }
  55. return size;
  56. }
  57. function getImagesDataFromJson(data, kind)
  58. {
  59. var entry = data.feed.entry;
  60. var isAlbum = kind === "album";
  61. var imagesData = [];
  62. jQuery.each(data.feed.entry, function(i, image){
  63. var imageTitle = isAlbum ? image.title.$t + " (" + image.gphoto$numphotos.$t + " images)" : image.summary.$t;
  64. if (!datasourceOptions.filter || imageTitle.match(datasourceOptions.filter))
  65. {
  66. var mediaData = image.media$group.media$content[0];
  67. var imageData = {
  68. thumbnailSrc : image.media$group.media$thumbnail[1].url,
  69. link: image.link[1].href,
  70. media: {
  71. src: mediaData.url,
  72. title: imageTitle,
  73. alt: imageTitle,
  74. width: mediaData.width,
  75. height: mediaData.height
  76. }
  77. };
  78. if (isAlbum)
  79. imageData.data = { album: image.gphoto$name.$t };
  80. imagesData.push(imageData);
  81. }
  82. });
  83. if (fromDataUrl.filter)
  84. {
  85. var dataUrlObj = Yox.getUrlData(options.dataUrl);
  86. delete dataUrlObj.queryFields.filter;
  87. options.dataUrl = Yox.urlDataToPath(dataUrlObj);
  88. }
  89. if (options.dataSourceOptions && options.dataSourceOptions.filter)
  90. delete options.dataSourceOptions.filter;
  91. return imagesData;
  92. }
  93. if (options.dataUrl)
  94. {
  95. var urlMatch = options.dataUrl.match(picasaRegex);
  96. if (urlMatch && urlMatch.length > 1)
  97. {
  98. fromDataUrl.user = urlMatch[1];
  99. if (urlMatch[2])
  100. fromDataUrl.album = urlMatch[2]
  101. if (urlMatch[4])
  102. $.extend(fromDataUrl, Yox.queryToJson(urlMatch[4]));
  103. }
  104. }
  105. var datasourceOptions = jQuery.extend({}, defaults, fromDataUrl, options.dataSourceOptions);
  106. if (datasourceOptions.user && !datasourceOptions.album && !datasourceOptions.q)
  107. datasourceOptions.thumbsize = 104;
  108. // Picasa web uses 'tags', while the API uses 'tag':
  109. if (datasourceOptions.tags)
  110. datasourceOptions.tag = datasourceOptions.tags;
  111. if (datasourceOptions.album == "")
  112. delete datasourceOptions.album;
  113. var screenSize = screen.width > screen.height ? screen.width : screen.height;
  114. var unknownSize = datasourceOptions.imgmax && $.inArray(datasourceOptions.imgmax, picasaImgMaxSizes) == -1 ? datasourceOptions.imgmax : null;
  115. // Save resources for smaller screens:
  116. if (!datasourceOptions.imgmax || unknownSize || screenSize < datasourceOptions.imgmax)
  117. datasourceOptions.imgmax = picasa_getMaxSize(unknownSize || screenSize, picasaImgMaxSizes, datasourceOptions.roundSizeUp);
  118. if (datasourceOptions.filter){
  119. if (typeof datasourceOptions.filter === "string")
  120. datasourceOptions.filter = new RegExp(datasourceOptions.filter, "i");
  121. }
  122. var feedUrl = getFeedUrl(datasourceOptions);
  123. var returnData = {};
  124. if (options.onLoadBegin)
  125. options.onLoadBegin();
  126. $.jsonp({
  127. url: feedUrl,
  128. async: false,
  129. dataType: 'jsonp',
  130. data: datasourceOptions,
  131. callbackParameter: "callback",
  132. success: function(data)
  133. {console.log(data);
  134. if (!data.feed.entry || data.feed.entry.length == 0)
  135. {
  136. if (options.onNoData)
  137. options.onNoData();
  138. return;
  139. }
  140. var kind = data.feed.entry[0].category[0].term.match(/.*#(.*)/)[1]; // album or photo
  141. if (kind === "album")
  142. $.extend(returnData, {
  143. title: data.feed.title.$t,
  144. createGroups: true
  145. });
  146. returnData.images = getImagesDataFromJson(data, kind);
  147. if (data.feed.title)
  148. returnData.title = data.feed.title.$t;
  149. if (returnData.images.length > 0 && datasourceOptions.setThumbnail && !datasourceOptions.setSingleAlbumThumbnails)
  150. {
  151. $.extend(returnData, {
  152. isGroup: true,
  153. link: data.feed.link[1].href,
  154. thumbnailSrc: data.feed.icon.$t,
  155. title: data.feed.title.$t
  156. });
  157. }
  158. if (callback)
  159. callback(returnData);
  160. if (options.onLoadComplete)
  161. options.onLoadComplete();
  162. },
  163. error : function(xOptions, textStatus){
  164. if (options.onLoadError)
  165. options.onLoadError("Picasa plugin encountered an error while retrieving data");
  166. }
  167. });
  168. }
  169. }