Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniketk9211 authored Apr 17, 2024
0 parents commit 3a48af0
Show file tree
Hide file tree
Showing 20 changed files with 1,588 additions and 0 deletions.
596 changes: 596 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Chem Drawing Tool #

TODO Describe the plugin shortly here.

TODO Provide more detailed description here.

## Installing via uploaded ZIP file ##

1. Log in to your Moodle site as an admin and go to _Site administration >
Plugins > Install plugins_.
2. Upload the ZIP file with the plugin code. You should only be prompted to add
extra details if your plugin type is not automatically detected.
3. Check the plugin validation report and finish the installation.

## Installing manually ##

The plugin can be also installed by putting the contents of this directory to

{your/moodle/dirroot}/lib/editor/tiny/plugins/chemdraw

Afterwards, log in to your Moodle site as an admin and go to _Site administration >
Notifications_ to complete the installation.

Alternatively, you can run

$ php admin/cli/upgrade.php

to complete the installation from the command line.

## License ##

2024 Aniket Kumar <aniketkj9211@gmail.com>

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 <https://www.gnu.org/licenses/>.
71 changes: 71 additions & 0 deletions amd/src/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Commands helper for the Moodle tiny_chemdraw plugin.
*
* @module plugintype_pluginname/commands
* @copyright 2024 Aniket Kumar <aniketkj9211@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import {getButtonImage} from "editor_tiny/utils";
import {get_string as getString} from "core/str";
import {handleAction} from "./ui";
import {component, startMolDrawButtonName, startMolDrawMenuItemName, icon} from "./common";

/**
* Handle the action for your plugin.
* @param {TinyMCE.editor} editor The tinyMCE editor instance.
*/
// handle Action funciton..


/**
* Get the setup function for the buttons.
*
* This is performed in an async function which ultimately returns the registration function as the
* Tiny.AddOnManager.Add() function does not support async functions.
*
* @returns {function} The registration function to call within the Plugin.add function.
*/
export const getSetup = async() => {
try {
const [startMolDrawButtonNameTitle, startMolDrawMenuItemNameTitle, buttonImage] = await Promise.all([
getString("button_startMolDraw", component),
getString("menuitem_startMolDraw", component),
getButtonImage("icon", component),
]);

return (editor) => {
editor.ui.registry.addIcon(icon, buttonImage.html);

editor.ui.registry.addButton(startMolDrawButtonName, {
icon,
tooltip: startMolDrawButtonNameTitle,
onAction: () => handleAction(editor),
});

editor.ui.registry.addMenuItem(startMolDrawMenuItemName, {
icon,
text: startMolDrawMenuItemNameTitle,
onAction: () => handleAction(editor),
});
};
} catch (error) {
// eslint-disable-next-line no-alert
alert("Error setting up plugin:", error);
}
};
32 changes: 32 additions & 0 deletions amd/src/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Common values helper for the Moodle tiny_chemdraw plugin.
*
* @module plugintype_pluginname/common
* @copyright 2024 Aniket Kumar <aniketkj9211@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

const component = 'tiny_moldraw';

export default {
component,
pluginName: `${component}/plugin`,
icon: component,
startMolDrawButtonName: `${component}_startMolDraw`,
startMolDrawMenuItemName: `${component}_startMolDraw`,
};
57 changes: 57 additions & 0 deletions amd/src/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Tiny tiny_chemdraw for Moodle.
*
* @module plugintype_pluginname/plugin
* @copyright 2024 Aniket Kumar <aniketkj9211@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import {
startMolDrawButtonName,
startMolDrawMenuItemName,
} from './common';

import {
addMenubarItem,
addToolbarButtons,
} from 'editor_tiny/utils';

const getToolbarConfiguration = (instanceConfig) => {
let toolbar = instanceConfig.toolbar;
toolbar = addToolbarButtons(toolbar, 'content', [
startMolDrawButtonName,
]);

return toolbar;
};

const getMenuConfiguration = (instanceConfig) => {
let menu = instanceConfig.menu;
menu = addMenubarItem(menu, 'file', [
startMolDrawMenuItemName,
].join(' '));

return menu;
};

export const configure = (instanceConfig) => {
return {
toolbar: getToolbarConfiguration(instanceConfig),
menu: getMenuConfiguration(instanceConfig),
};
};
53 changes: 53 additions & 0 deletions amd/src/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

/**
* Tiny tiny_chemdraw for Moodle.
*
* @module plugintype_pluginname/plugin
* @copyright 2024 Aniket Kumar <aniketkj9211@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import { getTinyMCE } from 'editor_tiny/loader';
import { getPluginMetadata } from 'editor_tiny/utils';

import { component, pluginName } from './common';
import { register as registerOptions } from './options';
import { getSetup as getCommandSetup } from './commands';
import * as Configuration from './configuration';

// Setup the tiny_moldraw Plugin.
export default new Promise((resolve) => {
Promise.all([
getTinyMCE(),
getPluginMetadata(component, pluginName),
getCommandSetup(),
]).then(([tinyMCE, pluginMetadata, setupCommands]) => {
// Register the plugin with TinyMCE
tinyMCE.PluginManager.add(pluginName, (editor) => {
// Register any options that your plugin has
registerOptions(editor);

// Setup any commands such as buttons, menu items, and so on.
setupCommands(editor);

// Return the pluginMetadata object. This is used by TinyMCE to display a help link for your plugin.
return pluginMetadata;
});

resolve([pluginName, Configuration]);
});
});
Loading

0 comments on commit 3a48af0

Please sign in to comment.