sync-options.plugin.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const PLUGIN_NAME = "Sync Options";
  2. /**
  3. * @type {{plugin: Function, plugin:name: string, hooks: object}}
  4. */
  5. module.exports = {
  6. "plugin": function (ui, bs) {
  7. ui.listen("sync-options", {
  8. "set": function (data) {
  9. ui.logger.debug("Setting option: {magenta:%s}:{cyan:%s}", data.path.join("."), data.value);
  10. bs.setOptionIn(data.path, data.value);
  11. },
  12. "setMany": function (data) {
  13. ui.logger.debug("Setting Many options...");
  14. if (data.value !== true) {
  15. data.value = false;
  16. }
  17. bs.setMany(function (item) {
  18. [
  19. ["codeSync"],
  20. ["ghostMode", "clicks"],
  21. ["ghostMode", "scroll"],
  22. ["ghostMode", "forms", "inputs"],
  23. ["ghostMode", "forms", "toggles"],
  24. ["ghostMode", "forms", "submit"]
  25. ].forEach(function (option) {
  26. item.setIn(option, data.value);
  27. });
  28. });
  29. return bs;
  30. }
  31. });
  32. },
  33. "hooks": {
  34. "markup": fileContent("sync-options.html"),
  35. "client:js": fileContent("sync-options.client.js"),
  36. "templates": [],
  37. "page": {
  38. path: "/sync-options",
  39. title: PLUGIN_NAME,
  40. template: "sync-options.html",
  41. controller: PLUGIN_NAME.replace(" ", "") + "Controller",
  42. order: 2,
  43. icon: "sync"
  44. }
  45. },
  46. "plugin:name": PLUGIN_NAME
  47. };
  48. function getPath (filepath) {
  49. return require("path").join(__dirname, filepath);
  50. }
  51. function fileContent (filepath) {
  52. return require("fs").readFileSync(getPath(filepath), "utf-8");
  53. }