[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/assign/feedback/editpdf/yui/src/editor/js/ -> annotationstamp.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 stamp.
  25   *
  26   * @namespace M.assignfeedback_editpdf
  27   * @class annotationstamp
  28   * @extends M.assignfeedback_editpdf.annotation
  29   */
  30  var ANNOTATIONSTAMP = function(config) {
  31      ANNOTATIONSTAMP.superclass.constructor.apply(this, [config]);
  32  };
  33  
  34  ANNOTATIONSTAMP.NAME = "annotationstamp";
  35  ANNOTATIONSTAMP.ATTRS = {};
  36  
  37  Y.extend(ANNOTATIONSTAMP, M.assignfeedback_editpdf.annotation, {
  38      /**
  39       * Draw a stamp annotation
  40       * @protected
  41       * @method draw
  42       * @return M.assignfeedback_editpdf.drawable
  43       */
  44      draw: function() {
  45          var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
  46              drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION),
  47              node,
  48              position;
  49  
  50          position = this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(this.x, this.y));
  51          node = Y.Node.create('<div/>');
  52          node.setStyles({
  53              'position': 'absolute',
  54              'display': 'inline-block',
  55              'backgroundImage': 'url(' + this.editor.get_stamp_image_url(this.path) + ')',
  56              'width': (this.endx - this.x),
  57              'height': (this.endy - this.y),
  58              'backgroundSize': '100% 100%',
  59              'zIndex': 50
  60          });
  61  
  62          drawingregion.append(node);
  63          node.setX(position.x);
  64          node.setY(position.y);
  65          drawable.store_position(node, position.x, position.y);
  66  
  67          // Bind events only when editing.
  68          if (!this.editor.get('readonly')) {
  69              // Pass through the event handlers on the div.
  70              node.on('gesturemovestart', this.editor.edit_start, null, this.editor);
  71              node.on('gesturemove', this.editor.edit_move, null, this.editor);
  72              node.on('gesturemoveend', this.editor.edit_end, null, this.editor);
  73          }
  74  
  75          drawable.nodes.push(node);
  76  
  77          this.drawable = drawable;
  78          return ANNOTATIONSTAMP.superclass.draw.apply(this);
  79      },
  80  
  81      /**
  82       * Draw the in progress edit.
  83       *
  84       * @public
  85       * @method draw_current_edit
  86       * @param M.assignfeedback_editpdf.edit edit
  87       */
  88      draw_current_edit: function(edit) {
  89          var bounds = new M.assignfeedback_editpdf.rect(),
  90              drawable = new M.assignfeedback_editpdf.drawable(this.editor),
  91              drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION),
  92              node,
  93              position;
  94  
  95          bounds.bound([edit.start, edit.end]);
  96          position = this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(bounds.x, bounds.y));
  97  
  98          node = Y.Node.create('<div/>');
  99          node.setStyles({
 100              'position': 'absolute',
 101              'display': 'inline-block',
 102              'backgroundImage': 'url(' + this.editor.get_stamp_image_url(edit.stamp) + ')',
 103              'width': bounds.width,
 104              'height': bounds.height,
 105              'backgroundSize': '100% 100%',
 106              'zIndex': 50
 107          });
 108  
 109          drawingregion.append(node);
 110          node.setX(position.x);
 111          node.setY(position.y);
 112          drawable.store_position(node, position.x, position.y);
 113  
 114          drawable.nodes.push(node);
 115  
 116          return drawable;
 117      },
 118  
 119      /**
 120       * Promote the current edit to a real annotation.
 121       *
 122       * @public
 123       * @method init_from_edit
 124       * @param M.assignfeedback_editpdf.edit edit
 125       * @return bool if width/height is more than min. required.
 126       */
 127      init_from_edit: function(edit) {
 128          var bounds = new M.assignfeedback_editpdf.rect();
 129          bounds.bound([edit.start, edit.end]);
 130  
 131          if (bounds.width < 40) {
 132              bounds.width = 40;
 133          }
 134          if (bounds.height < 40) {
 135              bounds.height = 40;
 136          }
 137          this.gradeid = this.editor.get('gradeid');
 138          this.pageno = this.editor.currentpage;
 139          this.x = bounds.x;
 140          this.y = bounds.y;
 141          this.endx = bounds.x + bounds.width;
 142          this.endy = bounds.y + bounds.height;
 143          this.colour = edit.annotationcolour;
 144          this.path = edit.stamp;
 145  
 146          // Min width and height is always more than 40px.
 147          return true;
 148      },
 149  
 150      /**
 151       * Move an annotation to a new location.
 152       * @public
 153       * @param int newx
 154       * @param int newy
 155       * @method move_annotation
 156       */
 157      move: function(newx, newy) {
 158          var diffx = newx - this.x,
 159              diffy = newy - this.y;
 160  
 161          this.x += diffx;
 162          this.y += diffy;
 163          this.endx += diffx;
 164          this.endy += diffy;
 165  
 166          if (this.drawable) {
 167              this.drawable.erase();
 168          }
 169          this.editor.drawables.push(this.draw());
 170      }
 171  
 172  });
 173  
 174  M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
 175  M.assignfeedback_editpdf.annotationstamp = ANNOTATIONSTAMP;


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