<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
var XWiki = (function(XWiki) {
// Start XWiki augmentation.

var editors = XWiki.editors = XWiki.editors || {};
/**
 * Autosave feature.
 * TODO Improve i18n support
 * TODO Don't save if there were no changes
 * TODO Support for the WYSIWYG editors
 * TODO Don't show in the class editor, if there is no class defined
 */
editors.AutoSave = Class.create({
  options : {
    /** Is the autosave enabled ? */
    enabled: false,
    /** If enabled, how frequent are the savings */
    frequency: 5, // minutes
    /** Is the UI for configuring the autosave enabled or not? */
    showConfigurationUI: true,
    /** Disabled text opacity **/
    disabledOpacity: 0.2,
    /**
     * Form to autosave, either a DOM element or its ID.
     * By default the form containing the element with the "xwikieditcontent" ID is used.
     * If no valid form is specified, then the autosave won't do anything at all.
     */
    form: undefined
  },
  /** Initialization */
  initialize : function(options) {
    this.options = Object.extend(Object.clone(this.options), options || { });
    this.form = $(this.options.form) || ($("xwikieditcontent") && $("xwikieditcontent").up('form'));
    if (!this.form || this.form.down('#autosaveControl')) {
      return;
    }
    this.initVersionMetadataElements();
    if (this.options.showConfigurationUI) {
      this.createUIElements();
      this.addListeners();
    }
    if (this.options.enabled) {
      this.startTimer();
    }
  },
  /**
   * The metadata elements are the version comment input and the minor edit checkbox in the editor form.
   * They may be missing if the document is new or if the wiki was configured not to display them.
   * If they are missing, hidden inputs are created and introduced in the form in their place.
   * By means of these, every autosaved version is marked as minor and contains the text "(Autosaved)" in the comment.
   */
  initVersionMetadataElements : function() {
    var container = new Element("div", {"class" : "hidden"});
    this.editComment = this.form.comment; // The element containing the edit comment from the edit form
    if (!this.editComment) {
      this.editComment = new Element('input', {type : "hidden", name: "comment"});
      this.customMetadataElementsContainer = container;
      container.insert(this.editComment);
    }
    this.minorEditCheckbox = this.form.minorEdit; // The minor edit checkbox from the edit form
    if (!this.minorEditCheckbox) {
      // Value already set, does not need to be switched on/off
      this.minorEditCheckbox = new Element('input', {type : "checkbox", name: "minorEdit", checked: true});
      this.customMetadataElementsContainer = container;
      container.insert(this.minorEditCheckbox);
    }
  },

  /**
   * The UI of the autosave feature is created and introduced at the beginning of the edit form. It comprises a checkbox
   * for enabling / disabling the autosave and an input that allows to set the autosave frequency.
   */
  createUIElements : function() {
    // Checkbox to enable/disable the autosave
    this.autosaveCheckbox = new Element('input', {type: "checkbox", checked: this.options.enabled, name: "doAutosave", id: "doAutosave"});
    // Input for setting the autosave frequency
    this.autosaveInput = new Element('input', {type: "text", value: this.options.frequency, size : "2", "class": "autosave-frequency"});
    // Labels
    var autosaveLabel = new Element('label', {'class': 'autosave', 'for' : "doAutosave"});
    autosaveLabel.appendChild(this.autosaveCheckbox);
    autosaveLabel.appendChild(document.createTextNode("$services.localization.render('core.edit.autosave')"));
    var frequencyLabel = new Element('label', {'class': 'frequency'});
    frequencyLabel.appendChild(document.createTextNode("$services.localization.render('core.edit.autosave.every') "));
    frequencyLabel.appendChild(this.autosaveInput);
    this.timeUnit = new Element('span');
    this.setTimeUnit();
    frequencyLabel.appendChild(document.createTextNode(" "));
    frequencyLabel.appendChild(this.timeUnit);
    if (!this.options.enabled) {
      frequencyLabel.setOpacity(this.options.disabledOpacity);
    }
    // A paragraph containing the whole thing
    var container = new Element('div', {"id": "autosaveControl"});
    container.appendChild(autosaveLabel);
    container.appendChild(document.createTextNode(" "));
    container.appendChild(frequencyLabel);<commit_msg>XWIKI-15854: No translation key used in autosave.js<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
var XWiki = (function(XWiki) {
// Start XWiki augmentation.

var editors = XWiki.editors = XWiki.editors || {};
/**
 * Autosave feature.
 * TODO Improve i18n support
 * TODO Don't save if there were no changes
 * TODO Support for the WYSIWYG editors
 * TODO Don't show in the class editor, if there is no class defined
 */
editors.AutoSave = Class.create({
  options : {
    /** Is the autosave enabled ? */
    enabled: false,
    /** If enabled, how frequent are the savings */
    frequency: 5, // minutes
    /** Is the UI for configuring the autosave enabled or not? */
    showConfigurationUI: true,
    /** Disabled text opacity **/
    disabledOpacity: 0.2,
    /**
     * Form to autosave, either a DOM element or its ID.
     * By default the form containing the element with the "xwikieditcontent" ID is used.
     * If no valid form is specified, then the autosave won't do anything at all.
     */
    form: undefined
  },
  /** Initialization */
  initialize : function(options) {
    this.options = Object.extend(Object.clone(this.options), options || { });
    this.form = $(this.options.form) || ($("xwikieditcontent") && $("xwikieditcontent").up('form'));
    if (!this.form || this.form.down('#autosaveControl')) {
      return;
    }
    this.initVersionMetadataElements();
    if (this.options.showConfigurationUI) {
      this.createUIElements();
      this.addListeners();
    }
    if (this.options.enabled) {
      this.startTimer();
    }
  },
  /**
   * The metadata elements are the version comment input and the minor edit checkbox in the editor form.
   * They may be missing if the document is new or if the wiki was configured not to display them.
   * If they are missing, hidden inputs are created and introduced in the form in their place.
   * By means of these, every autosaved version is marked as minor and contains the text "(Autosaved)" in the comment.
   */
  initVersionMetadataElements : function() {
    var container = new Element("div", {"class" : "hidden"});
    this.editComment = this.form.comment; // The element containing the edit comment from the edit form
    if (!this.editComment) {
      this.editComment = new Element('input', {type : "hidden", name: "comment"});
      this.customMetadataElementsContainer = container;
      container.insert(this.editComment);
    }
    this.minorEditCheckbox = this.form.minorEdit; // The minor edit checkbox from the edit form
    if (!this.minorEditCheckbox) {
      // Value already set, does not need to be switched on/off
      this.minorEditCheckbox = new Element('input', {type : "checkbox", name: "minorEdit", checked: true});
      this.customMetadataElementsContainer = container;
      container.insert(this.minorEditCheckbox);
    }
  },

  /**
   * The UI of the autosave feature is created and introduced at the beginning of the edit form. It comprises a checkbox
   * for enabling / disabling the autosave and an input that allows to set the autosave frequency.
   */
  createUIElements : function() {
    // Checkbox to enable/disable the autosave
    this.autosaveCheckbox = new Element('input', {type: "checkbox", checked: this.options.enabled, name: "doAutosave", id: "doAutosave"});
    // Input for setting the autosave frequency
    this.autosaveInput = new Element('input', {type: "text", value: this.options.frequency, size : "2", "class": "autosave-frequency"});
    // Labels
    var autosaveLabel = new Element('label', {'class': 'autosave', 'for' : "doAutosave"});
    autosaveLabel.appendChild(this.autosaveCheckbox);
    autosaveLabel.appendChild(document.createTextNode(" $services.localization.render('core.edit.autosave')"));
    var frequencyLabel = new Element('label', {'class': 'frequency'});
    frequencyLabel.appendChild(document.createTextNode("$services.localization.render('core.edit.autosave.every') "));
    frequencyLabel.appendChild(this.autosaveInput);
    this.timeUnit = new Element('span');
    this.setTimeUnit();
    frequencyLabel.appendChild(document.createTextNode(" "));
    frequencyLabel.appendChild(this.timeUnit);
    if (!this.options.enabled) {
      frequencyLabel.setOpacity(this.options.disabledOpacity);
    }
    // A paragraph containing the whole thing
    var container = new Element('div', {"id": "autosaveControl"});
    container.appendChild(autosaveLabel);
    container.appendChild(document.createTextNode(" "));
    container.appendChild(frequencyLabel);
{'fraction_non_alphanumeric': 0.1106141086571615, 'fraction_numerical': 0.004007082284968782, 'mean_word_length': 3.670147954743255, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4337622', 'n_tokens_mistral': 2991, 'n_tokens_neox': 2915, 'n_words': 1060}