popup.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 .js-back-view': function() {
  20. Popup.back();
  21. },
  22. 'click .js-close-pop-over': function() {
  23. Popup.close();
  24. },
  25. 'click .js-confirm': function() {
  26. this.__afterConfirmAction.call(this);
  27. },
  28. // This handler intends to solve a pretty tricky bug with our popup
  29. // transition. The transition is implemented using a large container
  30. // (.content-container) that is moved on the x-axis (from 0 to n*PopupSize)
  31. // inside a wrapper (.container-wrapper) with a hidden overflow. The problem
  32. // is that sometimes the wrapper is scrolled -- even if there are no
  33. // scrollbars. This happen for instance when the newly opened popup has some
  34. // focused field, the browser will automatically scroll the wrapper, resulting
  35. // in moving the whole popup container outside of the popup wrapper. To
  36. // disable this behavior we have to manually reset the scrollLeft position
  37. // whenever it is modified.
  38. 'scroll .content-wrapper': function(evt) {
  39. evt.currentTarget.scrollLeft = 0;
  40. }
  41. });
  42. // When a popup content is removed (ie, when the user press the "back" button),
  43. // we need to wait for the container translation to end before removing the
  44. // actual DOM element. For that purpose we use the undocumented `_uihooks` API.
  45. Popup.template.onRendered(function() {
  46. var container = this.find('.content-container');
  47. container._uihooks = {
  48. removeElement: function(node) {
  49. $(node).addClass('no-height');
  50. $(container).one(transitionEvent, function() {
  51. node.parentNode.removeChild(node);
  52. });
  53. }
  54. };
  55. });