summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-services/leftMenuServiceDS2.js
blob: 879da8e7b762f9175da526681452d18551a5ce7b (plain)
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
function isRealValue(obj){
	return obj && obj !== "null" && obj!== "undefined";
}
appDS2.factory('LeftMenuServiceDS2', function ($http,$log, $q) {
	return {
		getLeftMenu: function() {
			return $http.get('get_menu')
			.then(function(response) {
					if (typeof response.data === 'object') {
						return response.data;
					} else {
						return $q.reject(response.data);
					}
			}, function(response) {
				// something went wrong
				return $q.reject(response.data);
			});
		},
		getAppName: function() {
			return $http.get('get_app_name')
			.then(function(response) {
					if (typeof response.data === 'object') {
						return response.data;
					} else {
						return $q.reject(response.data);
					}
			}, function(response) {
				// something went wrong
				return $q.reject(response.data);
			});
		}
		
	};
});

/* check if the body height has changed */
function onElementHeightChange(elm, callback){
	if (!elm) {
		console.log('onElementHeightChange: null element!');
		return;
	}
    var lastHeight = elm.clientHeight, newHeight;
    (function run(){
        newHeight = elm.clientHeight;
        if( lastHeight != newHeight )
            callback();
        lastHeight = newHeight;

        if( elm.onElementHeightChangeTimer )
            clearTimeout(elm.onElementHeightChangeTimer);
        elm.onElementHeightChangeTimer = setTimeout(run, 200);
    })();
}

/*adjust height of left menu*/
function adjustLeftMenuHeight() {
	
	try{
		var footerTop = $('.footer-container').offset().top;
		var scrollTop = $(window).scrollTop();
		$(".menu-container").css({
			"height" : footerTop- scrollTop,
		});
	}catch(err){
		console.log('adjustLeftMenuHeight failed', err)
	}
}
/* adjust left menu height on scroll */
window.onscroll = function (e) {  
	adjustLeftMenuHeight();
} 

function adjustHeader() {
	var showHeader = getCookie("show_app_header");
	if(showHeader==''){
		$(".menu-container").css({
			"margin-top" : 45,
		});
	}else{
		$(".menu-container").css({
			"margin-top" : 0,
		});
	}
};
/* adjust left menu height on page load */
$(function() {
	adjustLeftMenuHeight();
	adjustHeader();
});


onElementHeightChange(document.body, function(){
	adjustLeftMenuHeight();
});

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}