Advertisement
Guest User

try mo to boss

a guest
Aug 22nd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. $(function() {
  2. // your code here
  3. var config;
  4. var baseUrl = 'http://api.themoviedb.org/3/',
  5. apiKey = '57ac6b482b34134f62606c12cdaba334';
  6.  
  7.  
  8. function initialize(callback) {
  9. $.get(baseUrl + 'configuration', {
  10. api_key: '57ac6b482b34134f62606c12cdaba334'
  11. },function(res) {
  12. config = res;
  13. console.log(config);
  14. callback(config);
  15. });
  16. }
  17.  
  18. function setEventHandlers(config) {
  19. $('#form-search').submit(function() {
  20. var query = $('.input-query').val();
  21. searchMovie(query);
  22. return false;
  23. });
  24.  
  25. $('.btn-now-showing').click(function() {
  26. loadNowShowing();
  27. return false;
  28. });
  29.  
  30. loadNowShowing();
  31.  
  32. $('.btn-upcoming').click(function() {
  33. loadUpcoming();
  34. return false;
  35. });
  36.  
  37. loadUpcoming();
  38.  
  39. $('.btn-popular').click(function() {
  40. loadPopular();
  41. return false;
  42. });
  43.  
  44. loadPopular();
  45.  
  46. $('.btn-top-rated').click(function() {
  47. loadTopRated();
  48. return false;
  49. });
  50.  
  51. loadTopRated();
  52.  
  53. }
  54.  
  55. function searchMovie(query) {
  56. var searchUrl = baseUrl + 'search/movie';
  57. $('.movies-list').html('');
  58. $.get(searchUrl, {
  59. query: query,
  60. api_key: apiKey
  61. }, function(response) {
  62. displayMovies(response);
  63. });
  64. }
  65.  
  66. function displayMovies(data) {
  67. data.results.forEach(function(movie) {
  68. var imageSrc = config.images.base_url + config.images.poster_sizes[3] + movie.poster_path;
  69. var htmlStr = [
  70. '<div class="col-md-4 portfolio-item">',
  71. '<a href="#">',
  72. '<img class="img-responsive" src="' + imageSrc + '" alt="">',
  73. '</a>',
  74. '<h3><center><font face="Maiandra GD">',
  75. '<a href="#">' + movie.title +'</a>',
  76. '</font></center></h3>',
  77. '</div>'
  78. ];
  79. $('.movies-list').append($(htmlStr.join('')));
  80. });
  81. }
  82.  
  83. function loadNowShowing() {
  84. var nowShowingUrl = baseUrl + 'movie/now_playing';
  85. $('.movies-list').html('');
  86. $.get(nowShowingUrl, {
  87. api_key: apiKey
  88. }, function(response) {
  89. displayMovies(response);
  90. });
  91. }
  92.  
  93. function loadUpcoming() {
  94. var upcomingUrl = baseUrl + 'movie/upcoming';
  95. $('.movies-list').html('');
  96. $.get(upcomingUrl, {
  97. api_key: apiKey
  98. }, function(response) {
  99. displayMovies(response);
  100. });
  101. }
  102.  
  103. function loadPopular() {
  104. var popularUrl = baseUrl + 'movie/popular';
  105. $('.movies-list').html('');
  106. $.get(popularUrl, {
  107. api_key: apiKey
  108. }, function(response) {
  109. displayMovies(response);
  110. });
  111. }
  112.  
  113. function loadTopRated() {
  114. var topRatedUrl = baseUrl + 'movie/top_rated';
  115. $('.movies-list').html('');
  116. $.get(topRatedUrl, {
  117. api_key: apiKey
  118. }, function(response) {
  119. displayMovies(response);
  120. });
  121. }
  122.  
  123. initialize(setEventHandlers);
  124.  
  125. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement