[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/feedback/editpdf/yui/src/editor/js/ -> drawable.js (source)

   1  // This file is part of Moodle - http://moodle.org/
   2  //
   3  // Moodle is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU General Public License as published by
   5  // the Free Software Foundation, either version 3 of the License, or
   6  // (at your option) any later version.
   7  //
   8  // Moodle is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU General Public License
  14  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  15  /* global SELECTOR */
  16  
  17  /**
  18   * Provides an in browser PDF editor.
  19   *
  20   * @module moodle-assignfeedback_editpdf-editor
  21   */
  22  
  23  /**
  24   * Class representing a drawable thing which contains both Y.Nodes, and Y.Shapes.
  25   *
  26   * @namespace M.assignfeedback_editpdf
  27   * @param M.assignfeedback_editpdf.editor editor
  28   * @class drawable
  29   */
  30  var DRAWABLE = function(editor) {
  31  
  32      /**
  33       * Reference to M.assignfeedback_editpdf.editor.
  34       * @property editor
  35       * @type M.assignfeedback_editpdf.editor
  36       * @public
  37       */
  38      this.editor = editor;
  39  
  40      /**
  41       * Array of Y.Shape
  42       * @property shapes
  43       * @type Y.Shape[]
  44       * @public
  45       */
  46      this.shapes = [];
  47  
  48      /**
  49       * Array of Y.Node
  50       * @property nodes
  51       * @type Y.Node[]
  52       * @public
  53       */
  54      this.nodes = [];
  55  
  56      /**
  57       * Delete the shapes from the drawable.
  58       * @protected
  59       * @method erase_drawable
  60       */
  61      this.erase = function() {
  62          if (this.shapes) {
  63              while (this.shapes.length > 0) {
  64                  this.editor.graphic.removeShape(this.shapes.pop());
  65              }
  66          }
  67          if (this.nodes) {
  68              while (this.nodes.length > 0) {
  69                  this.nodes.pop().remove();
  70              }
  71          }
  72      };
  73  
  74      /**
  75       * Update the positions of all absolutely positioned nodes, when the drawing canvas is scrolled
  76       * @public
  77       * @method scroll_update
  78       * @param scrollx int
  79       * @param scrolly int
  80       */
  81      this.scroll_update = function(scrollx, scrolly) {
  82          var i, x, y;
  83          for (i = 0; i < this.nodes.length; i++) {
  84              x = this.nodes[i].getData('x');
  85              y = this.nodes[i].getData('y');
  86              if (x !== undefined && y !== undefined) {
  87                  this.nodes[i].setX(parseInt(x, 10) - scrollx);
  88                  this.nodes[i].setY(parseInt(y, 10) - scrolly);
  89              }
  90          }
  91      };
  92  
  93      /**
  94       * Store the initial position of the node, so it can be updated when the drawing canvas is scrolled
  95       * @public
  96       * @method store_position
  97       * @param container
  98       * @param x
  99       * @param y
 100       */
 101      this.store_position = function(container, x, y) {
 102          var drawingregion, scrollx, scrolly;
 103  
 104          drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION);
 105          scrollx = parseInt(drawingregion.get('scrollLeft'), 10);
 106          scrolly = parseInt(drawingregion.get('scrollTop'), 10);
 107          container.setData('x', x + scrollx);
 108          container.setData('y', y + scrolly);
 109      };
 110  };
 111  
 112  M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
 113  M.assignfeedback_editpdf.drawable = DRAWABLE;


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1