mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
#46 upload component
This commit is contained in:
29
ng2-components/ng2-alfresco-upload/src/directives/file-draggable.directive.d.ts
vendored
Normal file
29
ng2-components/ng2-alfresco-upload/src/directives/file-draggable.directive.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ElementRef, EventEmitter } from 'angular2/core';
|
||||
export declare class FileDraggableDirective {
|
||||
el: ElementRef;
|
||||
onFilesAdded: EventEmitter<any>;
|
||||
files: File[];
|
||||
private _inputFocusClass;
|
||||
constructor(el: ElementRef);
|
||||
private _onDropFiles($event);
|
||||
private _traverseFileTree(item, x);
|
||||
private _onDragEnter($event);
|
||||
private _onDragLeave($event);
|
||||
private _preventDefault($event);
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
System.register(['angular2/core'], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var core_1;
|
||||
var FileDraggableDirective;
|
||||
return {
|
||||
setters:[
|
||||
function (core_1_1) {
|
||||
core_1 = core_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
FileDraggableDirective = (function () {
|
||||
function FileDraggableDirective(el) {
|
||||
this.el = el;
|
||||
this.onFilesAdded = new core_1.EventEmitter();
|
||||
this._inputFocusClass = false;
|
||||
console.log('FileDraggableComponent constructor', el);
|
||||
}
|
||||
FileDraggableDirective.prototype._onDropFiles = function ($event) {
|
||||
this._preventDefault($event);
|
||||
var items = $event.dataTransfer.items;
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i].webkitGetAsEntry();
|
||||
if (item) {
|
||||
this._traverseFileTree(item, -1);
|
||||
}
|
||||
else {
|
||||
var dt = $event.dataTransfer;
|
||||
var files = dt.files;
|
||||
this.onFilesAdded.emit(files);
|
||||
}
|
||||
}
|
||||
this.onFilesAdded.emit([]);
|
||||
this._inputFocusClass = false;
|
||||
};
|
||||
FileDraggableDirective.prototype._traverseFileTree = function (item, x) {
|
||||
if (item.isFile) {
|
||||
var self_1 = this;
|
||||
item.file(function (file) {
|
||||
self_1.onFilesAdded.emit([file]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (item.isDirectory) {
|
||||
var self_2 = this;
|
||||
var dirReader = item.createReader();
|
||||
dirReader.readEntries(function (entries) {
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
self_2._traverseFileTree(entries[i], i);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
FileDraggableDirective.prototype._onDragEnter = function ($event) {
|
||||
this._preventDefault($event);
|
||||
this._inputFocusClass = true;
|
||||
};
|
||||
FileDraggableDirective.prototype._onDragLeave = function ($event) {
|
||||
this._preventDefault($event);
|
||||
this._inputFocusClass = false;
|
||||
};
|
||||
FileDraggableDirective.prototype._preventDefault = function ($event) {
|
||||
$event.stopPropagation();
|
||||
$event.preventDefault();
|
||||
};
|
||||
__decorate([
|
||||
core_1.Output(),
|
||||
__metadata('design:type', core_1.EventEmitter)
|
||||
], FileDraggableDirective.prototype, "onFilesAdded", void 0);
|
||||
FileDraggableDirective = __decorate([
|
||||
core_1.Directive({
|
||||
selector: '[file-draggable]',
|
||||
host: {
|
||||
'(drop)': '_onDropFiles($event)',
|
||||
'(dragenter)': '_onDragEnter($event)',
|
||||
'(dragleave)': '_onDragLeave($event)',
|
||||
'(dragover)': '_preventDefault($event)',
|
||||
'[class.input-focus]': '_inputFocusClass'
|
||||
}
|
||||
}),
|
||||
__metadata('design:paramtypes', [core_1.ElementRef])
|
||||
], FileDraggableDirective);
|
||||
return FileDraggableDirective;
|
||||
}());
|
||||
exports_1("FileDraggableDirective", FileDraggableDirective);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=file-draggable.directive.js.map
|
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"file-draggable.directive.js","sourceRoot":"","sources":["file-draggable.directive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;YAcH;gBAMI,gCAAmB,EAAa;oBAAb,OA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;;0CAAA;gBAiEF,6BAAC;YAAD,CAAC,AAhED,IAgEC;YAhED,2DAgEC,CAAA"}
|
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {Directive, ElementRef, EventEmitter, Output} from 'angular2/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[file-draggable]',
|
||||
host: {
|
||||
'(drop)': '_onDropFiles($event)',
|
||||
'(dragenter)': '_onDragEnter($event)',
|
||||
'(dragleave)': '_onDragLeave($event)',
|
||||
'(dragover)': '_preventDefault($event)',
|
||||
'[class.input-focus]': '_inputFocusClass'
|
||||
}
|
||||
})
|
||||
export class FileDraggableDirective {
|
||||
@Output()
|
||||
onFilesAdded:EventEmitter<any> = new EventEmitter();
|
||||
files:File [];
|
||||
private _inputFocusClass:boolean = false;
|
||||
|
||||
constructor(public el:ElementRef) {
|
||||
console.log('FileDraggableComponent constructor', el);
|
||||
}
|
||||
|
||||
private _onDropFiles($event):void {
|
||||
this._preventDefault($event);
|
||||
|
||||
var items = $event.dataTransfer.items;
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i].webkitGetAsEntry();
|
||||
if (item) {
|
||||
this._traverseFileTree(item, -1);
|
||||
} else {
|
||||
let dt = $event.dataTransfer;
|
||||
let files = dt.files;
|
||||
this.onFilesAdded.emit(files);
|
||||
}
|
||||
}
|
||||
this.onFilesAdded.emit([]);
|
||||
|
||||
this._inputFocusClass = false;
|
||||
}
|
||||
|
||||
private _traverseFileTree(item, x):void {
|
||||
if (item.isFile) {
|
||||
let self = this;
|
||||
item.file(function (file) {
|
||||
self.onFilesAdded.emit([file]);
|
||||
});
|
||||
} else {
|
||||
if (item.isDirectory) {
|
||||
let self = this;
|
||||
let dirReader = item.createReader();
|
||||
dirReader.readEntries(function (entries) {
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
self._traverseFileTree(entries[i], i);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _onDragEnter($event):void {
|
||||
this._preventDefault($event);
|
||||
|
||||
this._inputFocusClass = true;
|
||||
}
|
||||
|
||||
private _onDragLeave($event):void {
|
||||
this._preventDefault($event);
|
||||
|
||||
this._inputFocusClass = false;
|
||||
}
|
||||
|
||||
private _preventDefault($event):void {
|
||||
$event.stopPropagation();
|
||||
$event.preventDefault();
|
||||
}
|
||||
}
|
23
ng2-components/ng2-alfresco-upload/src/directives/file-select.directive.d.ts
vendored
Normal file
23
ng2-components/ng2-alfresco-upload/src/directives/file-select.directive.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ElementRef, EventEmitter } from 'angular2/core';
|
||||
export declare class FileSelectDirective {
|
||||
el: ElementRef;
|
||||
onFilesAdded: EventEmitter<any>;
|
||||
constructor(el: ElementRef);
|
||||
private _onAdd();
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
System.register(['angular2/core'], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var core_1;
|
||||
var FileSelectDirective;
|
||||
return {
|
||||
setters:[
|
||||
function (core_1_1) {
|
||||
core_1 = core_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
FileSelectDirective = (function () {
|
||||
function FileSelectDirective(el) {
|
||||
this.el = el;
|
||||
this.onFilesAdded = new core_1.EventEmitter();
|
||||
console.log('FileSelectComponent constructor', el);
|
||||
}
|
||||
FileSelectDirective.prototype._onAdd = function () {
|
||||
var files = this.el.nativeElement.files;
|
||||
this.onFilesAdded.emit(files);
|
||||
};
|
||||
__decorate([
|
||||
core_1.Output(),
|
||||
__metadata('design:type', core_1.EventEmitter)
|
||||
], FileSelectDirective.prototype, "onFilesAdded", void 0);
|
||||
FileSelectDirective = __decorate([
|
||||
core_1.Directive({
|
||||
selector: '[file-select]',
|
||||
host: { '(change)': '_onAdd()' }
|
||||
}),
|
||||
__metadata('design:paramtypes', [core_1.ElementRef])
|
||||
], FileSelectDirective);
|
||||
return FileSelectDirective;
|
||||
}());
|
||||
exports_1("FileSelectDirective", FileSelectDirective);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=file-select.directive.js.map
|
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"file-select.directive.js","sourceRoot":"","sources":["file-select.directive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;YAQH;gBAKI,6BAAmB,EAAa;oBAAb,OAAE,GAAF,EAAE,CAAW;oBAFhC,iBAAY,GAAqB,IAAI,mBAAY,EAAE,CAAC;oBAGhD,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,EAAE,CAAC,CAAC;gBACvD,CAAC;gBAEO,oCAAM,GAAd;oBACI,IAAI,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;oBACxC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAClC,CAAC;gBAVD;oBAAC,aAAM,EAAE;;yEAAA;gBANb;oBAAC,gBAAS,CAAC;wBACP,QAAQ,EAAE,eAAe;wBACzB,IAAI,EAAE,EAAC,UAAU,EAAE,UAAU,EAAC;qBACjC,CAAC;;uCAAA;gBAcF,0BAAC;YAAD,CAAC,AAbD,IAaC;YAbD,qDAaC,CAAA"}
|
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {Directive, ElementRef, EventEmitter, Output} from 'angular2/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[file-select]',
|
||||
host: {'(change)': '_onAdd()'}
|
||||
})
|
||||
export class FileSelectDirective {
|
||||
|
||||
@Output()
|
||||
onFilesAdded:EventEmitter<any> = new EventEmitter();
|
||||
|
||||
constructor(public el:ElementRef) {
|
||||
console.log('FileSelectComponent constructor', el);
|
||||
}
|
||||
|
||||
private _onAdd():void {
|
||||
let files = this.el.nativeElement.files;
|
||||
this.onFilesAdded.emit(files);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user