popup.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // XXX This event list must be abstracted somewhere else.
  2. function whichTransitionEvent() {
  3. var t;
  4. var el = document.createElement('fakeelement');
  5. var transitions = {
  6. transition:'transitionend',
  7. OTransition:'oTransitionEnd',
  8. MozTransition:'transitionend',
  9. WebkitTransition:'webkitTransitionEnd'
  10. };
  11. for (t in transitions) {
  12. if (el.style[t] !== undefined) {
  13. return transitions[t];
  14. }
  15. }
  16. }
  17. var transitionEvent = whichTransitionEvent();
  18. Popup.template.events({
  19. click: function(evt) {
  20. if (evt.originalEvent) {
  21. evt.originalEvent.clickInPopup = true;
  22. }
  23. },
  24. 'click .js-back-view': function() {
  25. Popup.back();
  26. },
  27. 'click .js-close-pop-over': function() {
  28. Popup.close();
  29. },
  30. 'click .js-confirm': function() {
  31. this.__afterConfirmAction.call(this);
  32. },
  33. // This handler intends to solve a pretty tricky bug with our popup
  34. // transition. The transition is implemented using a large container
  35. // (.content-container) that is moved on the x-axis (from 0 to n*PopupSize)
  36. // inside a wrapper (.container-wrapper) with a hidden overflow. The problem
  37. // is that sometimes the wrapper is scrolled -- even if there are no
  38. // scrollbars. This happen for instance when the newly opened popup has some
  39. // focused field, the browser will automatically scroll the wrapper, resulting
  40. // in moving the whole popup container outside of the popup wrapper. To
  41. // disable this behavior we have to manually reset the scrollLeft position
  42. // whenever it is modified.
  43. 'scroll .content-wrapper': function(evt) {
  44. evt.currentTarget.scrollLeft = 0;
  45. }
  46. });
  47. // When a popup content is removed (ie, when the user press the "back" button),
  48. // we need to wait for the container translation to end before removing the
  49. // actual DOM element. For that purpose we use the undocumented `_uihooks` API.
  50. Popup.template.onRendered(function() {
  51. var container = this.find('.content-container');
  52. container._uihooks = {
  53. removeElement: function(node) {
  54. $(node).addClass('no-height');
  55. $(container).one(transitionEvent, function() {
  56. node.parentNode.removeChild(node);
  57. });
  58. }
  59. };
  60. });