| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898 |
- import { __values, __assign } from 'tslib';
- import { fromEvent } from 'rxjs';
- import { Directive, ElementRef, Renderer2, Input, Output, HostListener, EventEmitter, NgModule } from '@angular/core';
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var Position = /** @class */ (function () {
- function Position(x, y) {
- this.x = x;
- this.y = y;
- }
- /**
- * @param {?} e
- * @param {?=} el
- * @return {?}
- */
- Position.fromEvent = /**
- * @param {?} e
- * @param {?=} el
- * @return {?}
- */
- function (e, el) {
- if (el === void 0) { el = null; }
- /**
- * Fix issue: Resize doesn't work on Windows10 IE11 (and on some windows 7 IE11)
- * https://github.com/xieziyu/angular2-draggable/issues/164
- * e instanceof MouseEvent check returns false on IE11
- */
- if (this.isMouseEvent(e)) {
- return new Position(e.clientX, e.clientY);
- }
- else {
- if (el === null || e.changedTouches.length === 1) {
- return new Position(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
- }
- /**
- * Fix issue: Multiple phone draggables at the same time
- * https://github.com/xieziyu/angular2-draggable/issues/128
- */
- for (var i = 0; i < e.changedTouches.length; i++) {
- if (e.changedTouches[i].target === el) {
- return new Position(e.changedTouches[i].clientX, e.changedTouches[i].clientY);
- }
- }
- }
- };
- /**
- * @param {?} e
- * @return {?}
- */
- Position.isMouseEvent = /**
- * @param {?} e
- * @return {?}
- */
- function (e) {
- return Object.prototype.toString.apply(e).indexOf('MouseEvent') === 8;
- };
- /**
- * @param {?} obj
- * @return {?}
- */
- Position.isIPosition = /**
- * @param {?} obj
- * @return {?}
- */
- function (obj) {
- return !!obj && ('x' in obj) && ('y' in obj);
- };
- /**
- * @param {?} el
- * @return {?}
- */
- Position.getCurrent = /**
- * @param {?} el
- * @return {?}
- */
- function (el) {
- /** @type {?} */
- var pos = new Position(0, 0);
- if (window) {
- /** @type {?} */
- var computed = window.getComputedStyle(el);
- if (computed) {
- /** @type {?} */
- var x = parseInt(computed.getPropertyValue('left'), 10);
- /** @type {?} */
- var y = parseInt(computed.getPropertyValue('top'), 10);
- pos.x = isNaN(x) ? 0 : x;
- pos.y = isNaN(y) ? 0 : y;
- }
- return pos;
- }
- else {
- console.error('Not Supported!');
- return null;
- }
- };
- /**
- * @param {?} p
- * @return {?}
- */
- Position.copy = /**
- * @param {?} p
- * @return {?}
- */
- function (p) {
- return new Position(0, 0).set(p);
- };
- Object.defineProperty(Position.prototype, "value", {
- get: /**
- * @return {?}
- */
- function () {
- return { x: this.x, y: this.y };
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @template THIS
- * @this {THIS}
- * @param {?} p
- * @return {THIS}
- */
- Position.prototype.add = /**
- * @template THIS
- * @this {THIS}
- * @param {?} p
- * @return {THIS}
- */
- function (p) {
- (/** @type {?} */ (this)).x += p.x;
- (/** @type {?} */ (this)).y += p.y;
- return (/** @type {?} */ (this));
- };
- /**
- * @template THIS
- * @this {THIS}
- * @param {?} p
- * @return {THIS}
- */
- Position.prototype.subtract = /**
- * @template THIS
- * @this {THIS}
- * @param {?} p
- * @return {THIS}
- */
- function (p) {
- (/** @type {?} */ (this)).x -= p.x;
- (/** @type {?} */ (this)).y -= p.y;
- return (/** @type {?} */ (this));
- };
- /**
- * @param {?} n
- * @return {?}
- */
- Position.prototype.multiply = /**
- * @param {?} n
- * @return {?}
- */
- function (n) {
- this.x *= n;
- this.y *= n;
- };
- /**
- * @param {?} n
- * @return {?}
- */
- Position.prototype.divide = /**
- * @param {?} n
- * @return {?}
- */
- function (n) {
- this.x /= n;
- this.y /= n;
- };
- /**
- * @template THIS
- * @this {THIS}
- * @return {THIS}
- */
- Position.prototype.reset = /**
- * @template THIS
- * @this {THIS}
- * @return {THIS}
- */
- function () {
- (/** @type {?} */ (this)).x = 0;
- (/** @type {?} */ (this)).y = 0;
- return (/** @type {?} */ (this));
- };
- /**
- * @template THIS
- * @this {THIS}
- * @param {?} p
- * @return {THIS}
- */
- Position.prototype.set = /**
- * @template THIS
- * @this {THIS}
- * @param {?} p
- * @return {THIS}
- */
- function (p) {
- (/** @type {?} */ (this)).x = p.x;
- (/** @type {?} */ (this)).y = p.y;
- return (/** @type {?} */ (this));
- };
- return Position;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var HelperBlock = /** @class */ (function () {
- function HelperBlock(parent, renderer) {
- this.parent = parent;
- this.renderer = renderer;
- this._added = false;
- // generate helper div
- /** @type {?} */
- var helper = renderer.createElement('div');
- renderer.setStyle(helper, 'position', 'absolute');
- renderer.setStyle(helper, 'width', '100%');
- renderer.setStyle(helper, 'height', '100%');
- renderer.setStyle(helper, 'background-color', 'transparent');
- renderer.setStyle(helper, 'top', '0');
- renderer.setStyle(helper, 'left', '0');
- // done
- this._helper = helper;
- }
- /**
- * @return {?}
- */
- HelperBlock.prototype.add = /**
- * @return {?}
- */
- function () {
- // append div to parent
- if (this.parent && !this._added) {
- this.parent.appendChild(this._helper);
- this._added = true;
- }
- };
- /**
- * @return {?}
- */
- HelperBlock.prototype.remove = /**
- * @return {?}
- */
- function () {
- if (this.parent && this._added) {
- this.parent.removeChild(this._helper);
- this._added = false;
- }
- };
- /**
- * @return {?}
- */
- HelperBlock.prototype.dispose = /**
- * @return {?}
- */
- function () {
- this._helper = null;
- this._added = false;
- };
- Object.defineProperty(HelperBlock.prototype, "el", {
- get: /**
- * @return {?}
- */
- function () {
- return this._helper;
- },
- enumerable: true,
- configurable: true
- });
- return HelperBlock;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var AngularDraggableDirective = /** @class */ (function () {
- function AngularDraggableDirective(el, renderer) {
- this.el = el;
- this.renderer = renderer;
- this.allowDrag = true;
- this.moving = false;
- this.orignal = null;
- this.oldTrans = new Position(0, 0);
- this.tempTrans = new Position(0, 0);
- this.currTrans = new Position(0, 0);
- this.oldZIndex = '';
- this._zIndex = '';
- this.needTransform = false;
- this.draggingSub = null;
- /**
- * Bugfix: iFrames, and context unrelated elements block all events, and are unusable
- * https://github.com/xieziyu/angular2-draggable/issues/84
- */
- this._helperBlock = null;
- this.started = new EventEmitter();
- this.stopped = new EventEmitter();
- this.edge = new EventEmitter();
- /**
- * List of allowed out of bounds edges *
- */
- this.outOfBounds = {
- top: false,
- right: false,
- bottom: false,
- left: false
- };
- /**
- * Round the position to nearest grid
- */
- this.gridSize = 1;
- /**
- * Whether to limit the element stay in the bounds
- */
- this.inBounds = false;
- /**
- * Whether the element should use it's previous drag position on a new drag event.
- */
- this.trackPosition = true;
- /**
- * Input css scale transform of element so translations are correct
- */
- this.scale = 1;
- /**
- * Whether to prevent default event
- */
- this.preventDefaultEvent = false;
- /**
- * Set initial position by offsets
- */
- this.position = { x: 0, y: 0 };
- /**
- * Lock axis: 'x' or 'y'
- */
- this.lockAxis = null;
- /**
- * Emit position offsets when moving
- */
- this.movingOffset = new EventEmitter();
- /**
- * Emit position offsets when put back
- */
- this.endOffset = new EventEmitter();
- this._helperBlock = new HelperBlock(el.nativeElement, renderer);
- }
- Object.defineProperty(AngularDraggableDirective.prototype, "zIndex", {
- /** Set z-index when not dragging */
- set: /**
- * Set z-index when not dragging
- * @param {?} setting
- * @return {?}
- */
- function (setting) {
- this.renderer.setStyle(this.el.nativeElement, 'z-index', setting);
- this._zIndex = setting;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(AngularDraggableDirective.prototype, "ngDraggable", {
- set: /**
- * @param {?} setting
- * @return {?}
- */
- function (setting) {
- if (setting !== undefined && setting !== null && setting !== '') {
- this.allowDrag = !!setting;
- /** @type {?} */
- var element = this.getDragEl();
- if (this.allowDrag) {
- this.renderer.addClass(element, 'ng-draggable');
- }
- else {
- this.putBack();
- this.renderer.removeClass(element, 'ng-draggable');
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @return {?}
- */
- AngularDraggableDirective.prototype.ngOnInit = /**
- * @return {?}
- */
- function () {
- if (this.allowDrag) {
- /** @type {?} */
- var element = this.getDragEl();
- this.renderer.addClass(element, 'ng-draggable');
- }
- this.resetPosition();
- };
- /**
- * @return {?}
- */
- AngularDraggableDirective.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- this.bounds = null;
- this.handle = null;
- this.orignal = null;
- this.oldTrans = null;
- this.tempTrans = null;
- this.currTrans = null;
- this._helperBlock.dispose();
- this._helperBlock = null;
- if (this.draggingSub) {
- this.draggingSub.unsubscribe();
- }
- };
- /**
- * @param {?} changes
- * @return {?}
- */
- AngularDraggableDirective.prototype.ngOnChanges = /**
- * @param {?} changes
- * @return {?}
- */
- function (changes) {
- if (changes['position'] && !changes['position'].isFirstChange()) {
- /** @type {?} */
- var p = changes['position'].currentValue;
- if (!this.moving) {
- if (Position.isIPosition(p)) {
- this.oldTrans.set(p);
- }
- else {
- this.oldTrans.reset();
- }
- this.transform();
- }
- else {
- this.needTransform = true;
- }
- }
- };
- /**
- * @return {?}
- */
- AngularDraggableDirective.prototype.ngAfterViewInit = /**
- * @return {?}
- */
- function () {
- if (this.inBounds) {
- this.boundsCheck();
- this.oldTrans.add(this.tempTrans);
- this.tempTrans.reset();
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularDraggableDirective.prototype.getDragEl = /**
- * @private
- * @return {?}
- */
- function () {
- return this.handle ? this.handle : this.el.nativeElement;
- };
- /**
- * @return {?}
- */
- AngularDraggableDirective.prototype.resetPosition = /**
- * @return {?}
- */
- function () {
- if (Position.isIPosition(this.position)) {
- this.oldTrans.set(this.position);
- }
- else {
- this.oldTrans.reset();
- }
- this.tempTrans.reset();
- this.transform();
- };
- /**
- * @private
- * @param {?} p
- * @return {?}
- */
- AngularDraggableDirective.prototype.moveTo = /**
- * @private
- * @param {?} p
- * @return {?}
- */
- function (p) {
- if (this.orignal) {
- p.subtract(this.orignal);
- this.tempTrans.set(p);
- this.tempTrans.divide(this.scale);
- this.transform();
- if (this.bounds) {
- this.edge.emit(this.boundsCheck());
- }
- this.movingOffset.emit(this.currTrans.value);
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularDraggableDirective.prototype.transform = /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var translateX = this.tempTrans.x + this.oldTrans.x;
- /** @type {?} */
- var translateY = this.tempTrans.y + this.oldTrans.y;
- if (this.lockAxis === 'x') {
- translateX = this.oldTrans.x;
- this.tempTrans.x = 0;
- }
- else if (this.lockAxis === 'y') {
- translateY = this.oldTrans.y;
- this.tempTrans.y = 0;
- }
- // Snap to grid: by grid size
- if (this.gridSize > 1) {
- translateX = Math.round(translateX / this.gridSize) * this.gridSize;
- translateY = Math.round(translateY / this.gridSize) * this.gridSize;
- }
- /** @type {?} */
- var value = "translate(" + Math.round(translateX) + "px, " + Math.round(translateY) + "px)";
- this.renderer.setStyle(this.el.nativeElement, 'transform', value);
- this.renderer.setStyle(this.el.nativeElement, '-webkit-transform', value);
- this.renderer.setStyle(this.el.nativeElement, '-ms-transform', value);
- this.renderer.setStyle(this.el.nativeElement, '-moz-transform', value);
- this.renderer.setStyle(this.el.nativeElement, '-o-transform', value);
- // save current position
- this.currTrans.x = translateX;
- this.currTrans.y = translateY;
- };
- /**
- * @private
- * @return {?}
- */
- AngularDraggableDirective.prototype.pickUp = /**
- * @private
- * @return {?}
- */
- function () {
- // get old z-index:
- this.oldZIndex = this.el.nativeElement.style.zIndex ? this.el.nativeElement.style.zIndex : '';
- if (window) {
- this.oldZIndex = window.getComputedStyle(this.el.nativeElement, null).getPropertyValue('z-index');
- }
- if (this.zIndexMoving) {
- this.renderer.setStyle(this.el.nativeElement, 'z-index', this.zIndexMoving);
- }
- if (!this.moving) {
- this.started.emit(this.el.nativeElement);
- this.moving = true;
- /** @type {?} */
- var element = this.getDragEl();
- this.renderer.addClass(element, 'ng-dragging');
- /**
- * Fix performance issue:
- * https://github.com/xieziyu/angular2-draggable/issues/112
- */
- this.subscribeEvents();
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularDraggableDirective.prototype.subscribeEvents = /**
- * @private
- * @return {?}
- */
- function () {
- var _this = this;
- this.draggingSub = fromEvent(document, 'mousemove', { passive: false }).subscribe(function (event) { return _this.onMouseMove((/** @type {?} */ (event))); });
- this.draggingSub.add(fromEvent(document, 'touchmove', { passive: false }).subscribe(function (event) { return _this.onMouseMove((/** @type {?} */ (event))); }));
- this.draggingSub.add(fromEvent(document, 'mouseup', { passive: false }).subscribe(function () { return _this.putBack(); }));
- // checking if browser is IE or Edge - https://github.com/xieziyu/angular2-draggable/issues/153
- /** @type {?} */
- var isIEOrEdge = /msie\s|trident\//i.test(window.navigator.userAgent);
- if (!isIEOrEdge) {
- this.draggingSub.add(fromEvent(document, 'mouseleave', { passive: false }).subscribe(function () { return _this.putBack(); }));
- }
- this.draggingSub.add(fromEvent(document, 'touchend', { passive: false }).subscribe(function () { return _this.putBack(); }));
- this.draggingSub.add(fromEvent(document, 'touchcancel', { passive: false }).subscribe(function () { return _this.putBack(); }));
- };
- /**
- * @private
- * @return {?}
- */
- AngularDraggableDirective.prototype.unsubscribeEvents = /**
- * @private
- * @return {?}
- */
- function () {
- this.draggingSub.unsubscribe();
- this.draggingSub = null;
- };
- /**
- * @return {?}
- */
- AngularDraggableDirective.prototype.boundsCheck = /**
- * @return {?}
- */
- function () {
- if (this.bounds) {
- /** @type {?} */
- var boundary = this.bounds.getBoundingClientRect();
- /** @type {?} */
- var elem = this.el.nativeElement.getBoundingClientRect();
- /** @type {?} */
- var result = {
- 'top': this.outOfBounds.top ? true : boundary.top < elem.top,
- 'right': this.outOfBounds.right ? true : boundary.right > elem.right,
- 'bottom': this.outOfBounds.bottom ? true : boundary.bottom > elem.bottom,
- 'left': this.outOfBounds.left ? true : boundary.left < elem.left
- };
- if (this.inBounds) {
- if (!result.top) {
- this.tempTrans.y -= (elem.top - boundary.top) / this.scale;
- }
- if (!result.bottom) {
- this.tempTrans.y -= (elem.bottom - boundary.bottom) / this.scale;
- }
- if (!result.right) {
- this.tempTrans.x -= (elem.right - boundary.right) / this.scale;
- }
- if (!result.left) {
- this.tempTrans.x -= (elem.left - boundary.left) / this.scale;
- }
- this.transform();
- }
- return result;
- }
- };
- /** Get current offset */
- /**
- * Get current offset
- * @return {?}
- */
- AngularDraggableDirective.prototype.getCurrentOffset = /**
- * Get current offset
- * @return {?}
- */
- function () {
- return this.currTrans.value;
- };
- /**
- * @private
- * @return {?}
- */
- AngularDraggableDirective.prototype.putBack = /**
- * @private
- * @return {?}
- */
- function () {
- if (this._zIndex) {
- this.renderer.setStyle(this.el.nativeElement, 'z-index', this._zIndex);
- }
- else if (this.zIndexMoving) {
- if (this.oldZIndex) {
- this.renderer.setStyle(this.el.nativeElement, 'z-index', this.oldZIndex);
- }
- else {
- this.el.nativeElement.style.removeProperty('z-index');
- }
- }
- if (this.moving) {
- this.stopped.emit(this.el.nativeElement);
- // Remove the helper div:
- this._helperBlock.remove();
- if (this.needTransform) {
- if (Position.isIPosition(this.position)) {
- this.oldTrans.set(this.position);
- }
- else {
- this.oldTrans.reset();
- }
- this.transform();
- this.needTransform = false;
- }
- if (this.bounds) {
- this.edge.emit(this.boundsCheck());
- }
- this.moving = false;
- this.endOffset.emit(this.currTrans.value);
- if (this.trackPosition) {
- this.oldTrans.add(this.tempTrans);
- }
- this.tempTrans.reset();
- if (!this.trackPosition) {
- this.transform();
- }
- /** @type {?} */
- var element = this.getDragEl();
- this.renderer.removeClass(element, 'ng-dragging');
- /**
- * Fix performance issue:
- * https://github.com/xieziyu/angular2-draggable/issues/112
- */
- this.unsubscribeEvents();
- }
- };
- /**
- * @param {?} target
- * @param {?} element
- * @return {?}
- */
- AngularDraggableDirective.prototype.checkHandleTarget = /**
- * @param {?} target
- * @param {?} element
- * @return {?}
- */
- function (target, element) {
- // Checks if the target is the element clicked, then checks each child element of element as well
- // Ignores button clicks
- // Ignore elements of type button
- if (element.tagName === 'BUTTON') {
- return false;
- }
- // If the target was found, return true (handle was found)
- if (element === target) {
- return true;
- }
- // Recursively iterate this elements children
- for (var child in element.children) {
- if (element.children.hasOwnProperty(child)) {
- if (this.checkHandleTarget(target, element.children[child])) {
- return true;
- }
- }
- }
- // Handle was not found in this lineage
- // Note: return false is ignore unless it is the parent element
- return false;
- };
- /**
- * @param {?} event
- * @return {?}
- */
- AngularDraggableDirective.prototype.onMouseDown = /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- // 1. skip right click;
- if (event instanceof MouseEvent && event.button === 2) {
- return;
- }
- // 2. if handle is set, the element can only be moved by handle
- /** @type {?} */
- var target = event.target || event.srcElement;
- if (this.handle !== undefined && !this.checkHandleTarget(target, this.handle)) {
- return;
- }
- // 3. if allow drag is set to false, ignore the mousedown
- if (this.allowDrag === false) {
- return;
- }
- if (this.preventDefaultEvent) {
- event.stopPropagation();
- event.preventDefault();
- }
- this.orignal = Position.fromEvent(event, this.getDragEl());
- this.pickUp();
- };
- /**
- * @param {?} event
- * @return {?}
- */
- AngularDraggableDirective.prototype.onMouseMove = /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- if (this.moving && this.allowDrag) {
- if (this.preventDefaultEvent) {
- event.stopPropagation();
- event.preventDefault();
- }
- // Add a transparent helper div:
- this._helperBlock.add();
- this.moveTo(Position.fromEvent(event, this.getDragEl()));
- }
- };
- AngularDraggableDirective.decorators = [
- { type: Directive, args: [{
- selector: '[ngDraggable]',
- exportAs: 'ngDraggable'
- },] }
- ];
- /** @nocollapse */
- AngularDraggableDirective.ctorParameters = function () { return [
- { type: ElementRef },
- { type: Renderer2 }
- ]; };
- AngularDraggableDirective.propDecorators = {
- started: [{ type: Output }],
- stopped: [{ type: Output }],
- edge: [{ type: Output }],
- handle: [{ type: Input }],
- bounds: [{ type: Input }],
- outOfBounds: [{ type: Input }],
- gridSize: [{ type: Input }],
- zIndexMoving: [{ type: Input }],
- zIndex: [{ type: Input }],
- inBounds: [{ type: Input }],
- trackPosition: [{ type: Input }],
- scale: [{ type: Input }],
- preventDefaultEvent: [{ type: Input }],
- position: [{ type: Input }],
- lockAxis: [{ type: Input }],
- movingOffset: [{ type: Output }],
- endOffset: [{ type: Output }],
- ngDraggable: [{ type: Input }],
- onMouseDown: [{ type: HostListener, args: ['mousedown', ['$event'],] }, { type: HostListener, args: ['touchstart', ['$event'],] }]
- };
- return AngularDraggableDirective;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var ResizeHandle = /** @class */ (function () {
- function ResizeHandle(parent, renderer, type, css, onMouseDown) {
- var _this = this;
- this.parent = parent;
- this.renderer = renderer;
- this.type = type;
- this.css = css;
- this.onMouseDown = onMouseDown;
- // generate handle div
- /** @type {?} */
- var handle = renderer.createElement('div');
- renderer.addClass(handle, 'ng-resizable-handle');
- renderer.addClass(handle, css);
- // add default diagonal for se handle
- if (type === 'se') {
- renderer.addClass(handle, 'ng-resizable-diagonal');
- }
- // append div to parent
- if (this.parent) {
- parent.appendChild(handle);
- }
- // create and register event listener
- this._onResize = function (event) { onMouseDown(event, _this); };
- handle.addEventListener('mousedown', this._onResize, { passive: false });
- handle.addEventListener('touchstart', this._onResize, { passive: false });
- // done
- this._handle = handle;
- }
- /**
- * @return {?}
- */
- ResizeHandle.prototype.dispose = /**
- * @return {?}
- */
- function () {
- this._handle.removeEventListener('mousedown', this._onResize);
- this._handle.removeEventListener('touchstart', this._onResize);
- if (this.parent) {
- this.parent.removeChild(this._handle);
- }
- this._handle = null;
- this._onResize = null;
- };
- Object.defineProperty(ResizeHandle.prototype, "el", {
- get: /**
- * @return {?}
- */
- function () {
- return this._handle;
- },
- enumerable: true,
- configurable: true
- });
- return ResizeHandle;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var Size = /** @class */ (function () {
- function Size(width, height) {
- this.width = width;
- this.height = height;
- }
- /**
- * @param {?} el
- * @return {?}
- */
- Size.getCurrent = /**
- * @param {?} el
- * @return {?}
- */
- function (el) {
- /** @type {?} */
- var size = new Size(0, 0);
- if (window) {
- /** @type {?} */
- var computed = window.getComputedStyle(el);
- if (computed) {
- size.width = parseInt(computed.getPropertyValue('width'), 10);
- size.height = parseInt(computed.getPropertyValue('height'), 10);
- }
- return size;
- }
- else {
- console.error('Not Supported!');
- return null;
- }
- };
- /**
- * @param {?} s
- * @return {?}
- */
- Size.copy = /**
- * @param {?} s
- * @return {?}
- */
- function (s) {
- return new Size(0, 0).set(s);
- };
- /**
- * @template THIS
- * @this {THIS}
- * @param {?} s
- * @return {THIS}
- */
- Size.prototype.set = /**
- * @template THIS
- * @this {THIS}
- * @param {?} s
- * @return {THIS}
- */
- function (s) {
- (/** @type {?} */ (this)).width = s.width;
- (/** @type {?} */ (this)).height = s.height;
- return (/** @type {?} */ (this));
- };
- return Size;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var AngularResizableDirective = /** @class */ (function () {
- function AngularResizableDirective(el, renderer) {
- this.el = el;
- this.renderer = renderer;
- this._resizable = true;
- this._handles = {};
- this._handleType = [];
- this._handleResizing = null;
- this._direction = null;
- this._directionChanged = null;
- this._aspectRatio = 0;
- this._containment = null;
- this._origMousePos = null;
- /**
- * Original Size and Position
- */
- this._origSize = null;
- this._origPos = null;
- /**
- * Current Size and Position
- */
- this._currSize = null;
- this._currPos = null;
- /**
- * Initial Size and Position
- */
- this._initSize = null;
- this._initPos = null;
- /**
- * Snap to gird
- */
- this._gridSize = null;
- this._bounding = null;
- /**
- * Bugfix: iFrames, and context unrelated elements block all events, and are unusable
- * https://github.com/xieziyu/angular2-draggable/issues/84
- */
- this._helperBlock = null;
- this.draggingSub = null;
- this._adjusted = false;
- /**
- * Which handles can be used for resizing.
- * \@example
- * [rzHandles] = "'n,e,s,w,se,ne,sw,nw'"
- * equals to: [rzHandles] = "'all'"
- *
- *
- */
- this.rzHandles = 'e,s,se';
- /**
- * Whether the element should be constrained to a specific aspect ratio.
- * Multiple types supported:
- * boolean: When set to true, the element will maintain its original aspect ratio.
- * number: Force the element to maintain a specific aspect ratio during resizing.
- */
- this.rzAspectRatio = false;
- /**
- * Constrains resizing to within the bounds of the specified element or region.
- * Multiple types supported:
- * Selector: The resizable element will be contained to the bounding box of the first element found by the selector.
- * If no element is found, no containment will be set.
- * Element: The resizable element will be contained to the bounding box of this element.
- * String: Possible values: "parent".
- */
- this.rzContainment = null;
- /**
- * Snaps the resizing element to a grid, every x and y pixels.
- * A number for both width and height or an array values like [ x, y ]
- */
- this.rzGrid = null;
- /**
- * The minimum width the resizable should be allowed to resize to.
- */
- this.rzMinWidth = null;
- /**
- * The minimum height the resizable should be allowed to resize to.
- */
- this.rzMinHeight = null;
- /**
- * The maximum width the resizable should be allowed to resize to.
- */
- this.rzMaxWidth = null;
- /**
- * The maximum height the resizable should be allowed to resize to.
- */
- this.rzMaxHeight = null;
- /**
- * Whether to prevent default event
- */
- this.preventDefaultEvent = true;
- /**
- * emitted when start resizing
- */
- this.rzStart = new EventEmitter();
- /**
- * emitted when start resizing
- */
- this.rzResizing = new EventEmitter();
- /**
- * emitted when stop resizing
- */
- this.rzStop = new EventEmitter();
- this._helperBlock = new HelperBlock(el.nativeElement, renderer);
- }
- Object.defineProperty(AngularResizableDirective.prototype, "ngResizable", {
- /** Disables the resizable if set to false. */
- set: /**
- * Disables the resizable if set to false.
- * @param {?} v
- * @return {?}
- */
- function (v) {
- if (v !== undefined && v !== null && v !== '') {
- this._resizable = !!v;
- this.updateResizable();
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @param {?} changes
- * @return {?}
- */
- AngularResizableDirective.prototype.ngOnChanges = /**
- * @param {?} changes
- * @return {?}
- */
- function (changes) {
- if (changes['rzHandles'] && !changes['rzHandles'].isFirstChange()) {
- this.updateResizable();
- }
- if (changes['rzAspectRatio'] && !changes['rzAspectRatio'].isFirstChange()) {
- this.updateAspectRatio();
- }
- if (changes['rzContainment'] && !changes['rzContainment'].isFirstChange()) {
- this.updateContainment();
- }
- };
- /**
- * @return {?}
- */
- AngularResizableDirective.prototype.ngOnInit = /**
- * @return {?}
- */
- function () {
- this.updateResizable();
- };
- /**
- * @return {?}
- */
- AngularResizableDirective.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- this.removeHandles();
- this._containment = null;
- this._helperBlock.dispose();
- this._helperBlock = null;
- };
- /**
- * @return {?}
- */
- AngularResizableDirective.prototype.ngAfterViewInit = /**
- * @return {?}
- */
- function () {
- /** @type {?} */
- var elm = this.el.nativeElement;
- this._initSize = Size.getCurrent(elm);
- this._initPos = Position.getCurrent(elm);
- this._currSize = Size.copy(this._initSize);
- this._currPos = Position.copy(this._initPos);
- this.updateAspectRatio();
- this.updateContainment();
- };
- /** A method to reset size */
- /**
- * A method to reset size
- * @return {?}
- */
- AngularResizableDirective.prototype.resetSize = /**
- * A method to reset size
- * @return {?}
- */
- function () {
- this._currSize = Size.copy(this._initSize);
- this._currPos = Position.copy(this._initPos);
- this.doResize();
- };
- /** A method to get current status */
- /**
- * A method to get current status
- * @return {?}
- */
- AngularResizableDirective.prototype.getStatus = /**
- * A method to get current status
- * @return {?}
- */
- function () {
- if (!this._currPos || !this._currSize) {
- return null;
- }
- return {
- size: {
- width: this._currSize.width,
- height: this._currSize.height
- },
- position: {
- top: this._currPos.y,
- left: this._currPos.x
- }
- };
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.updateResizable = /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var element = this.el.nativeElement;
- // clear handles:
- this.renderer.removeClass(element, 'ng-resizable');
- this.removeHandles();
- // create new ones:
- if (this._resizable) {
- this.renderer.addClass(element, 'ng-resizable');
- this.createHandles();
- }
- };
- /** Use it to update aspect */
- /**
- * Use it to update aspect
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.updateAspectRatio = /**
- * Use it to update aspect
- * @private
- * @return {?}
- */
- function () {
- if (typeof this.rzAspectRatio === 'boolean') {
- if (this.rzAspectRatio && this._currSize.height) {
- this._aspectRatio = (this._currSize.width / this._currSize.height);
- }
- else {
- this._aspectRatio = 0;
- }
- }
- else {
- /** @type {?} */
- var r = Number(this.rzAspectRatio);
- this._aspectRatio = isNaN(r) ? 0 : r;
- }
- };
- /** Use it to update containment */
- /**
- * Use it to update containment
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.updateContainment = /**
- * Use it to update containment
- * @private
- * @return {?}
- */
- function () {
- if (!this.rzContainment) {
- this._containment = null;
- return;
- }
- if (typeof this.rzContainment === 'string') {
- if (this.rzContainment === 'parent') {
- this._containment = this.el.nativeElement.parentElement;
- }
- else {
- this._containment = document.querySelector(this.rzContainment);
- }
- }
- else {
- this._containment = this.rzContainment;
- }
- };
- /** Use it to create handle divs */
- /**
- * Use it to create handle divs
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.createHandles = /**
- * Use it to create handle divs
- * @private
- * @return {?}
- */
- function () {
- var e_1, _a, e_2, _b;
- if (!this.rzHandles) {
- return;
- }
- /** @type {?} */
- var tmpHandleTypes;
- if (typeof this.rzHandles === 'string') {
- if (this.rzHandles === 'all') {
- tmpHandleTypes = ['n', 'e', 's', 'w', 'ne', 'se', 'nw', 'sw'];
- }
- else {
- tmpHandleTypes = this.rzHandles.replace(/ /g, '').toLowerCase().split(',');
- }
- try {
- for (var tmpHandleTypes_1 = __values(tmpHandleTypes), tmpHandleTypes_1_1 = tmpHandleTypes_1.next(); !tmpHandleTypes_1_1.done; tmpHandleTypes_1_1 = tmpHandleTypes_1.next()) {
- var type = tmpHandleTypes_1_1.value;
- // default handle theme: ng-resizable-$type.
- /** @type {?} */
- var handle = this.createHandleByType(type, "ng-resizable-" + type);
- if (handle) {
- this._handleType.push(type);
- this._handles[type] = handle;
- }
- }
- }
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
- finally {
- try {
- if (tmpHandleTypes_1_1 && !tmpHandleTypes_1_1.done && (_a = tmpHandleTypes_1.return)) _a.call(tmpHandleTypes_1);
- }
- finally { if (e_1) throw e_1.error; }
- }
- }
- else {
- tmpHandleTypes = Object.keys(this.rzHandles);
- try {
- for (var tmpHandleTypes_2 = __values(tmpHandleTypes), tmpHandleTypes_2_1 = tmpHandleTypes_2.next(); !tmpHandleTypes_2_1.done; tmpHandleTypes_2_1 = tmpHandleTypes_2.next()) {
- var type = tmpHandleTypes_2_1.value;
- // custom handle theme.
- /** @type {?} */
- var handle = this.createHandleByType(type, this.rzHandles[type]);
- if (handle) {
- this._handleType.push(type);
- this._handles[type] = handle;
- }
- }
- }
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
- finally {
- try {
- if (tmpHandleTypes_2_1 && !tmpHandleTypes_2_1.done && (_b = tmpHandleTypes_2.return)) _b.call(tmpHandleTypes_2);
- }
- finally { if (e_2) throw e_2.error; }
- }
- }
- };
- /** Use it to create a handle */
- /**
- * Use it to create a handle
- * @private
- * @param {?} type
- * @param {?} css
- * @return {?}
- */
- AngularResizableDirective.prototype.createHandleByType = /**
- * Use it to create a handle
- * @private
- * @param {?} type
- * @param {?} css
- * @return {?}
- */
- function (type, css) {
- /** @type {?} */
- var _el = this.el.nativeElement;
- if (!type.match(/^(se|sw|ne|nw|n|e|s|w)$/)) {
- console.error('Invalid handle type:', type);
- return null;
- }
- return new ResizeHandle(_el, this.renderer, type, css, this.onMouseDown.bind(this));
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.removeHandles = /**
- * @private
- * @return {?}
- */
- function () {
- var e_3, _a;
- try {
- for (var _b = __values(this._handleType), _c = _b.next(); !_c.done; _c = _b.next()) {
- var type = _c.value;
- this._handles[type].dispose();
- }
- }
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
- finally {
- try {
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
- }
- finally { if (e_3) throw e_3.error; }
- }
- this._handleType = [];
- this._handles = {};
- };
- /**
- * @param {?} event
- * @param {?} handle
- * @return {?}
- */
- AngularResizableDirective.prototype.onMouseDown = /**
- * @param {?} event
- * @param {?} handle
- * @return {?}
- */
- function (event, handle) {
- // skip right click;
- if (event instanceof MouseEvent && event.button === 2) {
- return;
- }
- if (this.preventDefaultEvent) {
- // prevent default events
- event.stopPropagation();
- event.preventDefault();
- }
- if (!this._handleResizing) {
- this._origMousePos = Position.fromEvent(event);
- this.startResize(handle);
- this.subscribeEvents();
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.subscribeEvents = /**
- * @private
- * @return {?}
- */
- function () {
- var _this = this;
- this.draggingSub = fromEvent(document, 'mousemove', { passive: false }).subscribe(function (event) { return _this.onMouseMove((/** @type {?} */ (event))); });
- this.draggingSub.add(fromEvent(document, 'touchmove', { passive: false }).subscribe(function (event) { return _this.onMouseMove((/** @type {?} */ (event))); }));
- this.draggingSub.add(fromEvent(document, 'mouseup', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
- // fix for issue #164
- /** @type {?} */
- var isIEOrEdge = /msie\s|trident\//i.test(window.navigator.userAgent);
- if (!isIEOrEdge) {
- this.draggingSub.add(fromEvent(document, 'mouseleave', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
- }
- this.draggingSub.add(fromEvent(document, 'touchend', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
- this.draggingSub.add(fromEvent(document, 'touchcancel', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.unsubscribeEvents = /**
- * @private
- * @return {?}
- */
- function () {
- this.draggingSub.unsubscribe();
- this.draggingSub = null;
- };
- /**
- * @return {?}
- */
- AngularResizableDirective.prototype.onMouseLeave = /**
- * @return {?}
- */
- function () {
- if (this._handleResizing) {
- this.stopResize();
- this._origMousePos = null;
- this.unsubscribeEvents();
- }
- };
- /**
- * @param {?} event
- * @return {?}
- */
- AngularResizableDirective.prototype.onMouseMove = /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- if (this._handleResizing && this._resizable && this._origMousePos && this._origPos && this._origSize) {
- this.resizeTo(Position.fromEvent(event));
- this.onResizing();
- }
- };
- /**
- * @private
- * @param {?} handle
- * @return {?}
- */
- AngularResizableDirective.prototype.startResize = /**
- * @private
- * @param {?} handle
- * @return {?}
- */
- function (handle) {
- /** @type {?} */
- var elm = this.el.nativeElement;
- this._origSize = Size.getCurrent(elm);
- this._origPos = Position.getCurrent(elm); // x: left, y: top
- this._currSize = Size.copy(this._origSize);
- this._currPos = Position.copy(this._origPos);
- if (this._containment) {
- this.getBounding();
- }
- this.getGridSize();
- // Add a transparent helper div:
- this._helperBlock.add();
- this._handleResizing = handle;
- this.updateDirection();
- this.rzStart.emit(this.getResizingEvent());
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.stopResize = /**
- * @private
- * @return {?}
- */
- function () {
- // Remove the helper div:
- this._helperBlock.remove();
- this.rzStop.emit(this.getResizingEvent());
- this._handleResizing = null;
- this._direction = null;
- this._origSize = null;
- this._origPos = null;
- if (this._containment) {
- this.resetBounding();
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.onResizing = /**
- * @private
- * @return {?}
- */
- function () {
- this.rzResizing.emit(this.getResizingEvent());
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.getResizingEvent = /**
- * @private
- * @return {?}
- */
- function () {
- return {
- host: this.el.nativeElement,
- handle: this._handleResizing ? this._handleResizing.el : null,
- size: {
- width: this._currSize.width,
- height: this._currSize.height
- },
- position: {
- top: this._currPos.y,
- left: this._currPos.x
- },
- direction: __assign({}, this._directionChanged),
- };
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.updateDirection = /**
- * @private
- * @return {?}
- */
- function () {
- this._direction = {
- n: !!this._handleResizing.type.match(/n/),
- s: !!this._handleResizing.type.match(/s/),
- w: !!this._handleResizing.type.match(/w/),
- e: !!this._handleResizing.type.match(/e/)
- };
- this._directionChanged = __assign({}, this._direction);
- // if aspect ration should be preserved:
- if (this.rzAspectRatio) {
- // if north then west (unless ne)
- if (this._directionChanged.n && !this._directionChanged.e) {
- this._directionChanged.w = true;
- }
- // if south then east (unless sw)
- if (this._directionChanged.s && !this._directionChanged.w) {
- this._directionChanged.e = true;
- }
- // if east then south (unless ne)
- if (this._directionChanged.e && !this._directionChanged.n) {
- this._directionChanged.s = true;
- }
- // if west then south (unless nw)
- if (this._directionChanged.w && !this._directionChanged.n) {
- this._directionChanged.s = true;
- }
- }
- };
- /**
- * @private
- * @param {?} p
- * @return {?}
- */
- AngularResizableDirective.prototype.resizeTo = /**
- * @private
- * @param {?} p
- * @return {?}
- */
- function (p) {
- p.subtract(this._origMousePos);
- /** @type {?} */
- var tmpX = Math.round(p.x / this._gridSize.x) * this._gridSize.x;
- /** @type {?} */
- var tmpY = Math.round(p.y / this._gridSize.y) * this._gridSize.y;
- if (this._direction.n) {
- // n, ne, nw
- this._currPos.y = this._origPos.y + tmpY;
- this._currSize.height = this._origSize.height - tmpY;
- }
- else if (this._direction.s) {
- // s, se, sw
- this._currSize.height = this._origSize.height + tmpY;
- }
- if (this._direction.e) {
- // e, ne, se
- this._currSize.width = this._origSize.width + tmpX;
- }
- else if (this._direction.w) {
- // w, nw, sw
- this._currSize.width = this._origSize.width - tmpX;
- this._currPos.x = this._origPos.x + tmpX;
- }
- this.checkBounds();
- this.checkSize();
- this.adjustByRatio();
- this.doResize();
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.doResize = /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var container = this.el.nativeElement;
- if (!this._direction || this._direction.n || this._direction.s || this._aspectRatio) {
- this.renderer.setStyle(container, 'height', this._currSize.height + 'px');
- }
- if (!this._direction || this._direction.w || this._direction.e || this._aspectRatio) {
- this.renderer.setStyle(container, 'width', this._currSize.width + 'px');
- }
- this.renderer.setStyle(container, 'left', this._currPos.x + 'px');
- this.renderer.setStyle(container, 'top', this._currPos.y + 'px');
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.adjustByRatio = /**
- * @private
- * @return {?}
- */
- function () {
- if (this._aspectRatio && !this._adjusted) {
- if (this._direction.e || this._direction.w) {
- /** @type {?} */
- var newHeight = Math.floor(this._currSize.width / this._aspectRatio);
- if (this._direction.n) {
- this._currPos.y += this._currSize.height - newHeight;
- }
- this._currSize.height = newHeight;
- }
- else {
- /** @type {?} */
- var newWidth = Math.floor(this._aspectRatio * this._currSize.height);
- if (this._direction.n) {
- this._currPos.x += this._currSize.width - newWidth;
- }
- this._currSize.width = newWidth;
- }
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.checkBounds = /**
- * @private
- * @return {?}
- */
- function () {
- if (this._containment) {
- /** @type {?} */
- var maxWidth = this._bounding.width - this._bounding.pr - this._bounding.deltaL - this._bounding.translateX - this._currPos.x;
- /** @type {?} */
- var maxHeight = this._bounding.height - this._bounding.pb - this._bounding.deltaT - this._bounding.translateY - this._currPos.y;
- if (this._direction.n && (this._currPos.y + this._bounding.translateY < 0)) {
- this._currPos.y = -this._bounding.translateY;
- this._currSize.height = this._origSize.height + this._origPos.y + this._bounding.translateY;
- }
- if (this._direction.w && (this._currPos.x + this._bounding.translateX) < 0) {
- this._currPos.x = -this._bounding.translateX;
- this._currSize.width = this._origSize.width + this._origPos.x + this._bounding.translateX;
- }
- if (this._currSize.width > maxWidth) {
- this._currSize.width = maxWidth;
- }
- if (this._currSize.height > maxHeight) {
- this._currSize.height = maxHeight;
- }
- /**
- * Fix Issue: Additional check for aspect ratio
- * https://github.com/xieziyu/angular2-draggable/issues/132
- */
- if (this._aspectRatio) {
- this._adjusted = false;
- if ((this._direction.w || this._direction.e) &&
- (this._currSize.width / this._aspectRatio) >= maxHeight) {
- /** @type {?} */
- var newWidth = Math.floor(maxHeight * this._aspectRatio);
- if (this._direction.w) {
- this._currPos.x += this._currSize.width - newWidth;
- }
- this._currSize.width = newWidth;
- this._currSize.height = maxHeight;
- this._adjusted = true;
- }
- if ((this._direction.n || this._direction.s) &&
- (this._currSize.height * this._aspectRatio) >= maxWidth) {
- /** @type {?} */
- var newHeight = Math.floor(maxWidth / this._aspectRatio);
- if (this._direction.n) {
- this._currPos.y += this._currSize.height - newHeight;
- }
- this._currSize.width = maxWidth;
- this._currSize.height = newHeight;
- this._adjusted = true;
- }
- }
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.checkSize = /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var minHeight = !this.rzMinHeight ? 1 : this.rzMinHeight;
- /** @type {?} */
- var minWidth = !this.rzMinWidth ? 1 : this.rzMinWidth;
- if (this._currSize.height < minHeight) {
- this._currSize.height = minHeight;
- if (this._direction.n) {
- this._currPos.y = this._origPos.y + (this._origSize.height - minHeight);
- }
- }
- if (this._currSize.width < minWidth) {
- this._currSize.width = minWidth;
- if (this._direction.w) {
- this._currPos.x = this._origPos.x + (this._origSize.width - minWidth);
- }
- }
- if (this.rzMaxHeight && this._currSize.height > this.rzMaxHeight) {
- this._currSize.height = this.rzMaxHeight;
- if (this._direction.n) {
- this._currPos.y = this._origPos.y + (this._origSize.height - this.rzMaxHeight);
- }
- }
- if (this.rzMaxWidth && this._currSize.width > this.rzMaxWidth) {
- this._currSize.width = this.rzMaxWidth;
- if (this._direction.w) {
- this._currPos.x = this._origPos.x + (this._origSize.width - this.rzMaxWidth);
- }
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.getBounding = /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var el = this._containment;
- /** @type {?} */
- var computed = window.getComputedStyle(el);
- if (computed) {
- /** @type {?} */
- var p = computed.getPropertyValue('position');
- /** @type {?} */
- var nativeEl = window.getComputedStyle(this.el.nativeElement);
- /** @type {?} */
- var transforms = nativeEl.getPropertyValue('transform').replace(/[^-\d,]/g, '').split(',');
- this._bounding = {};
- this._bounding.width = el.clientWidth;
- this._bounding.height = el.clientHeight;
- this._bounding.pr = parseInt(computed.getPropertyValue('padding-right'), 10);
- this._bounding.pb = parseInt(computed.getPropertyValue('padding-bottom'), 10);
- this._bounding.deltaL = this.el.nativeElement.offsetLeft - this._currPos.x;
- this._bounding.deltaT = this.el.nativeElement.offsetTop - this._currPos.y;
- if (transforms.length >= 6) {
- this._bounding.translateX = parseInt(transforms[4], 10);
- this._bounding.translateY = parseInt(transforms[5], 10);
- }
- else {
- this._bounding.translateX = 0;
- this._bounding.translateY = 0;
- }
- this._bounding.position = computed.getPropertyValue('position');
- if (p === 'static') {
- this.renderer.setStyle(el, 'position', 'relative');
- }
- }
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.resetBounding = /**
- * @private
- * @return {?}
- */
- function () {
- if (this._bounding && this._bounding.position === 'static') {
- this.renderer.setStyle(this._containment, 'position', 'relative');
- }
- this._bounding = null;
- };
- /**
- * @private
- * @return {?}
- */
- AngularResizableDirective.prototype.getGridSize = /**
- * @private
- * @return {?}
- */
- function () {
- // set default value:
- this._gridSize = { x: 1, y: 1 };
- if (this.rzGrid) {
- if (typeof this.rzGrid === 'number') {
- this._gridSize = { x: this.rzGrid, y: this.rzGrid };
- }
- else if (Array.isArray(this.rzGrid)) {
- this._gridSize = { x: this.rzGrid[0], y: this.rzGrid[1] };
- }
- }
- };
- AngularResizableDirective.decorators = [
- { type: Directive, args: [{
- selector: '[ngResizable]',
- exportAs: 'ngResizable'
- },] }
- ];
- /** @nocollapse */
- AngularResizableDirective.ctorParameters = function () { return [
- { type: ElementRef },
- { type: Renderer2 }
- ]; };
- AngularResizableDirective.propDecorators = {
- ngResizable: [{ type: Input }],
- rzHandles: [{ type: Input }],
- rzAspectRatio: [{ type: Input }],
- rzContainment: [{ type: Input }],
- rzGrid: [{ type: Input }],
- rzMinWidth: [{ type: Input }],
- rzMinHeight: [{ type: Input }],
- rzMaxWidth: [{ type: Input }],
- rzMaxHeight: [{ type: Input }],
- preventDefaultEvent: [{ type: Input }],
- rzStart: [{ type: Output }],
- rzResizing: [{ type: Output }],
- rzStop: [{ type: Output }]
- };
- return AngularResizableDirective;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var AngularDraggableModule = /** @class */ (function () {
- function AngularDraggableModule() {
- }
- AngularDraggableModule.decorators = [
- { type: NgModule, args: [{
- imports: [],
- declarations: [
- AngularDraggableDirective,
- AngularResizableDirective
- ],
- exports: [
- AngularDraggableDirective,
- AngularResizableDirective
- ]
- },] }
- ];
- return AngularDraggableModule;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- export { AngularDraggableDirective, AngularResizableDirective, AngularDraggableModule, Position };
- //# sourceMappingURL=angular2-draggable.js.map
|