PageSourceSearch

https://www.cepu.gov.hk/js/common/setfonts.js

js cepu.gov.hk collected 2026-10-03 22:27:49 UTC 17,082 bytes, 537 lines download raw bytes

1// name of the cookie
2var COOKIE_NAME_COLOR_THEME = 'colorThemeName';
3
4// value of the cookie
5var COLOR_THEME_NAME_ARRAY = new Array("Blue","Green","Yellow");
6
7var expDays = 1; // number of days the cookie should last
8var path = "/";
9var domain ;
10var locapath = document.location.href
11
12org_path_start = locapath.indexOf("://") + 3;
13org_path_end = locapath.length;
14domain = locapath.substring(org_path_start, org_path_end);
15
16if (domain.toString().search('/')!= -1){
17	org_path_start = 0;
18	org_path_end = domain.indexOf("/");
19	domain = domain.substring(org_path_start, org_path_end);
20}
21
22function GetCookie (name) {  
23	var arg = name + "=";  
24	var alen = arg.length;  
25	var clen = document.cookie.length;  
26	var i = 0;  
27	while (i < clen) {    
28		var j = i + alen;    
29		if (document.cookie.substring(i, j) == arg)      
30			return getCookieVal (j);    
31		i = document.cookie.indexOf(" ", i) + 1;    
32		if (i == 0) break;   
33	}  
34	return null;
35}
36
37function SetCookie (name, value) {  
38	var argv = SetCookie.arguments;  
39	var argc = SetCookie.arguments.length;  
40	var expires = (argc > 2) ? argv[2] : null;  
41	var secure = (argc > 5) ? argv[5] : false;  
42	document.cookie = name + "=" + escape (value) + 
43	((path == null) ? "" : ("; path=" + path)) +  
44	((domain == null) ? "" : ("; domain=" + domain)) +    
45	((secure == true) ? "; secure" : "");
46}
47
48function DeleteCookie (name) {  
49	var exp = new Date();  
50	exp.setTime (exp.getTime() - 1);  
51	var cval = GetCookie (name);  
52	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
53}
54
55var exp = new Date(); 
56exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
57
58function amt(){
59	var count = GetCookie('sccount')
60	if(count == null) {
61		SetCookie('count','1')
62		return 1
63	} else {
64		var newcount = parseInt(count) + 1;
65		DeleteCookie('sccount')
66		SetCookie('sccount',newcount,exp)
67		return count
68	}
69}
70
71function getCookieVal(offset) {
72	var endstr = document.cookie.indexOf (";", offset);
73	if (endstr == -1)
74		endstr = document.cookie.length;
75	return unescape(document.cookie.substring(offset, endstr));
76}
77
78function checkCount() {
79	var sccount = GetCookie('sccount');
80	if (sccount == null) {
81		SetCookie('orgiurl',document.location.href, exp);
82		window.location.href=page;
83	}
84}
85
86function chglang(dist) {
87    dist = (dist=="") ? "tc_chi" : dist;
88	loc = location.href.replace("/english",'/' + dist);
89	location.href = loc;
90}
91
92function txtchglang(dist) {
93    dist = (dist=="") ? "tc_chi" : dist;
94	loc = location.href.replace("/textonly/english",'/' + dist);
95	location.href = loc;
96}
97
98function splitString (stringToSplit,separator) {
99	var arrayOfStrings = stringToSplit.split(separator);
100	return arrayOfStrings[1];
101}
102
103/* =============================================================================
104 * Handling the Font Size Changes
105 * ============================================================================= */
106
107// Removes leading and ending whitespaces
108// Trim double byte space also
109function Trim(str) {
110	return str.replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
111}
112 
113// global
114// var for Font Size and Linear Version
115var fontarray = new Array("Small","Normal","Large");
116var fontarray_txt = new Array("Small","Normal","Large");
117var fontarray_txt_tc = new Array("Small","Normal","Large");
118var myfonttitle = "";
119var myscreenmode = "";
120var displayfonttitle = "";
121
122
123// var for detect IE VERSION (for IE5.5 )
124var userAgent="";
125var ie_version=0;
126function GetIEVersion() {
127	userAgent = navigator.userAgent;
128	if (userAgent.indexOf('MSIE') != -1) {
129		ie_version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
130	}
131}
132
133// Cookie Functions:
134function createCookie(name,value,days) {
135	if (days != null) {
136		var date = new Date();
137		date.setTime(date.getTime()+(days*24*60*60*1000));
138		var expires = "; expires="+date.toGMTString();
139	} else expires = "";
140	document.cookie = name+"="+value+expires+"; path=/";
141}
142
143function readCookie(name) {
144	var nameEQ = name + "=";
145	var ca = document.cookie.split(';');
146	var caLength = ca.length;
147	for(var i=0;i < caLength;i++) {
148		var c = Trim(ca[i]);
149		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
150	}
151	return null;
152}
153
154function changeBannerImage() {	
155	var colorThemeName = getColorThemeNameFromCookie();
156	var oldSrc = $('#banner_image').attr('src');	
157	if(oldSrc != null) {		
158		var newSrc = oldSrc.replace(/(blue|green|yellow)/i, colorThemeName.toLowerCase());
159		$('#banner_image').attr('src', newSrc);		
160	}	
161}
162
163function changeColor(color){
164	createCookie(COOKIE_NAME_COLOR_THEME, color, 365);
165	loadingFontOnload();
166	changeBannerImage();
167	swapColorImage();
168}
169
170// Handle the Font
171function changeFont(title){
172	myfonttitle = title;
173
174	// display font is same for Format Version
175	displayfonttitle = myfonttitle;
176
177	// set fonttitle cookie to 2 months
178	createCookie("cnedfrttitle", myfonttitle, 365);
179
180	// switch the CSS
181	switchCss();
182
183	// swap the Font Image
184	swapFontImage();
185	
186	changeBannerImage();
187}
188
189function changeFont_txt(title){
190	myfonttitle = title;
191
192	// display font is same for Format Version
193	displayfonttitle = myfonttitle;
194
195	// set fonttitle cookie to 2 months
196	createCookie("cnedfrttitle", myfonttitle, 365);
197
198	// switch the CSS
199	switchCss();
200
201	// swap the Font Image
202	swapFontImage_txt();
203	
204	changeBannerImage();
205}
206
207function changeFont_txt_tc(title){
208	myfonttitle = title;
209
210	// display font is same for Format Version
211	displayfonttitle = myfonttitle;
212
213	// set fonttitle cookie to 2 months
214	createCookie("cnedfrttitle", myfonttitle, 365);
215
216	// switch the CSS
217	switchCss();
218
219	// swap the Font Image
220	swapFontImage_txt_tc();
221	
222	changeBannerImage();
223}
224
225function switchCss() {
226  // CAUTION reminder 20070913:
227  // 1) IE7 need a.disabled=true first, no matter how (is this true?)
228  // 2) firefox2.04 canNOT use: a.getAttribute("title").indexOf("linear"), else break for-loop
229  // 3) firefox can use: var1=a.getAttribute("title"), then compare on var1
230	var colorThemeName = getColorThemeNameFromCookie();
231
232	var linkArray = document.getElementsByTagName("link");
233	var linkArrayLength = linkArray.length;
234
235	for(i=0; i<linkArrayLength; i++)
236	{
237		a=linkArray[i];
238		// for all "stylesheet" in Link
239		if (a.getAttribute("rel").indexOf("stylesheet")!=-1)
240		{
241			var disable_flag = false;
242			// if it is linear mode, assume all css disable first
243			//if (myscreenmode==modeLinear) { disable_flag=true; }
244
245			// get the id of css object first
246			var id1 = a.getAttribute("id");
247			
248			if (id1 != null) {
249				if (id1.indexOf("normalCss")!=-1  ) {
250					// For "style.css"
251					// handled by default
252				} else if (id1.indexOf("mode")!=-1)  {
253					// For "modeMedium", "modeLarge", "modeExtra"
254					// for normal mode, disable first;
255					disable_flag = (id1.indexOf(displayfonttitle) < 0);					
256				} else if (id1.indexOf("color")!=-1) {
257					disable_flag = (id1.indexOf(colorThemeName)<0);
258				}
259
260			} // end id1!=null
261
262			// 20070917: finally set the enable or disable, set true first for IE7 bug
263			a.disabled = true;
264			a.disabled = disable_flag;			
265
266			// for IE5.5, disable can be set by a.disabled = true;
267			// BUT for ENABLE, IE5.5 need to set the alt-stylesheet as "stylesheet"
268			// CAUTION: do NOT set "alternate stylesheet" in this way, will hang IE5.5 browser
269			if (ie_version>0 && ie_version<6 && disable_flag==false) {
270				a.setAttribute("rel","stylesheet");
271			}
272
273		} // end if rel stylesheet
274	} // end for linkArray	
275}
276
277function swapColorImage() {
278	var lang = getLang();
279	var langIndex ; 
280	if(lang=='en' || lang=='txt_en') {
281		// English
282		langIndex = 0 ; 
283	}else if(lang=='tc' || lang=='txt_tc') { 
284	    // Traditional Chinese
285		langIndex = 1 ; 	
286	}else if(lang=='sc' || lang=='txt_sc') { 
287	    // Simple Chinese
288		langIndex = 2 ; 
289	}
290	 
291	var ChangeColourBlue = new Array() ; 
292	    ChangeColourBlue[0] = "Colour : Blue" ;
293		ChangeColourBlue[1] = "顏色 : 藍色" ;
294	    ChangeColourBlue[2] = "颜色 : 蓝色" ;
295	
296	// Green 
297	var ChangeColourGreen = new Array() ; 
298	    ChangeColourGreen[0] = "Colour : Green" ;
299		ChangeColourGreen[1] = "顏色 : 綠色" ;
300	    ChangeColourGreen[2] = "颜色 : 绿色" ;
301		
302	// Yellow
303	var ChangeColourYellow = new Array() ; 
304	    ChangeColourYellow[0] = "Colour : Yellow" ;
305		ChangeColourYellow[1] = "顏色 : 黃色" ;
306	    ChangeColourYellow[2] = "颜色 : 黄色" ;
307	
308	var html = '';
309	var currentColor = getColorThemeNameFromCookie();
310	for (i=0;i<COLOR_THEME_NAME_ARRAY.length;i++) {
311		if (currentColor==COLOR_THEME_NAME_ARRAY[i] ) {
312			if(currentColor == "Blue") {
313				html = '<a title=\"' + ChangeColourBlue[langIndex] + '\" class="colour_blue_active"><div class="access">Colour : Blue</div></a>'
314			}
315			if(currentColor == "Green") {
316				html = '<a title=\"' + ChangeColourGreen[langIndex] + '\" class="colour_green_active"><div class="access">Colour : Green</div></a>'
317			}
318			if(currentColor == "Yellow") {
319				html = '<a title=\"' + ChangeColourYellow[langIndex] + '\" class="colour_yellow_active"><div class="access">Colour : Yellow</div></a>'
320			}									
321		} else {
322			if (i == 0){
323				html = '<a title=\"' + ChangeColourBlue[langIndex] + '\" class="colour_blue" href="javascript:changeColor(\'Blue\');"><div class="access">Colour : Blue</div></a>';
324			}
325			if (i == 1){
326				html = '<a title=\"' + ChangeColourGreen[langIndex] + '\" class="colour_green" href="javascript:changeColor(\'Green\');"><div class="access">Colour : Green</div></a>';
327			}
328			if (i == 2){
329				html = '<a title=\"' + ChangeColourYellow[langIndex] + '\" class="colour_yellow" href="javascript:changeColor(\'Yellow\');"><div class="access">Colour : Yellow</div></a>';
330			}			
331		}
332
333		//fontimg = 'txtsize_area_Font_' + fontarray[i];
334		var parentLi = document.getElementById('li_'+COLOR_THEME_NAME_ARRAY[i]);
335		parentLi.innerHTML = html;
336	}
337}
338
339function swapFontImage() {
340	var lang = getLang();
341	var langIndex ; 
342	if(lang=='en' || lang=='txt_en') {
343		// English
344		langIndex = 0 ; 
345	}else if(lang=='tc' || lang=='txt_tc') { 
346	    // Traditional Chinese
347		langIndex = 1 ; 	
348	}else if(lang=='sc' || lang=='txt_sc') { 
349	    // Simple Chinese
350		langIndex = 2 ; 
351	}
352	 
353	var TextSizeDefault = new Array() ; 
354	    TextSizeDefault[0] = "Text Size : Default Size" ;
355		TextSizeDefault[1] = "字型大小 : 原設定" ;
356	    TextSizeDefault[2] = "字型大小 : 原设定" ;
357	
358	// Large 
359	var TextSizeLarge = new Array() ; 
360	    TextSizeLarge[0] = "Text Size : Larger" ;
361		TextSizeLarge[1] = "字型大小 : 較大" ;
362	    TextSizeLarge[2] = "字型大小 : 较大" ;
363		
364	// Largest
365	var TextSizeLargest = new Array() ; 
366	    TextSizeLargest[0] = "Text Size : Largest" ;
367		TextSizeLargest[1] = "字型大小 : 最大" ;
368	    TextSizeLargest[2] = "字型大小 : 最大" ;
369		
370	// display - swap on or off images
371	var fontarrayLength = fontarray.length;
372	for (i=0;i<fontarrayLength;i++) {					
373		if (displayfonttitle==fontarray[i] ) {
374			// seperate to 2 part, avoid change 'gif' to 'htm' when grab the website"Medium","Large","Extra"
375			if (displayfonttitle == "Small"){
376			fonttail = '<a class="font_size_s_active" title=\"' + TextSizeDefault[langIndex] + '\"><div class="access">Text Size : Default Size</div></a>';
377			}
378			if (displayfonttitle == "Normal"){
379			fonttail = '<a class="font_size_ss_active" title=\"' +  TextSizeLarge[langIndex]    + '\"><div class="access">Text Size : Larger</div></a>';
380			}
381			if (displayfonttitle == "Large"){
382			fonttail = '<a class="font_size_sss_active" title=\"' + TextSizeLargest[langIndex] + '\"><div class="access">Text Size : Largest</div></a>';
383			}
384			
385		} else {
386			if (i ==0){
387			fonttail = '<a class="font_size_s" href="javascript:changeFont(\'Small\');" title=\"' + TextSizeDefault[langIndex] + '\"><div class="access">Text Size : Default Size</div></a>';
388			}
389			if (i ==1){
390			fonttail = '<a class="font_size_ss" href="javascript:changeFont(\'Normal\');" title=\"' +  TextSizeLarge[langIndex] + '\"><div class="access">Text Size : Larger</div></a>';
391			}
392			if (i ==2){
393			fonttail = '<a class="font_size_sss" href="javascript:changeFont(\'Large\');" title=\"' + TextSizeLargest[langIndex] + '\"><div class="access">Text Size : Largest</div></a>';
394			}
395			//fonttail = 'A';
396		}
397
398		fontimg = 'txtsize_area_Font_' + fontarray[i];
399		var fontImgObj = document.getElementById(fontimg);
400		fontImgObj.innerHTML = fonttail;
401	}
402}
403
404
405function swapFontImage_txt() {
406	// display - swap on or off images
407	var fontarrayLength = fontarray_txt.length;
408	for (i=0;i<fontarrayLength;i++) {					
409		if (displayfonttitle==fontarray_txt[i] ) {
410			// seperate to 2 part, avoid change 'gif' to 'htm' when grab the website"Medium","Large","Extra"
411			if (displayfonttitle == "Small"){
412			fonttail = '&nbsp;[<a class="font_size_s_active" title="Text Size : Default Size">Default Size</a>]';
413			}
414			if (displayfonttitle == "Normal"){
415			fonttail = '&nbsp;[<a class="font_size_ss_active" title="Text Size : Larger">Larger</a>]';
416			}
417			if (displayfonttitle == "Large"){
418			fonttail = '&nbsp;[<a class="font_size_sss_active" title="Text Size : Largest">Largest</a>]';
419			}
420			
421		} else {
422			if (i ==0){
423			fonttail = '&nbsp;[<a class="font_size_s" href="javascript:changeFont_txt(\'Small\');" title="Text Size : Default Size">Default Size</a>]';
424			}
425			if (i ==1){
426			fonttail = '&nbsp;[<a class="font_size_ss" href="javascript:changeFont_txt(\'Normal\');" title="Text Size : Larger">Larger</a>]';
427			}
428			if (i ==2){
429			fonttail = '&nbsp;[<a class="font_size_sss" href="javascript:changeFont_txt(\'Large\');" title="Text Size : Largest">Largest</a>]';
430			}
431			//fonttail = 'A';
432		}
433		
434		fontimg = 'txtsize_area_Font_' + fontarray_txt[i];
435		var fontImgObj = document.getElementById(fontimg);
436		fontImgObj.innerHTML = fonttail;
437	}
438}
439
440
441function swapFontImage_txt_tc() {
442	// display - swap on or off images
443	var fontarrayLength = fontarray_txt_tc.length;
444	for (i=0;i<fontarrayLength;i++) {					
445		if (displayfonttitle==fontarray_txt_tc[i] ) {
446			// seperate to 2 part, avoid change 'gif' to 'htm' when grab the website"Medium","Large","Extra"
447			if (displayfonttitle == "Small"){
448			fonttail = '&nbsp;[<a class="font_size_s_active" title="字型大小:原設定">原設定</a>]';
449			}
450			if (displayfonttitle == "Normal"){
451			fonttail = '&nbsp;[<a class="font_size_ss_active" title="字型大小:較大">較大</a>]';
452			}
453			if (displayfonttitle == "Large"){
454			fonttail = '&nbsp;[<a class="font_size_sss_active" title="字型大小:最大">最大</a>]';
455			}
456			
457		} else {
458			if (i ==0){
459			fonttail = '&nbsp;
459[<a class="font_size_s" href="javascript:changeFont_txt_tc(\'Small\');" title="字型大小:原設定">原設定</a>]';
460			}
461			if (i ==1){
462			fonttail = '&nbsp;[<a class="font_size_ss" href="javascript:changeFont_txt_tc(\'Normal\');" title="字型大小:較大">較大</a>]';
463			}
464			if (i ==2){
465			fonttail = '&nbsp;[<a class="font_size_sss" href="javascript:changeFont_txt_tc(\'Large\');" title="字型大小:最大">最大</a>]';
466			}
467			//fonttail = 'A';
468		}
469		
470		fontimg = 'txtsize_area_Font_' + fontarray_txt_tc[i];
471		var fontImgObj = document.getElementById(fontimg);
472		fontImgObj.innerHTML = fonttail;
473	}
474}
475
476function readAccessCookie() {
477	// if FF or IE6+
478	if (ie_version==0 || ie_version>=6) {
479		myfonttitle = readCookie("cnedfrttitle");
480		if (myfonttitle==null) {myfonttitle=fontarray[0]; }
481
482		// for clear old R2 cookie
483		if (myfonttitle!=fontarray[0] && myfonttitle!=fontarray[1] && myfonttitle!=fontarray[2] )
484		   { myfonttitle = fontarray[0]; }
485
486		displayfonttitle = myfonttitle;
487	} else {
488		myfonttitle = fontarray[0];
489		displayfonttitle = myfonttitle;
490	}
491}
492
493// on load pages...
494// run by default
495function loadingFontOnload(){
496	GetIEVersion();
497	readAccessCookie();
498	switchCss();
499}
500
501loadingFontOnload();
502
503function switchMonth(mouth) {
504	switch(mouth) {
505		case 1 : strmm = "January"; break;
506		case 2 : strmm = "February"; break;
507		case 3 : strmm = "March"; break;
508		case 4 : strmm = "April"; break;
509		case 5 : strmm = "May"; break;
510		case 6 : strmm = "June"; break;
511		case 7 : strmm = "July"; break;
512		case 8 : strmm = "August"; break;
513		case 9 : strmm = "September"; break;
514		case 10 : strmm = "October"; break;
515		case 11 : strmm = "November"; break;
516		case 12 : strmm = "December"; break;
517	}
518	return strmm;
519}
520
521/* =============================================================================
522 * End Handling the Font Size Changes
523 * =============================================================================
524 */
525
526/*
527 * Color
528 */
529function getColorThemeNameFromCookie() {
530	var cookie = GetCookie(COOKIE_NAME_COLOR_THEME);
531	if(cookie == null) {
532		// need to set cookie ?
533		return COLOR_THEME_NAME_ARRAY[0];
534	} else {
535		return cookie;
536	}
537}

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.