summaryrefslogtreecommitdiff
blob: 33ffa3c8940b0c8491e5e666984ad41ec6b6bd8d (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
wmpAppBanner = wmpAppBanner || {};

(function () {

        /**
         * @class Cookie
         * @constructor
         */
        var Cookie = function () {
            this.initialize();
        };

        var p = Cookie.prototype;

        /**
         *
         * Initialization method.
         * @method initialize
         */
        p.initialize = function () {

        };

        /**
         * Get cookie (public method)
         *
         * @param c_name
         * @returns {string}
         */
        p.get = function (c_name) {

            var i, x, y, ARRcookies = document.cookie.split(";");
            for (i = 0; i < ARRcookies.length; i++) {
                x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
                y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
                x = x.replace(/^\s+|\s+$/g, "");
                if (x == c_name) {
                    return decodeURIComponent(y);
                }
            }
        };

        /**
         * Set cookie (public method)
         *
         * @param c_name
         * @param value
         * @param expireDays
         */
        p.set = function (c_name, value, expireDays) {
            var expireDate = new Date();
            expireDate.setDate(expireDate.getDate() + expireDays);

            var c_value = encodeURIComponent(value) + ((expireDays == null) ? "" : "; expires=" + expireDate.toUTCString()) + "; path=/;";
            document.cookie = c_name + "=" + c_value;
        };

        wmpAppBanner.Cookie = Cookie;
    }()
);