saasbook

movie_popup.js

Mar 13th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. var MoviePopup = {
  2. setup: function() {
  3. // add hidden 'div' to end of page to display popup:
  4. var popupDiv = $('<div id="movieInfo"></div>');
  5. popupDiv.hide().appendTo($('body'));
  6. $(document).on('click', '#movies a', MoviePopup.getMovieInfo);
  7. }
  8. ,getMovieInfo: function() {
  9. $.ajax({type: 'GET',
  10. url: $(this).attr('href'),
  11. timeout: 5000,
  12. success: MoviePopup.showMovieInfo,
  13. error: function(xhrObj, textStatus, exception) { alert('Error!'); }
  14. // 'success' and 'error' functions will be passed 3 args
  15. });
  16. return(false);
  17. }
  18. ,showMovieInfo: function(data, requestStatus, xhrObject) {
  19. // center a floater 1/2 as wide and 1/4 as tall as screen
  20. var oneFourth = Math.ceil($(window).width() / 4);
  21. $('#movieInfo').
  22. css({'left': oneFourth, 'width': 2*oneFourth, 'top': 250}).
  23. html(data).
  24. show();
  25. // make the Close link in the hidden element work
  26. $('#closeLink').click(MoviePopup.hideMovieInfo);
  27. return(false); // prevent default link action
  28. }
  29. ,hideMovieInfo: function() {
  30. $('#movieInfo').hide();
  31. return(false);
  32. }
  33. };
  34. $(MoviePopup.setup);
Add Comment
Please, Sign In to add comment