You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2017-2019 MuK IT GmbH.
  4. *
  5. * This file is part of MuK Preview Image
  6. * (see https://mukit.at).
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. **********************************************************************************/
  22. odoo.define('muk_preview_markdown.PreviewContentVector', function (require) {
  23. "use strict";
  24. var core = require('web.core');
  25. var ajax = require('web.ajax');
  26. var utils = require('web.utils');
  27. var session = require('web.session');
  28. var registry = require('muk_preview.registry');
  29. var AbstractPreviewContent = require('muk_preview.AbstractPreviewContent');
  30. var QWeb = core.qweb;
  31. var _t = core._t;
  32. var PreviewContentVector = AbstractPreviewContent.extend({
  33. events: _.extend({}, AbstractPreviewContent.prototype.events, {
  34. 'click .zoom-plus': '_onZoomIn',
  35. 'click .zoom-minus': '_onZoomOut',
  36. 'click .zoom-reset': '_onReset',
  37. }),
  38. template: "muk_preview.PreviewContentVector",
  39. jsLibs: [
  40. '/muk_web_preview_image/static/lib/svg-pan-zoom/svg-pan-zoom.js',
  41. ],
  42. willStart: function() {
  43. var def = $.ajax({
  44. url: this.url,
  45. dataType: "text",
  46. }).fail(function(jqXHR, textStatus) {
  47. console.error(textStatus);
  48. }).done(function(vector) {
  49. this.vector = vector;
  50. }.bind(this));
  51. return $.when(this._super.apply(this, arguments), def);
  52. },
  53. renderPreviewContent: function() {
  54. this.$('.vector-content').html(this.vector);
  55. this.svgPanZoom = this.$("svg").svgPanZoom({
  56. events: {
  57. mouseWheel: true,
  58. doubleClick: true,
  59. drag: true,
  60. dragCursor: "move",
  61. },
  62. animationTime: 300,
  63. zoomFactor: 0.1,
  64. maxZoom: 5,
  65. panFactor: 100,
  66. });
  67. return this._super.apply(this, arguments);
  68. },
  69. _onZoomIn: function(event) {
  70. console.log(this.svgPanZoom);
  71. this.svgPanZoom.zoomIn();
  72. },
  73. _onZoomOut: function(event) {
  74. this.svgPanZoom.zoomOut();
  75. },
  76. _onReset: function(event) {
  77. this.svgPanZoom.reset();
  78. },
  79. downloadable: true,
  80. printable: true,
  81. });
  82. registry.add('svg', PreviewContentVector);
  83. registry.add('.svg', PreviewContentVector);
  84. registry.add('image/svg+xml', PreviewContentVector);
  85. return PreviewContentVector;
  86. });