-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Danial Farid
authored and
Danial Farid
committed
Dec 7, 2015
1 parent
e472a1f
commit 4cdec8f
Showing
21 changed files
with
320 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ Upload on form submit or button click | |
<form ng-app="fileUpload" ng-controller="MyCtrl" name="form"> | ||
Single Image with validations | ||
<div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'" | ||
accept="image/*" ngf-max-size="20MB" ngf-min-height="100" | ||
ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
danialfarid
Owner
|
||
ngf-resize="{width: 100, height: 100}">Select</div> | ||
Multiple files | ||
<div class="button" ngf-select ng-model="files" ngf-multiple="true">Select</div> | ||
|
@@ -178,7 +178,7 @@ At least one of the `ngf-select` or `ngf-drop` are mandatory for the plugin to l | |
// to decide wethere to fix that file or not. | ||
|
||
*ngf-capture="'camera'" or "'other'" // allows mobile devices to capture using camera | ||
*accept="image/*" // standard HTML accept attribute for the browser specific popup window filtering | ||
*ngf-accept="'image/*'" // standard HTML accept attr, browser specific select popup window | ||
|
||
+ngf-allow-dir="boolean" // default true, allow dropping files only for Chrome webkit browser | ||
+ngf-drag-over-class="{pattern: 'image/*', accept:'acceptClass', reject:'rejectClass', delay:100}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 10.1.8 | ||
* @version 10.1.9 | ||
*/ | ||
|
||
(function () { | ||
|
@@ -421,7 +421,7 @@ if (!window.FileReader) { | |
* AngularJS file upload directives and services. Supoorts: file upload/drop/paste, resume, cancel/abort, | ||
* progress, resize, thumbnail, preview, validation and CORS | ||
* @author Danial <[email protected]> | ||
* @version 10.1.8 | ||
* @version 10.1.9 | ||
*/ | ||
|
||
if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | ||
|
@@ -442,7 +442,7 @@ if (window.XMLHttpRequest && !(window.FileAPI && FileAPI.shouldLoad)) { | |
|
||
var ngFileUpload = angular.module('ngFileUpload', []); | ||
|
||
ngFileUpload.version = '10.1.8'; | ||
ngFileUpload.version = '10.1.9'; | ||
|
||
ngFileUpload.service('UploadBase', ['$http', '$q', '$timeout', function ($http, $q, $timeout) { | ||
var upload = this; | ||
|
@@ -1992,13 +1992,13 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
}]); | ||
|
||
(function () { | ||
ngFileUpload.directive('ngfDrop', ['$parse', '$timeout', '$location', 'Upload', '$http', | ||
function ($parse, $timeout, $location, Upload, $http) { | ||
ngFileUpload.directive('ngfDrop', ['$parse', '$timeout', '$location', 'Upload', '$http', '$q', | ||
function ($parse, $timeout, $location, Upload, $http, $q) { | ||
return { | ||
restrict: 'AEC', | ||
require: '?ngModel', | ||
link: function (scope, elem, attr, ngModel) { | ||
linkDrop(scope, elem, attr, ngModel, $parse, $timeout, $location, Upload, $http); | ||
linkDrop(scope, elem, attr, ngModel, $parse, $timeout, $location, Upload, $http, $q); | ||
} | ||
}; | ||
}]); | ||
|
@@ -2023,7 +2023,7 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
}; | ||
}]); | ||
|
||
function linkDrop(scope, elem, attr, ngModel, $parse, $timeout, $location, upload, $http) { | ||
function linkDrop(scope, elem, attr, ngModel, $parse, $timeout, $location, upload, $http, $q) { | ||
var available = dropAvailable(); | ||
|
||
var attrGetter = function (name, scope, params) { | ||
|
@@ -2102,22 +2102,10 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
var html; | ||
try { | ||
html = (evt.dataTransfer && evt.dataTransfer.getData && evt.dataTransfer.getData('text/html')); | ||
} catch (e) {/* Fix IE11 that throw error calling getData */} | ||
} catch (e) {/* Fix IE11 that throw error calling getData */ | ||
} | ||
if (upload.shouldUpdateOn('dropUrl', attr, scope) && html) { | ||
var url; | ||
html.replace(/<img .*src *=\"([^\"]*)\"/, function (m, src) { | ||
url = src; | ||
}); | ||
if (url) { | ||
$http({url: url, method: 'get', responseType: 'arraybuffer'}).then(function (resp) { | ||
var arrayBufferView = new Uint8Array(resp.data); | ||
var type = resp.headers('content-type') || 'image/WebP'; | ||
var blob = new window.Blob([arrayBufferView], {type: type}); | ||
//var split = type.split('[/;]'); | ||
//blob.name = url.substring(0, 150).replace(/\W+/g, '') + '.' + (split.length > 1 ? split[1] : 'jpg'); | ||
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), [blob], evt); | ||
}); | ||
} | ||
extractUrlAndUpdateModel(html, evt); | ||
} else { | ||
extractFiles(evt, function (files) { | ||
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt); | ||
|
@@ -2126,6 +2114,9 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
} | ||
}, false); | ||
elem[0].addEventListener('paste', function (evt) { | ||
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { | ||
evt.preventDefault(); | ||
} | ||
if (isDisabled() || !upload.shouldUpdateOn('paste', attr, scope)) return; | ||
var files = []; | ||
var clipboard = evt.clipboardData || evt.originalEvent.clipboardData; | ||
|
@@ -2135,10 +2126,54 @@ ngFileUpload.service('UploadResize', ['UploadValidate', '$q', function (UploadVa | |
files.push(clipboard.items[k].getAsFile()); | ||
} | ||
} | ||
} | ||
if (files.length) { | ||
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt); | ||
} else { | ||
var html; | ||
try { | ||
html = (clipboard && clipboard.getData && clipboard.getData('text/html')); | ||
} catch (e) {/* Fix IE11 that throw error calling getData */ | ||
} | ||
if (upload.shouldUpdateOn('pasteUrl', attr, scope) && html) { | ||
extractUrlAndUpdateModel(html, evt); | ||
} | ||
} | ||
}, false); | ||
|
||
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1 && | ||
attrGetter('ngfEnableFirefoxPaste', scope)) { | ||
elem.attr('contenteditable', true); | ||
elem.on('keypress', function (e) { | ||
if (!e.metaKey && !e.ctrlKey) { | ||
e.preventDefault(); | ||
} | ||
}); | ||
} | ||
|
||
function extractUrlAndUpdateModel(html, evt) { | ||
var urls = []; | ||
html.replace(/<(img src|img [^>]* src) *=\"([^\"]*)\"/gi, function (m, n, src) { | ||
urls.push(src); | ||
}); | ||
var promises = [], files = []; | ||
if (urls.length) { | ||
angular.forEach(urls, function (url) { | ||
promises.push($http({url: url, method: 'get', responseType: 'arraybuffer'}).then(function (resp) { | ||
var arrayBufferView = new Uint8Array(resp.data); | ||
var type = resp.headers('content-type') || 'image/WebP'; | ||
var blob = new window.Blob([arrayBufferView], {type: type}); | ||
files.push(blob); | ||
//var split = type.split('[/;]'); | ||
//blob.name = url.substring(0, 150).replace(/\W+/g, '') + '.' + (split.length > 1 ? split[1] : 'jpg'); | ||
})); | ||
}); | ||
$q.all(promises).then(function () { | ||
upload.updateModel(ngModel, attr, scope, attrGetter('ngfChange') || attrGetter('ngfDrop'), files, evt); | ||
}); | ||
} | ||
} | ||
|
||
function calculateDragOverClass(scope, attr, evt, callback) { | ||
var obj = attrGetter('ngfDragOverClass', scope, {$event: evt}), dClass = 'dragover'; | ||
if (angular.isString(obj)) { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* progress, resize, thumbnail, preview, validation and CORS | ||
* FileAPI Flash shim for old browsers not supporting FormData | ||
* @author Danial <[email protected]> | ||
* @version 10.1.8 | ||
* @version 10.1.9 | ||
*/ | ||
|
||
(function () { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
your examples uses just "accept" instead of ngf-accept. Also, how is this different from ngf-pattern?