<commit_before>/*!
 * OS.js - JavaScript Cloud/Web Desktop Platform
 *
 * Copyright (c) 2011-2016, <NAME> <<EMAIL>>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author  <NAME> <<EMAIL>>
 * @licence Simplified BSD License
 */
(function(Utils, API, GUI, Process) {
  'use strict';

  /**
   * The predefined events are as follows:
   * <pre><code>
   *  inited        When window has been inited and rendered  => ()
   *  focus         When window gets focus                    => ()
   *  blur          When window loses focus                   => ()
   *  destroy       When window is closed                     => ()
   *  maximize      When window is maxmimized                 => ()
   *  minimize      When window is minimized                  => ()
   *  restore       When window is restored                   => ()
   *  resize        When window is resized                    => (w, h)
   *  resized       Triggers after window is resized          => (w, h)
   *  move          When window is moved                      => (x, y)
   *  moved         Triggers after window is moved            => (x, y)
   *  keydown       When keydown                              => (ev, keyCode, shiftKey, ctrlKey, altKey)
   *  keyup         When keyup                                => (ev, keyCode, shiftKey, ctrlKey, altKey)
   *  keypress      When keypress                             => (ev, keyCode, shiftKey, ctrlKey, altKey)
   *  drop          When a drop event occurs                  => (ev, type, item, args, srcEl)
   *  drop:upload   When a upload file was dropped            => (ev, <File>, args)
   *  drop:file     When a internal file object was dropped   => (ev, VFS.File, args, srcEl)
   * </code></pre>
   * @typedef WindowEvent
   */

  /////////////////////////////////////////////////////////////////////////////
  // HELPERS
  /////////////////////////////////////////////////////////////////////////////

  /**
   * Get next z-index for Window
   * @return integer
   */
  var getNextZindex = (function() {
    var _lzindex  = 1;
    var _ltzindex = 100000;

    return function(ontop) {
      if ( typeof ontop !== 'undefined' && ontop === true ) {
        return (_ltzindex += 2);
      }
      return (_lzindex += 2);
    };
  })();

  /**
   * Wrapper for stopPropagation()
   * @return boolean
   */
  function stopPropagation(ev) {
    if ( ev ) {
      ev.stopPropagation();
    }
    return false;
  }

  /**
   * Get viewport (Wrapper)
   *
   * @return {Object}
   * @api OSjs.API.getWindowSpace()
   */
  function getWindowSpace() {
    var wm = OSjs.Core.getWindowManager();
    if ( wm ) {
      return wm.getWindowSpace();
    }
    return Utils.getRect();
  }

  /**
   * Get CSS animation duration
   */
  function getAnimDuration() {
    var wm = OSjs.Core.getWindowManager();
    if ( wm ) {
      return wm.getAnimDuration();
    }
    return 301;
  }

  /**
   * Wrapper to wait for animations to finish
   */
  function waitForAnimation(cb) {
    var wm = OSjs.Core.getWindowManager();
    var anim = wm ? wm.getSetting('animations') : false;
    if ( anim ) {
      setTimeout(function() {
        cb();
      }, getAnimDuration());
    } else {
      cb();
    }
  }

  /**
   * Creates media queries from configuration file
   */
  var createMediaQueries = (function() {
    var queries;

    function _createQueries() {
      var result = {};

      var wm = OSjs.Core.getWindowManager();
      if ( wm ) {
        var qs = wm._settings.get('mediaQueries') || {};

        Object.keys(qs).forEach(function(k) {
          if ( qs[k] ) {
            result[k] = function(w, h, ref) {
              return w <= qs[k];
            };
          }
        });
      }

      return result;
    }

    return function() {
      if ( !queries ) {
        queries = _createQueries();
      }
      return queries;
    };
  })();

  /**
   * Checks window dimensions and makes media queries dynamic
   */
  function checkMediaQueries(win) {
    if ( !win._$element ) {
      return;
    }

    var qs = win._properties.media_queries || {};
    var w = win._dimension.w;
    var h = win._dimension.h;
    var n = '';
    var k;

    for ( k in qs ) {
      if ( qs.hasOwnProperty(k) ) {
        if ( qs[k](w, h, win) ) {
          n = k;
          break;
        }
      }
    }

    win._$element.setAttribute('data-media', n);
  }

  /////////////////////////////////////////////////////////////////////////////
  // WINDOW
  /////////////////////////////////////////////////////////////////////////////

  /**
   * Window Class
   *
   * <pre><b>
   * YOU CANNOT CANNOT USE THIS VIA 'new' KEYWORD.
   * </b></pre>
   *<commit_msg>Updated Window docs<commit_after>/*!
 * OS.js - JavaScript Cloud/Web Desktop Platform
 *
 * Copyright (c) 2011-2016, <NAME> <<EMAIL>>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author  <NAME> <<EMAIL>>
 * @licence Simplified BSD License
 */
(function(Utils, API, GUI, Process) {
  'use strict';

  /**
   * The predefined events are as follows:
   * <pre><code>
   *  inited        When window has been inited and rendered  => ()
   *  focus         When window gets focus                    => ()
   *  blur          When window loses focus                   => ()
   *  destroy       When window is closed                     => ()
   *  maximize      When window is maxmimized                 => ()
   *  minimize      When window is minimized                  => ()
   *  restore       When window is restored                   => ()
   *  resize        When window is resized                    => (w, h)
   *  resized       Triggers after window is resized          => (w, h)
   *  move          When window is moved                      => (x, y)
   *  moved         Triggers after window is moved            => (x, y)
   *  keydown       When keydown                              => (ev, keyCode, shiftKey, ctrlKey, altKey)
   *  keyup         When keyup                                => (ev, keyCode, shiftKey, ctrlKey, altKey)
   *  keypress      When keypress                             => (ev, keyCode, shiftKey, ctrlKey, altKey)
   *  drop          When a drop event occurs                  => (ev, type, item, args, srcEl)
   *  drop:upload   When a upload file was dropped            => (ev, <File>, args)
   *  drop:file     When a internal file object was dropped   => (ev, VFS.File, args, srcEl)
   * </code></pre>
   * @typedef WindowEvent
   */

  /////////////////////////////////////////////////////////////////////////////
  // HELPERS
  /////////////////////////////////////////////////////////////////////////////

  /**
   * Get next z-index for Window
   * @return integer
   */
  var getNextZindex = (function() {
    var _lzindex  = 1;
    var _ltzindex = 100000;

    return function(ontop) {
      if ( typeof ontop !== 'undefined' && ontop === true ) {
        return (_ltzindex += 2);
      }
      return (_lzindex += 2);
    };
  })();

  /**
   * Wrapper for stopPropagation()
   * @return boolean
   */
  function stopPropagation(ev) {
    if ( ev ) {
      ev.stopPropagation();
    }
    return false;
  }

  /**
   * Get viewport (Wrapper)
   *
   * @return {Object}
   * @api OSjs.API.getWindowSpace()
   */
  function getWindowSpace() {
    var wm = OSjs.Core.getWindowManager();
    if ( wm ) {
      return wm.getWindowSpace();
    }
    return Utils.getRect();
  }

  /**
   * Get CSS animation duration
   */
  function getAnimDuration() {
    var wm = OSjs.Core.getWindowManager();
    if ( wm ) {
      return wm.getAnimDuration();
    }
    return 301;
  }

  /**
   * Wrapper to wait for animations to finish
   */
  function waitForAnimation(cb) {
    var wm = OSjs.Core.getWindowManager();
    var anim = wm ? wm.getSetting('animations') : false;
    if ( anim ) {
      setTimeout(function() {
        cb();
      }, getAnimDuration());
    } else {
      cb();
    }
  }

  /**
   * Creates media queries from configuration file
   */
  var createMediaQueries = (function() {
    var queries;

    function _createQueries() {
      var result = {};

      var wm = OSjs.Core.getWindowManager();
      if ( wm ) {
        var qs = wm._settings.get('mediaQueries') || {};

        Object.keys(qs).forEach(function(k) {
          if ( qs[k] ) {
            result[k] = function(w, h, ref) {
              return w <= qs[k];
            };
          }
        });
      }

      return result;
    }

    return function() {
      if ( !queries ) {
        queries = _createQueries();
      }
      return queries;
    };
  })();

  /**
   * Checks window dimensions and makes media queries dynamic
   */
  function checkMediaQueries(win) {
    if ( !win._$element ) {
      return;
    }

    var qs = win._properties.media_queries || {};
    var w = win._dimension.w;
    var h = win._dimension.h;
    var n = '';
    var k;

    for ( k in qs ) {
      if ( qs.hasOwnProperty(k) ) {
        if ( qs[k](w, h, win) ) {
          n = k;
          break;
        }
      }
    }

    win._$element.setAttribute('data-media', n);
  }

  /////////////////////////////////////////////////////////////////////////////
  // WINDOW
  /////////////////////////////////////////////////////////////////////////////

  /**
   * Window Class
   *
{'fraction_non_alphanumeric': 0.15562130177514794, 'fraction_numerical': 0.0037193575655114115, 'mean_word_length': 1.6766968325791856, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '498622', 'n_tokens_mistral': 3441, 'n_tokens_neox': 3241, 'n_words': 1082}