etherpad-lite icon indicating copy to clipboard operation
etherpad-lite copied to clipboard

Unable to understand the workflow of adding a plugin

Open sonikanishk opened this issue 5 years ago • 1 comments

So I'm trying to build a custom spellcheck plugin using a ML API, and I'm referring the current spellcheck plugin but I'm unable to understand how exactly it works

'use strict';

const padcookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie;

const postAceInit = function (hook, context) {
  const $outer = $('iframe[name="ace_outer"]').contents().find('iframe');
  const $inner = $outer.contents().find('#innerdocbody');
  const spellcheck = {
    enable() {
      $inner.attr('spellcheck', 'true');
      $inner.find('div').each(function () {
        $(this).attr('spellcheck', 'true');
        $(this).find('div').each(function () {
          $(this).attr('spellcheck', 'true');
        });
      });
    },
    disable() {
      $inner.attr('spellcheck', 'false');
      $inner.find('div').each(function () {
        $(this).attr('spellcheck', 'false');
        $(this).find('span').each(function () {
          $(this).attr('spellcheck', 'false');
        });
      });
    },
  };
  /* init */
  if (padcookie.getPref('spellcheck') === false) {
    $('#options-spellcheck').val();
    $('#options-spellcheck').attr('checked', 'unchecked');
    $('#options-spellcheck').attr('checked', false);
  } else {
    $('#options-spellcheck').attr('checked', 'checked');
  }

  if ($('#options-spellcheck').is(':checked')) {
    spellcheck.enable();
  } else {
    spellcheck.disable();
  }

  /* on click */
  $('#options-spellcheck').on('click', () => {
    if ($('#options-spellcheck').is(':checked')) {
      padcookie.setPref('spellcheck', true);
      spellcheck.enable();
    } else {
      padcookie.setPref('spellcheck', false);
      spellcheck.disable();
    }
    if (window.browser.chrome) window.location.reload();
  });
};
exports.postAceInit = postAceInit;
  1. I am unable understand the use of cookie here
  2. How exactly is the content being pushed into the spellcheck function?
  3. From where is the spellcheck function checking the spelling?
  4. Does it keep checking the entire text that the user enters or just the latest word entered by the user

Waiting for your reply! Thank You

sonikanishk avatar Jan 05 '21 14:01 sonikanishk

@sonikanishk did you figure this out yet? If you are still stuck let me know and we can reopen, AFAIk you got this sorted..

Please don't leave stale issues :)

JohnMcLear avatar Jan 12 '21 14:01 JohnMcLear