include/js/auth.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 63
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 7
mnd 1
bc 1
fnc 6
bpm 0.1666
cpm 1.1666
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A auth.js ➔ setup_social_media_login_popup 0 3 1
A auth.js ➔ open_popup 0 12 2
A auth.js ➔ screen_center_pos 0 11 1
1
/**
2
 * Method checks login window status
3
 * 
4
 * @param Popup
5
 *            window object
6
 * @param Handler
7
 *            login handler
8
 */
9
function check_login_status(Popup, Handler) {
10
	return (function() {
11
		if (Popup.closed) {
12
			Handler()
13
		} else {
14
			setTimeout(check_login_status(Popup, Handler), 100)
15
		}
16
	})
17
}
18
19
/**
20
 * Method calculates screen's center
21
 */ 
22
function screen_center_pos(PopUpWidth, PopUpHeight)
23
{
24
	var Width = $(window).width()
25
26
	var Height = $(window).height()
27
28
	return({
29
		x : (Width/2 - PopUpWidth/2) , 
30
		y : (Height/2 - PopUpHeight/2)
31
	})
32
}
33
34
/**
35
 * Open login pop up
36
 * 
37
 * @param URL
38
 *            Login url
39
 * @param Title
40
 *            Popup title
41
 * @param Handler
42
 *            OnLogin handler
43
 */
44
function open_popup(URL, Title, Handler) {
45
	return (function() {
46
		var PopupWidth = Math.min($(window).width(), 800)
47
		var PopupHeight = Math.min($(window).height(), 600)
48
		var Pos = screen_center_pos(PopupWidth, PopupHeight)
49
		var Params = "width=" + PopupWidth + ",height=" + PopupHeight + ",toolbar=0,scrollbars=0,status=0,resizable=0,location=0,menuBar=0,left=" + Pos.x + ",top=" + Pos.y
50
51
		var Popup = window.open(URL, Title, Params)
52
		setTimeout(check_login_status(Popup, Handler), 2000)
53
		Popup.focus()
54
	})
55
}
56
57
/**
58
 * Setup login pop up
59
 * 
60
 * @param $Button
61
 *            Trigger button
62
 * @param URL
63
 *            Login url
64
 * @param Title
65
 *            Popup title
66
 * @param Handler
67
 *            OnLogin handler
68
 */
69
function setup_social_media_login_popup($Button, URL, Title, Handler) {
70
	$Button.click(open_popup(URL, Title, Handler));
71
}