forked from fatlinesofcode/ngDraggable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-clone.html
executable file
·150 lines (138 loc) · 4.15 KB
/
example-clone.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<title>ngDraggable</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootswatch/2.3.1/spruce/bootstrap.min.css">
<style>
*{
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
[ng-drag], [ng-drag-clone]{
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.drag-object, [ng-drag-clone], [ng-drop] [ng-drag]{
width: 100px;
height: 100px;
background: rgba(255,0,0, 0.5);
color:white;
text-align: center;
padding-top:40px;
display: inline-block;
margin:0 10px;
cursor: move;
position: relative;
overflow: hidden;
}
.drag-object [ng-drag]{
width: 100px;
height: 100px;
position: absolute;
top:0; left:0;
padding: 0;
margin: 0;
}
[ng-drag-clone]{
margin: 0;
}
[ng-drag].drag-over{
border:solid 1px red;
}
[ng-drag].dragging{
opacity: 0.5;
}
[ng-drop]{
background: rgba(0,255,0, 0.5);
text-align: center;
width: 600px;
height: 200px;
padding-top:90px;
display: block;
margin:20px auto;
position: relative;
}
[ng-drop].drag-enter{
border:solid 5px red;
}
[ng-drop] span.title{
display: block;
position: absolute;
top:50%;
left:50%;
width: 200px;
height: 20px;
margin-left: -100px;
margin-top: -10px;
}
[ng-drop] div{
position: relative;
z-index: 2;
}
</style>
</head>
<body ng-app="ExampleApp">
<div class="container" ng-controller="MainCtrl">
<div class="row">
<h1>ngDraggable Clone Example</h1>
</div>
<div class="drag-object" ng-repeat="obj in draggableObjects" ng-if="obj.allowClone !== false">
{{obj.name}}
<div ng-drag="true" ng-drag-data="obj"></div>
</div>
<div class="drag-object" style="background-color: transparent; overflow: visible">
<div ng-drag="true" class="drag-object" ng-drag-data="draggableObjects[3]">{{draggableObjects[3].name}}</div>
</div>
<hr/>
<div ng-drop="true" ng-drop-success="onDropComplete1($data,$event)">
<span class="title">Drop area #1</span>
<div ng-repeat="obj in droppedObjects1" ng-drag="true" ng-drag-data="obj" ng-drag-success="onDragSuccess1($data,$event)">
{{obj.name}}
</div>
</div>
<hr>
</div>
<div ng-drag-clone="">
{{clonedData.name}}
</div>
<footer style="margin-top:2000px;">footer</footer>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script src="ngDraggable.js"></script>
<script>
angular.module('ExampleApp', ['ngDraggable']).
controller('MainCtrl', function ($scope) {
$scope.draggableObjects = [{name:'one'}, {name:'two'}, {name:'three'}, {name:'no-clone', allowClone:false}];
$scope.droppedObjects1 = [];
$scope.droppedObjects2= [];
$scope.onDropComplete1=function(data,evt){
var index = $scope.droppedObjects1.indexOf(data);
if (index == -1)
$scope.droppedObjects1.push(data);
}
$scope.onDragSuccess1=function(data,evt){
var index = $scope.droppedObjects1.indexOf(data);
if (index > -1) {
$scope.droppedObjects1.splice(index, 1);
}
}
$scope.onDragSuccess2=function(data,evt){
var index = $scope.droppedObjects2.indexOf(data);
if (index > -1) {
$scope.droppedObjects2.splice(index, 1);
}
}
$scope.onDropComplete2=function(data,evt){
var index = $scope.droppedObjects2.indexOf(data);
if (index == -1) {
$scope.droppedObjects2.push(data);
}
}
var inArray = function(array, obj) {
var index = array.indexOf(obj);
}
});
</script>
</body>
</html>