PageSourceSearch

http://rusraptors.ru/lib/pkp/js/functions/fontController.js

js rusraptors.ru collected 2026-10-02 18:38:41 UTC 3,912 bytes, 92 lines download raw bytes

1/**
2 * Font Controller
3 * For creating a font size changer interface with minimum effort
4 * Copyright (c) 2009 Hafees (http://cool-javascripts.com)
5 * License: Free to use, modify, distribute as long as this header is kept :)
6 *
7 */
8
9/**
10 * Required: jQuery 1.x library,
11 * Optional: jQuery Cookie Plugin (if used, the last used font size will be saved)
12 * Usage: (For more details visit
13 * This function can be called inside a $(document).ready()
14 * Eg: fontSize("#controls", "#content", 9, 12, 20); where,
15 * #controls - where control is the element id, where the controllers will be created.
16 * #content - for which element the font size changes to apply. In this case font size of content div will be changed
17 * 9 - minimum font size
18 * 12 - default font size
19 * 20 - maximum font size
20 *
21 */
22function fontSize(container, target, minSize, defSize, maxSize, baseUrl) {
23	/*Editable settings*/
24	var minCaption = "Make font size smaller"; //title for smallFont button
25	var defCaption = "Make font size default"; //title for defaultFont button
26	var maxCaption = "Make font size larger"; //title for largefont button
27
28	var cookie = 'font-size';
29
30	//Now we'll add the font size changer interface in container
31	var smallFontHtml = "<a href='javascript:void(0);' class='pkp_controllers_fontController_smallFont' title='" + minCaption +"'>" + minCaption + "</a> ";
32	var defFontHtml = "<a href='javascript:void(0);' class='pkp_controllers_fontController_defaultFont' title='" + defCaption +"'>" + defCaption + "</a> ";
33	var largeFontHtml = "<a href='javascript:void(0);' class='pkp_controllers_fontController_largeFont' title='" + maxCaption +"'>" + maxCaption + "</a> ";
34	$(container).html(smallFontHtml + defFontHtml + largeFontHtml);
35
36	//Read cookie & sets the fontsize
37	if ($.cookie != undefined) {
38		var value = $.cookie(cookie);
39		if (value !=null) {
40			$(target).css('font-size', parseInt(value, 10));
41		}
42	}
43
44	//on clicking small font button, font size is decreased by 1px
45	$(container + " .pkp_controllers_fontController_smallFont").click(function(){
46		var curSize = parseInt($(target).css("font-size"), 10);
47		var newSize = curSize - 1;
48		if (newSize >= minSize) {
49			$(target).css('font-size', newSize);
50		}
51		if (newSize <= minSize) {
52			$(container + " .pkp_controllers_fontController_smallFont").addClass("pkp_controllers_fontController_sdisabled");
53		}
54		if (newSize < maxSize) {
55			$(container + " .pkp_controllers_fontController_largeFont").removeClass("pkp_controllers_fontController_ldisabled");
56		}
57		updatefontCookie(newSize, baseUrl); //sets the cookie
58
59	});
60
61	//on clicking default font size button, font size is reset
62	$(container + " .pkp_controllers_fontController_defaultFont").click(function(){
63		$(target).css('font-size', defSize);
64		$(container + " .pkp_controllers_fontController_smallFont").removeClass("pkp_controllers_fontController_sdisabled");
65		$(container + " .pkp_controllers_fontController_largeFont").removeClass("pkp_controllers_fontController_ldisabled");
66		updatefontCookie(defSize, baseUrl);
67	});
68
69	//on clicking large font size button, font size is incremented by 1 to the maximum limit
70	$(container + " .pkp_controllers_fontController_largeFont").click(function(){
71		var curSize = parseInt($(target).css("font-size"), 10);
72		var newSize = curSize + 1;
73		if (newSize <= maxSize) {
74			$(target).css('font-size', newSize);
75		}
76		if (newSize > minSize) {
77			$(container + " .pkp_controllers_fontController_smallFont").removeClass("pkp_controllers_fontController_sdisabled");
78		}
79		if (newSize >= maxSize) {
80			$(container + " .pkp_controllers_fontController_largeFont").addClass("pkp_controllers_fontController_ldisabled");
81		}
82		updatefontCookie(newSize, baseUrl);
83	});
84
85	function updatefontCookie(size, baseUrl) {
86		if ($.cookie != undefined) { //If cookie plugin available, set a cookie
87			var cookie = 'font-size';
88			$.cookie(cookie, size, { path: baseUrl });
89		}
90	}
91}
92

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.