Guest User

Untitled

a guest
Nov 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. <aura:component>
  2. <ltng:require scripts="{!join(',',
  3. $Resource.jquery_3_2_1_min_JS,
  4. $Resource.PUBSUB_EventBus2_JS
  5. )}"
  6. afterScriptsLoaded="{!c.demonstrate}"
  7. />
  8.  
  9. <aura:attribute access="private" type="String" name="tags" />
  10.  
  11. <lightning:input aura:id="query" name="tag" label="Tag" value="{!v.tags}" />
  12. <lightning:button variant="brand" label="Submit" onclick="{!c.searchFlicker}"/>
  13.  
  14. <div aura:id="lastQuery"></div>
  15. <ol aura:id="searchResults"></ol>
  16. </aura:component>
  17.  
  18. ({
  19. demonstrate : function(component, event, helper) {
  20. $Jsdp.EventBus2.subscribe('/search/tags', helper.displayLastQuery(component));
  21. $Jsdp.EventBus2.subscribe('/search/resultSet', helper.performSearch(component));
  22. $Jsdp.EventBus2.subscribe('/search/tags', helper.displayResultTemplate(component));
  23. },
  24.  
  25. searchFlicker : function(component, event, helper) {
  26. var tags = component.get('v.tags').trim();
  27. if (tags) {
  28. $Jsdp.EventBus2.publish('/search/tags', [tags]);
  29. }
  30. }
  31. })
  32.  
  33. ({
  34. displayLastQuery : function(component) {
  35. return function(topic, tags) {
  36. component.find('lastQuery')
  37. .getElement()
  38. .innerHTML = '<p> Searched for: '
  39. + '<strong>' + tags + '</strong>'
  40. + '</p>';
  41. }
  42. },
  43.  
  44. performSearch : function(component) {
  45. var self = this;
  46. return function(topic, tags) {
  47. var params = {results: tags};
  48. $A.createComponent('c:PUBSUB_FlickerSearchResults', params, self.appendResults(component));
  49. };
  50. },
  51.  
  52. appendResults : function(component) {
  53. return function(newElement, status, errorMessage) {
  54. if (status === 'SUCCESS') {
  55. var renderBox = component.find('searchResults');
  56. var body = renderBox.get('v.body') || [];
  57. body.push(newElement);
  58. renderBox.set('v.body', body);
  59. }
  60. else {
  61. console.error('Something went wrong!:', errorMessage);
  62. }
  63. };
  64. },
  65.  
  66. displayResultTemplate : function(component) {
  67. var self = this;
  68. return function(topic, tags) {
  69. var params = {
  70. tags: tags,
  71. tagmode: 'any',
  72. format: 'json'
  73. };
  74. $.getJSON(
  75. 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?',
  76. params,
  77. self.publishResultSet
  78. );
  79. }
  80. },
  81.  
  82. publishResultSet: function(data) {
  83. if (data && data.items && data.items.length) {
  84. $Jsdp.EventBus2.publish('/search/resultSet', {items: data.items});
  85. }
  86. }
  87. })
Add Comment
Please, Sign In to add comment