forked from olton/metroui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-menu.js
More file actions
153 lines (129 loc) · 4.59 KB
/
start-menu.js
File metadata and controls
153 lines (129 loc) · 4.59 KB
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
151
152
153
/**
* use this plugin if you want to make tiled menu like windows 8 start menu
* what plugin needs for?
* it needs for following elements structure
* <div class="page">
* <div class="tiles">
* <div class="tile-group">
* <div class="tile"></div>
* <div class="tile"></div>
* .........
* <div class="tile"></div>
* </div>
* </div>
* </div>
*
* if you do some changes, for example, move tile from one group, you have to use
* $('.tiles').trigger('changed')
* and all tiles will placed to own place
*/
(function($) {
$.StartMenu = function(element, options) {
var $startMenu,
plugin = this,
maxGroupHeight;
plugin.init = function() {
var resizeTimer;
$startMenu = $('.tiles');
addMouseWheel();
setPageWidth();
tuneUpStartMenu(); // need twice
$(window).on('resize', function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function(){
tuneUpStartMenu();
}, 200);
});
$startMenu.on('changed', function(){
tuneUpStartMenu();
});
};
/**
* called on init
* and on resize window
* and any tiles moves
*/
var tuneUpStartMenu = function () {
var $groups = $startMenu.find('.tile-group');
if ($groups.length === 0) {
return;
}
maxGroupHeight = $(window).height() - $($groups.get(0)).offset().top;
$groups.each(function(index, group){
var $group = $(group);
// finding min width for group
var groupWidth = 0;
var $tiles = $group.find('.tile');
if ($tiles.length === 0) {
return;
}
// finding min width according to the widest tile
$tiles.each(function(index, tile){
var $tile = $(tile);
var tileWidth = 161;
if ($tile.hasClass('double')) {
tileWidth = 322;
} else if ($tile.hasClass('triple')) {
tileWidth = 483;
} else if ($tile.hasClass('quadro')) {
tileWidth = 644;
}
if (tileWidth > groupWidth) {
groupWidth = tileWidth;
}
});
$group.css({
width: 'auto',
maxWidth: groupWidth
});
var counter, groupHeight_,
groupHeight = $group.height();
while (groupHeight > maxGroupHeight) {
if (counter > $tiles.length) { // protection from endless loop
break;
} else if (groupHeight === groupHeight_) {
counter++;
} else {
counter = 1;
}
groupHeight_ = groupHeight;
groupWidth += 161;
$group.css({
'maxWidth': groupWidth
});
groupHeight = $group.height();
}
});
setPageWidth();
};
var setPageWidth = function () {
var tilesWidth = 0;
$startMenu.find(".tile-group").each(function(){
tilesWidth += $(this).outerWidth() + 80;
});
$startMenu.css("width", 120 + tilesWidth + 20);
$(".page").css('width', '').css({
width: $(document).width()
});
};
var addMouseWheel = function (){
$("body").mousewheel(function(event, delta){
var scroll_value = delta * 50;
$(document).scrollLeft($(document).scrollLeft() - scroll_value);
return false;
});
};
plugin.init();
};
$.fn.StartMenu = function(options) {
return this.each(function() {
if (undefined == $(this).data('StartMenu')) {
var plugin = new $.StartMenu(this, options);
$(this).data('StartMenu', plugin);
}
});
};
})(jQuery);
$(function(){
$.StartMenu();
});