{"size": 2211, "ext": "js", "max_stars_repo_path": "public/bower_components/angular-downloader/src/js/angular-downloader.js", "max_stars_repo_name": "tannerP/Bittycasting", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/bower_components/angular-downloader/src/js/angular-downloader.js", "max_issues_repo_name": "tannerP/Bittycasting", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/bower_components/angular-downloader/src/js/angular-downloader.js", "max_forks_repo_name": "tannerP/Bittycasting", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.5857142857, "max_line_length": 146, "alphanum_fraction": 0.5554047942}
/*global angular*/
(function withAngular(angular) {
  'use strict';

  angular.module('720kb.downloader', [])
  .directive('downloader', ['$rootScope', '$compile', '$document', '$window', function manageDirective($rootScope, $compile, $document, $window) {
    return {
      'restrict': 'A',
      'link': function linkingFunction(scope, elem, attrs) {

        var customDownloadText = attrs.downloaderCustomText || 'Download Now';
        if (attrs.downloader &&
          attrs.downloaderClasses) {

          scope.$watch(attrs.downloader, function watchListener(newValue) {
            var blob
              , objectUrl
              , downloadElement
              , newElem;
            if (newValue &&
              newValue.contentType &&
              newValue.responseData &&
              newValue.fileName) {


              blob = new $window.Blob([newValue.responseData], {'type': newValue.contentType});
              objectUrl = $window.URL.createObjectURL(blob);

              downloadElement = $document[0].createElement('a');
              downloadElement.download = newValue.fileName;
              downloadElement.href = objectUrl;
              downloadElement.textContent = customDownloadText;
              downloadElement.target = '_self';

              downloadElement.dataset.downloadurl = [newValue.contentType, downloadElement.download, downloadElement.href].join(':');
              downloadElement.draggable = true;


              angular.forEach(attrs.downloaderClasses.split(' '), function iterator(value) {

                downloadElement.classList.add(value);
              });

              downloadElement.classList.add('dragout');

              newElem = $compile(downloadElement)(scope);
              newElem.off('click');

              elem.css({'display':'none'});
              elem.after(newElem);
            }
          });

        if (attrs.downloaderReset) {

            scope.$watch(attrs.downloaderReset, function watchListener(newValue) {

              if (newValue) {

                elem.next()[0].remove();
                elem.css({'display':'block'});
              }
            });
          }
        }
      }
    };
  }]);
}(angular));
