PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/1.3/source/raw/api/core/ajax/jsonp.html

https://github.com/kissyteam/kissyteam.github.com
HTML | 68 lines | 60 code | 8 blank | 0 comment | 0 complexity | 523fff768bfdfe2fc2fa6b976e9d8c7a MD5 | raw file
Possible License(s): Apache-2.0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. button { margin:10px; }
  6. div { color:blue; font-weight:bold; }
  7. span { color:red; }
  8. .loading {
  9. background: url("http://img02.taobaocdn.com/tps/i2/T16WJqXaXeXXXXXXXX-32-32.gif") no-repeat scroll 50% 50% transparent;
  10. width: 100px;
  11. height: 100px !important;
  12. margin: 20px;
  13. }
  14. </style>
  15. <script src="http://g.tbcdn.cn/kissy/k/1.3.2/seed.js" data-config="{combine:true}"></script>
  16. </head>
  17. <body>
  18. <button id='jsonp'>get pics from flickr</button>
  19. <div id="photo-list"></div>
  20. <script>
  21. KISSY.use('node,io',function (S,Node,IO) {
  22. var $ = Node.all,
  23. photoList = $('#photo-list');
  24. $("#jsonp").attr("disabled",false);
  25. $("#jsonp").on("click", function () {
  26. $(this).attr("disabled",true);
  27. photoList.addClass('loading');
  28. new IO({
  29. dataType:'jsonp',
  30. url:"http://api.flickr.com/services/rest/",
  31. data:{
  32. 'method': 'flickr.favorites.getPublicList',
  33. 'api_key': '5d93c2e473e39e9307e86d4a01381266',
  34. 'user_id': '26211501@N07',
  35. 'per_page': 10,
  36. 'format': 'json'
  37. },
  38. jsonp:"jsoncallback",
  39. success:function (data) {
  40. var html = 'Fetch photo failed, pls try again!';
  41. if (data.stat === 'ok') {
  42. html='';
  43. S.each(data.photos.photo, function (item, i) {
  44. html += '<img style="display:none" src="http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_t.jpg" />';
  45. });
  46. }
  47. photoList.html(html).all('img').each(function (img) {
  48. img.on('load', function () {
  49. photoList.removeClass('loading');
  50. img.detach();
  51. img.fadeIn(3);
  52. });
  53. });
  54. }
  55. });
  56. });
  57. });
  58. </script>
  59. </body>
  60. </html>