Skip to content

Commit

Permalink
MDL-46779 editor: add emoji picker atto plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie committed Nov 1, 2019
1 parent e04a73c commit 11786e6
Show file tree
Hide file tree
Showing 11 changed files with 591 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/editor/atto/plugins/emojipicker/classes/privacy/provider.php
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for atto_emojipicker.
*
* @package atto_emojipicker
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace atto_emojipicker\privacy;

defined('MOODLE_INTERNAL') || die();

/**
* Privacy Subsystem for atto_emojipicker implementing null_provider.
*
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}
27 changes: 27 additions & 0 deletions lib/editor/atto/plugins/emojipicker/lang/en/atto_emojipicker.php
@@ -0,0 +1,27 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Strings for component 'atto_emojipicker', language 'en'.
*
* @package atto_emojipicker
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['emojipicker'] = 'Emoji picker';
$string['pluginname'] = 'Emoji Picker';
$string['privacy:metadata'] = 'The atto_emojipicker plugin does not store any personal data.';
48 changes: 48 additions & 0 deletions lib/editor/atto/plugins/emojipicker/lib.php
@@ -0,0 +1,48 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Atto text editor emoji picker plugin lib.
*
* @package atto_emojipicker
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Initialise the strings required for JS.
*
* @return void
*/
function atto_emojipicker_strings_for_js() {
global $PAGE;
$PAGE->requires->strings_for_js(['emojipicker'], 'atto_emojipicker');
}

/**
* Sends the parameters to JS module.
*
* @return array
*/
function atto_emojipicker_params_for_js() {
global $CFG;

return [
'disabled' => empty($CFG->allowemojipicker) ? true : false
];
}
8 changes: 8 additions & 0 deletions lib/editor/atto/plugins/emojipicker/styles.css
@@ -0,0 +1,8 @@
.emoji-picker-dialogue.moodle-dialogue-base .moodle-dialogue .moodle-dialogue-bd {
padding: 0;
}

.emoji-picker-dialogue .emoji-picker {
box-shadow: none !important; /* stylelint-disable-line declaration-no-important */
border: 0;
}
29 changes: 29 additions & 0 deletions lib/editor/atto/plugins/emojipicker/version.php
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Atto text editor emoji picker plugin version file.
*
* @package atto_emojipicker
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2019101700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2019101200; // Requires this Moodle version.
$plugin->component = 'atto_emojipicker'; // Full name of the plugin (used for diagnostics).
@@ -0,0 +1,140 @@
YUI.add('moodle-atto_emojipicker-button', function (Y, NAME) {

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/*
* @package atto_emojipicker
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* @module moodle-atto_emojipicker-button
*/
var COMPONENTNAME = 'atto_emojipicker';

/**
* Atto text editor emoji picker plugin.
*
* @namespace M.atto_emojipicker
* @class button
* @extends M.editor_atto.EditorPlugin
*/

Y.namespace('M.atto_emojipicker').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {

/**
* A reference to the current selection at the time that the dialogue
* was opened.
*
* @property _currentSelection
* @type Range
* @private
*/
_currentSelection: null,

initializer: function() {
if (this.get('disabled')) {
return;
}

this.addButton({
icon: 'e/emoticons',
callback: this._displayDialogue
});
},

/**
* Display the emoji picker.
*
* @method _displayDialogue
* @private
*/
_displayDialogue: function() {
// Store the current selection.
this._currentSelection = this.get('host').getSelection();
if (this._currentSelection === false) {
return;
}

var dialogue = this.getDialogue({
headerContent: M.util.get_string('emojipicker', COMPONENTNAME),
width: 'auto',
focusAfterHide: true,
additionalBaseClass: 'emoji-picker-dialogue'
}, true);

// Set the dialogue content, and then show the dialogue.
dialogue.set('bodyContent', this._getDialogueContent())
.show();
},

/**
* Insert the emoticon.
*
* @method _insertEmote
* @param {String} emoji
* @private
*/
_insertEmoji: function(emoji) {
var host = this.get('host');

// Hide the dialogue.
this.getDialogue({
focusAfterHide: null
}).hide();

// Focus on the previous selection.
host.setSelection(this._currentSelection);

// And add the character.
host.insertContentAtFocusPoint(emoji);

this.markUpdated();
},

/**
* Generates the content of the dialogue, attaching event listeners to
* the content.
*
* @method _getDialogueContent
* @return {Node} Node containing the dialogue content
* @private
*/
_getDialogueContent: function() {
var wrapper = Y.Node.create('<div></div>');

require(['core/templates', 'core/emoji/picker'], function(Templates, initialiseEmojiPicker) {
Templates.render('core/emoji/picker', {}).then(function(html) {
var domNode = wrapper.getDOMNode();
domNode.innerHTML = html;
initialiseEmojiPicker(domNode, this._insertEmoji.bind(this));
this.getDialogue().centerDialogue();
}.bind(this));
}.bind(this));

return wrapper;
}
}, {
ATTRS: {
disabled: {
value: true
}
}
});


}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 11786e6

Please sign in to comment.