MDL-18014 Atto: Add notification support to Atto.

This commit is contained in:
Damyon Wiese 2014-07-21 10:08:24 +08:00
parent 2ba6706d12
commit 75c86d13c7
7 changed files with 304 additions and 3 deletions

View File

@ -39,4 +39,6 @@ $string['plugin_title_shortcut'] = '{$a->title} [{$a->shortcut}]';
$string['confirm'] = 'Confirm';
$string['cancel'] = 'Cancel';
$string['recover'] = 'Recover';
$string['infostatus'] = 'Information';
$string['warningstatus'] = 'Warning';
$string['confirmrecover'] = 'A previously unsaved version of the text for field "{$a->label}" was found. Do you want to recover it?';

View File

@ -181,3 +181,34 @@ div.editor_atto_content:hover .atto_control {
padding-top: 5px;
padding-bottom: 5px;
}
.editor_atto_notification {
position: relative;
bottom: 0px;
height: 1.5em;
margin-top: -2.5em;
margin-left: 1px;
margin-right: 1px;
margin-bottom: 1em;
}
.editor_atto_notification .atto_info {
display: inline-block;
background-color: #F2F2F2;
padding: 0.5em;
padding-left: 1em;
padding-right: 1em;
border-top-right-radius: 1em;
}
.editor_atto_notification .atto_warning {
display: inline-block;
background-color: #FFD700;
padding: 0.5em;
padding-left: 1em;
padding-right: 1em;
border-top-right-radius: 1em;
}
.dir-rtl .editor_atto_notification .atto_info,
.dir-rtl .editor_atto_notification .atto_warning {
border-top-right-radius: 0;
border-top-left-radius: 1em;
}

View File

