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.

94 lines
2.8 KiB

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