os-js/osjs-client

View on GitHub
src/styles/_window.scss

Summary

Maintainability
Test Coverage
/*
 * OS.js - JavaScript Cloud/Web Desktop Platform
 *
 * Copyright (c) Anders Evenrud <andersevenrud@gmail.com>
 * 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  Anders Evenrud <andersevenrud@gmail.com>
 * @license Simplified BSD License
 */

$direction-list: "nw" "sw" "ne" "se" "n" "s" "w" "e";

@mixin osjs-window-maximized {
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

.osjs-window-behavior-lofi {
  position: absolute;
  border: 2px solid #000;
}

.osjs-window-resize {
  z-index: 10;
  position: absolute;
  min-width: 1em;
  min-height: 1em;

  &[data-direction^="n"] {
    top: -$resize-handle-size;
  }

  &[data-direction^="s"] {
    bottom: -$resize-handle-size;
  }

  &[data-direction$="w"] {
    left: -$resize-handle-size;
  }

  &[data-direction$="e"] {
    right: -$resize-handle-size;
  }

  @each $d in $direction-list {
    &[data-direction="#{$d}"] {
      cursor: #{$d}-resize;
    }
  }

  &[data-direction="s"],
  &[data-direction="n"] {
    left: $resize-handle-size;
    right: $resize-handle-size;
  }

  &[data-direction="e"],
  &[data-direction="w"] {
    top: $resize-handle-size;
    bottom: $resize-handle-size;
  }
}

.osjs-window-inner {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100%;
  width: 100%;
  flex-direction: column;
}

.osjs-window-header {
  display: flex;
  position: relative;
  box-sizing: border-box;
  flex: 0 0;
  min-height: 2.2em;

  & > div {
    height: 100%;
  }
}

.osjs-window-icon {
  & > div {
    width: $base-margin;
    height: $base-margin;
    background: url('src/styles/logo-blue-32x32.png') no-repeat 50% 50%;
    background-size: cover;
    cursor: pointer;
  }
}

.osjs-window-title {
  flex-grow: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.osjs-window-button {
  cursor: pointer;
  min-width: 1em;
  position: relative;
  flex-basis: 1em;

  * {
    pointer-events: none;
  }

  & > div {
    width: $base-margin;
    height: $base-margin;
  }

  &:not(:last-child) {
    margin-right: $base-margin / 4;
  }
}

.osjs-root[data-dir="rtl"] {
  .osjs-window-button:not(:last-child) {
    margin-right: 0;
    margin-left: $base-margin / 4;
  }
}

.osjs-window-content {
  box-sizing: border-box;
  position: relative;
  z-index: 1;
  overflow: hidden;
  width: 100%;
  height: 100%;
  max-width: 100%;
  flex: 1 1;
  user-select: auto;
}

.osjs-window {
  position: absolute;
  box-sizing: border-box;
  user-select: none;
  visibility: visible;
  touch-action: none;

  /* This actually increases performance */
  -webkit-transform: translate3d(0, 0, 0);
  -moz-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-perspective: 1000;
  -moz-perspective: 1000;
  perspective: 1000;

  &::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999999999;
    display: none;
  }

  &[data-maximized=true] {
    @include osjs-window-maximized();

    .osjs-window-resize {
      cursor: inherit !important;
    }
  }

  &[data-minimized=true] {
    display: none;
    visibility: hidden;
  }

  &[data-focused=false] iframe {
    pointer-events: none;
  }

  &[data-resizing=true],
  &[data-moving=true] {
    cursor: move;
  }

  &[data-loading=true]::after {
    display: block;
  }

  &.osjs__drop {
    outline: 2px solid #000;
  }

  &[data-minimizable=false] .osjs-window-button[data-action=minimize],
  &[data-maximizable=false] .osjs-window-button[data-action=maximize],
  &[data-closable=false] .osjs-window-button[data-action=close],
  &[data-resizable=false] .osjs-window-resize {
    display: none;
  }
}

.osjs-root[data-window-action="true"] {
  .osjs-window {
    /* FIXME: Maybe limit this as to increase perf ? */
    * {
      pointer-events: none;
    }
  }
}

.osjs-root[data-mobile="true"] {
  .osjs-window {
    @include osjs-window-maximized();

    opacity: 1;

    .osjs-window-button[data-action=maximize] {
      display: none;
    }
  }
}