-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
118 lines (104 loc) · 2.35 KB
/
controller.js
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
;(function( $, undefined ) {
$( document ).ready(
function() {
var $collection = $( '.collection' );
var unloadGraph = function( $graph, complete ) {
$( '.node', $graph ).css(
{
marginLeft: '-8px',
marginTop: '-8px'
}
);
$graph
.off(
'.sunsoft',
'**'
)
.fadeOut(
250,
function() {
complete.call( this );
}
);
$( '#page' )
.stop()
.fadeOut( 250 );
$( '#target' )
.stop()
.fadeOut( 250 );
};
var loadGraph = function( $graph ) {
var $nodes = $( '.node', $graph );
var $siblings = $nodes.filter( ':not(.origin)' );
var radius_min = 100;
var radius_max = 150;
var angle = 0;
var distribution = 2 * Math.PI / $siblings.length;
$graph.fadeIn(
250,
function() {
$( this )
.on(
'click.sunsoft',
'.node a',
function( e ) {
e.preventDefault();
var _self = this;
unloadGraph(
$graph,
function() {
loadGraph( $( $( _self ).attr( 'href' ) ) );
}
);
}
)
.on(
'mouseenter.sunsoft',
'.node a',
function() {
var $target = $( $( this ).attr( 'href' ) );
$( '#target' )
.html(
'<h1>' + $target.data( 'page-title' ) + '</h1>' +
'<p>' + $target.data( 'page-description' ) + '</p>'
)
.stop()
.fadeIn( 250 );
}
)
.on(
'mouseleave.sunsoft',
'.node a',
function() {
$( '#target' )
.stop()
.fadeOut( 250 );
}
)
}
);
$siblings.each(
function() {
var radius = Math.floor( Math.random() * ( radius_max - radius_min ) + radius_min );
var x = radius * Math.cos( angle );
var y = radius * Math.sin( angle );
$( this ).css(
{
marginLeft: ( x - 8 ) + 'px',
marginTop: ( y - 8 ) + 'px'
}
);
angle += distribution;
}
);
$( '#page' )
.html(
'<h1>' + $graph.data( 'page-title' ) + '</h1>' +
'<p>' + $graph.data( 'page-description' ) + '</p>'
)
.fadeIn( 250 );
};
loadGraph( $( '#home', $collection ) );
}
);
})( jQuery );