// JSON.stringify a value and pass it as a font-family of head element
// --------------------------------------------------------------------------------
// @param $value: value to be stringified
// @parem $flag: output driver

@mixin json-encode($value, $flag: all) {
  $flag: if(not index(all regular media comment, $flag), all, $flag);
  $json: json-encode($value);

  // Persistent comment
  @if $flag == comment or $flag == all {
    /*! json-encode: #{$json} */
  }
  // Regular property value pair
  @if $flag == regular or $flag == all {
    // All browsers except IE8-
    body::before {
      // This element must be in the render tree to get it via getComputedStyle(document.body, ':before');
      content: json-encode($value);
      display: block;
      height: 0;
      overflow: hidden;
      width: 0;
    }

    // All browsers except Opera (Presto based)
    head {
      font-family: json-encode($value);
    }
  }

  // Falsy media query
  @if $flag == media or $flag == all {
    @media -json-encode {
      json {
        json: $json;
      }
    }
  }
}
