/
script.js
208 lines (161 loc) · 6.11 KB
/
script.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
$(function() {
// == Login Form UI Actions ================================================
var formStatus = false; // true == form is open; false == forme is closed
// variables to specify form dimensions
var x1 = 0;
var x2 = 0;
var y1 = 0;
var y2 = 0;
$('#login-form').insertAfter('#footer'); // move login form to end of document
var positionIndicator = '<span class="position-br" style="display: block; width: 1px; height: 1px; position: absolute; bottom: 0; right: 0;"></span>'; // Snipplet to get bottom-right position
$('#login-form > :last-child').after(positionIndicator); // place snipplet after last element in form-container
$('#login-trigger').click(function() { // display login form
var offsetSubheader = $('#subheader').offset(); // get position of #subheader
var posX = parseInt(offsetSubheader.left) + $('#subheader').width() - $('#login-form').width(); // calculate position for login-form
$('#login-form').css('left', posX).slideToggle('fast', function() { // slide down and set position in callback
var rbPos = $('.position-br').offset();
x1 = posX; // left
x2 = rbPos.left; // right
y1 = offsetSubheader.top; // top
y2 = rbPos.top; // bottom
$('#username').focus();
});
formStatus = true;
return false;
});
$('#login-form input.inline-text').each(function() { // hide overlaying <label> elements if there input-elements are NOT empty.
if ($(this).val()) { // check if value is set
$(this).prev('label').addClass('focus').hide();
}
});
$('#login-form input').focus(function() { // hide label if input-field get focus
$(this).prev('label').addClass('focus').hide();
});
$('#login-form input').blur(function() { // show label if imput-field is empty and hase no focus
if ($(this).val() === false) { // check if value is empty
$('#login-form .focus').removeClass('focus').show();
}
});
function closeLoginForm () {
$('#login-form').slideUp().removeClass('login-show');
return false;
}
$('#close-login').click(function() { // close login-form onClick
closeLoginForm();
return false; // disable action onClick
});
// TODO: this can be replaced with a .mouseleave() event
$(document).click(function(event) { // events to perform on mouse-click somewhere on document
if (formStatus === true) { // check if form is open
// save mouse-click position
var xClick = event.pageX;
var yClick = event.pageY;
// x1/y1--------------x2/y1
// | |
// | |
// | Login - Form |
// | |
// | |
// | |
// x1/y2--------------x2/y2
var x0 = 0;
var y0 = 0;
// work around for unmotivated clicks in webkit
if (xClick === 0 && yClick === 0) { return; }
// Check if Click was inside or outside of form
if (xClick < x1 || xClick > x2) {
x0 = 1;
}
if (yClick < y1 || yClick > y2) {
y0 = 1;
}
// If 1 (true) clode form
if (x0 === 1 || y0 === 1) {
formStatus = closeLoginForm();
}
}
});
// $('#login-form input[type="submit"]').click(function() { // events on submit-button click
// return false; // temp disabled
// });
// == /Login Form UI Actions ================================================
$('#global-search-form').addClass('lable-overley');
$('#global-search-form > #search').attr('value', '');
$('#global-search-form input').focusin(function() {
var thisId = this.id;
hideLabel(thisId);
});
$('#global-search-form input').focusout(function() {
var thisId = this.id;
showLabel(thisId);
});
// == Functions ============================================================
// == Dropdown Menus
// test - move to upper section
$('.dropdown-menu-content').hide(); // hide dropdown-menu
$('.dropdown-menu').click(function() {
var objectID, date;
if ($(".dropdown-menu-content").is(":hidden")) {
if (this.id) { // if ID is set use this ID
objectID = this.id;
// console.log('true');
// console.log(objectID);
} else { // if no ID is set create one
date = new Date();
objectID = $(this).attr('class') + '-' + date.getTime(); // make unique id
$(this).attr('id', objectID);
}
dropDownMenu(objectID);
} else {
slideupFast('.dropdown-menu-content');
}
return false;
});
// /test
function dropDownMenu (trigger_id) {
// console.log('Trigger ID: ' + trigger_id);
// get Menu-Item position X/Y
var menuItemH = $(trigger_id).height();
// console.log(menuItemH);
var menuPos = $('#'+trigger_id).offset();
// console.log(menuPos);
var menuPosY = parseInt(menuPos.top) + 25;
var menuPosX = parseInt(menuPos.left) - 10; // dropdown content has 10px margin.
var dropDownMenuID = $("#"+trigger_id).next('ul').attr('id');
if (!dropDownMenuID) {
dropDownMenuID = trigger_id + '-content';
$("#"+trigger_id).next('ul').attr('id', dropDownMenuID);
}
$("#"+dropDownMenuID).insertAfter('#footer');
$("#"+dropDownMenuID).css({
top: menuPosY,
left: menuPosX
}).slideDown('fast');
return true;
}
$('.dropdown-menu-content').mouseleave(function() {
if ($(".dropdown-menu-content").is(":visible")) {
slideupFast('.dropdown-menu-content');
}
});
function slideupFast (e) {
$(e).slideUp('fast');
return true;
}
// == /Dropdown Menus
// Hide overlaying <label>
function hideLabel (e) {
$('label[for="' + e + '"]').addClass('focus').hide();
return true;
}
// Show overlaying <label>, if <input> is emty, else do nothing
function showLabel (e) {
var eVal = $('#' + e).val(); // get <input> value
if (eVal === false) { // check if value is empty and show <label> again
$('label[for="' + e + '"]').removeClass('focus').show();
return true;
} else {
return false;
}
}
});