@ -478,6 +478,95 @@ Y.namespace('M.editor_atto.Editor').init = function(config) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A notify function for the Atto editor.
*
* @module moodle-editor_atto-notify
* @submodule notify-base
* @package editor_atto
* @copyright 2014 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function EditorNotify() {}
EditorNotify.ATTRS= {
};
// There is no error type here - because you should make errors more obvious.
var NOTIFY_WARNING = 'atto_warning',
NOTIFY_INFO = 'atto_info';
EditorNotify.prototype = {
/**
* A single Y.Overlay for this editor. There is only ever one - it is replaced if a new message comes in.
*
* @property messageOverlay
* @type {Y.Overlay}
*/
messageOverlay: null,
/**
* Show a notification in a floaty overlay somewhere in the atto editor text area.
*
* @method showMessage
* @chainable
*/
showMessage: function(message, type) {
if (this.messageOverlay === null) {
this.messageOverlay = Y.Node.create('<div class="editor_atto_notification"></div>');
this.messageOverlay.hide();
this._wrapper.append(this.messageOverlay);
this.messageOverlay.on('click', function() {
this.messageOverlay.hide();
}, this);
}
var messageTypeIcon = '';
if (type === NOTIFY_WARNING) {
messageTypeIcon = '<img width="16" height="16" src="' +
M.util.image_url('i/warning', 'moodle') +
'" alt="' + M.util.get_string('warning', 'moodle') + '"/>';
} else if (type === NOTIFY_INFO) {
messageTypeIcon = '<img width="16" height="16" src="' +
M.util.image_url('i/info', 'moodle') +
'" alt="' + M.util.get_string('info', 'moodle') + '"/>';
}
var bodyContent = Y.Node.create('<div class="' + type + '" role="alert" aria-live="assertive">' +
messageTypeIcon + ' ' +
Y.Escape.html(message) +
'</div>');
this.messageOverlay.empty();
this.messageOverlay.append(bodyContent);
this.messageOverlay.show();
return this;
}
};
Y.Base.mix(Y.M.editor_atto.Editor, [EditorNotify]);
// 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/>.
/**
* @module moodle-editor_atto-editor
* @submodule textarea

File diff suppressed because one or more lines are too long

View File

@ -475,6 +475,95 @@ Y.namespace('M.editor_atto.Editor').init = function(config) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A notify function for the Atto editor.
*
* @module moodle-editor_atto-notify
* @submodule notify-base
* @package editor_atto
* @copyright 2014 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function EditorNotify() {}
EditorNotify.ATTRS= {
};
// There is no error type here - because you should make errors more obvious.
var NOTIFY_WARNING = 'atto_warning',
NOTIFY_INFO = 'atto_info';
EditorNotify.prototype = {
/**
* A single Y.Overlay for this editor. There is only ever one - it is replaced if a new message comes in.
*
* @property messageOverlay
* @type {Y.Overlay}
*/
messageOverlay: null,
/**
* Show a notification in a floaty overlay somewhere in the atto editor text area.
*
* @method showMessage
* @chainable
*/
showMessage: function(message, type) {
if (this.messageOverlay === null) {
this.messageOverlay = Y.Node.create('<div class="editor_atto_notification"></div>');
this.messageOverlay.hide();
this._wrapper.append(this.messageOverlay);
this.messageOverlay.on('click', function() {
this.messageOverlay.hide();
}, this);
}
var messageTypeIcon = '';
if (type === NOTIFY_WARNING) {
messageTypeIcon = '<img width="16" height="16" src="' +
M.util.image_url('i/warning', 'moodle') +
'" alt="' + M.util.get_string('warning', 'moodle') + '"/>';
} else if (type === NOTIFY_INFO) {
messageTypeIcon = '<img width="16" height="16" src="' +
M.util.image_url('i/info', 'moodle') +
'" alt="' + M.util.get_string('info', 'moodle') + '"/>';
}
var bodyContent = Y.Node.create('<div class="' + type + '" role="alert" aria-live="assertive">' +
messageTypeIcon + ' ' +
Y.Escape.html(message) +
'</div>');
this.messageOverlay.empty();
this.messageOverlay.append(bodyContent);
this.messageOverlay.show();
return this;
}
};
Y.Base.mix(Y.M.editor_atto.Editor, [EditorNotify]);
// 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/>.
/**
* @module moodle-editor_atto-editor
* @submodule textarea

View File

@ -4,6 +4,7 @@
"moodle-editor_atto-editor": {
"jsfiles": [
"editor.js",
"notify.js",
"textarea.js",
"autosave.js",
"clean.js",

View File

@ -0,0 +1,89 @@
// 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/>.
/**
* A notify function for the Atto editor.
*
* @module moodle-editor_atto-notify
* @submodule notify-base
* @package editor_atto
* @copyright 2014 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function EditorNotify() {}
EditorNotify.ATTRS= {
};
// There is no error type here - because you should make errors more obvious.
var NOTIFY_WARNING = 'atto_warning',
NOTIFY_INFO = 'atto_info';
EditorNotify.prototype = {
/**
* A single Y.Overlay for this editor. There is only ever one - it is replaced if a new message comes in.
*
* @property messageOverlay
* @type {Y.Overlay}
*/
messageOverlay: null,
/**
* Show a notification in a floaty overlay somewhere in the atto editor text area.
*
* @method showMessage
* @chainable
*/
showMessage: function(message, type) {
if (this.messageOverlay === null) {
this.messageOverlay = Y.Node.create('<div class="editor_atto_notification"></div>');
this.messageOverlay.hide();
this._wrapper.append(this.messageOverlay);
this.messageOverlay.on('click', function() {
this.messageOverlay.hide();
}, this);
}
var messageTypeIcon = '';
if (type === NOTIFY_WARNING) {
messageTypeIcon = '<img width="16" height="16" src="' +
M.util.image_url('i/warning', 'moodle') +
'" alt="' + M.util.get_string('warning', 'moodle') + '"/>';
} else if (type === NOTIFY_INFO) {
messageTypeIcon = '<img width="16" height="16" src="' +
M.util.image_url('i/info', 'moodle') +
'" alt="' + M.util.get_string('info', 'moodle') + '"/>';
}
var bodyContent = Y.Node.create('<div class="' + type + '" role="alert" aria-live="assertive">' +
messageTypeIcon + ' ' +
Y.Escape.html(message) +
'</div>');
this.messageOverlay.empty();
this.messageOverlay.append(bodyContent);
this.messageOverlay.show();
return this;
}
};
Y.Base.mix(Y.M.editor_atto.Editor, [EditorNotify]);