PageSourceSearch

https://secure.mygov.in/themes/custom/mygov_radix/src/assets/js/swithcer.js?v=1.x

js mygov.in collected 2026-10-01 08:47:05 UTC 21,543 bytes, 689 lines download raw bytes

1//Style Sheet Switcher Oct 10th, 2006
2//Author: Dynamic Drive: http://www.dynamicdrive.com
3//Usage terms: http://www.dynamicdrive.com/notice.htm
4
5//Unofficial Update to fix Safari 5.1 glitch re: alternate stylesheets or the disabled property in regards to them
6// See: http://www.dynamicdrive.com/forums/showthread.php?p=259199 for more info
7
8var manual_or_random="manual" //"manual" or "random"
9var randomsetting="3 days" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
10
11//////No need to edit beyond here//////////////
12
13function getCookie(Name) { 
14var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
15if (document.cookie.match(re)) //if cookie found
16return document.cookie.match(re)[0].split("=")[1] //return its value
17return null
18}
19
20function setCookie(name, value, days) {
21var expireDate = new Date()
22//set "expstring" to either future or past date, to set or delete cookie, respectively
23var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
24document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
25}
26 
27function deleteCookie(name){
28setCookie(name, "moot")
29}
30
31
32function setStylesheet(title, randomize){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled
33var i, cacheobj, altsheets=[""];
34if(setStylesheet.chosen)
35try{
36document.getElementsByTagName('head')[0].removeChild(setStylesheet.chosen);
37}catch(e){}
38for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
39if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title
40cacheobj.disabled = true
41altsheets.push(cacheobj) //store reference to alt stylesheets inside array
42if(cacheobj.getAttribute("title") == title){ //enable alternate stylesheet with title that matches parameter
43cacheobj.disabled = false //enable chosen style sheet
44setStylesheet.chosen = document.createElement('link');//cloneNode(false);
45setStylesheet.chosen.rel = 'stylesheet';
46setStylesheet.chosen.type = 'text/css';
47if(cacheobj.media)
48setStylesheet.chosen.media = cacheobj.media;
49setStylesheet.chosen.href = cacheobj.href;
50document.getElementsByTagName('head')[0].appendChild(setStylesheet.chosen);
51}
52}
53}
54if (typeof randomize!="undefined"){ //if second paramter is defined, randomly enable an alt style sheet (includes non)
55var randomnumber=Math.floor(Math.random()*altsheets.length)
56altsheets[randomnumber].disabled=false
57}
58return (typeof randomize!="undefined" && altsheets[randomnumber]!="")? altsheets[randomnumber].getAttribute("title") : "" //if in "random" mode, return "title" of randomly enabled alt stylesheet
59}
60
61
62
63function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
64//alert(styletitle);
65if (document.getElementById){
66setStylesheet(styletitle)
67setCookie("mysheet", styletitle, days)
68}
69}
70
71function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu
72if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu
73var element=(element.type=="select-one") ? element.options : element
74for (var i=0; i<element.length; i++){
75if (element[i].value==selectedtitle){ //if match found between form element value and cookie value
76if (element[i].tagName=="OPTION") //if this is a select menu
77element[i].selected=true
78else{ //else if it's a radio button
79element[i].checked=true
80}
81break
82}
83}
84}
85}
86
87if (manual_or_random=="manual"){ //IF MANUAL MODE
88var selectedtitle=getCookie("mysheet")
89if (document.getElementById && selectedtitle!=null) //load user chosen style sheet from cookie if there is one stored
90setStylesheet(selectedtitle)
91}
92else if (manual_or_random=="random"){ //IF AUTO RANDOM MODE
93if (randomsetting=="eachtime")
94setStylesheet("", "random")
95else if (randomsetting=="sessiononly"){ //if "sessiononly" setting
96if (getCookie("mysheet_s")==null) //if "mysheet_s" session cookie is empty
97document.cookie="mysheet_s="+setStylesheet("", "random")+"; path=/" //activate random alt stylesheet while remembering its "title" value
98else
99setStylesheet(getCookie("mysheet_s")) //just activate random alt stylesheet stored in cookie
100}
101else if (randomsetting.search(/^[1-9]+ days/i)!=-1){ //if "x days" setting
102if (getCookie("mysheet_r")==null || parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){ //if "mysheet_r" cookie is empty or admin has changed number of days to persist in "x days" variable
103setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting)) //activate random alt stylesheet while remembering its "title" value
104setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting)) //Also remember the number of days to persist per the "x days" variable
105}
106else
107setStylesheet(getCookie("mysheet_r")) //just activate random alt stylesheet stored in cookie
108} 
109}
110
111
112jQuery(document).ready(function(){
113
114// jQuery('.color-dark').click(function(){
115
116// var thirtyDays = 1000*60*60*24*30;
117// var expireDate = new Date((new Date()).valueOf() + thirtyDays);
118
119// document.cookie = 'contrast' +"="+ 1 +"; expires="+expireDate.toGMTString()+"; path=/";
120// var site_temp_uri = document.location.origin;
121// jQuery("[href*='change.css']").remove();
122// jQuery('head').append('<link rel="stylesheet" type="text/css" media="screen" href="'+site_temp_uri+'/themes/custom/mygov_radix/src/assets/css/change.css">');
123
124// });
125
126jQuery('.color-dark').on('click', function () {
127
128  var thirtyDays = 1000 * 60 * 60 * 24 * 30;
129  var expireDate = new Date(Date.now() + thirtyDays);
130
131  document.cookie = "contrast=1; expires=" + expireDate.toUTCString() + "; path=/";
132
133  //var site_temp_uri = document.location.origin;
134
135  // Add class to body
136  jQuery('body').addClass('color-white-to-black');
137
138  // Remove existing stylesheet
139  // jQuery("link[href*='change.css']").remove();
140  document
141    .querySelectorAll("link[data-contrast-style]")
142    .forEach(link => link.remove());
143
144  // Add new stylesheet
145  // jQuery('head').append(
146  //   '<link rel="stylesheet" type="text/css" media="screen" href="' + site_temp_uri + '/themes/custom/mygov_radix/src/assets/css/change.css">'
147  // );
148  const CSS_PATH = "/themes/custom/mygov_radix/src/assets/css/change.css";
149
150if (!document.querySelector('link[data-contrast-style]')) {
151    const link = document.createElement("link");
152    link.rel = "stylesheet";
153    link.type = "text/css";
154    link.media = "screen";
155    link.href = CSS_PATH;
156    link.setAttribute("data-contrast-style", "true");
157    document.head.appendChild(link);
158}
159
160});
161
162
163jQuery('.hight-contrast').on('click', function () {
164
165
166var thirtyDays = 1000*60*60*24*30;
167var expireDate = new Date((new Date()).valueOf() + thirtyDays);
168
169document.cookie = 'contrast' +"="+ 0 +"; expires="+expireDate.toGMTString()+"; path=/";
170
171
172 // remove class to body
173  jQuery('body').removeClass('color-white-to-black');
174  // jQuery("link[href*='change.css']").remove();
175  document
176    .querySelectorAll("link[data-contrast-style]")
177    .forEach(link => link.remove());
178});
179
180// if(getCookie('contrast') == "1") {
181// var site_temp_uri = document.location.origin;
182// jQuery('head').append('<link rel="stylesheet" type="text/css" media="screen" href="'+site_temp_uri+'/themes/custom/mygov_radix/src/assets/css/change.css">');
183// // Add class to body
184//   jQuery('body').addClass('color-white-to-black');
185// }
186if (getCookie("contrast") === "1") {
187
188    const CSS_PATH = "/themes/custom/mygov_radix/src/assets/css/change.css";
189
190    if (!document.querySelector('link[data-contrast-style]')) {
191        const link = document.createElement("link");
192        link.rel = "stylesheet";
193        link.type = "text/css";
194        link.media = "screen";
195        link.href = CSS_PATH;
196        link.setAttribute("data-contrast-style", "true");
197        document.head.appendChild(link);
198    }
199
200    jQuery("body").addClass("color-white-to-black");
201}
202
203
204if(getCookie('contrast') == "0" ) {
205//  jQuery("link[href*='change.css']").remove();
206document
207    .querySelectorAll("link[data-contrast-style]")
208    .forEach(link => link.remove());
209// remove class to body
210  jQuery('body').removeClass('color-white-to-black');
211}
212
213 
214
215});
216
217 // Highlisht links
218 jQuery("#highlightLinks").click(function(e) {
219  //alert('test');
220    e.preventDefault();
221    jQuery("body").toggleClass("highlightLinks");
222
223    if (jQuery("body").hasClass("highlightLinks")) {
224      var thirtyDays = 1000 * 60 * 60 * 24 * 30;
225      var expireDate = new Date(new Date().valueOf() + thirtyDays);
226
227      document.cookie =
228        "highlightLinks" +
229        "=" +
230        1 +
231        "; expires=" +
232        expireDate.toGMTString() +
233        "; path=/";
234      if (!window.location.origin) {
235        window.location.origin =
236          window.location.protocol +
237          "//" +
238          window.location.hostname +
239          (window.location.port ? ":" + window.location.port : "");
240        var site_temp_uri = window.location.origin;
241      } else {
242        var site_temp_uri = document.location.origin;
243      }
244    } else {
245      var thirtyDays = 1000 * 60 * 60 * 24 * 30;
246      var expireDate = new Date(new Date().valueOf() + thirtyDays);
247
248      document.cookie =
249        "highlightLinks" +
250        "=" +
251        0 +
252        "; expires=" +
253        expireDate.toGMTString() +
254        "; path=/";
255    }
256  });
257
258  if (getCookie("highlightLinks") == "1") {
259    if (!window.location.origin) {
260      window.location.origin =
261        window.location.protocol +
262        "//" +
263        window.location.hostname +
264        (window.location.port ? ":" + window.location.port : "");
265      var site_temp_uri = window.location.origin;
266    } else {
267      var site_temp_uri = document.location.origin;
268    }
269    jQuery("body").addClass("highlightLinks");
270    jQuery("#highlightLinks")
271      .addClass("link-selected")
272      .attr("aria-label", "Highlight Links - Selected")
273      .attr("title", "Highlight Links - Selected");
274  }
275
276  if (getCookie("highlightLinks") == "0") {
277    jQuery("body").removeClass("highlightLinks");
278    jQuery("#highlightLinks")
279      .removeClass("link-selected")
280      .attr("aria-label", "Highlight Links")
281      .attr("title", "Highlight Links");
282  }
283
284  // Text spacing
285  jQuery("#addletterspacing").click(function(e) {
286    e.preventDefault();
287    jQuery("body").toggleClass("addletterspacing");
288
289    if (jQuery("body").hasClass("addletterspacing")) {
290      var thirtyDays = 1000 * 60 * 60 * 24 * 30;
291      var expireDate = new Date(new Date().valueOf() + thirtyDays);
292
293      document.cookie =
294        "addletterspacing" +
295        "=" +
296        1 +
297        "; expires=" +
298        expireDate.toGMTString() +
299        "; path=/";
300      if (!window.location.origin) {
301        window.location.origin =
302          window.location.protocol +
303          "//" +
304          window.location.hostname +
305          (window.location.port ? ":" + window.location.port : "");
306        var site_temp_uri = window.location.origin;
307      } else {
308        var site_temp_uri = document.location.origin;
309      }
310    } else {
311      var thirtyDays = 1000 * 60 * 60 * 24 * 30;
312      var expireDate = new Date(new Date().valueOf() + thirtyDays);
313
314      document.cookie =
315        "addletterspacing" +
316        "=" +
317        0 +
318        "; expires=" +
319        expireDate.toGMTString() +
320        "; path=/";
321    }
322  });
323
324  if (getCookie("addletterspacing") == "1") {
325    if (!window.location.origin) {
326      window.location.origin =
327        window.location.protocol +
328        "//" +
329        window.location.hostname +
330        (window.location.port ? ":" + window.location.port : "");
331      var site_temp_uri = window.location.origin;
332    } else {
333      var site_temp_uri = document.location.origin;
334    }
335    jQuery("body").addClass("addletterspacing");
336  }
337
338  if (getCookie("addletterspacing") == "0") {
339    jQuery("body").removeClass("addletterspacing");
340  }
341
342  // Text lineheight
343  jQuery("#addlineheight").click(function(e) {
344    e.preventDefault();
345    jQuery("body").toggleClass("addlineheight");
346
347    if (jQuery("body").hasClass("addlineheight")) {
348      var thirtyDays = 1000 * 60 * 60 * 24 * 30;
349      var expireDate = new Date(new Date().valueOf() + thirtyDays);
350
351      document.cookie =
352        "addlineheight" +
353        "=" +
354        1 +
355        "; expires=" +
356        expireDate.toGMTString() +
357        "; path=/";
358      if (!window.location.origin) {
359        window.location.origin =
360          window.location.protocol +
361          "//" +
362          window.location.hostname +
363          (window.location.port ? ":" + window.location.port : "");
364        var site_temp_uri = window.location.origin;
365      } else {
366        var site_temp_uri = document.location.origin;
367      }
368    } else {
369      var thirtyDays = 1000 * 60 * 60 * 24 * 30;
370      var expireDate = new Date(new Date().valueOf() + thirtyDays);
371
372      document.cookie =
373        "addlineheight" +
374        "=" +
375        0 +
376        "; expires=" +
377        expireDate.toGMTString() +
378        "; path=/";
379    }
380  });
381
382  if (getCookie("addlineheight") == "1") {
383    if (!window.location.origin) {
384      window.location.origin =
385        window.location.protocol +
386        "//" +
387        window.location.hostname +
388        (window.location.port ? ":" + window.location.port : "");
389      var site_temp_uri = window.location.origin;
390    } else {
391      var site_temp_uri = document.location.origin;
392    }
393    jQuery("body").addClass("addlineheight");
394  }
395
396  if (getCookie("addlineheight") == "0") {
397    jQuery("body").removeClass("addlineheight");
398  }
399
400 // big cursor
401 jQuery("#bigcursor").click(function(e) {
402  e.preventDefault();
403  jQuery("body").toggleClass("big-cursor");
404
405  if (jQuery("body").hasClass("big-cursor")) {
406    var thirtyDays = 1000 * 60 * 60 * 24 * 30;
407    var expireDate = new Date(new Date().valueOf() + thirtyDays);
408
409    document.cookie =
410      "big-cursor" +
411      "=" +
412      1 +
413      "; expires=" +
414      expireDate.toGMTString() +
415      "; path=/";
416    if (!window.location.origin) {
417      window.location.origin =
418        window.location.protocol +
419        "//" +
420        window.location.hostname +
421        (window.location.port ? ":" + window.location.port : "");
422      var site_temp_uri = window.location.origin;
423    } else {
424      var site_temp_uri = document.location.origin;
425    }
426  } else {
427    var thirtyDays = 1000 * 60 * 60 * 24 * 30;
428    var expireDate = new Date(new Date().valueOf() + thirtyDays);
429
430    document.cookie =
431      "big-cursor" +
432      "=" +
433      0 +
434      "; expires=" +
435      expireDate.toGMTString() +
436      "; path=/";
437  }
438});
439
440if (getCookie("big-cursor") == "1") {
441  if (!window.location.origin) {
442    window.location.origin =
443      window.location.protocol +
444      "//" +
445      window.location.hostname +
446      (window.location.port ? ":" + window.location.port : "");
447    var site_temp_uri = window.location.origin;
448  } else {
449    var site_temp_uri = document.location.origin;
450  }
451  jQuery("body").addClass("big-cursor");
452}
453
454if (getCookie("big-cursor") == "0") {
455  jQuery("body").removeClass("big-cursor");
456}
457
458 // Hide Images
459 jQuery("#hideimage").click(function(e) {
460  e.preventDefault();
461  jQuery("body").toggleClass("hide-image");
462
463  if (jQuery("body").hasClass("hide-image")) {
464    var thirtyDays = 1000 * 60 * 60 * 24 * 30;
465    var expireDate = new Date(new Date().valueOf() + thirtyDays);
466
467    document.cookie =
468      "hide-image" +
469      "=" +
470      1 +
471      "; expires=" +
472      expireDate.toGMTString() +
473      "; path=/";
474    if (!window.location.origin) {
475      window.location.origin =
476        window.location.protocol +
477        "//" +
478        window.location.hostname +
479        (window.location.port ? ":" + window.location.port : "");
480      var site_temp_uri = window.location.origin;
481    } else {
482      var site_temp_uri = document.location.origin;
483    }
484  } else {
485    var thirtyDays = 1000 * 60 * 60 * 24 * 30;
486    var expireDate = new Date(new Date().valueOf() + thirtyDays);
487
488    document.cookie =
489      "hide-image" +
490      "=" +
491      0 +
492      "; expires=" +
493      expireDate.toGMTString() +
494      "; path=/";
495  }
496});
497
498if (getCookie("hide-image") == "1") {
499  if (!window.location.origin) {
500    window.location.origin =
501      window.location.protocol +
502      "//" +
503      window.location.hostname +
504      (window.location.port ? ":" + window.location.port : "");
505    var site_temp_uri = window.location.origin;
506  } else {
507    var site_temp_uri = document.location.origin;
508  }
509  jQuery("body").addClass("hide-image");
510}
511
512if (getCookie("hide-image") == "0") {
513  jQuery("body").removeClass("hide-image");
514}
515
516// Hide Images
517 jQuery("#invertLinks").click(function(e) {
518  e.preventDefault();
519  jQuery("html").toggleClass("invert-bg");
520
521  if (jQuery("html").hasClass("invert-bg")) {
522    var thirtyDays = 1000 * 60 * 60 * 24 * 30;
523    var expireDate = new Date(new Date().valueOf() + thirtyDays);
524
525    document.cookie =
526      "invert-bg" +
527      "=" +
528      1 +
529      "; expires=" +
530      expireDate.toGMTString() +
531      "; path=/";
532    if (!window.location.origin) {
533      window.location.origin =
534        window.location.protocol +
535        "//" +
536        window.location.hostname +
537        (window.location.port ? ":" + window.location.port : "");
538      var site_temp_uri = window.location.origin;
539    } else {
540      var site_temp_uri = document.location.origin;
541    }
542  } else {
543    var thirtyDays = 1000 * 60 * 60 * 24 * 30;
544    var expireDate = new Date(new Date().valueOf() + thirtyDays);
545
546    document.cookie =
547      "invert-bg" +
548      "=" +
549      0 +
550      "; expires=" +
551      expireDate.toGMTString() +
552      "; path=/";
553  }
554});
555
556if (getCookie("invert-bg") == "1") {
557  if (!window.location.origin) {
558    window.location.origin =
559      window.location.protocol +
560      "//" +
561      window.location.hostname +
562      (window.location.port ? ":" + window.location.port : "");
563    var site_temp_uri = window.location.origin;
564  } else {
565    var site_temp_uri = document.location.origin;
566  }
567  jQuery("html").addClass("invert-bg");
568}
569
570if (getCookie("invert-bg") == "0") {
571  jQuery("html").removeClass("invert-bg");
572}
573
574
575
576
577
578document.addEventListener("DOMContentLoaded", () => {
579
580    const btn = document.getElementById("saturationLinks");
581
582    // ICONS
583    const icons = [
584        document.getElementById("saturate-text-0"), // default
585        document.getElementById("saturate-text-1"), // low
586        document.getElementById("saturate-text-2"), // high
587        document.getElementById("saturate-text-3")  // desaturate
588    ];
589
590    // TEXT
591    const texts = [
592        document.getElementById("saturate-detail-text-0"), // default
593        document.getElementById("saturate-detail-text-1"), // low
594        document.getElementById("saturate-detail-text-2"), // high
595        document.getElementById("saturate-detail-text-3")  // desaturate
596    ];
597
598    // BARS
599    const bars = document.querySelectorAll("#featureStepsSaturate .step");
600
601    // TICK
602    const tick = document.getElementById("tickIcon-saturate");
603
604    // BODY CLASSES
605    const bodyClasses = [
606        "saturate-low",        // stage 0
607        "saturate-high",       // stage 1
608        "saturate-desaturate"  // stage 2
609    ];
610
611    // Load saved stage from cookies
612    function getCookie(name) {
613        const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
614        return match ? match[2] : null;
615    }
616
617    function setCookie(name, value) {
618        document.cookie = `${name}=${value}; path=/; max-age=31536000`; // 1 year
619    }
620
621    function deleteCookie(name) {
622        document.cookie = `${name}=; path=/; max-age=0`;
623    }
624
625    let stage = parseInt(getCookie("saturation_stage"), 10);
626    if (isNaN(stage)) stage = -1; // if no cookie found, use initial stage
627
628    // Update body classes
629    function updateBodyClass() {
630        document.body.classList.remove(...bodyClasses);
631        if (stage >= 0) {
632            document.body.classList.add(bodyClasses[stage]);
633        }
634    }
635
636    function resetUI() {
637        icons.forEach((icon, i) => icon.style.display = (i === 0 ? "inline-block" : "none"));
638        texts.forEach((txt, i) => txt.style.display = (i === 0 ? "inline-block" : "none"));
639        bars.forEach(bar => bar.classList.remove("active"));
640        tick.style.display = "none";
641
642        stage = -1;
643        document.body.classList.remove(...bodyClasses);
644        deleteCookie("saturation_stage");
645    }
646
647    function updateUI() {
648        if (stage === -1) {
649            resetUI();
650            return;
651        }
652
653        icons.forEach((icon, i) =>
654            icon.style.display = (i === stage + 1 ? "inline-block" : "none")
655        );
656
657        texts.forEach((txt, i) =>
658            txt.style.display = (i === stage + 1 ? "inline-block" : "none")
659        );
660
661        tick.style.display = "inline-block";
662
663        bars.forEach((bar, i) => {
664            if (i <= stage) bar.classList.add("active");
665            else bar.classList.remove("active");
666        });
667
668        updateBodyClass();
669        setCookie("saturation_stage", stage);
670    }
671
672    btn.addEventListener("click", () => {
673        if (stage === 2) {
674            resetUI();
675            return;
676        }
677
678        stage++;
679        updateUI();
680    });
681
682    // Load UI based on cookie (if exists)
683    if (stage >= 0) {
684        updateUI();
685    } else {
686        resetUI();
687    }
688});
689

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.