diff options
-rw-r--r-- | plugins/note/init.php | 3 | ||||
-rw-r--r-- | plugins/note/note.css | 3 | ||||
-rw-r--r-- | plugins/note/note.js | 87 |
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(); - } -}; + }); +}); |