Skip to content

Commit 1b39d22

Browse files
authored
Merge pull request #11 from CoderAjay/development
Development
2 parents 9fdce57 + fb84452 commit 1b39d22

File tree

9 files changed

+245
-97
lines changed

9 files changed

+245
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ typings/*
1616

1717
dist/*
1818
**/*.js
19+
**/*.js.map
1920
**/*.d.ts

.npmignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
make.js
2+
# compiled output
3+
/.tmp
4+
/src
5+
6+
/Architecture.md
7+
# dependencies
8+
/node_modules
9+
/bower_components
10+
11+
# IDEs and editors
12+
/.idea
13+
/.vscode
14+
.project
15+
.classpath
16+
.c9/
17+
*.launch
18+
.settings/
19+
tslint.json
20+
.editorconfig
21+
22+
23+
# misc
24+
/.sass-cache
25+
/connect.lock
26+
/coverage/*
27+
/libpeerconnection.log
28+
npm-debug.log
29+
testem.log
30+
/typings
31+
32+
# e2e
33+
/e2e/*.js
34+
/e2e/*.map
35+
36+
#System Files
37+
.DS_Store
38+
Thumbs.db

package.json

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
{
22
"name": "ng2-draggable",
3-
"version": "0.0.9",
3+
"version": "0.1.0",
44
"description": "Angular2 directive draggable.",
5-
"main": "dist/ng-draggable.js",
6-
"typings": "ng2-draggable.d.ts",
5+
"main": "dist/draggable.module.js",
6+
"typings": "dist/draggable.module.d.ts",
77
"scripts": {
8-
"task.compile:system": "./.config/bundle.js",
9-
"task.compile:common": "./node_modules/.bin/tsc -p tsconfig.publish.json",
10-
"task.compile": "npm run task.compile:common && npm run task.compile:system",
11-
"task.clean": "./node_modules/.bin/del dist \"ng2-draggable.+(js|d.ts|js.map)\"",
12-
"prepublish": "npm run task.clean && npm run task.compile",
13-
"lite": "lite-server",
14-
"start": "concurrently \"npm run ;tsc:w\" \"npm run lite\" ",
15-
"tsc:w": "tsc -w"
8+
"compile": "node ./node_modules/@angular/compiler-cli/src/main.js -p src/",
9+
"prepublish": "npm run clean && npm run compile && rm -rf dist/node_modules && npm run build",
10+
"clean": "rm -rf dist && rm -rf bundles",
11+
"build": "node make.js"
1612
},
1713
"repository": {
1814
"type": "git",
@@ -33,28 +29,19 @@
3329
"homepage": "https://github.com/CoderAjay/ng2Draggable#readme",
3430
"dependencies": {},
3531
"peerDependencies": {
36-
"@angular/common": "~2.2.0",
37-
"@angular/compiler": "~2.2.0",
38-
"@angular/core": "~2.2.0"
32+
"@angular/core": "^2.4.10",
33+
"rxjs": "^5.0.0-beta.12",
34+
"zone.js": "^0.6.23"
3935
},
4036
"devDependencies": {
41-
"@angular/common": "~2.2.0",
42-
"@angular/compiler": "~2.2.0",
43-
"@angular/core": "~2.2.0",
44-
"@angular/platform-browser": "~2.2.0",
45-
"@angular/platform-browser-dynamic": "~2.2.0",
46-
"core-js": "^2.4.1",
47-
"reflect-metadata": "^0.1.8",
48-
"rxjs": "5.0.0-beta.12",
49-
"systemjs": "0.19.39",
50-
"zone.js": "^0.6.25",
51-
"@types/core-js": "^0.9.34",
52-
"@types/node": "^6.0.45",
53-
"concurrently": "^3.0.0",
54-
"del": "^2.2.2",
55-
"del-cli": "^0.2.0",
56-
"lite-server": "^2.2.2",
57-
"systemjs-builder": "^0.15.34",
58-
"typescript": "^2.0.3"
37+
"@angular/common": "^2.4.10",
38+
"@angular/compiler": "^2.4.10",
39+
"@angular/compiler-cli": "^2.4.10",
40+
"@angular/core": "^2.4.10",
41+
"rxjs": "^5.0.0-beta.12",
42+
"systemjs-builder": "^0.16.4",
43+
"tslint": "3.13.0",
44+
"typescript": "~2.0.3",
45+
"zone.js": "^0.6.23"
5946
}
6047
}
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Directive, ElementRef, Renderer, OnDestroy, OnInit } from '@angular/core';
1+
import { Directive, ElementRef, Renderer, OnDestroy, OnInit, AfterViewInit, Input } from '@angular/core';
22

33

44
@Directive({
@@ -9,55 +9,60 @@ import { Directive, ElementRef, Renderer, OnDestroy, OnInit } from '@angular/cor
99
'(drag)': 'onDrag($event)'
1010
}
1111
})
12-
export class Draggable implements OnDestroy, OnInit {
12+
export class DraggableDirecrtive implements OnDestroy, OnInit, AfterViewInit {
1313
private Δx: number = 0;
1414
private Δy: number = 0;
15+
16+
private canDrag:boolean = true;
17+
18+
@Input('draggable')
19+
set draggable(val:any){
20+
if(val === undefined || val === null || val === '' ) return;
21+
this.canDrag = !!val;
22+
}
1523
private mustBePosition: Array<string> = ['absolute', 'fixed', 'relative'];
1624
constructor(
1725
private el: ElementRef, private renderer: Renderer
1826
) {
27+
28+
}
29+
30+
ngOnInit(): void {
31+
this.renderer.setElementAttribute(this.el.nativeElement, 'draggable', 'true');
32+
}
33+
ngAfterViewInit(){
1934
try {
20-
if (this.mustBePosition.indexOf(this.el.nativeElement.style.position) === -1) {
21-
console.warn(this.el.nativeElement, 'Must be having position attribute set to ' + this.mustBePosition.join('|'));
35+
let position = window.getComputedStyle(this.el.nativeElement).position;
36+
if (this.mustBePosition.indexOf(position) === -1) {
37+
console.warn( this.el.nativeElement, 'Must be having position attribute set to ' + this.mustBePosition.join('|'));
2238
}
2339
} catch (ex) {
2440
console.error(ex);
2541
}
2642
}
27-
public ngOnInit(): void {
28-
this.renderer.setElementAttribute(this.el.nativeElement, 'draggable', 'true');
43+
ngOnDestroy(): void {
44+
this.renderer.setElementAttribute(this.el.nativeElement, 'draggable', 'false');
2945
}
46+
3047
onDragStart(event: MouseEvent) {
3148
this.Δx = event.x - this.el.nativeElement.offsetLeft;
3249
this.Δy = event.y - this.el.nativeElement.offsetTop;
3350
}
51+
3452
onDrag(event: MouseEvent) {
3553
this.doTranslation(event.x, event.y);
3654
}
55+
3756
onDragEnd(event: MouseEvent) {
3857
this.Δx = 0;
3958
this.Δy = 0;
4059
}
60+
4161
doTranslation(x: number, y: number) {
4262
if (!x || !y) return;
4363
this.renderer.setElementStyle(this.el.nativeElement, 'top', (y - this.Δy) + 'px');
4464
this.renderer.setElementStyle(this.el.nativeElement, 'left', (x - this.Δx) + 'px');
4565
}
46-
public ngOnDestroy(): void {
47-
this.renderer.setElementAttribute(this.el.nativeElement, 'draggable', 'false');
48-
}
49-
50-
}
66+
5167

52-
import { NgModule } from '@angular/core';
53-
import { CommonModule } from '@angular/common';
54-
55-
56-
const DRAGGABLE_DIRECTIVES: any[] = [Draggable];
57-
58-
@NgModule({
59-
imports: [CommonModule],
60-
exports: DRAGGABLE_DIRECTIVES,
61-
declarations: DRAGGABLE_DIRECTIVES
62-
})
63-
export class DraggableModule { }
68+
}

src/draggable.module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule } from '@angular/core';
2+
3+
import { DraggableDirecrtive } from './draggable.directive';
4+
@NgModule({
5+
imports: [],
6+
declarations: [ DraggableDirecrtive ],
7+
exports: [ DraggableDirecrtive ],
8+
providers: []
9+
})
10+
export class Ng2DraggableModule { }

src/tsconfig.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"compilerOptions": {
3+
"noImplicitAny": true,
4+
"module": "commonjs",
5+
"target": "es5",
6+
"emitDecoratorMetadata": true,
7+
"experimentalDecorators": true,
8+
"inlineSourceMap": true,
9+
"inlineSources": true,
10+
"declaration": true,
11+
"suppressImplicitAnyIndexErrors": true,
12+
"removeComments": true,
13+
"moduleResolution": "node",
14+
"lib": [
15+
"dom",
16+
"es6"
17+
],
18+
"outDir": "../dist",
19+
"typeRoots": [
20+
"../node_modules/@types"
21+
]
22+
},
23+
"exclude": [
24+
"../node_modules",
25+
"../dist"
26+
],
27+
"awesomeTypescriptLoaderOptions": {
28+
"forkChecker": true,
29+
"useWebpackText": true
30+
},
31+
"angularCompilerOptions": {
32+
"genDir": "../dist",
33+
"debug": false
34+
}
35+
}

tsconfig.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

tsconfig.publish.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)