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