cc315a60ea7c59a3cabdc10f1b6eacc87f87f2e9.svn-base 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Sort Flickr images by tags</title>
  5. <style type="text/css">
  6. @import "../../resources/dojo.css";
  7. @import "../../resources/dnd.css";
  8. body {
  9. padding: 1em;
  10. }
  11. /* application-specific settings */
  12. #status {font-weight: bold;}
  13. .container {padding: 5px; cursor: default; background: #f8f8ff;}
  14. .wrap1 {float: left; width: 275px; height: 600px; overflow: auto; margin-right: 1em;}
  15. .wrap1 div {min-height: 100px;}
  16. .wrap2 {width: 350px; height: 170px; overflow: auto;}
  17. .wrap2 div {min-height: 150px;}
  18. .container .name {font-weight: bold; padding-right: 4px;}
  19. .container .image {padding: 5px;}
  20. body.dojoDndCopy, body.dojoDndMove {color: #888;}
  21. .dojoDndCopy .container, .dojoDndMove .container {background: #ddf;}
  22. /* container-specific settings */
  23. .dojoDndContainer {border: 1px solid white; color: black;}
  24. .dojoDndContainerOver {border: 1px solid black; color: black;}
  25. .container.dojoDndTargetDisabled {background: #ccc; color: #888;}
  26. /* item-specific settings */
  27. .dojoDndItemOver {background: #feb;}
  28. .dojoDndItemSelected {background: #ccf; color: #444;}
  29. .dojoDndItemAnchor {background: #ccf; color: black;}
  30. .dojoDndItemOver.dojoDndItemSelected {background: #ec8;}
  31. .dojoDndItemOver.dojoDndItemAnchor {background: #ec8;}
  32. .dojoDndItemBefore {border-top: 3px solid red;}
  33. .dojoDndItemAfter {border-bottom: 3px solid red;}
  34. .dojoDndHorizontal .dojoDndItemBefore {border-top: none;}
  35. .dojoDndHorizontal .dojoDndItemAfter {border-bottom: none;}
  36. .dojoDndHorizontal .dojoDndItemBefore img {border-left: 3px solid red;}
  37. .dojoDndHorizontal .dojoDndItemAfter img {border-right: 3px solid red;}
  38. </style>
  39. <script type="text/javascript" src="../../dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
  40. <script type="text/javascript" src="../../dnd/common.js"></script>
  41. <script type="text/javascript" src="../../dnd/autoscroll.js"></script>
  42. <script type="text/javascript" src="../../dnd/Container.js"></script>
  43. <script type="text/javascript" src="../../dnd/Selector.js"></script>
  44. <script type="text/javascript" src="../../dnd/Source.js"></script>
  45. <script type="text/javascript" src="../../dnd/Avatar.js"></script>
  46. <script type="text/javascript" src="../../dnd/Manager.js"></script>
  47. <script type="text/javascript">
  48. dojo.require("dojo.parser");
  49. dojo.require("dojo.io.script");
  50. dojo.require("dojo.dnd.Source");
  51. // The main image container creator
  52. var main_creator = function(item, hint){
  53. var type = [];
  54. if(item.tags.search(/cat/i) >= 0){ type.push("cat"); }
  55. if(item.tags.search(/dog/i) >= 0){ type.push("dog"); }
  56. var node;
  57. if(hint == "avatar"){
  58. node = dojo.doc.createElement("span");
  59. node.innerHTML = "<img src='" + item.media.m.replace(/_m\./, "_s.") + "'/>";
  60. }else{
  61. var t = ["<table border='0' cellpadding='0' cellspacing='0' width='250'>"];
  62. t.push("<tr><td colspan='2' class='image' align='center' width='250'><img src='" +
  63. item.media.m + "'/></td></tr>");
  64. t.push("<tr><td class='name' valign='top'>Title:</td><td class='value'><a href='" +
  65. item.link + "' target='_blank'>" +
  66. (item.title ? item.title : "<em>untitled</em>") + "</a></td></tr>");
  67. t.push("<tr><td class='name' valign='top'>Author:</td><td class='value'>" +
  68. item.author + "</td></tr>");
  69. t.push("<tr><td class='name' valign='top'>Tags:</td><td class='value'>" +
  70. item.tags + "</td></tr>");
  71. t.push("</table>");
  72. node = dojo.doc.createElement("div");
  73. node.innerHTML = t.join("");
  74. }
  75. node.id = dojo.dnd.getUniqueId();
  76. return {node: node, data: item, type: type};
  77. };
  78. // The band image container creator
  79. var band_creator = function(item, hint){
  80. var type = [];
  81. if(item.tags.search(/cat/i) >= 0){ type.push("cat"); }
  82. if(item.tags.search(/dog/i) >= 0){ type.push("dog"); }
  83. var src = item.media.m.replace(/_m\./, "_s.");
  84. var node = dojo.doc.createElement("span");
  85. node.innerHTML = "<img src='" + src + "'/>";
  86. node.id = dojo.dnd.getUniqueId();
  87. return {node: node, data: item, type: type};
  88. };
  89. // Flickr's JSONP function
  90. var jsonFlickrFeed = function(data){
  91. if(!data.items || !data.items.length){
  92. dojo.byId("status").innerHTML = "Flickr didn't return any images";
  93. return;
  94. }
  95. dojo.byId("status").innerHTML = data.items.length + " images were retrieved";
  96. // initialize sources
  97. c1.selectAll().deleteSelectedNodes();
  98. c2.selectAll().deleteSelectedNodes();
  99. c3.selectAll().deleteSelectedNodes();
  100. // populate the main source
  101. c1.insertNodes(false, data.items);
  102. };
  103. var init = function(){
  104. // replace the avatar string to make it more human readable
  105. dojo.dnd.Avatar.prototype._generateText = function(){
  106. return (this.manager.copy ? "copy" : "mov") +
  107. "ing " + this.manager.nodes.length + " item" +
  108. (this.manager.nodes.length != 1 ? "s" : "");
  109. };
  110. // ask Flickr for images
  111. var td = dojo.io.script.get({
  112. url: "http://api.flickr.com/services/feeds/photos_public.gne",
  113. content: {tags: "cat,dog,cow", tagmode: "any", format: "json"},
  114. handleAs: "text/javascript",
  115. preventCache: true
  116. });
  117. td.addErrback(function(){
  118. dojo.byId("status").innerHTML = "Flickr failed to return images";
  119. });
  120. };
  121. dojo.addOnLoad(init);
  122. </script>
  123. </head>
  124. <body>
  125. <h1>Sort Flickr images by tags</h1>
  126. <p>This simple web application retrieves public images from Flickr that were tagged either as "cat", "dog", or "cow".
  127. You can copy/move images in different containers according to their tags.</p>
  128. <p>Following selection modes are supported by default:</p>
  129. <ul>
  130. <li>Simple click &mdash; selects a single element, all other elements will be unselected.</li>
  131. <li>Ctrl+click &mdash; toggles a selection state of an element (use Meta key on Mac).</li>
  132. <li>Shift+click &mdash; selects a range of element from the previous anchor to the current element.</li>
  133. <li>Ctrl+Shift+click &mdash; adds a range of element from the previous anchor to the current element (use Meta key on Mac).</li>
  134. </ul>
  135. <p>Following drop modes are supported by default:</p>
  136. <ul>
  137. <li>Simple drop &mdash; moves elements to the valid target removing them from the source. It can be used to reorganize elements within a single source/target.</li>
  138. <li>Ctrl+drop &mdash; copies elements to the valid target (use Meta key on Mac).</li>
  139. </ul>
  140. <p>Now scroll down and start dragging and dropping, rearrange images using DnD, copy and move them back!</p>
  141. <p>Status: <span id="status">retrieving a list of Flickr images...</span></p>
  142. <div class="wrap1">
  143. <div dojoType="dojo.dnd.Source" jsId="c1" accept="cat, dog, cow" class="container">
  144. <script type="dojo/method" event="creator" args="item, hint">return main_creator(item, hint);</script>
  145. </div>
  146. </div>
  147. <p>Tag: cat</p>
  148. <div class="wrap2">
  149. <div dojoType="dojo.dnd.Source" jsId="c2" accept="cat" horizontal="true" class="container">
  150. <script type="dojo/method" event="creator" args="item, hint">return band_creator(item, hint);</script>
  151. </div>
  152. </div>
  153. <p>Tag: dog</p>
  154. <div class="wrap2">
  155. <div dojoType="dojo.dnd.Source" jsId="c3" accept="dog" horizontal="true" class="container">
  156. <script type="dojo/method" event="creator" args="item, hint">return band_creator(item, hint);</script>
  157. </div>
  158. </div>
  159. </body>
  160. </html>