Skip to content

Angular 1.x and HTML5 code snippets to select, upload, preview, and delete images and other media.

Notifications You must be signed in to change notification settings

GoodUncleFood/spud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

.service('SPUD', function() {

  let make = function(selectorId, imageId, dataObject, scope) {
    let selector = document.getElementById(selectorId);
    let image;
    if (imageId) {
      image = document.getElementById(imageId);
    }

    let select = function() {
      let reader = new FileReader();
      reader.onload = function(event) {
        let dataURL = reader.result;
        if (image) {
          image.src = dataURL;
        }
        dataObject.data = dataURL;
        scope.$apply();
      };
      dataObject.fileName = selector.value.split(/(\\|\/)/g).pop();
      let file = selector.files[0];
      reader.readAsDataURL(file);
    };

    let discard = function() {
      selector.value = '';
      if (image) {
        image.src = '';
      }
      dataObject.data = undefined;
      dataObject.fileName = undefined;
    };

    return {
      select: select,
      discard: discard,
    };

  };

  return {
    make: make,
  };

});

About

Angular 1.x and HTML5 code snippets to select, upload, preview, and delete images and other media.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published