File tree 5 files changed +49
-17
lines changed
5 files changed +49
-17
lines changed Original file line number Diff line number Diff line change 53
53
} ;
54
54
55
55
56
- // I reposition the given slave.
57
- $scope . repositionSlave = function ( slave , x , y ) {
58
-
59
- slave . x = x ;
60
- slave . y = y ;
61
-
62
- } ;
63
-
64
-
65
56
// -- Set Scope Variables. ---------------------- //
66
57
67
58
Original file line number Diff line number Diff line change
1
+ ( function ( ng , app ) {
2
+
3
+ "use strict" ;
4
+
5
+ app . controller (
6
+ "SlaveController" ,
7
+ function ( $scope ) {
8
+
9
+
10
+ // -- Define Scope Methods. --------------------- //
11
+
12
+
13
+ // I remove the current slave from the collection.
14
+ $scope . remove = function ( ) {
15
+
16
+ // Pass this responsibility up the scope chain to the master controller (and its
17
+ // collection of slave instances).
18
+ $scope . removeSlave ( $scope . slave ) ;
19
+
20
+ } ;
21
+
22
+
23
+ // I reposition the current slave.
24
+ $scope . reposition = function ( x , y ) {
25
+
26
+ $scope . slave . x = x ;
27
+ $scope . slave . y = y ;
28
+
29
+ } ;
30
+
31
+
32
+ }
33
+ ) ;
34
+
35
+ } ) ( angular , demo ) ;
Original file line number Diff line number Diff line change 110
110
element . on ( "mousemove.bnMaster" , handleMouseMove ) ;
111
111
element . on ( "mouseup.bnMaster" , handleMouseUp ) ;
112
112
113
- // The user clicked on the master directly.
113
+ // The user clicked on the master canvas directly. We'll use this as an invite
114
+ // to create a new slave handle.
114
115
} else {
115
116
116
117
$scope . $apply (
126
127
}
127
128
128
129
129
- // I listen for mouse movements to broadcast new position deltas to all of
130
- // the slaves.
130
+ // I listen for mouse movements to broadcast new position deltas to all of the slaves.
131
131
function handleMouseMove ( event ) {
132
132
133
133
controller . moveTo (
Original file line number Diff line number Diff line change 32
32
// the slave directly, as this WILL happen inside of a $digest.
33
33
function reposition ( deltaX , deltaY ) {
34
34
35
- $scope . repositionSlave (
36
- $scope . slave ,
35
+ $scope . reposition (
37
36
( $scope . slave . x + deltaX ) ,
38
37
( $scope . slave . y + deltaY )
39
38
) ;
96
95
$scope . $apply (
97
96
function ( ) {
98
97
99
- $scope . removeSlave ( $scope . slave ) ;
98
+ $scope . remove ( ) ;
100
99
101
100
}
102
101
) ;
125
124
"$destroy" ,
126
125
function ( event ) {
127
126
127
+ // Clean up the master-slave binding in case this element is removed outside
128
+ // of our internal event handling.
129
+ masterController . unbind ( slaveController ) ;
130
+
131
+ // Clear any existing mouse bindings.
128
132
element . off ( "mousedown.bnSlave" ) ;
129
133
$document . off ( "mousemove.bnSlave" ) ;
130
134
$document . off ( "mouseup.bnSlave" ) ;
Original file line number Diff line number Diff line change 14
14
</ h1 >
15
15
16
16
17
- <!-- BEGIN: Master. -->
17
+ <!-- BEGIN: Master Canvas . -->
18
18
< div
19
19
ng-controller ="MasterController "
20
20
bn-master
25
25
< ol class ="handles ">
26
26
< li
27
27
ng-repeat ="slave in slaves "
28
+ ng-controller ="SlaveController "
28
29
bn-slave
29
30
class ="slave "
30
31
ng-style ="{ left: ( slave.x + 'px' ), top: ( slave.y + 'px' ) } ">
55
56
56
57
57
58
</ div >
58
- <!-- END: Master. -->
59
+ <!-- END: Master Canvas . -->
59
60
60
61
61
62
<!-- Load jQuery and AngularJS from the CDN. -->
71
72
<!-- Load the app module and its classes. -->
72
73
< script type ="text/javascript " src ="app/main.js "> </ script >
73
74
< script type ="text/javascript " src ="app/controllers/master-controller.js "> </ script >
75
+ < script type ="text/javascript " src ="app/controllers/slave-controller.js "> </ script >
74
76
< script type ="text/javascript " src ="app/directives/master.js "> </ script >
75
77
< script type ="text/javascript " src ="app/directives/slave.js "> </ script >
76
78
You can’t perform that action at this time.
0 commit comments