useAsset: function()

in assets/app/views/editor/add-image.js [43:79]


  useAsset: function (e) {
    e.preventDefault(); e.stopPropagation();

    if (!this.selectedImage) return this.remove();

    var self = this,
        selectedImage = $(this.selectedImage).children('img'),
        selectedFiles = $(this.selectedImage).children('[type=file]'),
        repo = [this.github.owner, this.github.name].join('/'),
        branch = this.github.branch,
        fileName;

    if (selectedFiles.length > 0) {
      var file = $('#asset')[0].files[0];
      this.uploadNewAsset(file);
      window.federalist.dispatcher.once('github:upload:success', function(json){
        var path = json.content['download_url'];
        self.trigger('asset:selected', {
          src: path,
          repo: repo,
          branch: branch,
          title: 'Freshly uploaded'
        });
      });
    }
    else {
      fileName = selectedImage.attr('src').split('/' + this.github.uploadDir + '/')[1];
      this.trigger('asset:selected', {
        src: selectedImage.attr('src'),
        repo: repo,
        branch: branch,
        filePath: [this.github.uploadDir, fileName].join('/'),
        title: selectedImage.attr('title')
      });
    }

  },