Skip to content

Commit b44b6e5

Browse files
committed
First commit.
0 parents  commit b44b6e5

File tree

7 files changed

+645
-0
lines changed

7 files changed

+645
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# AngularJS Directive Controllers
3+
4+
by (Ben Nadel)[1]
5+
6+
This is an exploration of the use of Controllers in Directives as a means to faciliate
7+
inter-directive communication.
8+
9+
[1] http://www.bennadel.com

app/controllers/master-controller.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(function( ng, app ) {
2+
3+
"use strict";
4+
5+
app.controller(
6+
"MasterController",
7+
function( $scope ) {
8+
9+
10+
// -- Define Controller Methods. ---------------- //
11+
12+
13+
// I get the next available ID for a new slave.
14+
function getNextID() {
15+
16+
if ( ! $scope.slaves.length ) {
17+
18+
return( 1 );
19+
20+
}
21+
22+
var lastSlave = $scope.slaves[ $scope.slaves.length - 1 ];
23+
24+
return( lastSlave.id + 1 );
25+
26+
}
27+
28+
29+
// -- Define Scope Methods. --------------------- //
30+
31+
32+
// I add a new slave at the given position.
33+
$scope.addSlave = function( x, y ) {
34+
35+
$scope.slaves.push({
36+
id: getNextID(),
37+
x: x,
38+
y: y
39+
});
40+
41+
};
42+
43+
44+
// I remove the given slave from the collection.
45+
$scope.removeSlave = function( slave ) {
46+
47+
// Find the slave in the collection.
48+
var index = $scope.slaves.indexOf( slave );
49+
50+
// Splice out slave.
51+
$scope.slaves.splice( index, 1 );
52+
53+
};
54+
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+
// -- Set Scope Variables. ---------------------- //
66+
67+
68+
// This is our list of slaves and their coordinates. Starting with an initial
69+
// collection of one.
70+
$scope.slaves = [
71+
{
72+
id: 1,
73+
x: 100,
74+
y: 100
75+
}
76+
];
77+
78+
79+
}
80+
);
81+
82+
})( angular, demo );

app/css/demo.css

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
body {
3+
font-family: tahoma, geneva, sans-serif ;
4+
margin: 0px 0px 0px 0px ;
5+
padding: 0px 0px 0px 0px ;
6+
}
7+
8+
div.master {
9+
bottom: 0px ;
10+
left: 0px ;
11+
position: fixed ;
12+
right: 0px ;
13+
top: 0px ;
14+
}
15+
16+
ol.handles {
17+
bottom: 0px ;
18+
cursor: pointer ;
19+
left: 0px ;
20+
list-style-type: none ;
21+
margin: 0px 0px 0px 0px ;
22+
padding: 0px 0px 0px 0px ;
23+
position: fixed ;
24+
right: 200px ;
25+
top: 0px ;
26+
}
27+
28+
ol.handles li {
29+
background-color: #F0F0F0 ;
30+
border: 1px solid #CCCCCC ;
31+
border-radius: 35px 35px 35px 35px ;
32+
cursor: pointer ;
33+
font-weight: bold ;
34+
height: 35px ;
35+
line-height: 34px ;
36+
margin: -17.5px 0px 0px -17.5px ;
37+
padding: 0px 0px 0px 0px ;
38+
position: absolute ;
39+
text-align: center ;
40+
width: 35px ;
41+
}
42+
43+
ol.leaderboard {
44+
background-color: #F0F0F0 ;
45+
bottom: 0px ;
46+
list-style-type: none ;
47+
margin: 0px 0px 0px 0px ;
48+
overflow: auto ;
49+
padding: 0px 0px 0px 0px ;
50+
position: fixed ;
51+
right: 0px ;
52+
top: 0px ;
53+
width: 200px ;
54+
}
55+
56+
ol.leaderboard li {
57+
border-bottom: 1px solid #CCCCCC ;
58+
font-size: 16px ;
59+
margin: 0px 0px 0px 0px ;
60+
padding: 5px 0px 0px 0px ;
61+
text-align: center ;
62+
}
63+
64+
ol.leaderboard div.label {
65+
border: 1px dotted #CCCCCC ;
66+
border-radius: 35px 35px 35px 35px ;
67+
font-weight: bold ;
68+
height: 35px ;
69+
line-height: 34px ;
70+
margin: 0px auto 0px auto ;
71+
width: 35px ;
72+
}
73+
74+
ol.leaderboard div.position {}
75+
76+
ol.leaderboard div.position:after {
77+
clear: both ;
78+
content: "" ;
79+
display: block ;
80+
}
81+
82+
ol.leaderboard span.coordinate {
83+
float: left ;
84+
padding: 5px 0px 10px 0px ;
85+
width: 50% ;
86+
}

0 commit comments

Comments
 (0)