[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 STROKEWEIGHT, SELECTOR, SELECTEDBORDERCOLOUR, SELECTEDFILLCOLOUR */ 16 17 /** 18 * Provides an in browser PDF editor. 19 * 20 * @module moodle-assignfeedback_editpdf-editor 21 */ 22 23 /** 24 * Class representing a highlight. 25 * 26 * @namespace M.assignfeedback_editpdf 27 * @class annotation 28 * @constructor 29 */ 30 var ANNOTATION = function(config) { 31 ANNOTATION.superclass.constructor.apply(this, [config]); 32 }; 33 34 ANNOTATION.NAME = "annotation"; 35 ANNOTATION.ATTRS = {}; 36 37 Y.extend(ANNOTATION, Y.Base, { 38 /** 39 * Reference to M.assignfeedback_editpdf.editor. 40 * @property editor 41 * @type M.assignfeedback_editpdf.editor 42 * @public 43 */ 44 editor: null, 45 46 /** 47 * Grade id 48 * @property gradeid 49 * @type Int 50 * @public 51 */ 52 gradeid: 0, 53 54 /** 55 * Comment page number 56 * @property pageno 57 * @type Int 58 * @public 59 */ 60 pageno: 0, 61 62 /** 63 * X position 64 * @property x 65 * @type Int 66 * @public 67 */ 68 x: 0, 69 70 /** 71 * Y position 72 * @property y 73 * @type Int 74 * @public 75 */ 76 y: 0, 77 78 /** 79 * Ending x position 80 * @property endx 81 * @type Int 82 * @public 83 */ 84 endx: 0, 85 86 /** 87 * Ending y position 88 * @property endy 89 * @type Int 90 * @public 91 */ 92 endy: 0, 93 94 /** 95 * Path 96 * @property path 97 * @type String - list of points like x1,y1:x2,y2 98 * @public 99 */ 100 path: '', 101 102 /** 103 * Tool. 104 * @property type 105 * @type String 106 * @public 107 */ 108 type: 'rect', 109 110 /** 111 * Annotation colour. 112 * @property colour 113 * @type String 114 * @public 115 */ 116 colour: 'red', 117 118 /** 119 * Reference to M.assignfeedback_editpdf.drawable 120 * @property drawable 121 * @type M.assignfeedback_editpdf.drawable 122 * @public 123 */ 124 drawable: false, 125 126 /** 127 * Initialise the annotation. 128 * 129 * @method initializer 130 * @return void 131 */ 132 initializer: function(config) { 133 this.editor = config.editor || null; 134 this.gradeid = parseInt(config.gradeid, 10) || 0; 135 this.pageno = parseInt(config.pageno, 10) || 0; 136 this.x = parseInt(config.x, 10) || 0; 137 this.y = parseInt(config.y, 10) || 0; 138 this.endx = parseInt(config.endx, 10) || 0; 139 this.endy = parseInt(config.endy, 10) || 0; 140 this.path = config.path || ''; 141 this.type = config.type || 'rect'; 142 this.colour = config.colour || 'red'; 143 this.drawable = false; 144 }, 145 146 /** 147 * Clean a comment record, returning an oject with only fields that are valid. 148 * @public 149 * @method clean 150 * @return {} 151 */ 152 clean: function() { 153 return { 154 gradeid: this.gradeid, 155 x: parseInt(this.x, 10), 156 y: parseInt(this.y, 10), 157 endx: parseInt(this.endx, 10), 158 endy: parseInt(this.endy, 10), 159 type: this.type, 160 path: this.path, 161 pageno: this.pageno, 162 colour: this.colour 163 }; 164 }, 165 166 /** 167 * Draw a selection around this annotation if it is selected. 168 * @public 169 * @method draw_highlight 170 * @return M.assignfeedback_editpdf.drawable 171 */ 172 draw_highlight: function() { 173 var bounds, 174 drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION), 175 offsetcanvas = this.editor.get_dialogue_element(SELECTOR.DRAWINGCANVAS).getXY(), 176 shape; 177 178 if (this.editor.currentannotation === this) { 179 // Draw a highlight around the annotation. 180 bounds = new M.assignfeedback_editpdf.rect(); 181 bounds.bound([new M.assignfeedback_editpdf.point(this.x, this.y), 182 new M.assignfeedback_editpdf.point(this.endx, this.endy)]); 183 184 shape = this.editor.graphic.addShape({ 185 type: Y.Rect, 186 width: bounds.width, 187 height: bounds.height, 188 stroke: { 189 weight: STROKEWEIGHT, 190 color: SELECTEDBORDERCOLOUR 191 }, 192 fill: { 193 color: SELECTEDFILLCOLOUR 194 }, 195 x: bounds.x, 196 y: bounds.y 197 }); 198 this.drawable.shapes.push(shape); 199 200 // Add a delete X to the annotation. 201 var deleteicon = Y.Node.create('<img src="' + M.util.image_url('trash', 'assignfeedback_editpdf') + '"/>'), 202 deletelink = Y.Node.create('<a href="#" role="button"></a>'); 203 204 deleteicon.setAttrs({ 205 'alt': M.util.get_string('deleteannotation', 'assignfeedback_editpdf') 206 }); 207 deleteicon.setStyles({ 208 'backgroundColor': 'white' 209 }); 210 deletelink.addClass('deleteannotationbutton'); 211 deletelink.append(deleteicon); 212 213 drawingregion.append(deletelink); 214 deletelink.setData('annotation', this); 215 deletelink.setStyle('zIndex', '200'); 216 217 deletelink.on('click', this.remove, this); 218 deletelink.on('key', this.remove, 'space,enter', this); 219 220 deletelink.setX(offsetcanvas[0] + bounds.x + bounds.width - 18); 221 deletelink.setY(offsetcanvas[1] + bounds.y + 6); 222 this.drawable.nodes.push(deletelink); 223 } 224 return this.drawable; 225 }, 226 227 /** 228 * Draw an annotation 229 * @public 230 * @method draw 231 * @return M.assignfeedback_editpdf.drawable|false 232 */ 233 draw: function() { 234 // Should be overridden by the subclass. 235 this.draw_highlight(); 236 return this.drawable; 237 }, 238 239 /** 240 * Delete an annotation 241 * @protected 242 * @method remove 243 * @param event 244 */ 245 remove: function(e) { 246 var annotations, 247 i; 248 249 e.preventDefault(); 250 251 annotations = this.editor.pages[this.editor.currentpage].annotations; 252 for (i = 0; i < annotations.length; i++) { 253 if (annotations[i] === this) { 254 annotations.splice(i, 1); 255 if (this.drawable) { 256 this.drawable.erase(); 257 } 258 this.editor.currentannotation = false; 259 this.editor.save_current_page(); 260 return; 261 } 262 } 263 }, 264 265 /** 266 * Move an annotation to a new location. 267 * @public 268 * @param int newx 269 * @param int newy 270 * @method move_annotation 271 */ 272 move: function(newx, newy) { 273 var diffx = newx - this.x, 274 diffy = newy - this.y, 275 newpath, oldpath, xy, 276 x, y; 277 278 this.x += diffx; 279 this.y += diffy; 280 this.endx += diffx; 281 this.endy += diffy; 282 283 if (this.path) { 284 newpath = []; 285 oldpath = this.path.split(':'); 286 Y.each(oldpath, function(position) { 287 xy = position.split(','); 288 x = parseInt(xy[0], 10); 289 y = parseInt(xy[1], 10); 290 newpath.push((x + diffx) + ',' + (y + diffy)); 291 }); 292 293 this.path = newpath.join(':'); 294 295 } 296 if (this.drawable) { 297 this.drawable.erase(); 298 } 299 this.editor.drawables.push(this.draw()); 300 }, 301 302 /** 303 * Draw the in progress edit. 304 * 305 * @public 306 * @method draw_current_edit 307 * @param M.assignfeedback_editpdf.edit edit 308 */ 309 draw_current_edit: function(edit) { 310 var noop = edit && false; 311 // Override me please. 312 return noop; 313 }, 314 315 /** 316 * Promote the current edit to a real annotation. 317 * 318 * @public 319 * @method init_from_edit 320 * @param M.assignfeedback_editpdf.edit edit 321 * @return bool if width/height is more than min. required. 322 */ 323 init_from_edit: function(edit) { 324 var bounds = new M.assignfeedback_editpdf.rect(); 325 bounds.bound([edit.start, edit.end]); 326 327 this.gradeid = this.editor.get('gradeid'); 328 this.pageno = this.editor.currentpage; 329 this.x = bounds.x; 330 this.y = bounds.y; 331 this.endx = bounds.x + bounds.width; 332 this.endy = bounds.y + bounds.height; 333 this.colour = edit.annotationcolour; 334 this.path = ''; 335 return (bounds.has_min_width() && bounds.has_min_height()); 336 } 337 338 }); 339 340 M.assignfeedback_editpdf = M.assignfeedback_editpdf || {}; 341 M.assignfeedback_editpdf.annotation = ANNOTATION;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |