# all files / ol/ dom.js

48.15% Statements 13/27
20% Branches 2/10
16.67% Functions 1/6
48.15% Lines 13/27

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    801×

    1×
    3×
    3×
    3×

    3×
    3×

    3×

    1×

    1×

    1×

    1×

    1×

     goog.provide('ol.dom');

    /**
     * Create an html canvas element and returns its 2d context.
     * @param {number=} opt_width Canvas width.
     * @param {number=} opt_height Canvas height.
     * @return {CanvasRenderingContext2D} The context.
     */
    ol.dom.createCanvasContext2D = function(opt_width, opt_height) {
      var canvas = document.createElement('CANVAS');
      Eif (opt_width) {
        canvas.width = opt_width;
      }
      Eif (opt_height) {
        canvas.height = opt_height;
      }
      return canvas.getContext('2d');
    };

    /**
     * Get the current computed width for the given element including margin,
     * padding and border.
     * Equivalent to jQuery's `$(el).outerWidth(true)`.
     * @param {!Element} element Element.
     * @return {number} The width.
     */
    ol.dom.outerWidth = function(element) {
      var width = element.offsetWidth;
      var style = getComputedStyle(element);
      width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10);

      return width;
    };

    /**
     * Get the current computed height for the given element including margin,
     * padding and border.
     * Equivalent to jQuery's `$(el).outerHeight(true)`.
     * @param {!Element} element Element.
     * @return {number} The height.
     */
    ol.dom.outerHeight = function(element) {
      var height = element.offsetHeight;
      var style = getComputedStyle(element);
      height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10);

      return height;
    };

    /**
     * @param {Node} newNode Node to replace old node
     * @param {Node} oldNode The node to be replaced
     */
    ol.dom.replaceNode = function(newNode, oldNode) {
      var parent = oldNode.parentNode;
      if (parent) {
        parent.replaceChild(newNode, oldNode);
      }
    };

    /**
     * @param {Node} node The node to remove.
     * @returns {Node} The node that was removed or null.
     */
    ol.dom.removeNode = function(node) {
      return node && node.parentNode ? node.parentNode.removeChild(node) : null;
    };

    /**
     * @param {Node} node The node to remove the children from.
     */
    ol.dom.removeChildren = function(node) {
      while (node.lastChild) {
        node.removeChild(node.lastChild);
      }
    };