PageSourceSearch

https://ef.gov.sa/Style%20Library/EF26/js/EF-Cookies.js

js ef.gov.sa collected 2026-10-07 22:24:17 UTC 5,600 bytes, 197 lines download raw bytes

1(function ($) {
2  "use strict";
3
4  var COOKIE_NAME = "EF_COOKIE_CONSENT";
5  var COOKIE_VALUE = "accepted";
6  var COOKIE_REJECT_VALUE = "rejected";
7  var COOKIE_DAYS = 365;
8
9  // ✅ GLOBAL text variable (fixes the issue)
10  var text = getText();
11
12  function isArabic() {
13    var path = (window.location.pathname || "").toLowerCase();
14    var htmlDir = String($("html").attr("dir") || "").toLowerCase();
15    var htmlLang = String($("html").attr("lang") || "").toLowerCase();
16
17    return (
18      path.indexOf("/ar") === 0 ||
19      path.indexOf("/ar/") > -1 ||
20      htmlDir === "rtl" ||
21      htmlLang.indexOf("ar") === 0
22    );
23  }
24
25  function getText() {
26    if (isArabic()) {
27      return {
28        bannerAria: "الموافقة على ملفات تعريف الارتباط",
29        closeAria: "إغلاق إشعار ملفات تعريف الارتباط",
30        title: "ملفات تعريف الارتباط",
31        description:
32          "هذا الموقع يستخدم ملفات تعريف الارتباط الخاصة للتأكد من سهولة الاستخدام وضمان تحسين تجربتك أثناء التصفح. من خلال الاستمرار في تصفح هذا الموقع، فإنك تقر بقبول استخدام ملفات تعريف الارتباط.",
33        privacyText: "سياسة الخصوصية",
34        privacyUrl: "/ar/Pages/privacy-policy.aspx",
35        acceptText: "قبول",
36        rejectText: "رفض",
37        confirmText: "تأكيد خياراتي",
38        rejectAllText: "رفض الكل ",
39      };
40    }
41
42    return {
43      bannerAria: "Cookie consent",
44      closeAria: "Close cookie banner",
45      title: "Cookies",
46      description:
47        "Use of Cookies by this site is just to guarantee Ease of Access and better user experience while browsing. Continuation of your browsing acknowledges your approval for Terms and Conditions of this site and its use of Cookies.",
48      privacyText: "Privacy Policy",
49      privacyUrl: "/en/Pages/privacy-policy.aspx",
50      acceptText: "Accept",
51      rejectText: "Reject",
52      confirmText: "Confirm My Cookies",
53      rejectAllText: "Reject All",
54    };
55  }
56
57  function setCookie(name, value, days) {
58    var date = new Date();
59    date.setTime(date.getTime() + days * 86400000);
60
61    document.cookie =
62      name +
63      "=" +
64      encodeURIComponent(value) +
65      "; expires=" +
66      date.toUTCString() +
67      "; path=/; SameSite=Lax";
68  }
69
70  function getCookie(name) {
71    var nameEQ = name + "=";
72    var ca = document.cookie.split(";");
73
74    for (var i = 0; i < ca.length; i++) {
75      var c = ca[i].trim();
76      if (c.indexOf(nameEQ) === 0)
77        return decodeURIComponent(c.substring(nameEQ.length));
78    }
79    return "";
80  }
81
82  // Save preferences
83  function savePreferences() {
84    var prefs = {
85      performance: $("#perfCookies").is(":checked"),
86      analytics: $("#analyticsCookies").is(":checked"),
87      marketing: $("#marketingCookies").is(":checked"),
88    };
89
90    setCookie(COOKIE_NAME, JSON.stringify(prefs), COOKIE_DAYS);
91  }
92
93  // Load preferences
94  function loadPreferences() {
95    var saved = getCookie(COOKIE_NAME);
96    if (!saved) return;
97
98    try {
99      var prefs = JSON.parse(saved);
100
101      $("#perfCookies").prop("checked", prefs.performance);
102      $("#analyticsCookies").prop("checked", prefs.analytics);
103      $("#marketingCookies").prop("checked", prefs.marketing);
104    } catch (e) {}
105  }
106
107  function applyText() {
108    $("#cookieTitleText").text(text.title);
109    $("#cookieDescription").text(text.description);
110
111    $("#cookiePrivacyLink")
112      .attr("href", text.privacyUrl)
113      .text(text.privacyText);
114
115    $("#acceptBtn").text(text.acceptText);
116    $("#rejectBtn").text(text.rejectText);
117  }
118
119  function showBanner() {
120    $("#cookieBanner").css({ display: "flex", opacity: 1 });
121  }
122
123  function hideBanner() {
124    $("#cookieBanner").fadeOut(200);
125  }
126
127  // ✅ FIXED: text.confirmText & text.rejectAllText now work
128  function switchToManageMode() {
129    $("#cookieDescription").hide();
130    $("#cookiePrivacyLink").hide();
131    $("#manageCookiePanel").show();
132
133    $("#acceptBtn").text(text.confirmText);
134    $("#rejectBtn").text(text.rejectAllText);
135    $("#manageBtn").hide();
136
137    loadPreferences();
138  }
139
140  function bindEvents() {
141    $("#acceptBtn")
142      .off("click")
143      .on("click", function () {
144        if ($("#manageCookiePanel").is(":visible")) {
145          savePreferences();
146          hideBanner();
147          return;
148        }
149
150        setCookie(COOKIE_NAME, COOKIE_VALUE, COOKIE_DAYS);
151        hideBanner();
152      });
153
154    $("#rejectBtn")
155      .off("click")
156      .on("click", function () {
157        var rejected = {
158          performance: false,
159          analytics: false,
160          marketing: false,
161        };
162
163        setCookie(COOKIE_NAME, JSON.stringify(rejected), COOKIE_DAYS);
164        hideBanner();
165      });
166
167    $("#closeBtn")
168      .off("click")
169      .on("click", function () {
170        hideBanner();
171      });
172
173    $("#manageBtn")
174      .off("click")
175      .on("click", function () {
176        switchToManageMode();
177      });
178  }
179
180  function initCookieBanner() {
181    if (!$("#cookieBanner").length) return;
182
183    applyText();
184    bindEvents();
185
186    if (getCookie(COOKIE_NAME)) {
187      $("#cookieBanner").hide();
188      return;
189    }
190
191    showBanner();
192  }
193
194  $(function () {
195    initCookieBanner();
196  });
197})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.