angular2-draggable.umd.js 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('@angular/core')) :
  3. typeof define === 'function' && define.amd ? define('angular2-draggable', ['exports', 'rxjs', '@angular/core'], factory) :
  4. (factory((global['angular2-draggable'] = {}),global.rxjs,global.ng.core));
  5. }(this, (function (exports,rxjs,core) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. var Position = /** @class */ (function () {
  11. function Position(x, y) {
  12. this.x = x;
  13. this.y = y;
  14. }
  15. /**
  16. * @param {?} e
  17. * @param {?=} el
  18. * @return {?}
  19. */
  20. Position.fromEvent = /**
  21. * @param {?} e
  22. * @param {?=} el
  23. * @return {?}
  24. */
  25. function (e, el) {
  26. if (el === void 0) {
  27. el = null;
  28. }
  29. /**
  30. * Fix issue: Resize doesn't work on Windows10 IE11 (and on some windows 7 IE11)
  31. * https://github.com/xieziyu/angular2-draggable/issues/164
  32. * e instanceof MouseEvent check returns false on IE11
  33. */
  34. if (this.isMouseEvent(e)) {
  35. return new Position(e.clientX, e.clientY);
  36. }
  37. else {
  38. if (el === null || e.changedTouches.length === 1) {
  39. return new Position(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
  40. }
  41. /**
  42. * Fix issue: Multiple phone draggables at the same time
  43. * https://github.com/xieziyu/angular2-draggable/issues/128
  44. */
  45. for (var i = 0; i < e.changedTouches.length; i++) {
  46. if (e.changedTouches[i].target === el) {
  47. return new Position(e.changedTouches[i].clientX, e.changedTouches[i].clientY);
  48. }
  49. }
  50. }
  51. };
  52. /**
  53. * @param {?} e
  54. * @return {?}
  55. */
  56. Position.isMouseEvent = /**
  57. * @param {?} e
  58. * @return {?}
  59. */
  60. function (e) {
  61. return Object.prototype.toString.apply(e).indexOf('MouseEvent') === 8;
  62. };
  63. /**
  64. * @param {?} obj
  65. * @return {?}
  66. */
  67. Position.isIPosition = /**
  68. * @param {?} obj
  69. * @return {?}
  70. */
  71. function (obj) {
  72. return !!obj && ('x' in obj) && ('y' in obj);
  73. };
  74. /**
  75. * @param {?} el
  76. * @return {?}
  77. */
  78. Position.getCurrent = /**
  79. * @param {?} el
  80. * @return {?}
  81. */
  82. function (el) {
  83. /** @type {?} */
  84. var pos = new Position(0, 0);
  85. if (window) {
  86. /** @type {?} */
  87. var computed = window.getComputedStyle(el);
  88. if (computed) {
  89. /** @type {?} */
  90. var x = parseInt(computed.getPropertyValue('left'), 10);
  91. /** @type {?} */
  92. var y = parseInt(computed.getPropertyValue('top'), 10);
  93. pos.x = isNaN(x) ? 0 : x;
  94. pos.y = isNaN(y) ? 0 : y;
  95. }
  96. return pos;
  97. }
  98. else {
  99. console.error('Not Supported!');
  100. return null;
  101. }
  102. };
  103. /**
  104. * @param {?} p
  105. * @return {?}
  106. */
  107. Position.copy = /**
  108. * @param {?} p
  109. * @return {?}
  110. */
  111. function (p) {
  112. return new Position(0, 0).set(p);
  113. };
  114. Object.defineProperty(Position.prototype, "value", {
  115. get: /**
  116. * @return {?}
  117. */ function () {
  118. return { x: this.x, y: this.y };
  119. },
  120. enumerable: true,
  121. configurable: true
  122. });
  123. /**
  124. * @template THIS
  125. * @this {THIS}
  126. * @param {?} p
  127. * @return {THIS}
  128. */
  129. Position.prototype.add = /**
  130. * @template THIS
  131. * @this {THIS}
  132. * @param {?} p
  133. * @return {THIS}
  134. */
  135. function (p) {
  136. ( /** @type {?} */(this)).x += p.x;
  137. ( /** @type {?} */(this)).y += p.y;
  138. return ( /** @type {?} */(this));
  139. };
  140. /**
  141. * @template THIS
  142. * @this {THIS}
  143. * @param {?} p
  144. * @return {THIS}
  145. */
  146. Position.prototype.subtract = /**
  147. * @template THIS
  148. * @this {THIS}
  149. * @param {?} p
  150. * @return {THIS}
  151. */
  152. function (p) {
  153. ( /** @type {?} */(this)).x -= p.x;
  154. ( /** @type {?} */(this)).y -= p.y;
  155. return ( /** @type {?} */(this));
  156. };
  157. /**
  158. * @param {?} n
  159. * @return {?}
  160. */
  161. Position.prototype.multiply = /**
  162. * @param {?} n
  163. * @return {?}
  164. */
  165. function (n) {
  166. this.x *= n;
  167. this.y *= n;
  168. };
  169. /**
  170. * @param {?} n
  171. * @return {?}
  172. */
  173. Position.prototype.divide = /**
  174. * @param {?} n
  175. * @return {?}
  176. */
  177. function (n) {
  178. this.x /= n;
  179. this.y /= n;
  180. };
  181. /**
  182. * @template THIS
  183. * @this {THIS}
  184. * @return {THIS}
  185. */
  186. Position.prototype.reset = /**
  187. * @template THIS
  188. * @this {THIS}
  189. * @return {THIS}
  190. */
  191. function () {
  192. ( /** @type {?} */(this)).x = 0;
  193. ( /** @type {?} */(this)).y = 0;
  194. return ( /** @type {?} */(this));
  195. };
  196. /**
  197. * @template THIS
  198. * @this {THIS}
  199. * @param {?} p
  200. * @return {THIS}
  201. */
  202. Position.prototype.set = /**
  203. * @template THIS
  204. * @this {THIS}
  205. * @param {?} p
  206. * @return {THIS}
  207. */
  208. function (p) {
  209. ( /** @type {?} */(this)).x = p.x;
  210. ( /** @type {?} */(this)).y = p.y;
  211. return ( /** @type {?} */(this));
  212. };
  213. return Position;
  214. }());
  215. /**
  216. * @fileoverview added by tsickle
  217. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  218. */
  219. var HelperBlock = /** @class */ (function () {
  220. function HelperBlock(parent, renderer) {
  221. this.parent = parent;
  222. this.renderer = renderer;
  223. this._added = false;
  224. // generate helper div
  225. /** @type {?} */
  226. var helper = renderer.createElement('div');
  227. renderer.setStyle(helper, 'position', 'absolute');
  228. renderer.setStyle(helper, 'width', '100%');
  229. renderer.setStyle(helper, 'height', '100%');
  230. renderer.setStyle(helper, 'background-color', 'transparent');
  231. renderer.setStyle(helper, 'top', '0');
  232. renderer.setStyle(helper, 'left', '0');
  233. // done
  234. this._helper = helper;
  235. }
  236. /**
  237. * @return {?}
  238. */
  239. HelperBlock.prototype.add = /**
  240. * @return {?}
  241. */
  242. function () {
  243. // append div to parent
  244. if (this.parent && !this._added) {
  245. this.parent.appendChild(this._helper);
  246. this._added = true;
  247. }
  248. };
  249. /**
  250. * @return {?}
  251. */
  252. HelperBlock.prototype.remove = /**
  253. * @return {?}
  254. */
  255. function () {
  256. if (this.parent && this._added) {
  257. this.parent.removeChild(this._helper);
  258. this._added = false;
  259. }
  260. };
  261. /**
  262. * @return {?}
  263. */
  264. HelperBlock.prototype.dispose = /**
  265. * @return {?}
  266. */
  267. function () {
  268. this._helper = null;
  269. this._added = false;
  270. };
  271. Object.defineProperty(HelperBlock.prototype, "el", {
  272. get: /**
  273. * @return {?}
  274. */ function () {
  275. return this._helper;
  276. },
  277. enumerable: true,
  278. configurable: true
  279. });
  280. return HelperBlock;
  281. }());
  282. /**
  283. * @fileoverview added by tsickle
  284. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  285. */
  286. var AngularDraggableDirective = /** @class */ (function () {
  287. function AngularDraggableDirective(el, renderer) {
  288. this.el = el;
  289. this.renderer = renderer;
  290. this.allowDrag = true;
  291. this.moving = false;
  292. this.orignal = null;
  293. this.oldTrans = new Position(0, 0);
  294. this.tempTrans = new Position(0, 0);
  295. this.currTrans = new Position(0, 0);
  296. this.oldZIndex = '';
  297. this._zIndex = '';
  298. this.needTransform = false;
  299. this.draggingSub = null;
  300. /**
  301. * Bugfix: iFrames, and context unrelated elements block all events, and are unusable
  302. * https://github.com/xieziyu/angular2-draggable/issues/84
  303. */
  304. this._helperBlock = null;
  305. this.started = new core.EventEmitter();
  306. this.stopped = new core.EventEmitter();
  307. this.edge = new core.EventEmitter();
  308. /**
  309. * List of allowed out of bounds edges *
  310. */
  311. this.outOfBounds = {
  312. top: false,
  313. right: false,
  314. bottom: false,
  315. left: false
  316. };
  317. /**
  318. * Round the position to nearest grid
  319. */
  320. this.gridSize = 1;
  321. /**
  322. * Whether to limit the element stay in the bounds
  323. */
  324. this.inBounds = false;
  325. /**
  326. * Whether the element should use it's previous drag position on a new drag event.
  327. */
  328. this.trackPosition = true;
  329. /**
  330. * Input css scale transform of element so translations are correct
  331. */
  332. this.scale = 1;
  333. /**
  334. * Whether to prevent default event
  335. */
  336. this.preventDefaultEvent = false;
  337. /**
  338. * Set initial position by offsets
  339. */
  340. this.position = { x: 0, y: 0 };
  341. /**
  342. * Lock axis: 'x' or 'y'
  343. */
  344. this.lockAxis = null;
  345. /**
  346. * Emit position offsets when moving
  347. */
  348. this.movingOffset = new core.EventEmitter();
  349. /**
  350. * Emit position offsets when put back
  351. */
  352. this.endOffset = new core.EventEmitter();
  353. this._helperBlock = new HelperBlock(el.nativeElement, renderer);
  354. }
  355. Object.defineProperty(AngularDraggableDirective.prototype, "zIndex", {
  356. /** Set z-index when not dragging */
  357. set: /**
  358. * Set z-index when not dragging
  359. * @param {?} setting
  360. * @return {?}
  361. */ function (setting) {
  362. this.renderer.setStyle(this.el.nativeElement, 'z-index', setting);
  363. this._zIndex = setting;
  364. },
  365. enumerable: true,
  366. configurable: true
  367. });
  368. Object.defineProperty(AngularDraggableDirective.prototype, "ngDraggable", {
  369. set: /**
  370. * @param {?} setting
  371. * @return {?}
  372. */ function (setting) {
  373. if (setting !== undefined && setting !== null && setting !== '') {
  374. this.allowDrag = !!setting;
  375. /** @type {?} */
  376. var element = this.getDragEl();
  377. if (this.allowDrag) {
  378. this.renderer.addClass(element, 'ng-draggable');
  379. }
  380. else {
  381. this.putBack();
  382. this.renderer.removeClass(element, 'ng-draggable');
  383. }
  384. }
  385. },
  386. enumerable: true,
  387. configurable: true
  388. });
  389. /**
  390. * @return {?}
  391. */
  392. AngularDraggableDirective.prototype.ngOnInit = /**
  393. * @return {?}
  394. */
  395. function () {
  396. if (this.allowDrag) {
  397. /** @type {?} */
  398. var element = this.getDragEl();
  399. this.renderer.addClass(element, 'ng-draggable');
  400. }
  401. this.resetPosition();
  402. };
  403. /**
  404. * @return {?}
  405. */
  406. AngularDraggableDirective.prototype.ngOnDestroy = /**
  407. * @return {?}
  408. */
  409. function () {
  410. this.bounds = null;
  411. this.handle = null;
  412. this.orignal = null;
  413. this.oldTrans = null;
  414. this.tempTrans = null;
  415. this.currTrans = null;
  416. this._helperBlock.dispose();
  417. this._helperBlock = null;
  418. if (this.draggingSub) {
  419. this.draggingSub.unsubscribe();
  420. }
  421. };
  422. /**
  423. * @param {?} changes
  424. * @return {?}
  425. */
  426. AngularDraggableDirective.prototype.ngOnChanges = /**
  427. * @param {?} changes
  428. * @return {?}
  429. */
  430. function (changes) {
  431. if (changes['position'] && !changes['position'].isFirstChange()) {
  432. /** @type {?} */
  433. var p = changes['position'].currentValue;
  434. if (!this.moving) {
  435. if (Position.isIPosition(p)) {
  436. this.oldTrans.set(p);
  437. }
  438. else {
  439. this.oldTrans.reset();
  440. }
  441. this.transform();
  442. }
  443. else {
  444. this.needTransform = true;
  445. }
  446. }
  447. };
  448. /**
  449. * @return {?}
  450. */
  451. AngularDraggableDirective.prototype.ngAfterViewInit = /**
  452. * @return {?}
  453. */
  454. function () {
  455. if (this.inBounds) {
  456. this.boundsCheck();
  457. this.oldTrans.add(this.tempTrans);
  458. this.tempTrans.reset();
  459. }
  460. };
  461. /**
  462. * @private
  463. * @return {?}
  464. */
  465. AngularDraggableDirective.prototype.getDragEl = /**
  466. * @private
  467. * @return {?}
  468. */
  469. function () {
  470. return this.handle ? this.handle : this.el.nativeElement;
  471. };
  472. /**
  473. * @return {?}
  474. */
  475. AngularDraggableDirective.prototype.resetPosition = /**
  476. * @return {?}
  477. */
  478. function () {
  479. if (Position.isIPosition(this.position)) {
  480. this.oldTrans.set(this.position);
  481. }
  482. else {
  483. this.oldTrans.reset();
  484. }
  485. this.tempTrans.reset();
  486. this.transform();
  487. };
  488. /**
  489. * @private
  490. * @param {?} p
  491. * @return {?}
  492. */
  493. AngularDraggableDirective.prototype.moveTo = /**
  494. * @private
  495. * @param {?} p
  496. * @return {?}
  497. */
  498. function (p) {
  499. if (this.orignal) {
  500. p.subtract(this.orignal);
  501. this.tempTrans.set(p);
  502. this.tempTrans.divide(this.scale);
  503. this.transform();
  504. if (this.bounds) {
  505. this.edge.emit(this.boundsCheck());
  506. }
  507. this.movingOffset.emit(this.currTrans.value);
  508. }
  509. };
  510. /**
  511. * @private
  512. * @return {?}
  513. */
  514. AngularDraggableDirective.prototype.transform = /**
  515. * @private
  516. * @return {?}
  517. */
  518. function () {
  519. /** @type {?} */
  520. var translateX = this.tempTrans.x + this.oldTrans.x;
  521. /** @type {?} */
  522. var translateY = this.tempTrans.y + this.oldTrans.y;
  523. if (this.lockAxis === 'x') {
  524. translateX = this.oldTrans.x;
  525. this.tempTrans.x = 0;
  526. }
  527. else if (this.lockAxis === 'y') {
  528. translateY = this.oldTrans.y;
  529. this.tempTrans.y = 0;
  530. }
  531. // Snap to grid: by grid size
  532. if (this.gridSize > 1) {
  533. translateX = Math.round(translateX / this.gridSize) * this.gridSize;
  534. translateY = Math.round(translateY / this.gridSize) * this.gridSize;
  535. }
  536. /** @type {?} */
  537. var value = "translate(" + Math.round(translateX) + "px, " + Math.round(translateY) + "px)";
  538. this.renderer.setStyle(this.el.nativeElement, 'transform', value);
  539. this.renderer.setStyle(this.el.nativeElement, '-webkit-transform', value);
  540. this.renderer.setStyle(this.el.nativeElement, '-ms-transform', value);
  541. this.renderer.setStyle(this.el.nativeElement, '-moz-transform', value);
  542. this.renderer.setStyle(this.el.nativeElement, '-o-transform', value);
  543. // save current position
  544. this.currTrans.x = translateX;
  545. this.currTrans.y = translateY;
  546. };
  547. /**
  548. * @private
  549. * @return {?}
  550. */
  551. AngularDraggableDirective.prototype.pickUp = /**
  552. * @private
  553. * @return {?}
  554. */
  555. function () {
  556. // get old z-index:
  557. this.oldZIndex = this.el.nativeElement.style.zIndex ? this.el.nativeElement.style.zIndex : '';
  558. if (window) {
  559. this.oldZIndex = window.getComputedStyle(this.el.nativeElement, null).getPropertyValue('z-index');
  560. }
  561. if (this.zIndexMoving) {
  562. this.renderer.setStyle(this.el.nativeElement, 'z-index', this.zIndexMoving);
  563. }
  564. if (!this.moving) {
  565. this.started.emit(this.el.nativeElement);
  566. this.moving = true;
  567. /** @type {?} */
  568. var element = this.getDragEl();
  569. this.renderer.addClass(element, 'ng-dragging');
  570. /**
  571. * Fix performance issue:
  572. * https://github.com/xieziyu/angular2-draggable/issues/112
  573. */
  574. this.subscribeEvents();
  575. }
  576. };
  577. /**
  578. * @private
  579. * @return {?}
  580. */
  581. AngularDraggableDirective.prototype.subscribeEvents = /**
  582. * @private
  583. * @return {?}
  584. */
  585. function () {
  586. var _this = this;
  587. this.draggingSub = rxjs.fromEvent(document, 'mousemove', { passive: false }).subscribe(function (event) { return _this.onMouseMove(( /** @type {?} */(event))); });
  588. this.draggingSub.add(rxjs.fromEvent(document, 'touchmove', { passive: false }).subscribe(function (event) { return _this.onMouseMove(( /** @type {?} */(event))); }));
  589. this.draggingSub.add(rxjs.fromEvent(document, 'mouseup', { passive: false }).subscribe(function () { return _this.putBack(); }));
  590. // checking if browser is IE or Edge - https://github.com/xieziyu/angular2-draggable/issues/153
  591. /** @type {?} */
  592. var isIEOrEdge = /msie\s|trident\//i.test(window.navigator.userAgent);
  593. if (!isIEOrEdge) {
  594. this.draggingSub.add(rxjs.fromEvent(document, 'mouseleave', { passive: false }).subscribe(function () { return _this.putBack(); }));
  595. }
  596. this.draggingSub.add(rxjs.fromEvent(document, 'touchend', { passive: false }).subscribe(function () { return _this.putBack(); }));
  597. this.draggingSub.add(rxjs.fromEvent(document, 'touchcancel', { passive: false }).subscribe(function () { return _this.putBack(); }));
  598. };
  599. /**
  600. * @private
  601. * @return {?}
  602. */
  603. AngularDraggableDirective.prototype.unsubscribeEvents = /**
  604. * @private
  605. * @return {?}
  606. */
  607. function () {
  608. this.draggingSub.unsubscribe();
  609. this.draggingSub = null;
  610. };
  611. /**
  612. * @return {?}
  613. */
  614. AngularDraggableDirective.prototype.boundsCheck = /**
  615. * @return {?}
  616. */
  617. function () {
  618. if (this.bounds) {
  619. /** @type {?} */
  620. var boundary = this.bounds.getBoundingClientRect();
  621. /** @type {?} */
  622. var elem = this.el.nativeElement.getBoundingClientRect();
  623. /** @type {?} */
  624. var result = {
  625. 'top': this.outOfBounds.top ? true : boundary.top < elem.top,
  626. 'right': this.outOfBounds.right ? true : boundary.right > elem.right,
  627. 'bottom': this.outOfBounds.bottom ? true : boundary.bottom > elem.bottom,
  628. 'left': this.outOfBounds.left ? true : boundary.left < elem.left
  629. };
  630. if (this.inBounds) {
  631. if (!result.top) {
  632. this.tempTrans.y -= (elem.top - boundary.top) / this.scale;
  633. }
  634. if (!result.bottom) {
  635. this.tempTrans.y -= (elem.bottom - boundary.bottom) / this.scale;
  636. }
  637. if (!result.right) {
  638. this.tempTrans.x -= (elem.right - boundary.right) / this.scale;
  639. }
  640. if (!result.left) {
  641. this.tempTrans.x -= (elem.left - boundary.left) / this.scale;
  642. }
  643. this.transform();
  644. }
  645. return result;
  646. }
  647. };
  648. /** Get current offset */
  649. /**
  650. * Get current offset
  651. * @return {?}
  652. */
  653. AngularDraggableDirective.prototype.getCurrentOffset = /**
  654. * Get current offset
  655. * @return {?}
  656. */
  657. function () {
  658. return this.currTrans.value;
  659. };
  660. /**
  661. * @private
  662. * @return {?}
  663. */
  664. AngularDraggableDirective.prototype.putBack = /**
  665. * @private
  666. * @return {?}
  667. */
  668. function () {
  669. if (this._zIndex) {
  670. this.renderer.setStyle(this.el.nativeElement, 'z-index', this._zIndex);
  671. }
  672. else if (this.zIndexMoving) {
  673. if (this.oldZIndex) {
  674. this.renderer.setStyle(this.el.nativeElement, 'z-index', this.oldZIndex);
  675. }
  676. else {
  677. this.el.nativeElement.style.removeProperty('z-index');
  678. }
  679. }
  680. if (this.moving) {
  681. this.stopped.emit(this.el.nativeElement);
  682. // Remove the helper div:
  683. this._helperBlock.remove();
  684. if (this.needTransform) {
  685. if (Position.isIPosition(this.position)) {
  686. this.oldTrans.set(this.position);
  687. }
  688. else {
  689. this.oldTrans.reset();
  690. }
  691. this.transform();
  692. this.needTransform = false;
  693. }
  694. if (this.bounds) {
  695. this.edge.emit(this.boundsCheck());
  696. }
  697. this.moving = false;
  698. this.endOffset.emit(this.currTrans.value);
  699. if (this.trackPosition) {
  700. this.oldTrans.add(this.tempTrans);
  701. }
  702. this.tempTrans.reset();
  703. if (!this.trackPosition) {
  704. this.transform();
  705. }
  706. /** @type {?} */
  707. var element = this.getDragEl();
  708. this.renderer.removeClass(element, 'ng-dragging');
  709. /**
  710. * Fix performance issue:
  711. * https://github.com/xieziyu/angular2-draggable/issues/112
  712. */
  713. this.unsubscribeEvents();
  714. }
  715. };
  716. /**
  717. * @param {?} target
  718. * @param {?} element
  719. * @return {?}
  720. */
  721. AngularDraggableDirective.prototype.checkHandleTarget = /**
  722. * @param {?} target
  723. * @param {?} element
  724. * @return {?}
  725. */
  726. function (target, element) {
  727. // Checks if the target is the element clicked, then checks each child element of element as well
  728. // Ignores button clicks
  729. // Ignore elements of type button
  730. if (element.tagName === 'BUTTON') {
  731. return false;
  732. }
  733. // If the target was found, return true (handle was found)
  734. if (element === target) {
  735. return true;
  736. }
  737. // Recursively iterate this elements children
  738. for (var child in element.children) {
  739. if (element.children.hasOwnProperty(child)) {
  740. if (this.checkHandleTarget(target, element.children[child])) {
  741. return true;
  742. }
  743. }
  744. }
  745. // Handle was not found in this lineage
  746. // Note: return false is ignore unless it is the parent element
  747. return false;
  748. };
  749. /**
  750. * @param {?} event
  751. * @return {?}
  752. */
  753. AngularDraggableDirective.prototype.onMouseDown = /**
  754. * @param {?} event
  755. * @return {?}
  756. */
  757. function (event) {
  758. // 1. skip right click;
  759. if (event instanceof MouseEvent && event.button === 2) {
  760. return;
  761. }
  762. // 2. if handle is set, the element can only be moved by handle
  763. /** @type {?} */
  764. var target = event.target || event.srcElement;
  765. if (this.handle !== undefined && !this.checkHandleTarget(target, this.handle)) {
  766. return;
  767. }
  768. // 3. if allow drag is set to false, ignore the mousedown
  769. if (this.allowDrag === false) {
  770. return;
  771. }
  772. if (this.preventDefaultEvent) {
  773. event.stopPropagation();
  774. event.preventDefault();
  775. }
  776. this.orignal = Position.fromEvent(event, this.getDragEl());
  777. this.pickUp();
  778. };
  779. /**
  780. * @param {?} event
  781. * @return {?}
  782. */
  783. AngularDraggableDirective.prototype.onMouseMove = /**
  784. * @param {?} event
  785. * @return {?}
  786. */
  787. function (event) {
  788. if (this.moving && this.allowDrag) {
  789. if (this.preventDefaultEvent) {
  790. event.stopPropagation();
  791. event.preventDefault();
  792. }
  793. // Add a transparent helper div:
  794. this._helperBlock.add();
  795. this.moveTo(Position.fromEvent(event, this.getDragEl()));
  796. }
  797. };
  798. AngularDraggableDirective.decorators = [
  799. { type: core.Directive, args: [{
  800. selector: '[ngDraggable]',
  801. exportAs: 'ngDraggable'
  802. },] }
  803. ];
  804. /** @nocollapse */
  805. AngularDraggableDirective.ctorParameters = function () {
  806. return [
  807. { type: core.ElementRef },
  808. { type: core.Renderer2 }
  809. ];
  810. };
  811. AngularDraggableDirective.propDecorators = {
  812. started: [{ type: core.Output }],
  813. stopped: [{ type: core.Output }],
  814. edge: [{ type: core.Output }],
  815. handle: [{ type: core.Input }],
  816. bounds: [{ type: core.Input }],
  817. outOfBounds: [{ type: core.Input }],
  818. gridSize: [{ type: core.Input }],
  819. zIndexMoving: [{ type: core.Input }],
  820. zIndex: [{ type: core.Input }],
  821. inBounds: [{ type: core.Input }],
  822. trackPosition: [{ type: core.Input }],
  823. scale: [{ type: core.Input }],
  824. preventDefaultEvent: [{ type: core.Input }],
  825. position: [{ type: core.Input }],
  826. lockAxis: [{ type: core.Input }],
  827. movingOffset: [{ type: core.Output }],
  828. endOffset: [{ type: core.Output }],
  829. ngDraggable: [{ type: core.Input }],
  830. onMouseDown: [{ type: core.HostListener, args: ['mousedown', ['$event'],] }, { type: core.HostListener, args: ['touchstart', ['$event'],] }]
  831. };
  832. return AngularDraggableDirective;
  833. }());
  834. /*! *****************************************************************************
  835. Copyright (c) Microsoft Corporation. All rights reserved.
  836. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  837. this file except in compliance with the License. You may obtain a copy of the
  838. License at http://www.apache.org/licenses/LICENSE-2.0
  839. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  840. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  841. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  842. MERCHANTABLITY OR NON-INFRINGEMENT.
  843. See the Apache Version 2.0 License for specific language governing permissions
  844. and limitations under the License.
  845. ***************************************************************************** */
  846. var __assign = Object.assign || function __assign(t) {
  847. for (var s, i = 1, n = arguments.length; i < n; i++) {
  848. s = arguments[i];
  849. for (var p in s)
  850. if (Object.prototype.hasOwnProperty.call(s, p))
  851. t[p] = s[p];
  852. }
  853. return t;
  854. };
  855. function __values(o) {
  856. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  857. if (m)
  858. return m.call(o);
  859. return {
  860. next: function () {
  861. if (o && i >= o.length)
  862. o = void 0;
  863. return { value: o && o[i++], done: !o };
  864. }
  865. };
  866. }
  867. /**
  868. * @fileoverview added by tsickle
  869. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  870. */
  871. var ResizeHandle = /** @class */ (function () {
  872. function ResizeHandle(parent, renderer, type, css, onMouseDown) {
  873. var _this = this;
  874. this.parent = parent;
  875. this.renderer = renderer;
  876. this.type = type;
  877. this.css = css;
  878. this.onMouseDown = onMouseDown;
  879. // generate handle div
  880. /** @type {?} */
  881. var handle = renderer.createElement('div');
  882. renderer.addClass(handle, 'ng-resizable-handle');
  883. renderer.addClass(handle, css);
  884. // add default diagonal for se handle
  885. if (type === 'se') {
  886. renderer.addClass(handle, 'ng-resizable-diagonal');
  887. }
  888. // append div to parent
  889. if (this.parent) {
  890. parent.appendChild(handle);
  891. }
  892. // create and register event listener
  893. this._onResize = function (event) { onMouseDown(event, _this); };
  894. handle.addEventListener('mousedown', this._onResize, { passive: false });
  895. handle.addEventListener('touchstart', this._onResize, { passive: false });
  896. // done
  897. this._handle = handle;
  898. }
  899. /**
  900. * @return {?}
  901. */
  902. ResizeHandle.prototype.dispose = /**
  903. * @return {?}
  904. */
  905. function () {
  906. this._handle.removeEventListener('mousedown', this._onResize);
  907. this._handle.removeEventListener('touchstart', this._onResize);
  908. if (this.parent) {
  909. this.parent.removeChild(this._handle);
  910. }
  911. this._handle = null;
  912. this._onResize = null;
  913. };
  914. Object.defineProperty(ResizeHandle.prototype, "el", {
  915. get: /**
  916. * @return {?}
  917. */ function () {
  918. return this._handle;
  919. },
  920. enumerable: true,
  921. configurable: true
  922. });
  923. return ResizeHandle;
  924. }());
  925. /**
  926. * @fileoverview added by tsickle
  927. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  928. */
  929. var Size = /** @class */ (function () {
  930. function Size(width, height) {
  931. this.width = width;
  932. this.height = height;
  933. }
  934. /**
  935. * @param {?} el
  936. * @return {?}
  937. */
  938. Size.getCurrent = /**
  939. * @param {?} el
  940. * @return {?}
  941. */
  942. function (el) {
  943. /** @type {?} */
  944. var size = new Size(0, 0);
  945. if (window) {
  946. /** @type {?} */
  947. var computed = window.getComputedStyle(el);
  948. if (computed) {
  949. size.width = parseInt(computed.getPropertyValue('width'), 10);
  950. size.height = parseInt(computed.getPropertyValue('height'), 10);
  951. }
  952. return size;
  953. }
  954. else {
  955. console.error('Not Supported!');
  956. return null;
  957. }
  958. };
  959. /**
  960. * @param {?} s
  961. * @return {?}
  962. */
  963. Size.copy = /**
  964. * @param {?} s
  965. * @return {?}
  966. */
  967. function (s) {
  968. return new Size(0, 0).set(s);
  969. };
  970. /**
  971. * @template THIS
  972. * @this {THIS}
  973. * @param {?} s
  974. * @return {THIS}
  975. */
  976. Size.prototype.set = /**
  977. * @template THIS
  978. * @this {THIS}
  979. * @param {?} s
  980. * @return {THIS}
  981. */
  982. function (s) {
  983. ( /** @type {?} */(this)).width = s.width;
  984. ( /** @type {?} */(this)).height = s.height;
  985. return ( /** @type {?} */(this));
  986. };
  987. return Size;
  988. }());
  989. /**
  990. * @fileoverview added by tsickle
  991. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  992. */
  993. var AngularResizableDirective = /** @class */ (function () {
  994. function AngularResizableDirective(el, renderer) {
  995. this.el = el;
  996. this.renderer = renderer;
  997. this._resizable = true;
  998. this._handles = {};
  999. this._handleType = [];
  1000. this._handleResizing = null;
  1001. this._direction = null;
  1002. this._directionChanged = null;
  1003. this._aspectRatio = 0;
  1004. this._containment = null;
  1005. this._origMousePos = null;
  1006. /**
  1007. * Original Size and Position
  1008. */
  1009. this._origSize = null;
  1010. this._origPos = null;
  1011. /**
  1012. * Current Size and Position
  1013. */
  1014. this._currSize = null;
  1015. this._currPos = null;
  1016. /**
  1017. * Initial Size and Position
  1018. */
  1019. this._initSize = null;
  1020. this._initPos = null;
  1021. /**
  1022. * Snap to gird
  1023. */
  1024. this._gridSize = null;
  1025. this._bounding = null;
  1026. /**
  1027. * Bugfix: iFrames, and context unrelated elements block all events, and are unusable
  1028. * https://github.com/xieziyu/angular2-draggable/issues/84
  1029. */
  1030. this._helperBlock = null;
  1031. this.draggingSub = null;
  1032. this._adjusted = false;
  1033. /**
  1034. * Which handles can be used for resizing.
  1035. * \@example
  1036. * [rzHandles] = "'n,e,s,w,se,ne,sw,nw'"
  1037. * equals to: [rzHandles] = "'all'"
  1038. *
  1039. *
  1040. */
  1041. this.rzHandles = 'e,s,se';
  1042. /**
  1043. * Whether the element should be constrained to a specific aspect ratio.
  1044. * Multiple types supported:
  1045. * boolean: When set to true, the element will maintain its original aspect ratio.
  1046. * number: Force the element to maintain a specific aspect ratio during resizing.
  1047. */
  1048. this.rzAspectRatio = false;
  1049. /**
  1050. * Constrains resizing to within the bounds of the specified element or region.
  1051. * Multiple types supported:
  1052. * Selector: The resizable element will be contained to the bounding box of the first element found by the selector.
  1053. * If no element is found, no containment will be set.
  1054. * Element: The resizable element will be contained to the bounding box of this element.
  1055. * String: Possible values: "parent".
  1056. */
  1057. this.rzContainment = null;
  1058. /**
  1059. * Snaps the resizing element to a grid, every x and y pixels.
  1060. * A number for both width and height or an array values like [ x, y ]
  1061. */
  1062. this.rzGrid = null;
  1063. /**
  1064. * The minimum width the resizable should be allowed to resize to.
  1065. */
  1066. this.rzMinWidth = null;
  1067. /**
  1068. * The minimum height the resizable should be allowed to resize to.
  1069. */
  1070. this.rzMinHeight = null;
  1071. /**
  1072. * The maximum width the resizable should be allowed to resize to.
  1073. */
  1074. this.rzMaxWidth = null;
  1075. /**
  1076. * The maximum height the resizable should be allowed to resize to.
  1077. */
  1078. this.rzMaxHeight = null;
  1079. /**
  1080. * Whether to prevent default event
  1081. */
  1082. this.preventDefaultEvent = true;
  1083. /**
  1084. * emitted when start resizing
  1085. */
  1086. this.rzStart = new core.EventEmitter();
  1087. /**
  1088. * emitted when start resizing
  1089. */
  1090. this.rzResizing = new core.EventEmitter();
  1091. /**
  1092. * emitted when stop resizing
  1093. */
  1094. this.rzStop = new core.EventEmitter();
  1095. this._helperBlock = new HelperBlock(el.nativeElement, renderer);
  1096. }
  1097. Object.defineProperty(AngularResizableDirective.prototype, "ngResizable", {
  1098. /** Disables the resizable if set to false. */
  1099. set: /**
  1100. * Disables the resizable if set to false.
  1101. * @param {?} v
  1102. * @return {?}
  1103. */ function (v) {
  1104. if (v !== undefined && v !== null && v !== '') {
  1105. this._resizable = !!v;
  1106. this.updateResizable();
  1107. }
  1108. },
  1109. enumerable: true,
  1110. configurable: true
  1111. });
  1112. /**
  1113. * @param {?} changes
  1114. * @return {?}
  1115. */
  1116. AngularResizableDirective.prototype.ngOnChanges = /**
  1117. * @param {?} changes
  1118. * @return {?}
  1119. */
  1120. function (changes) {
  1121. if (changes['rzHandles'] && !changes['rzHandles'].isFirstChange()) {
  1122. this.updateResizable();
  1123. }
  1124. if (changes['rzAspectRatio'] && !changes['rzAspectRatio'].isFirstChange()) {
  1125. this.updateAspectRatio();
  1126. }
  1127. if (changes['rzContainment'] && !changes['rzContainment'].isFirstChange()) {
  1128. this.updateContainment();
  1129. }
  1130. };
  1131. /**
  1132. * @return {?}
  1133. */
  1134. AngularResizableDirective.prototype.ngOnInit = /**
  1135. * @return {?}
  1136. */
  1137. function () {
  1138. this.updateResizable();
  1139. };
  1140. /**
  1141. * @return {?}
  1142. */
  1143. AngularResizableDirective.prototype.ngOnDestroy = /**
  1144. * @return {?}
  1145. */
  1146. function () {
  1147. this.removeHandles();
  1148. this._containment = null;
  1149. this._helperBlock.dispose();
  1150. this._helperBlock = null;
  1151. };
  1152. /**
  1153. * @return {?}
  1154. */
  1155. AngularResizableDirective.prototype.ngAfterViewInit = /**
  1156. * @return {?}
  1157. */
  1158. function () {
  1159. /** @type {?} */
  1160. var elm = this.el.nativeElement;
  1161. this._initSize = Size.getCurrent(elm);
  1162. this._initPos = Position.getCurrent(elm);
  1163. this._currSize = Size.copy(this._initSize);
  1164. this._currPos = Position.copy(this._initPos);
  1165. this.updateAspectRatio();
  1166. this.updateContainment();
  1167. };
  1168. /** A method to reset size */
  1169. /**
  1170. * A method to reset size
  1171. * @return {?}
  1172. */
  1173. AngularResizableDirective.prototype.resetSize = /**
  1174. * A method to reset size
  1175. * @return {?}
  1176. */
  1177. function () {
  1178. this._currSize = Size.copy(this._initSize);
  1179. this._currPos = Position.copy(this._initPos);
  1180. this.doResize();
  1181. };
  1182. /** A method to get current status */
  1183. /**
  1184. * A method to get current status
  1185. * @return {?}
  1186. */
  1187. AngularResizableDirective.prototype.getStatus = /**
  1188. * A method to get current status
  1189. * @return {?}
  1190. */
  1191. function () {
  1192. if (!this._currPos || !this._currSize) {
  1193. return null;
  1194. }
  1195. return {
  1196. size: {
  1197. width: this._currSize.width,
  1198. height: this._currSize.height
  1199. },
  1200. position: {
  1201. top: this._currPos.y,
  1202. left: this._currPos.x
  1203. }
  1204. };
  1205. };
  1206. /**
  1207. * @private
  1208. * @return {?}
  1209. */
  1210. AngularResizableDirective.prototype.updateResizable = /**
  1211. * @private
  1212. * @return {?}
  1213. */
  1214. function () {
  1215. /** @type {?} */
  1216. var element = this.el.nativeElement;
  1217. // clear handles:
  1218. this.renderer.removeClass(element, 'ng-resizable');
  1219. this.removeHandles();
  1220. // create new ones:
  1221. if (this._resizable) {
  1222. this.renderer.addClass(element, 'ng-resizable');
  1223. this.createHandles();
  1224. }
  1225. };
  1226. /** Use it to update aspect */
  1227. /**
  1228. * Use it to update aspect
  1229. * @private
  1230. * @return {?}
  1231. */
  1232. AngularResizableDirective.prototype.updateAspectRatio = /**
  1233. * Use it to update aspect
  1234. * @private
  1235. * @return {?}
  1236. */
  1237. function () {
  1238. if (typeof this.rzAspectRatio === 'boolean') {
  1239. if (this.rzAspectRatio && this._currSize.height) {
  1240. this._aspectRatio = (this._currSize.width / this._currSize.height);
  1241. }
  1242. else {
  1243. this._aspectRatio = 0;
  1244. }
  1245. }
  1246. else {
  1247. /** @type {?} */
  1248. var r = Number(this.rzAspectRatio);
  1249. this._aspectRatio = isNaN(r) ? 0 : r;
  1250. }
  1251. };
  1252. /** Use it to update containment */
  1253. /**
  1254. * Use it to update containment
  1255. * @private
  1256. * @return {?}
  1257. */
  1258. AngularResizableDirective.prototype.updateContainment = /**
  1259. * Use it to update containment
  1260. * @private
  1261. * @return {?}
  1262. */
  1263. function () {
  1264. if (!this.rzContainment) {
  1265. this._containment = null;
  1266. return;
  1267. }
  1268. if (typeof this.rzContainment === 'string') {
  1269. if (this.rzContainment === 'parent') {
  1270. this._containment = this.el.nativeElement.parentElement;
  1271. }
  1272. else {
  1273. this._containment = document.querySelector(this.rzContainment);
  1274. }
  1275. }
  1276. else {
  1277. this._containment = this.rzContainment;
  1278. }
  1279. };
  1280. /** Use it to create handle divs */
  1281. /**
  1282. * Use it to create handle divs
  1283. * @private
  1284. * @return {?}
  1285. */
  1286. AngularResizableDirective.prototype.createHandles = /**
  1287. * Use it to create handle divs
  1288. * @private
  1289. * @return {?}
  1290. */
  1291. function () {
  1292. var e_1, _a, e_2, _b;
  1293. if (!this.rzHandles) {
  1294. return;
  1295. }
  1296. /** @type {?} */
  1297. var tmpHandleTypes;
  1298. if (typeof this.rzHandles === 'string') {
  1299. if (this.rzHandles === 'all') {
  1300. tmpHandleTypes = ['n', 'e', 's', 'w', 'ne', 'se', 'nw', 'sw'];
  1301. }
  1302. else {
  1303. tmpHandleTypes = this.rzHandles.replace(/ /g, '').toLowerCase().split(',');
  1304. }
  1305. try {
  1306. for (var tmpHandleTypes_1 = __values(tmpHandleTypes), tmpHandleTypes_1_1 = tmpHandleTypes_1.next(); !tmpHandleTypes_1_1.done; tmpHandleTypes_1_1 = tmpHandleTypes_1.next()) {
  1307. var type = tmpHandleTypes_1_1.value;
  1308. // default handle theme: ng-resizable-$type.
  1309. /** @type {?} */
  1310. var handle = this.createHandleByType(type, "ng-resizable-" + type);
  1311. if (handle) {
  1312. this._handleType.push(type);
  1313. this._handles[type] = handle;
  1314. }
  1315. }
  1316. }
  1317. catch (e_1_1) {
  1318. e_1 = { error: e_1_1 };
  1319. }
  1320. finally {
  1321. try {
  1322. if (tmpHandleTypes_1_1 && !tmpHandleTypes_1_1.done && (_a = tmpHandleTypes_1.return))
  1323. _a.call(tmpHandleTypes_1);
  1324. }
  1325. finally {
  1326. if (e_1)
  1327. throw e_1.error;
  1328. }
  1329. }
  1330. }
  1331. else {
  1332. tmpHandleTypes = Object.keys(this.rzHandles);
  1333. try {
  1334. for (var tmpHandleTypes_2 = __values(tmpHandleTypes), tmpHandleTypes_2_1 = tmpHandleTypes_2.next(); !tmpHandleTypes_2_1.done; tmpHandleTypes_2_1 = tmpHandleTypes_2.next()) {
  1335. var type = tmpHandleTypes_2_1.value;
  1336. // custom handle theme.
  1337. /** @type {?} */
  1338. var handle = this.createHandleByType(type, this.rzHandles[type]);
  1339. if (handle) {
  1340. this._handleType.push(type);
  1341. this._handles[type] = handle;
  1342. }
  1343. }
  1344. }
  1345. catch (e_2_1) {
  1346. e_2 = { error: e_2_1 };
  1347. }
  1348. finally {
  1349. try {
  1350. if (tmpHandleTypes_2_1 && !tmpHandleTypes_2_1.done && (_b = tmpHandleTypes_2.return))
  1351. _b.call(tmpHandleTypes_2);
  1352. }
  1353. finally {
  1354. if (e_2)
  1355. throw e_2.error;
  1356. }
  1357. }
  1358. }
  1359. };
  1360. /** Use it to create a handle */
  1361. /**
  1362. * Use it to create a handle
  1363. * @private
  1364. * @param {?} type
  1365. * @param {?} css
  1366. * @return {?}
  1367. */
  1368. AngularResizableDirective.prototype.createHandleByType = /**
  1369. * Use it to create a handle
  1370. * @private
  1371. * @param {?} type
  1372. * @param {?} css
  1373. * @return {?}
  1374. */
  1375. function (type, css) {
  1376. /** @type {?} */
  1377. var _el = this.el.nativeElement;
  1378. if (!type.match(/^(se|sw|ne|nw|n|e|s|w)$/)) {
  1379. console.error('Invalid handle type:', type);
  1380. return null;
  1381. }
  1382. return new ResizeHandle(_el, this.renderer, type, css, this.onMouseDown.bind(this));
  1383. };
  1384. /**
  1385. * @private
  1386. * @return {?}
  1387. */
  1388. AngularResizableDirective.prototype.removeHandles = /**
  1389. * @private
  1390. * @return {?}
  1391. */
  1392. function () {
  1393. var e_3, _a;
  1394. try {
  1395. for (var _b = __values(this._handleType), _c = _b.next(); !_c.done; _c = _b.next()) {
  1396. var type = _c.value;
  1397. this._handles[type].dispose();
  1398. }
  1399. }
  1400. catch (e_3_1) {
  1401. e_3 = { error: e_3_1 };
  1402. }
  1403. finally {
  1404. try {
  1405. if (_c && !_c.done && (_a = _b.return))
  1406. _a.call(_b);
  1407. }
  1408. finally {
  1409. if (e_3)
  1410. throw e_3.error;
  1411. }
  1412. }
  1413. this._handleType = [];
  1414. this._handles = {};
  1415. };
  1416. /**
  1417. * @param {?} event
  1418. * @param {?} handle
  1419. * @return {?}
  1420. */
  1421. AngularResizableDirective.prototype.onMouseDown = /**
  1422. * @param {?} event
  1423. * @param {?} handle
  1424. * @return {?}
  1425. */
  1426. function (event, handle) {
  1427. // skip right click;
  1428. if (event instanceof MouseEvent && event.button === 2) {
  1429. return;
  1430. }
  1431. if (this.preventDefaultEvent) {
  1432. // prevent default events
  1433. event.stopPropagation();
  1434. event.preventDefault();
  1435. }
  1436. if (!this._handleResizing) {
  1437. this._origMousePos = Position.fromEvent(event);
  1438. this.startResize(handle);
  1439. this.subscribeEvents();
  1440. }
  1441. };
  1442. /**
  1443. * @private
  1444. * @return {?}
  1445. */
  1446. AngularResizableDirective.prototype.subscribeEvents = /**
  1447. * @private
  1448. * @return {?}
  1449. */
  1450. function () {
  1451. var _this = this;
  1452. this.draggingSub = rxjs.fromEvent(document, 'mousemove', { passive: false }).subscribe(function (event) { return _this.onMouseMove(( /** @type {?} */(event))); });
  1453. this.draggingSub.add(rxjs.fromEvent(document, 'touchmove', { passive: false }).subscribe(function (event) { return _this.onMouseMove(( /** @type {?} */(event))); }));
  1454. this.draggingSub.add(rxjs.fromEvent(document, 'mouseup', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
  1455. // fix for issue #164
  1456. /** @type {?} */
  1457. var isIEOrEdge = /msie\s|trident\//i.test(window.navigator.userAgent);
  1458. if (!isIEOrEdge) {
  1459. this.draggingSub.add(rxjs.fromEvent(document, 'mouseleave', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
  1460. }
  1461. this.draggingSub.add(rxjs.fromEvent(document, 'touchend', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
  1462. this.draggingSub.add(rxjs.fromEvent(document, 'touchcancel', { passive: false }).subscribe(function () { return _this.onMouseLeave(); }));
  1463. };
  1464. /**
  1465. * @private
  1466. * @return {?}
  1467. */
  1468. AngularResizableDirective.prototype.unsubscribeEvents = /**
  1469. * @private
  1470. * @return {?}
  1471. */
  1472. function () {
  1473. this.draggingSub.unsubscribe();
  1474. this.draggingSub = null;
  1475. };
  1476. /**
  1477. * @return {?}
  1478. */
  1479. AngularResizableDirective.prototype.onMouseLeave = /**
  1480. * @return {?}
  1481. */
  1482. function () {
  1483. if (this._handleResizing) {
  1484. this.stopResize();
  1485. this._origMousePos = null;
  1486. this.unsubscribeEvents();
  1487. }
  1488. };
  1489. /**
  1490. * @param {?} event
  1491. * @return {?}
  1492. */
  1493. AngularResizableDirective.prototype.onMouseMove = /**
  1494. * @param {?} event
  1495. * @return {?}
  1496. */
  1497. function (event) {
  1498. if (this._handleResizing && this._resizable && this._origMousePos && this._origPos && this._origSize) {
  1499. this.resizeTo(Position.fromEvent(event));
  1500. this.onResizing();
  1501. }
  1502. };
  1503. /**
  1504. * @private
  1505. * @param {?} handle
  1506. * @return {?}
  1507. */
  1508. AngularResizableDirective.prototype.startResize = /**
  1509. * @private
  1510. * @param {?} handle
  1511. * @return {?}
  1512. */
  1513. function (handle) {
  1514. /** @type {?} */
  1515. var elm = this.el.nativeElement;
  1516. this._origSize = Size.getCurrent(elm);
  1517. this._origPos = Position.getCurrent(elm); // x: left, y: top
  1518. this._currSize = Size.copy(this._origSize);
  1519. this._currPos = Position.copy(this._origPos);
  1520. if (this._containment) {
  1521. this.getBounding();
  1522. }
  1523. this.getGridSize();
  1524. // Add a transparent helper div:
  1525. this._helperBlock.add();
  1526. this._handleResizing = handle;
  1527. this.updateDirection();
  1528. this.rzStart.emit(this.getResizingEvent());
  1529. };
  1530. /**
  1531. * @private
  1532. * @return {?}
  1533. */
  1534. AngularResizableDirective.prototype.stopResize = /**
  1535. * @private
  1536. * @return {?}
  1537. */
  1538. function () {
  1539. // Remove the helper div:
  1540. this._helperBlock.remove();
  1541. this.rzStop.emit(this.getResizingEvent());
  1542. this._handleResizing = null;
  1543. this._direction = null;
  1544. this._origSize = null;
  1545. this._origPos = null;
  1546. if (this._containment) {
  1547. this.resetBounding();
  1548. }
  1549. };
  1550. /**
  1551. * @private
  1552. * @return {?}
  1553. */
  1554. AngularResizableDirective.prototype.onResizing = /**
  1555. * @private
  1556. * @return {?}
  1557. */
  1558. function () {
  1559. this.rzResizing.emit(this.getResizingEvent());
  1560. };
  1561. /**
  1562. * @private
  1563. * @return {?}
  1564. */
  1565. AngularResizableDirective.prototype.getResizingEvent = /**
  1566. * @private
  1567. * @return {?}
  1568. */
  1569. function () {
  1570. return {
  1571. host: this.el.nativeElement,
  1572. handle: this._handleResizing ? this._handleResizing.el : null,
  1573. size: {
  1574. width: this._currSize.width,
  1575. height: this._currSize.height
  1576. },
  1577. position: {
  1578. top: this._currPos.y,
  1579. left: this._currPos.x
  1580. },
  1581. direction: __assign({}, this._directionChanged),
  1582. };
  1583. };
  1584. /**
  1585. * @private
  1586. * @return {?}
  1587. */
  1588. AngularResizableDirective.prototype.updateDirection = /**
  1589. * @private
  1590. * @return {?}
  1591. */
  1592. function () {
  1593. this._direction = {
  1594. n: !!this._handleResizing.type.match(/n/),
  1595. s: !!this._handleResizing.type.match(/s/),
  1596. w: !!this._handleResizing.type.match(/w/),
  1597. e: !!this._handleResizing.type.match(/e/)
  1598. };
  1599. this._directionChanged = __assign({}, this._direction);
  1600. // if aspect ration should be preserved:
  1601. if (this.rzAspectRatio) {
  1602. // if north then west (unless ne)
  1603. if (this._directionChanged.n && !this._directionChanged.e) {
  1604. this._directionChanged.w = true;
  1605. }
  1606. // if south then east (unless sw)
  1607. if (this._directionChanged.s && !this._directionChanged.w) {
  1608. this._directionChanged.e = true;
  1609. }
  1610. // if east then south (unless ne)
  1611. if (this._directionChanged.e && !this._directionChanged.n) {
  1612. this._directionChanged.s = true;
  1613. }
  1614. // if west then south (unless nw)
  1615. if (this._directionChanged.w && !this._directionChanged.n) {
  1616. this._directionChanged.s = true;
  1617. }
  1618. }
  1619. };
  1620. /**
  1621. * @private
  1622. * @param {?} p
  1623. * @return {?}
  1624. */
  1625. AngularResizableDirective.prototype.resizeTo = /**
  1626. * @private
  1627. * @param {?} p
  1628. * @return {?}
  1629. */
  1630. function (p) {
  1631. p.subtract(this._origMousePos);
  1632. /** @type {?} */
  1633. var tmpX = Math.round(p.x / this._gridSize.x) * this._gridSize.x;
  1634. /** @type {?} */
  1635. var tmpY = Math.round(p.y / this._gridSize.y) * this._gridSize.y;
  1636. if (this._direction.n) {
  1637. // n, ne, nw
  1638. this._currPos.y = this._origPos.y + tmpY;
  1639. this._currSize.height = this._origSize.height - tmpY;
  1640. }
  1641. else if (this._direction.s) {
  1642. // s, se, sw
  1643. this._currSize.height = this._origSize.height + tmpY;
  1644. }
  1645. if (this._direction.e) {
  1646. // e, ne, se
  1647. this._currSize.width = this._origSize.width + tmpX;
  1648. }
  1649. else if (this._direction.w) {
  1650. // w, nw, sw
  1651. this._currSize.width = this._origSize.width - tmpX;
  1652. this._currPos.x = this._origPos.x + tmpX;
  1653. }
  1654. this.checkBounds();
  1655. this.checkSize();
  1656. this.adjustByRatio();
  1657. this.doResize();
  1658. };
  1659. /**
  1660. * @private
  1661. * @return {?}
  1662. */
  1663. AngularResizableDirective.prototype.doResize = /**
  1664. * @private
  1665. * @return {?}
  1666. */
  1667. function () {
  1668. /** @type {?} */
  1669. var container = this.el.nativeElement;
  1670. if (!this._direction || this._direction.n || this._direction.s || this._aspectRatio) {
  1671. this.renderer.setStyle(container, 'height', this._currSize.height + 'px');
  1672. }
  1673. if (!this._direction || this._direction.w || this._direction.e || this._aspectRatio) {
  1674. this.renderer.setStyle(container, 'width', this._currSize.width + 'px');
  1675. }
  1676. this.renderer.setStyle(container, 'left', this._currPos.x + 'px');
  1677. this.renderer.setStyle(container, 'top', this._currPos.y + 'px');
  1678. };
  1679. /**
  1680. * @private
  1681. * @return {?}
  1682. */
  1683. AngularResizableDirective.prototype.adjustByRatio = /**
  1684. * @private
  1685. * @return {?}
  1686. */
  1687. function () {
  1688. if (this._aspectRatio && !this._adjusted) {
  1689. if (this._direction.e || this._direction.w) {
  1690. /** @type {?} */
  1691. var newHeight = Math.floor(this._currSize.width / this._aspectRatio);
  1692. if (this._direction.n) {
  1693. this._currPos.y += this._currSize.height - newHeight;
  1694. }
  1695. this._currSize.height = newHeight;
  1696. }
  1697. else {
  1698. /** @type {?} */
  1699. var newWidth = Math.floor(this._aspectRatio * this._currSize.height);
  1700. if (this._direction.n) {
  1701. this._currPos.x += this._currSize.width - newWidth;
  1702. }
  1703. this._currSize.width = newWidth;
  1704. }
  1705. }
  1706. };
  1707. /**
  1708. * @private
  1709. * @return {?}
  1710. */
  1711. AngularResizableDirective.prototype.checkBounds = /**
  1712. * @private
  1713. * @return {?}
  1714. */
  1715. function () {
  1716. if (this._containment) {
  1717. /** @type {?} */
  1718. var maxWidth = this._bounding.width - this._bounding.pr - this._bounding.deltaL - this._bounding.translateX - this._currPos.x;
  1719. /** @type {?} */
  1720. var maxHeight = this._bounding.height - this._bounding.pb - this._bounding.deltaT - this._bounding.translateY - this._currPos.y;
  1721. if (this._direction.n && (this._currPos.y + this._bounding.translateY < 0)) {
  1722. this._currPos.y = -this._bounding.translateY;
  1723. this._currSize.height = this._origSize.height + this._origPos.y + this._bounding.translateY;
  1724. }
  1725. if (this._direction.w && (this._currPos.x + this._bounding.translateX) < 0) {
  1726. this._currPos.x = -this._bounding.translateX;
  1727. this._currSize.width = this._origSize.width + this._origPos.x + this._bounding.translateX;
  1728. }
  1729. if (this._currSize.width > maxWidth) {
  1730. this._currSize.width = maxWidth;
  1731. }
  1732. if (this._currSize.height > maxHeight) {
  1733. this._currSize.height = maxHeight;
  1734. }
  1735. /**
  1736. * Fix Issue: Additional check for aspect ratio
  1737. * https://github.com/xieziyu/angular2-draggable/issues/132
  1738. */
  1739. if (this._aspectRatio) {
  1740. this._adjusted = false;
  1741. if ((this._direction.w || this._direction.e) &&
  1742. (this._currSize.width / this._aspectRatio) >= maxHeight) {
  1743. /** @type {?} */
  1744. var newWidth = Math.floor(maxHeight * this._aspectRatio);
  1745. if (this._direction.w) {
  1746. this._currPos.x += this._currSize.width - newWidth;
  1747. }
  1748. this._currSize.width = newWidth;
  1749. this._currSize.height = maxHeight;
  1750. this._adjusted = true;
  1751. }
  1752. if ((this._direction.n || this._direction.s) &&
  1753. (this._currSize.height * this._aspectRatio) >= maxWidth) {
  1754. /** @type {?} */
  1755. var newHeight = Math.floor(maxWidth / this._aspectRatio);
  1756. if (this._direction.n) {
  1757. this._currPos.y += this._currSize.height - newHeight;
  1758. }
  1759. this._currSize.width = maxWidth;
  1760. this._currSize.height = newHeight;
  1761. this._adjusted = true;
  1762. }
  1763. }
  1764. }
  1765. };
  1766. /**
  1767. * @private
  1768. * @return {?}
  1769. */
  1770. AngularResizableDirective.prototype.checkSize = /**
  1771. * @private
  1772. * @return {?}
  1773. */
  1774. function () {
  1775. /** @type {?} */
  1776. var minHeight = !this.rzMinHeight ? 1 : this.rzMinHeight;
  1777. /** @type {?} */
  1778. var minWidth = !this.rzMinWidth ? 1 : this.rzMinWidth;
  1779. if (this._currSize.height < minHeight) {
  1780. this._currSize.height = minHeight;
  1781. if (this._direction.n) {
  1782. this._currPos.y = this._origPos.y + (this._origSize.height - minHeight);
  1783. }
  1784. }
  1785. if (this._currSize.width < minWidth) {
  1786. this._currSize.width = minWidth;
  1787. if (this._direction.w) {
  1788. this._currPos.x = this._origPos.x + (this._origSize.width - minWidth);
  1789. }
  1790. }
  1791. if (this.rzMaxHeight && this._currSize.height > this.rzMaxHeight) {
  1792. this._currSize.height = this.rzMaxHeight;
  1793. if (this._direction.n) {
  1794. this._currPos.y = this._origPos.y + (this._origSize.height - this.rzMaxHeight);
  1795. }
  1796. }
  1797. if (this.rzMaxWidth && this._currSize.width > this.rzMaxWidth) {
  1798. this._currSize.width = this.rzMaxWidth;
  1799. if (this._direction.w) {
  1800. this._currPos.x = this._origPos.x + (this._origSize.width - this.rzMaxWidth);
  1801. }
  1802. }
  1803. };
  1804. /**
  1805. * @private
  1806. * @return {?}
  1807. */
  1808. AngularResizableDirective.prototype.getBounding = /**
  1809. * @private
  1810. * @return {?}
  1811. */
  1812. function () {
  1813. /** @type {?} */
  1814. var el = this._containment;
  1815. /** @type {?} */
  1816. var computed = window.getComputedStyle(el);
  1817. if (computed) {
  1818. /** @type {?} */
  1819. var p = computed.getPropertyValue('position');
  1820. /** @type {?} */
  1821. var nativeEl = window.getComputedStyle(this.el.nativeElement);
  1822. /** @type {?} */
  1823. var transforms = nativeEl.getPropertyValue('transform').replace(/[^-\d,]/g, '').split(',');
  1824. this._bounding = {};
  1825. this._bounding.width = el.clientWidth;
  1826. this._bounding.height = el.clientHeight;
  1827. this._bounding.pr = parseInt(computed.getPropertyValue('padding-right'), 10);
  1828. this._bounding.pb = parseInt(computed.getPropertyValue('padding-bottom'), 10);
  1829. this._bounding.deltaL = this.el.nativeElement.offsetLeft - this._currPos.x;
  1830. this._bounding.deltaT = this.el.nativeElement.offsetTop - this._currPos.y;
  1831. if (transforms.length >= 6) {
  1832. this._bounding.translateX = parseInt(transforms[4], 10);
  1833. this._bounding.translateY = parseInt(transforms[5], 10);
  1834. }
  1835. else {
  1836. this._bounding.translateX = 0;
  1837. this._bounding.translateY = 0;
  1838. }
  1839. this._bounding.position = computed.getPropertyValue('position');
  1840. if (p === 'static') {
  1841. this.renderer.setStyle(el, 'position', 'relative');
  1842. }
  1843. }
  1844. };
  1845. /**
  1846. * @private
  1847. * @return {?}
  1848. */
  1849. AngularResizableDirective.prototype.resetBounding = /**
  1850. * @private
  1851. * @return {?}
  1852. */
  1853. function () {
  1854. if (this._bounding && this._bounding.position === 'static') {
  1855. this.renderer.setStyle(this._containment, 'position', 'relative');
  1856. }
  1857. this._bounding = null;
  1858. };
  1859. /**
  1860. * @private
  1861. * @return {?}
  1862. */
  1863. AngularResizableDirective.prototype.getGridSize = /**
  1864. * @private
  1865. * @return {?}
  1866. */
  1867. function () {
  1868. // set default value:
  1869. this._gridSize = { x: 1, y: 1 };
  1870. if (this.rzGrid) {
  1871. if (typeof this.rzGrid === 'number') {
  1872. this._gridSize = { x: this.rzGrid, y: this.rzGrid };
  1873. }
  1874. else if (Array.isArray(this.rzGrid)) {
  1875. this._gridSize = { x: this.rzGrid[0], y: this.rzGrid[1] };
  1876. }
  1877. }
  1878. };
  1879. AngularResizableDirective.decorators = [
  1880. { type: core.Directive, args: [{
  1881. selector: '[ngResizable]',
  1882. exportAs: 'ngResizable'
  1883. },] }
  1884. ];
  1885. /** @nocollapse */
  1886. AngularResizableDirective.ctorParameters = function () {
  1887. return [
  1888. { type: core.ElementRef },
  1889. { type: core.Renderer2 }
  1890. ];
  1891. };
  1892. AngularResizableDirective.propDecorators = {
  1893. ngResizable: [{ type: core.Input }],
  1894. rzHandles: [{ type: core.Input }],
  1895. rzAspectRatio: [{ type: core.Input }],
  1896. rzContainment: [{ type: core.Input }],
  1897. rzGrid: [{ type: core.Input }],
  1898. rzMinWidth: [{ type: core.Input }],
  1899. rzMinHeight: [{ type: core.Input }],
  1900. rzMaxWidth: [{ type: core.Input }],
  1901. rzMaxHeight: [{ type: core.Input }],
  1902. preventDefaultEvent: [{ type: core.Input }],
  1903. rzStart: [{ type: core.Output }],
  1904. rzResizing: [{ type: core.Output }],
  1905. rzStop: [{ type: core.Output }]
  1906. };
  1907. return AngularResizableDirective;
  1908. }());
  1909. /**
  1910. * @fileoverview added by tsickle
  1911. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1912. */
  1913. var AngularDraggableModule = /** @class */ (function () {
  1914. function AngularDraggableModule() {
  1915. }
  1916. AngularDraggableModule.decorators = [
  1917. { type: core.NgModule, args: [{
  1918. imports: [],
  1919. declarations: [
  1920. AngularDraggableDirective,
  1921. AngularResizableDirective
  1922. ],
  1923. exports: [
  1924. AngularDraggableDirective,
  1925. AngularResizableDirective
  1926. ]
  1927. },] }
  1928. ];
  1929. return AngularDraggableModule;
  1930. }());
  1931. /**
  1932. * @fileoverview added by tsickle
  1933. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1934. */
  1935. /**
  1936. * @fileoverview added by tsickle
  1937. * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1938. */
  1939. exports.AngularDraggableDirective = AngularDraggableDirective;
  1940. exports.AngularResizableDirective = AngularResizableDirective;
  1941. exports.AngularDraggableModule = AngularDraggableModule;
  1942. exports.Position = Position;
  1943. Object.defineProperty(exports, '__esModule', { value: true });
  1944. })));
  1945. //# sourceMappingURL=angular2-draggable.umd.js.map