Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Provides an in browser PDF editor.
18
 *
19
 * @module moodle-assignfeedback_editpdf-editor
20
 */
21
 
22
/**
23
 * Class representing a drawable thing which contains both Y.Nodes, and Y.Shapes.
24
 *
25
 * @namespace M.assignfeedback_editpdf
26
 * @param M.assignfeedback_editpdf.editor editor
27
 * @class drawable
28
 */
29
var DRAWABLE = function(editor) {
30
 
31
    /**
32
     * Reference to M.assignfeedback_editpdf.editor.
33
     * @property editor
34
     * @type M.assignfeedback_editpdf.editor
35
     * @public
36
     */
37
    this.editor = editor;
38
 
39
    /**
40
     * Array of Y.Shape
41
     * @property shapes
42
     * @type Y.Shape[]
43
     * @public
44
     */
45
    this.shapes = [];
46
 
47
    /**
48
     * Array of Y.Node
49
     * @property nodes
50
     * @type Y.Node[]
51
     * @public
52
     */
53
    this.nodes = [];
54
 
55
    /**
56
     * Delete the shapes from the drawable.
57
     * @protected
58
     * @method erase_drawable
59
     */
60
    this.erase = function() {
61
        if (this.shapes) {
62
            while (this.shapes.length > 0) {
63
                this.editor.graphic.removeShape(this.shapes.pop());
64
            }
65
        }
66
        if (this.nodes) {
67
            while (this.nodes.length > 0) {
68
                this.nodes.pop().remove();
69
            }
70
        }
71
    };
72
 
73
    /**
74
     * Update the positions of all absolutely positioned nodes, when the drawing canvas is scrolled
75
     * @public
76
     * @method scroll_update
77
     * @param scrollx int
78
     * @param scrolly int
79
     */
80
    this.scroll_update = function(scrollx, scrolly) {
81
        var i, x, y;
82
        for (i = 0; i < this.nodes.length; i++) {
83
            x = this.nodes[i].getData('x');
84
            y = this.nodes[i].getData('y');
85
            if (x !== undefined && y !== undefined) {
86
                this.nodes[i].setX(parseInt(x, 10) - scrollx);
87
                this.nodes[i].setY(parseInt(y, 10) - scrolly);
88
            }
89
        }
90
    };
91
 
92
    /**
93
     * Store the initial position of the node, so it can be updated when the drawing canvas is scrolled
94
     * @public
95
     * @method store_position
96
     * @param container
97
     * @param x
98
     * @param y
99
     */
100
    this.store_position = function(container, x, y) {
101
        var drawingregion, scrollx, scrolly;
102
 
103
        drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION);
104
        scrollx = parseInt(drawingregion.get('scrollLeft'), 10);
105
        scrolly = parseInt(drawingregion.get('scrollTop'), 10);
106
        container.setData('x', x + scrollx);
107
        container.setData('y', y + scrolly);
108
    };
109
};
110
 
111
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
112
M.assignfeedback_editpdf.drawable = DRAWABLE;