<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 widgets = XWiki.widgets = XWiki.widgets || {};
/**
 * Full screen editing for textareas or maximizable elements.
 */
widgets.FullScreen = Class.create({
  // Some layout settings, to be customized for other skins
  /** Maximized element margins */
  margin : 0,
  /** Full screen activator / deactivator button size */
  buttonSize : 16,
  editFullScreenLabel: $jsontool.serialize($services.localization.render('core.editors.fullscreen.editFullScreen')),
  exitFullScreenLabel: $jsontool.serialize($services.localization.render('core.editors.fullscreen.exitFullScreen')),
  /**
   * Full screen control initialization
   * Identifies the elements that must be visible in full screen: the textarea or the rich text editor, along with their
   * toolbar and the form buttons.
   * Creates two buttons for closing the fullscreen: one (image) to insert in the toolbar, and one (plain form button)
   * to add next to the form's action buttons.
   * Finally, the textareas and rich text editors in the form are equipped with their own fullscreen activators,
   * inserted in the corresponding toolbar, if there is any, or simply next to the textarea in the document
   * (see the {@link #addBehavior} function),
   */
  initialize : function() {
    // The action buttons need to be visible in full screen
    this.buttons = $(document.body).down(".bottombuttons");
    // If there are no buttons, at least the Exit FS button should be visible, so create an empty button container
    if (!this.buttons) {
      this.buttons = new Element("div", {"class" : "bottombuttons"}).update(new Element("div", {"class" : "buttons"}));
      this.buttons._x_isCustom = true;
      // It doesn't matter where the container is, it will only be needed in fullScreen.
      document.body.appendChild(this.buttons.hide());
    }
    // When the full screen is activated, the buttons will be brought in the fullscreen, thus removed from their parent
    // element, where they are replaced by a placeholder, so that we know exactly where to put them back.
    this.buttonsPlaceholder = new Element("span");
    // Placeholder for the toolbar, see above.
    this.toolbarPlaceholder = new Element("span");
    // The controls that will close the fullscreen
    this.createCloseButtons();
    // Prepare textareas / maximizable elements for full screen editing
    $$('textarea', '.maximizable').each(function(element) {
      this.addBehavior(element);
    }.bind(this));
    document.observe('xwiki:dom:updated', function(event) {
      event.memo.elements.each(function(element) {
        element.select('textarea', '.maximizable').each(function(element) {
          this.addBehavior(element);
        }.bind(this));
      }.bind(this));
    }.bind(this));
    // When comming back from preview, check if the user was in full screen before hitting preview, and if so restore
    // that full screen
    this.maximizedReference = $(document.body).down("input[name='x-maximized']");
    if (this.maximizedReference && this.maximizedReference.value != "") {
      var matches = $$(this.maximizedReference.value);
      if (matches && matches.length > 0) {
        this.makeFullScreen(matches[0]);
      }
    }
    // Cleanup before the window unloads.
    this.unloadHandler = this.cleanup.bind(this);
    Event.observe(window, 'unload', this.unloadHandler);
  },
  /** According to the type of each element being maximized, a button in created and attached to it. */
  addBehavior : function (item) {
    if (this.isXWikiEditor(item) && this.isMaximizable(item)) {
      this.addWikiContentButton(item);
    } else if (this.isVisibleTextareaOrMaximizable(item) && this.isMaximizable(item)) {
      this.addElementButton(item);
    }
  },
  isMaximizable: function (item) {
    return !item.hasClassName('not-maximizable');
  },
  // Some simple functions that help deciding what kind of editor is the target element
  isXWikiEditor : function (textarea) {
    // WYSIWYG Editor or Wiki Editor
    return textarea.name == 'content' && textarea.visible();
  },
  isVisibleTextareaOrMaximizable : function (textarea) {
    // Any other visible textarea or textarea with maximizable class.
    return textarea.visible() || textarea.hasClassName('maximizable');
  },
  /** Adds the fullscreen button in the Wiki editor toolbar. */
  addWikiContentButton : function (textarea) {
    textarea._toolbar = $(document.body).down(".leftmenu2");
    // Normally there should be a simple toolbar with basic actions
    if (textarea._toolbar) {
      textarea._toolbar.insert({top: this.createOpenButton(textarea)});
    } else {
      this.addElementButton(textarea);
    }
  },
  addElementButton: function (element) {
    Element.insert(element, {before: this.createOpenLink(element)});
  },
  /** Creates a full screen activator button for the given element. */
  createOpenButton : function (targetElement) {
    // Create HTML element
    var fullScreenActivator = new Element('img', {
      'class': 'fullScreenEditButton',
      title: this.editFullScreenLabel,
      alt: this.editFullScreenLabel,
      src: $jsontool.serialize($xwiki.getSkinFile('icons/silk/arrow_out.png'))
    });
    // Add functionality
    fullScreenActivator.observe('click', this.makeFullScreen.bind(this, targetElement));
    fullScreenActivator.observe('mousedown', this.preventDrag.bindAsEventListener(this));
    // Remember the button associated with each maximizable element
    targetElement._x_fullScreenActivator = fullScreenActivator;
    fullScreenActivator._x_maximizedElement = targetElement;
    return fullScreenActivator;
  },
  createOpenLink : function (targetElement) {
    // Create HTML element
    var fullScreenActivatorContainer = new Element('div', {<commit_msg>Revert "XWIKI-16690: Textarea maximize link should be hidden when the textarea is hidden"<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 widgets = XWiki.widgets = XWiki.widgets || {};
/**
 * Full screen editing for textareas or maximizable elements.
 */
widgets.FullScreen = Class.create({
  // Some layout settings, to be customized for other skins
  /** Maximized element margins */
  margin : 0,
  /** Full screen activator / deactivator button size */
  buttonSize : 16,
  editFullScreenLabel: $jsontool.serialize($services.localization.render('core.editors.fullscreen.editFullScreen')),
  exitFullScreenLabel: $jsontool.serialize($services.localization.render('core.editors.fullscreen.exitFullScreen')),
  /**
   * Full screen control initialization
   * Identifies the elements that must be visible in full screen: the textarea or the rich text editor, along with their
   * toolbar and the form buttons.
   * Creates two buttons for closing the fullscreen: one (image) to insert in the toolbar, and one (plain form button)
   * to add next to the form's action buttons.
   * Finally, the textareas and rich text editors in the form are equipped with their own fullscreen activators,
   * inserted in the corresponding toolbar, if there is any, or simply next to the textarea in the document
   * (see the {@link #addBehavior} function),
   */
  initialize : function() {
    // The action buttons need to be visible in full screen
    this.buttons = $(document.body).down(".bottombuttons");
    // If there are no buttons, at least the Exit FS button should be visible, so create an empty button container
    if (!this.buttons) {
      this.buttons = new Element("div", {"class" : "bottombuttons"}).update(new Element("div", {"class" : "buttons"}));
      this.buttons._x_isCustom = true;
      // It doesn't matter where the container is, it will only be needed in fullScreen.
      document.body.appendChild(this.buttons.hide());
    }
    // When the full screen is activated, the buttons will be brought in the fullscreen, thus removed from their parent
    // element, where they are replaced by a placeholder, so that we know exactly where to put them back.
    this.buttonsPlaceholder = new Element("span");
    // Placeholder for the toolbar, see above.
    this.toolbarPlaceholder = new Element("span");
    // The controls that will close the fullscreen
    this.createCloseButtons();
    // Prepare textareas / maximizable elements for full screen editing
    $$('textarea', '.maximizable').each(function(element) {
      this.addBehavior(element);
    }.bind(this));
    document.observe('xwiki:dom:updated', function(event) {
      event.memo.elements.each(function(element) {
        element.select('textarea', '.maximizable').each(function(element) {
          this.addBehavior(element);
        }.bind(this));
      }.bind(this));
    }.bind(this));
    // When comming back from preview, check if the user was in full screen before hitting preview, and if so restore
    // that full screen
    this.maximizedReference = $(document.body).down("input[name='x-maximized']");
    if (this.maximizedReference && this.maximizedReference.value != "") {
      var matches = $$(this.maximizedReference.value);
      if (matches && matches.length > 0) {
        this.makeFullScreen(matches[0]);
      }
    }
    // Cleanup before the window unloads.
    this.unloadHandler = this.cleanup.bind(this);
    Event.observe(window, 'unload', this.unloadHandler);
  },
  /** According to the type of each element being maximized, a button in created and attached to it. */
  addBehavior : function (item) {
    if (!this.isNotMaximizable(item)) {
      if (this.isWikiContent(item)) {
        this.addWikiContentButton(item);
      } else if (this.isWikiField(item)) {
        this.addWikiFieldButton(item);
      } else {
        // a div element with class maximazable
        this.addElementButton(item);
      }
    }
  },
  isNotMaximizable: function (item) {
    return !item.hasClassName('not-maximizable');
  },
  // Some simple functions that help deciding what kind of editor is the target element
  isWikiContent : function (textarea) {
    // If the textarea is not visible, then the WYSIWYG editor is active.
    return textarea.name == 'content' && textarea.visible();
  },
  isWikiField : function (textarea) {
    // If the textarea is not visible, then the WYSIWYG editor is active.
    return textarea.visible();
  },
  /** Adds the fullscreen button in the Wiki editor toolbar. */
  addWikiContentButton : function (textarea) {
    textarea._toolbar = $(document.body).down(".leftmenu2");
    // Normally there should be a simple toolbar with basic actions
    if (textarea._toolbar) {
      textarea._toolbar.insert({top: this.createOpenButton(textarea)});
    } else {
      this.addWikiFieldButton(textarea);
    }
  },
  addElementButton: function(element) {
    Element.insert(element, {before: this.createOpenLink(element)});
  },
  addWikiFieldButton : function (textarea) {
    Element.insert(textarea, {before: this.createOpenLink(textarea)});
  },
  /** Creates a full screen activator button for the given element. */
  createOpenButton : function (targetElement) {
    // Create HTML element
    var fullScreenActivator = new Element('img', {
      'class': 'fullScreenEditButton',
      title: this.editFullScreenLabel,
      alt: this.editFullScreenLabel,
      src: $jsontool.serialize($xwiki.getSkinFile('icons/silk/arrow_out.png'))
    });
    // Add functionality
    fullScreenActivator.observe('click', this.makeFullScreen.bind(this, targetElement));
    fullScreenActivator.observe('mousedown', this.preventDrag.bindAsEventListener(this));
    // Remember the button associated with each maximizable element
    targetElement._x_fullScreenActivator = fullScreenActivator;
    fullScreenActivator._x_maximizedElement = targetElement;
    return fullScreenActivator;
  },
  createOpenLink : function (targetElement) {
    // Create HTML element
    var fullScreenActivatorContainer = new Element('div', {
{'fraction_non_alphanumeric': 0.103974864825369, 'fraction_numerical': 0.003141896828876224, 'mean_word_length': 3.6921494686321563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3026419', 'n_tokens_mistral': 3777, 'n_tokens_neox': 3670, 'n_words': 1300}