summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-02-01 13:16:23 +0300
committerAndrew Dolgov <[email protected]>2022-02-01 13:16:23 +0300
commit6077175c57b4f793880467d4c32d7391f4b0a038 (patch)
tree8ab81363079f76919efb4b36659c13ebc4026136 /plugins
parent478c9b64a94261e9b7e68de571bf85144636509e (diff)
plugins/note: allow editing note by clicking on it
Diffstat (limited to 'plugins')
-rw-r--r--plugins/note/init.php3
-rw-r--r--plugins/note/note.css3
-rw-r--r--plugins/note/note.js87
3 files changed, 58 insertions, 35 deletions
diff --git a/plugins/note/init.php b/plugins/note/init.php
index a22b2894d..65f7e04e9 100644
--- a/plugins/note/init.php
+++ b/plugins/note/init.php
@@ -15,6 +15,9 @@ class Note extends Plugin {
return file_get_contents(__DIR__ . "/note.js");
}
+ function get_css() {
+ return file_get_contents(__DIR__ . "/note.css");
+ }
function hook_article_button($line) {
return "<i class='material-icons' onclick=\"Plugins.Note.edit(".$line["id"].")\"
diff --git a/plugins/note/note.css b/plugins/note/note.css
new file mode 100644
index 000000000..6bef7a877
--- /dev/null
+++ b/plugins/note/note.css
@@ -0,0 +1,3 @@
+.article-note[data-note-for] {
+ cursor : pointer;
+}
diff --git a/plugins/note/note.js b/plugins/note/note.js
index a46acb355..ea173bba6 100644
--- a/plugins/note/note.js
+++ b/plugins/note/note.js
@@ -1,41 +1,58 @@
-/* global dojo, Plugins, xhr, App, Notify, fox, __ */
-
-Plugins.Note = {
- edit: function(id) {
- const dialog = new fox.SingleUseDialog({
- title: __("Edit article note"),
- execute: function () {
- if (this.validate()) {
- Notify.progress("Saving article note...", true);
-
- xhr.json("backend.php", this.attr('value'), (reply) => {
- Notify.close();
- dialog.hide();
-
- if (reply) {
- App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => {
- elem.querySelector(".body").innerHTML = reply.note;
-
- if (reply.note)
- elem.show();
- else
- elem.hide();
+/* global require, Plugins, PluginHost, xhr, App, Notify, fox, __ */
+
+require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
+ ready(function() {
+
+ Plugins.Note = {
+ set_click_handler: function() {
+ document.querySelectorAll(".article-note[data-note-for]").forEach((note) => {
+ note.onclick = function() {
+ Plugins.Note.edit(this.getAttribute('data-note-for'));
+ }
+ });
+ },
+ edit: function(id) {
+ const dialog = new fox.SingleUseDialog({
+ title: __("Edit article note"),
+ execute: function () {
+ if (this.validate()) {
+ Notify.progress("Saving article note...", true);
+
+ xhr.json("backend.php", this.attr('value'), (reply) => {
+ Notify.close();
+ dialog.hide();
+
+ if (reply) {
+ App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => {
+ elem.querySelector(".body").innerHTML = reply.note;
+
+ if (reply.note)
+ elem.show();
+ else
+ elem.hide();
+ });
+ }
});
}
+ },
+ content: __("Loading, please wait...")
+ });
+
+ const tmph = dojo.connect(dialog, 'onShow', function () {
+ dojo.disconnect(tmph);
+
+ xhr.post("backend.php", App.getPhArgs("note", "edit", {id: id}), (reply) => {
+ dialog.attr('content', reply);
});
- }
- },
- content: __("Loading, please wait...")
- });
+ });
- const tmph = dojo.connect(dialog, 'onShow', function () {
- dojo.disconnect(tmph);
+ dialog.show();
+ }
+ };
- xhr.post("backend.php", App.getPhArgs("note", "edit", {id: id}), (reply) => {
- dialog.attr('content', reply);
- });
+ PluginHost.register(PluginHost.HOOK_HEADLINE_RENDERED, function() {
+ Plugins.Note.set_click_handler();
+ return true;
});
-
- dialog.show();
- }
-};
+ });
+});