From 51fa3376a0f9f0877e2f16a70577d4e4a055ec45 Mon Sep 17 00:00:00 2001 From: BS391 Date: Tue, 9 Nov 2021 11:49:41 +0600 Subject: [PATCH] initial commit --- README.MD | 48 +++++ ajax.php | 43 ++++ classes/output_image.php | 81 +++++++ classes/privacy/provider.php | 40 ++++ lang/en/atto_sharing.php | 42 ++++ lib.php | 73 +++++++ pix/sharing.png | Bin 0 -> 322 bytes pix/sharing.svg | 1 + settings.php | 31 +++ version.php | 32 +++ .../moodle-atto_sharing-button-debug.js | 201 ++++++++++++++++++ .../moodle-atto_sharing-button-min.js | 1 + .../moodle-atto_sharing-button.js | 201 ++++++++++++++++++ yui/src/button/build.json | 10 + yui/src/button/js/button.js | 196 +++++++++++++++++ yui/src/button/meta/atto_sharing.json | 7 + 16 files changed, 1007 insertions(+) create mode 100644 README.MD create mode 100644 ajax.php create mode 100644 classes/output_image.php create mode 100644 classes/privacy/provider.php create mode 100644 lang/en/atto_sharing.php create mode 100644 lib.php create mode 100644 pix/sharing.png create mode 100644 pix/sharing.svg create mode 100644 settings.php create mode 100644 version.php create mode 100644 yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-debug.js create mode 100644 yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-min.js create mode 100644 yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button.js create mode 100644 yui/src/button/build.json create mode 100644 yui/src/button/js/button.js create mode 100644 yui/src/button/meta/atto_sharing.json diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..bfa2e42 --- /dev/null +++ b/README.MD @@ -0,0 +1,48 @@ +# Moodle atto-sharing plugin + +Moodle Atto Sharing is an atto sub-plugin to easily create and integrate Social Sharing button to Moodle atto editor. + +This library helps you generate Sharing Button in Text editor. Generate buttons based on the given URL. + + + +## Features +- Easy Social Sharing Button integration in Moodle Atto Editor +- Easy to use + +## Configuration + +You can install this plugin from [Moodle plugins directory](https://moodle.org/plugins) or can download from [Github](https://github.com/eLearning-BS23/). + +## Toolbar Settings +``` + Dashboard -> Site administration -> Plugins -> Text editors -> Atto HTML editor -> Atto toolbar settings +``` +toolbar-config-settings + +## usages +> After installing the plugin, you can use the plugin by following: + +- Go to Atto HTML editor: +- Click on Sharing icon from Toolbar +- Insert Sharing content +- Checked in which social media you want to share and provide the page url that url you want to share. +- Done! + + + + + +## License + +This program 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. + +This program 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 +this program. If not, see . diff --git a/ajax.php b/ajax.php new file mode 100644 index 0000000..3005440 --- /dev/null +++ b/ajax.php @@ -0,0 +1,43 @@ +. + +/** + * Generate the Sharing. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ + +define('AJAX_SCRIPT', true); + +global $CFG,$PAGE; +require_once(__DIR__ . '/../../../../../config.php'); + +$contextid = required_param('contextid', PARAM_INT); +$content = required_param('content', PARAM_RAW); +$courseid = required_param('id', PARAM_RAW); + +list($context, $course, $cm) = get_context_info_array($contextid); + +$PAGE->set_url('/lib/editor/atto/plugins/sharing/ajax.php'); +$PAGE->set_context($context); + +require_login($course, false, $cm); +require_sesskey(); + + diff --git a/classes/output_image.php b/classes/output_image.php new file mode 100644 index 0000000..ae256bf --- /dev/null +++ b/classes/output_image.php @@ -0,0 +1,81 @@ +. + +/** + * This file contains a class that provides functions for generate a QR code. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace atto_sharing; + +use Endroid\QrCode\Color\Color; +use Endroid\QrCode\Encoding\Encoding; +use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow; +use Endroid\QrCode\QrCode; +use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin; +use Endroid\QrCode\Writer\PngWriter; +use DOMDocument; +use Exception; +use stdClass; + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot . '/lib/editor/atto/plugins/sharing/thirdparty/vendor/autoload.php'); +require_once($CFG->dirroot . '/course/lib.php'); + +/** + * Class output_image + * + * Output QR code. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class output_image +{ + /** + * QR code is saved in this file. + * @var string + */ + protected $file; + + /** + * Output file type. + * 0 - png, 1 - svg + * @var int + */ + protected $format; + + /** + * Course for which the sharing is created. + * @var stdClass + */ + protected $context; + + /** + * @param $context + */ + public function __construct($context) + { + $this->format = 2; + $this->context = $context; + } + +} diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php new file mode 100644 index 0000000..6801241 --- /dev/null +++ b/classes/privacy/provider.php @@ -0,0 +1,40 @@ +. + +/** + * Privacy Subsystem implementation for atto_sharing. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace atto_sharing\privacy; + +use core_privacy\local\metadata\null_provider; + +defined('MOODLE_INTERNAL') || die(); + +class provider implements null_provider +{ + + /** + * @inheritDoc + */ + public static function get_reason(): string + { + return 'privacy:metadata'; + } +} \ No newline at end of file diff --git a/lang/en/atto_sharing.php b/lang/en/atto_sharing.php new file mode 100644 index 0000000..1a04ec1 --- /dev/null +++ b/lang/en/atto_sharing.php @@ -0,0 +1,42 @@ +. + +/** + * Language file for atto_sharing. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ + +$string["pluginname"] = 'Sharing'; +$string["sharing_settings"] = 'Sharing settings'; +$string["sharing_size"] = 'Size'; +$string["sharing_size_desc"] = 'Height and width of Sharing'; +$string["sharing_margin"] = 'Margin'; +$string["sharing_margin_desc"] = 'Margin for Sharing'; +$string["sharingcontent"] = 'QR code content'; +$string["insertsharing"] = 'Insert Sharing Button'; +$string["backgroundcolor"] = 'Background color (RGBA)'; +$string["forgroungcolor"] = 'Foreground color (RGBA)'; + + +$string["facebook"] = 'Facebook Share'; +$string["linkedin"] = 'Linkedin Share'; +$string["twiter"] = 'Twiter Share'; +$string["googleplus_share"] = 'Gooele Plus Share'; +$string["url"] = 'Sharing URL'; diff --git a/lib.php b/lib.php new file mode 100644 index 0000000..23c9922 --- /dev/null +++ b/lib.php @@ -0,0 +1,73 @@ +. + +/** + * Atto Sharing library function. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Set params for this plugin. + * @param string $elementid + * @param stdClass $options + * @param stdClass $fpoptions + * @return array + * @throws coding_exception + * @throws dml_exception + */ +function atto_sharing_params_for_js($elementid, $options, $fpoptions) { + global $USER; + + // Disabled if: + // - Not logged in or guest. + $disabled = !isloggedin() || isguestuser() ; + + $context = $options['context']; + if (!$context) { + $context = context_system::instance(); + } + + return array( + 'disabled' => $disabled, + 'contextid' => $context->id + ); + +} + +/** + * Initialise the js strings required for this module. + */ +function atto_sharing_strings_for_js() { + global $PAGE; + + $PAGE->requires->strings_for_js( + array( + 'pluginname', + 'facebook', + 'twiter', + 'linkedin', + 'insertsharing', + 'url', + ), + 'atto_sharing' + ); +} \ No newline at end of file diff --git a/pix/sharing.png b/pix/sharing.png new file mode 100644 index 0000000000000000000000000000000000000000..921f93348e73b9267a30c06da34053b977266eb5 GIT binary patch literal 322 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjY)RhkE)4%caKYZ?lYt`NJzX3_ zJUX9Var9z#6kxqzuD8j^J6}NmfuC*n&fYYe7Rz4i^$#uu9^`gW-O|18fQx#Ut*pQw zgMbkJ{j2M1?f%OO$2=C46}z~)P3-06^3cysdLHKss#4=S!mI|xAPXq9owS$tN8Y;|6I=7 zyeoP)XKH?AbKX{cyioI@-fS`N55i(?s!=OdE~@CgOnJR^$Hu)+xT`A?O=s7&yUnXh zZrS>0S6E%{RufyEMX`Z_y1wZZn~$69J??!a^zxQ|#c1*6F9m*WlbgD%UR?f_NP@}c Su%n>RV(@hJb6Mw<&;$U?Duy%w literal 0 HcmV?d00001 diff --git a/pix/sharing.svg b/pix/sharing.svg new file mode 100644 index 0000000..c0ff42f --- /dev/null +++ b/pix/sharing.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/settings.php b/settings.php new file mode 100644 index 0000000..908a0d0 --- /dev/null +++ b/settings.php @@ -0,0 +1,31 @@ +. + +/** + * Moodle global Settings file for atto_sharing. + * + * @package atto_sharing + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ + +defined('MOODLE_INTERNAL') || die(); + +$ADMIN->add('editoratto', new admin_category('atto_sharing', new lang_string('sharing_settings', 'atto_sharing'))); + +if ($ADMIN->fulltree) { +} diff --git a/version.php b/version.php new file mode 100644 index 0000000..35d677f --- /dev/null +++ b/version.php @@ -0,0 +1,32 @@ +. + +/** + * version file for atto_sharing. + * + * @package atto_qrcode + * @copyright 2021 Brain Station 23 Ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2021090100; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2019111803; // Requires this Moodle version. +$plugin->component = 'atto_sharing'; // Full name of the plugin (used for diagnostics). +$plugin->release = 'v1.0.0'; +$plugin->maturity = MATURITY_STABLE; \ No newline at end of file diff --git a/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-debug.js b/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-debug.js new file mode 100644 index 0000000..260dbdf --- /dev/null +++ b/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-debug.js @@ -0,0 +1,201 @@ +YUI.add('moodle-atto_sharing-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 . + +/* + * @package atto_sharing + * @copyright 2021 Brain station 23 ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * @module moodle-atto_sharing-button + * @namespace M.atto_sharing + * @class Button + * @extends M.editor_atto.EditorPlugin + */ + +var COMPONENTNAME = 'atto_sharing', + // @codingStandardsIgnoreStart + IMAGETEMPLATE = '', + TEMPLATES = '
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.facebook+'
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.twiter+'
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.linkedin+'
' + + '' + + '' + + '' + + '
', + THUMBIMAGE = ''; +// @codingStandardsIgnoreEnd + +Y.use('core/event') + .namespace('M.atto_sharing').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, + /** + * Add event listeners. + * + * @method initializer + */ + + initializer: function() { + + // If we don't have the capability to view then give up. + if (this.get('disabled')) { + return; + } + + this.addButton({ + icon: 'sharing', + iconComponent: COMPONENTNAME, + callback: this._handleQrCodeGenerator, + callbackArgs: 'sharing' + }); + }, + + /** + * Handle sharing video contetn import to text area + * @method _handleQrCodeGenerator + * @private + */ + _handleQrCodeGenerator: function() { + + var dialogue = this.getDialogue({ + headerContent: M.util.get_string('insertsharing', COMPONENTNAME), + focusAfterHide: true, + width: 660 + }); + + dialogue.set('bodyContent', this._getDialogueContent(this.get('host').getSelection())).show(); + // M.form.shortforms({formid: 'atto_sharing_form'}); + }, + + /** + * Returns the dialogue content for the tool. + * + * @method _getDialogueContent + * @param {WrappedRange[]} selection Current editor selection + * @return {Y.Node} + * @private + */ + _getDialogueContent: function(selection) { + var context = { + facebook: this.get('facebook'), + twiter: this.get('twiter'), + }; + var content = Y.Node.create( + Y.Handlebars.compile(TEMPLATES)(context) + ); + return this._attachEvents(content, selection); + }, + /** + * Attaches required events to the content node. + * + * @method _attachEvents + * @param {Y.Node} content The content to which events will be attached + * @param {WrappedRange[]} selection Current editor selection + * @return {Y.Node} + * @private + */ + _attachEvents: function(content, selection) { + content.one('.submit').on('click', function(e) { + e.preventDefault(); + var facebook = ''; + var twiter = ''; + var linkedin = ''; + var url = ''; + if(document.getElementById('facebook').checked) { + facebook = 'facebook'; + }if(document.getElementById('twiter').checked) { + twiter = 'twiter'; + }if(document.getElementById('linkedin').checked) { + linkedin = 'linkedin'; + } + url = document.getElementById('url').value; + if(url == null || url== ''){ + alert('Url Required'); + return; + } + this._getMediaHTMLSharing(selection,facebook,twiter,linkedin,url); + }, this); + + return content; + }, + /** + * Returns the HTML to be inserted to the text area for the link tab. + * + * @method _getMediaHTMLLink + * @param {Y.Node} tab The tab from which to extract data + * @return {String} The compiled markup + * @private + */ + _getMediaHTMLSharing: function(selection,facebook,twiter,linkedin,url) { + var parentContext = this; + var mediaHTML=''; + if (facebook === 'facebook'){ + mediaHTML +='' + + ' Facebook ' + + ''; + } + if (twiter === 'twiter'){ + mediaHTML +='' + + '\n' + + ' \n' + + ' Twiter'; + } + if (linkedin === 'linkedin'){ + mediaHTML +='' + + ' Linkedin'; + } + var host = parentContext.get('host'); + + parentContext.getDialogue({ + focusAfterHide: null + }).hide(); + // eslint-disable-next-line promise/always-return + if (mediaHTML) { + host.setSelection(selection); + host.insertContentAtFocusPoint(mediaHTML); + parentContext.markUpdated(); + } + } + }); + + + +}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]}); diff --git a/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-min.js b/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-min.js new file mode 100644 index 0000000..515e620 --- /dev/null +++ b/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button-min.js @@ -0,0 +1 @@ +YUI.add("moodle-atto_sharing-button",function(i,t){var e="atto_sharing",n='
'+M.str.atto_sharing.facebook+'
'+M.str.atto_sharing.twiter+'
'+M.str.atto_sharing.linkedin+'
";i.use("core/event").namespace("M.atto_sharing").Button=i.Base.create("button",i.M.editor_atto.EditorPlugin,[],{_currentSelection:null,initializer:function(){this.get("disabled")||this.addButton({icon:"sharing",iconComponent:e,callback:this._handleQrCodeGenerator,callbackArgs:"sharing"})},_handleQrCodeGenerator:function(){this.getDialogue({headerContent:M.util.get_string("insertsharing",e),focusAfterHide:!0,width:660}).set("bodyContent",this._getDialogueContent(this.get("host").getSelection())).show()},_getDialogueContent:function(t){var e={facebook:this.get("facebook"),twiter:this.get("twiter")},a=i.Node.create(i.Handlebars.compile(n)(e));return this._attachEvents(a,t)},_attachEvents:function(t,o){return t.one(".submit").on("click",function(t){var e,a,i,n;t.preventDefault(),n=i=a=e="",document.getElementById("facebook").checked&&(e="facebook"),document.getElementById("twiter").checked&&(a="twiter"),document.getElementById("linkedin").checked&&(i="linkedin"),null!=(n=document.getElementById("url").value)&&""!=n?this._getMediaHTMLSharing(o,e,a,i,n):alert("Url Required")},this),t},_getMediaHTMLSharing:function(t,e,a,i,n){var o,r=this,l="";"facebook"===e&&(l+=' Facebook '),"twiter"===a&&(l+='\n \n Twiter'),"linkedin"===i&&(l+=' Linkedin'),o=r.get("host"),r.getDialogue({focusAfterHide:null}).hide(),l&&(o.setSelection(t),o.insertContentAtFocusPoint(l),r.markUpdated())}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); \ No newline at end of file diff --git a/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button.js b/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button.js new file mode 100644 index 0000000..260dbdf --- /dev/null +++ b/yui/build/moodle-atto_sharing-button/moodle-atto_sharing-button.js @@ -0,0 +1,201 @@ +YUI.add('moodle-atto_sharing-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 . + +/* + * @package atto_sharing + * @copyright 2021 Brain station 23 ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * @module moodle-atto_sharing-button + * @namespace M.atto_sharing + * @class Button + * @extends M.editor_atto.EditorPlugin + */ + +var COMPONENTNAME = 'atto_sharing', + // @codingStandardsIgnoreStart + IMAGETEMPLATE = '', + TEMPLATES = '
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.facebook+'
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.twiter+'
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.linkedin+'
' + + '' + + '' + + '' + + '
', + THUMBIMAGE = ''; +// @codingStandardsIgnoreEnd + +Y.use('core/event') + .namespace('M.atto_sharing').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, + /** + * Add event listeners. + * + * @method initializer + */ + + initializer: function() { + + // If we don't have the capability to view then give up. + if (this.get('disabled')) { + return; + } + + this.addButton({ + icon: 'sharing', + iconComponent: COMPONENTNAME, + callback: this._handleQrCodeGenerator, + callbackArgs: 'sharing' + }); + }, + + /** + * Handle sharing video contetn import to text area + * @method _handleQrCodeGenerator + * @private + */ + _handleQrCodeGenerator: function() { + + var dialogue = this.getDialogue({ + headerContent: M.util.get_string('insertsharing', COMPONENTNAME), + focusAfterHide: true, + width: 660 + }); + + dialogue.set('bodyContent', this._getDialogueContent(this.get('host').getSelection())).show(); + // M.form.shortforms({formid: 'atto_sharing_form'}); + }, + + /** + * Returns the dialogue content for the tool. + * + * @method _getDialogueContent + * @param {WrappedRange[]} selection Current editor selection + * @return {Y.Node} + * @private + */ + _getDialogueContent: function(selection) { + var context = { + facebook: this.get('facebook'), + twiter: this.get('twiter'), + }; + var content = Y.Node.create( + Y.Handlebars.compile(TEMPLATES)(context) + ); + return this._attachEvents(content, selection); + }, + /** + * Attaches required events to the content node. + * + * @method _attachEvents + * @param {Y.Node} content The content to which events will be attached + * @param {WrappedRange[]} selection Current editor selection + * @return {Y.Node} + * @private + */ + _attachEvents: function(content, selection) { + content.one('.submit').on('click', function(e) { + e.preventDefault(); + var facebook = ''; + var twiter = ''; + var linkedin = ''; + var url = ''; + if(document.getElementById('facebook').checked) { + facebook = 'facebook'; + }if(document.getElementById('twiter').checked) { + twiter = 'twiter'; + }if(document.getElementById('linkedin').checked) { + linkedin = 'linkedin'; + } + url = document.getElementById('url').value; + if(url == null || url== ''){ + alert('Url Required'); + return; + } + this._getMediaHTMLSharing(selection,facebook,twiter,linkedin,url); + }, this); + + return content; + }, + /** + * Returns the HTML to be inserted to the text area for the link tab. + * + * @method _getMediaHTMLLink + * @param {Y.Node} tab The tab from which to extract data + * @return {String} The compiled markup + * @private + */ + _getMediaHTMLSharing: function(selection,facebook,twiter,linkedin,url) { + var parentContext = this; + var mediaHTML=''; + if (facebook === 'facebook'){ + mediaHTML +='' + + ' Facebook ' + + ''; + } + if (twiter === 'twiter'){ + mediaHTML +='' + + '\n' + + ' \n' + + ' Twiter'; + } + if (linkedin === 'linkedin'){ + mediaHTML +='' + + ' Linkedin'; + } + var host = parentContext.get('host'); + + parentContext.getDialogue({ + focusAfterHide: null + }).hide(); + // eslint-disable-next-line promise/always-return + if (mediaHTML) { + host.setSelection(selection); + host.insertContentAtFocusPoint(mediaHTML); + parentContext.markUpdated(); + } + } + }); + + + +}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]}); diff --git a/yui/src/button/build.json b/yui/src/button/build.json new file mode 100644 index 0000000..97e58aa --- /dev/null +++ b/yui/src/button/build.json @@ -0,0 +1,10 @@ +{ + "name": "moodle-atto_sharing-button", + "builds": { + "moodle-atto_sharing-button": { + "jsfiles": [ + "button.js" + ] + } + } +} \ No newline at end of file diff --git a/yui/src/button/js/button.js b/yui/src/button/js/button.js new file mode 100644 index 0000000..d48b92d --- /dev/null +++ b/yui/src/button/js/button.js @@ -0,0 +1,196 @@ +// 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 . + +/* + * @package atto_sharing + * @copyright 2021 Brain station 23 ltd. + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * @module moodle-atto_sharing-button + * @namespace M.atto_sharing + * @class Button + * @extends M.editor_atto.EditorPlugin + */ + +var COMPONENTNAME = 'atto_sharing', + // @codingStandardsIgnoreStart + IMAGETEMPLATE = '', + TEMPLATES = '
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.facebook+'
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.twiter+'
' + + '
'+ + '
' + + '' + + '
'+M.str.atto_sharing.linkedin+'
' + + '' + + '' + + '' + + '
', + THUMBIMAGE = ''; +// @codingStandardsIgnoreEnd + +Y.use('core/event') + .namespace('M.atto_sharing').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, + /** + * Add event listeners. + * + * @method initializer + */ + + initializer: function() { + + // If we don't have the capability to view then give up. + if (this.get('disabled')) { + return; + } + + this.addButton({ + icon: 'sharing', + iconComponent: COMPONENTNAME, + callback: this._handleQrCodeGenerator, + callbackArgs: 'sharing' + }); + }, + + /** + * Handle sharing video contetn import to text area + * @method _handleQrCodeGenerator + * @private + */ + _handleQrCodeGenerator: function() { + + var dialogue = this.getDialogue({ + headerContent: M.util.get_string('insertsharing', COMPONENTNAME), + focusAfterHide: true, + width: 660 + }); + + dialogue.set('bodyContent', this._getDialogueContent(this.get('host').getSelection())).show(); + // M.form.shortforms({formid: 'atto_sharing_form'}); + }, + + /** + * Returns the dialogue content for the tool. + * + * @method _getDialogueContent + * @param {WrappedRange[]} selection Current editor selection + * @return {Y.Node} + * @private + */ + _getDialogueContent: function(selection) { + var context = { + facebook: this.get('facebook'), + twiter: this.get('twiter'), + }; + var content = Y.Node.create( + Y.Handlebars.compile(TEMPLATES)(context) + ); + return this._attachEvents(content, selection); + }, + /** + * Attaches required events to the content node. + * + * @method _attachEvents + * @param {Y.Node} content The content to which events will be attached + * @param {WrappedRange[]} selection Current editor selection + * @return {Y.Node} + * @private + */ + _attachEvents: function(content, selection) { + content.one('.submit').on('click', function(e) { + e.preventDefault(); + var facebook = ''; + var twiter = ''; + var linkedin = ''; + var url = ''; + if(document.getElementById('facebook').checked) { + facebook = 'facebook'; + }if(document.getElementById('twiter').checked) { + twiter = 'twiter'; + }if(document.getElementById('linkedin').checked) { + linkedin = 'linkedin'; + } + url = document.getElementById('url').value; + if(url == null || url== ''){ + alert('Url Required'); + return; + } + this._getMediaHTMLSharing(selection,facebook,twiter,linkedin,url); + }, this); + + return content; + }, + /** + * Returns the HTML to be inserted to the text area for the link tab. + * + * @method _getMediaHTMLLink + * @param {Y.Node} tab The tab from which to extract data + * @return {String} The compiled markup + * @private + */ + _getMediaHTMLSharing: function(selection,facebook,twiter,linkedin,url) { + var parentContext = this; + var mediaHTML=''; + if (facebook === 'facebook'){ + mediaHTML +='' + + ' Facebook ' + + ''; + } + if (twiter === 'twiter'){ + mediaHTML +='' + + '\n' + + ' \n' + + ' Twiter'; + } + if (linkedin === 'linkedin'){ + mediaHTML +='' + + ' Linkedin'; + } + var host = parentContext.get('host'); + + parentContext.getDialogue({ + focusAfterHide: null + }).hide(); + // eslint-disable-next-line promise/always-return + if (mediaHTML) { + host.setSelection(selection); + host.insertContentAtFocusPoint(mediaHTML); + parentContext.markUpdated(); + } + } + }); + diff --git a/yui/src/button/meta/atto_sharing.json b/yui/src/button/meta/atto_sharing.json new file mode 100644 index 0000000..4503e1e --- /dev/null +++ b/yui/src/button/meta/atto_sharing.json @@ -0,0 +1,7 @@ +{ + "moodle-atto_sharing-button": { + "requires": [ + "moodle-editor_atto-plugin" + ] + } +} \ No newline at end of file