UNPKG

ng-drag-and-drop

Version:
205 lines (197 loc) 7.14 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('ng-drag-and-drop', ['exports', '@angular/core'], factory) : (global = global || self, factory(global['ng-drag-and-drop'] = {}, global.ng.core)); }(this, function (exports, core) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DragMeService = /** @class */ (function () { function DragMeService() { } DragMeService.decorators = [ { type: core.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ DragMeService.ctorParameters = function () { return []; }; /** @nocollapse */ DragMeService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function DragMeService_Factory() { return new DragMeService(); }, token: DragMeService, providedIn: "root" }); return DragMeService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DraggerDirective = /** @class */ (function () { function DraggerDirective(elementRef) { this.elementRef = elementRef; } /** * @return {?} */ DraggerDirective.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var el = this.elementRef.nativeElement; el.draggable = 'true'; el.addEventListener('dragstart', (/** * @param {?} e * @return {?} */ function (e) { el.classList.add('drag-src'); _this.setDefaultStyle(); e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text', JSON.stringify(_this.dragdata)); })); // Remove the drag-src class el.addEventListener('dragend', (/** * @param {?} e * @return {?} */ function (e) { e.preventDefault(); _this.removeStyle(); el.classList.remove('drag-src'); })); }; /** * @return {?} */ DraggerDirective.prototype.setDefaultStyle = /** * @return {?} */ function () { /** @type {?} */ var el = this.elementRef.nativeElement; el.style.backgroundColor = '#ccc'; el.style.color = '#fff'; el.style.padding = '5px'; el.style.margin = '1px'; }; /** * @return {?} */ DraggerDirective.prototype.removeStyle = /** * @return {?} */ function () { /** @type {?} */ var el = this.elementRef.nativeElement; el.removeAttribute('style'); }; DraggerDirective.decorators = [ { type: core.Directive, args: [{ selector: '[dragMe]' },] } ]; /** @nocollapse */ DraggerDirective.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; DraggerDirective.propDecorators = { dragdata: [{ type: core.Input }] }; return DraggerDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DropperDirective = /** @class */ (function () { function DropperDirective(elementRef) { this.elementRef = elementRef; this.dropped = new core.EventEmitter(); } /** * @return {?} */ DropperDirective.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var el = this.elementRef.nativeElement; el.addEventListener('dragenter', (/** * @param {?} e * @return {?} */ function (e) { el.classList.add('over'); })); el.addEventListener('dragleave', (/** * @param {?} e * @return {?} */ function (e) { el.classList.remove('over'); })); el.addEventListener('dragover', (/** * @param {?} e * @return {?} */ function (e) { if (e.preventDefault) { e.preventDefault(); } e.dataTransfer.dropEffect = 'move'; return false; })); el.addEventListener('drop', (/** * @param {?} e * @return {?} */ function (e) { if (e.stopPropagation) { e.stopPropagation(); } el.classList.remove('over'); /** @type {?} */ var data = JSON.parse(e.dataTransfer.getData('text')); _this.dropped.emit(data); return false; })); }; DropperDirective.decorators = [ { type: core.Directive, args: [{ selector: '[dropHere]' },] } ]; /** @nocollapse */ DropperDirective.ctorParameters = function () { return [ { type: core.ElementRef } ]; }; DropperDirective.propDecorators = { dropped: [{ type: core.Output }] }; return DropperDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DragMeModule = /** @class */ (function () { function DragMeModule() { } DragMeModule.decorators = [ { type: core.NgModule, args: [{ declarations: [DraggerDirective, DropperDirective], imports: [], exports: [DraggerDirective, DropperDirective] },] } ]; return DragMeModule; }()); exports.DragMeModule = DragMeModule; exports.DragMeService = DragMeService; exports.DraggerDirective = DraggerDirective; exports.DropperDirective = DropperDirective; Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=ng-drag-and-drop.umd.js.map