FullWindowZoomHelper.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @license
  3. * Copyright (C) 2014 KO GmbH <copyright@kogmbh.com>
  4. *
  5. * @licstart
  6. * This file is part of WebODF.
  7. *
  8. * WebODF is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU Affero General Public License (GNU AGPL)
  10. * as published by the Free Software Foundation, either version 3 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * WebODF is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with WebODF. If not, see <http://www.gnu.org/licenses/>.
  20. * @licend
  21. *
  22. * @source: http://www.webodf.org/
  23. * @source: https://github.com/kogmbh/WebODF/
  24. */
  25. /*global define, document, window */
  26. define("webodf/editor/FullWindowZoomHelper", [], function () {
  27. "use strict";
  28. // fullscreen pinch-zoom adaption
  29. var FullWindowZoomHelper = function FullWindowZoomHelper(toolbarContainerElement, canvasContainerElement) {
  30. function translateToolbar() {
  31. var y = document.body.scrollTop;
  32. toolbarContainerElement.style.WebkitTransformOrigin = "center top";
  33. toolbarContainerElement.style.WebkitTransform = 'translateY(' + y + 'px)';
  34. }
  35. function repositionContainer() {
  36. canvasContainerElement.style.top = toolbarContainerElement.getBoundingClientRect().height + 'px';
  37. }
  38. this.destroy = function(callback) {
  39. window.removeEventListener('scroll', translateToolbar);
  40. window.removeEventListener('focusout', translateToolbar);
  41. window.removeEventListener('touchmove', translateToolbar);
  42. window.removeEventListener('resize', repositionContainer);
  43. callback();
  44. };
  45. function init() {
  46. var metaElement, toolbarStyle;
  47. // prevent any zooming on the window TODO: do not overwrite any other existing content of viewport metadata
  48. metaElement = document.createElement("meta");
  49. metaElement.setAttribute("name", "viewport");
  50. metaElement.setAttribute("content", "width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0");
  51. document.head.appendChild(metaElement);
  52. // set the toolbar absolute and fixed to top
  53. toolbarStyle = toolbarContainerElement.style;
  54. toolbarStyle.top = 0;
  55. toolbarStyle.left = 0;
  56. toolbarStyle.right = 0;
  57. toolbarStyle.position = "absolute";
  58. toolbarStyle.zIndex = 5;
  59. toolbarStyle.boxShadow = "0 1px 5px rgba(0, 0, 0, 0.25)";
  60. repositionContainer();
  61. window.addEventListener('scroll', translateToolbar);
  62. window.addEventListener('focusout', translateToolbar);
  63. window.addEventListener('touchmove', translateToolbar);
  64. window.addEventListener('resize', repositionContainer);
  65. }
  66. init();
  67. };
  68. return FullWindowZoomHelper;
  69. });