Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
var STAMPPICKER_NAME = "Colourpicker",
2
    STAMPPICKER;
3
 
4
/**
5
 * Provides an in browser PDF editor.
6
 *
7
 * @module moodle-assignfeedback_editpdf-editor
8
 */
9
 
10
/**
11
 * This is a drop down list of stamps.
12
 *
13
 * @namespace M.assignfeedback_editpdf
14
 * @class stamppicker
15
 * @constructor
16
 * @extends M.assignfeedback_editpdf.dropdown
17
 */
18
STAMPPICKER = function(config) {
19
    STAMPPICKER.superclass.constructor.apply(this, [config]);
20
};
21
 
22
Y.extend(STAMPPICKER, M.assignfeedback_editpdf.dropdown, {
23
 
24
    /**
25
     * Initialise the menu.
26
     *
27
     * @method initializer
28
     * @return void
29
     */
30
    initializer: function(config) {
31
        var stamplist = Y.Node.create('<ul role="menu" class="assignfeedback_editpdf_menu"/>');
32
 
33
        // Build a list of stamped buttons.
34
        Y.each(this.get('stamps'), function(stamp) {
35
            var button, listitem, title;
36
 
37
            title = M.util.get_string('stamp', 'assignfeedback_editpdf');
38
            button = Y.Node.create('<button><img height="16" width="16" alt="' + title + '" src="' + stamp + '"/></button>');
39
            button.setAttribute('data-stamp', stamp);
40
            button.setAttribute('role', 'menuitem');
41
            button.setStyle('backgroundImage', 'none');
42
            listitem = Y.Node.create('<li/>');
43
            listitem.append(button);
44
            listitem.setAttribute('role', 'none');
45
            stamplist.append(listitem);
46
        }, this);
47
 
48
 
49
        // Set the call back.
50
        stamplist.delegate('click', this.callback_handler, 'button', this);
51
        stamplist.delegate('key', this.callback_handler, 'down:13', 'button', this);
52
 
53
        // Set the accessible header text.
54
        this.set('headerText', M.util.get_string('stamppicker', 'assignfeedback_editpdf'));
55
 
56
        // Set the body content.
57
        this.set('bodyContent', stamplist);
58
 
59
        STAMPPICKER.superclass.initializer.call(this, config);
60
    },
61
    callback_handler: function(e) {
62
        e.preventDefault();
63
        var callback = this.get('callback'),
64
            callbackcontext = this.get('context'),
65
            bind;
66
 
67
        this.hide();
68
 
69
        // Call the callback with the specified context.
70
        bind = Y.bind(callback, callbackcontext, e);
71
 
72
        bind();
73
    }
74
}, {
75
    NAME: STAMPPICKER_NAME,
76
    ATTRS: {
77
        /**
78
         * The list of stamps this stamp picker supports.
79
         *
80
         * @attribute stamps
81
         * @type String[] - the stamp filenames.
82
         * @default {}
83
         */
84
        stamps: {
85
            value: []
86
        },
87
 
88
        /**
89
         * The function called when a new stamp is chosen.
90
         *
91
         * @attribute callback
92
         * @type function
93
         * @default null
94
         */
95
        callback: {
96
            value: null
97
        },
98
 
99
        /**
100
         * The context passed to the callback when a stamp is chosen.
101
         *
102
         * @attribute context
103
         * @type Y.Node
104
         * @default null
105
         */
106
        context: {
107
            value: null
108
        }
109
    }
110
});
111
 
112
M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
113
M.assignfeedback_editpdf.stamppicker = STAMPPICKER;