Sha256: 0ecd0a5281d0cc9a105560716e59c0f4056c23d811d4897bcbba8f4b05798053

Contents?: true

Size: 1023 Bytes

Versions: 5

Compression:

Stored size: 1023 Bytes

Contents

import $ from 'jquery';

/**
 * @method readFileAsDataURL
 *
 * read contents of file as representing URL
 *
 * @param {File} file
 * @return {Promise} - then: dataUrl
 */
export function readFileAsDataURL(file) {
  return $.Deferred((deferred) => {
    $.extend(new FileReader(), {
      onload: (e) => {
        const dataURL = e.target.result;
        deferred.resolve(dataURL);
      },
      onerror: (err) => {
        deferred.reject(err);
      }
    }).readAsDataURL(file);
  }).promise();
}

/**
 * @method createImage
 *
 * create `<image>` from url string
 *
 * @param {String} url
 * @return {Promise} - then: $image
 */
export function createImage(url) {
  return $.Deferred((deferred) => {
    const $img = $('<img>');

    $img.one('load', () => {
      $img.off('error abort');
      deferred.resolve($img);
    }).one('error abort', () => {
      $img.off('load').detach();
      deferred.reject($img);
    }).css({
      display: 'none'
    }).appendTo(document.body).attr('src', url);
  }).promise();
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
promethee-1.4.13 node_modules/summernote/src/js/base/core/async.js
promethee-1.4.12 node_modules/summernote/src/js/base/core/async.js
promethee-1.4.11 node_modules/summernote/src/js/base/core/async.js
promethee-1.4.10 node_modules/summernote/src/js/base/core/async.js
promethee-1.4.9 node_modules/summernote/src/js/base/core/async.js