From 95d5ea397f517801c9f5c7207890486b81f8fb0b Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 23 Aug 2005 17:44:50 +0000 Subject: [PATCH] persisting font choice git-svn-id: svn://svn.open-ils.org/ILS/trunk@1709 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/common/js/config.js | 2 + Open-ILS/web/opac/common/js/init.js | 3 +- Open-ILS/web/opac/common/js/opac_utils.js | 59 ++++++----------------- Open-ILS/web/opac/common/js/org_utils.js | 5 ++ Open-ILS/web/opac/common/js/utils.js | 26 +++++----- 5 files changed, 38 insertions(+), 57 deletions(-) diff --git a/Open-ILS/web/opac/common/js/config.js b/Open-ILS/web/opac/common/js/config.js index 34593eaa81..047c7c6468 100644 --- a/Open-ILS/web/opac/common/js/config.js +++ b/Open-ILS/web/opac/common/js/config.js @@ -16,6 +16,7 @@ var PARAM_RID = "rid"; /* record id */ var COOKIE_SB = "sbe"; var COOKIE_SES = "ses"; var COOKIE_IDS = "ids"; +var COOKIE_FONT = "fnt"; /* these are the actual param values - set on page load */ @@ -183,6 +184,7 @@ function attachEvt(scope, name, action) { } createEvt("common", "init"); /* f() : what happens on page init */ +createEvt("common", "pageRendered"); /* f() : what happens when the page is done (up to the skin to call this even)*/ createEvt("common", "unload"); /* f() : what happens on window unload (clean memory, etc.)*/ createEvt("mresult", "run"); /* f() : kick of the page*/ createEvt("mresult", "idsReceived"); /* f(ids) */ diff --git a/Open-ILS/web/opac/common/js/init.js b/Open-ILS/web/opac/common/js/init.js index 86c9be0c7c..ea1021513b 100644 --- a/Open-ILS/web/opac/common/js/init.js +++ b/Open-ILS/web/opac/common/js/init.js @@ -5,6 +5,7 @@ window.onunload = windowUnload; attachEvt("common", "init", loadUIObjects); attachEvt("common", "init", initParams); +attachEvt("common", "init", initCookies); attachEvt("common", "init", drawOrgTree); attachEvt("common", "unload", _tree_killer); attachEvt("common", "unload", clearUIObjects); @@ -12,7 +13,7 @@ attachEvt("common", "unload", cleanRemoteRequests); function init() { runEvt('common','init'); - scaleFont("medium"); + setFontSize(getFontSize()); switch(findCurrentPage()) { case MRESULT: runEvt('mresult', 'run'); break; case RRESULT: runEvt('rresult', 'run'); break; diff --git a/Open-ILS/web/opac/common/js/opac_utils.js b/Open-ILS/web/opac/common/js/opac_utils.js index 87d53ca087..98d599b08d 100644 --- a/Open-ILS/web/opac/common/js/opac_utils.js +++ b/Open-ILS/web/opac/common/js/opac_utils.js @@ -67,7 +67,7 @@ function findCurrentPage() { /* sets all of the params values ----------------------------- */ var TERM, STYPE, LOCATION, DEPTH, FORM, OFFSET, COUNT, - HITCOUNT, RANKS, SEARCHBAR_EXTRAS; + HITCOUNT, RANKS, SEARCHBAR_EXTRAS, FONTSIZE; function initParams() { var cgi = new CGI(); @@ -95,6 +95,12 @@ function initParams() { if(isNaN(RID)) RID = 0; } +function initCookies() { + FONTSIZE = "medium"; + var font = fontCookie.get(COOKIE_FONT); + if(font) FONTSIZE = font; +} + /* URL param accessors */ function getTerm(){return TERM;} function getStype(){return STYPE;} @@ -108,6 +114,8 @@ function getSearchBarExtras(){return SEARCHBAR_EXTRAS;} function getMrid(){return MRID;}; function getRid(){return RID;}; +function getFontSize(){return FONTSIZE;}; + /* builds an opac URL. If no page is defined, the current page is used @@ -376,53 +384,14 @@ function orgSelect(id) { updateLoc(id, findOrgDepth(id)); } - -/* ------------------------------------------------------------------------------------------------------ */ -/* org tree utilities */ -/* ------------------------------------------------------------------------------------------------------ */ - -/* takes an org unit or id and return the numeric depth */ -function findOrgDepth(org_id_or_node) { - return findOrgType(findOrgUnit(org_id_or_node).ou_type()).depth(); -} - -/* takes the org type id from orgunit.ou_type() field and returns - the org type object */ -function findOrgType(type_id) { - if(typeof type_id == 'object') return type_id; - for(var type in globalOrgTypes) { - var t =globalOrgTypes[type]; - if( t.id() == type_id || t.id() == parseInt(type_id) ) - return t; - } - return null; +var fontCookie = new cookieObject("fonts", 1, "/", COOKIE_FONT); +function setFontSize(size) { + scaleFonts(size); + fontCookie.put(COOKIE_FONT, size); + fontCookie.write(); } -/* returns an org unit by id. if an object is passed in as the id, - then the object is assumed to be an org unit and is returned */ -function findOrgUnit(org_id) { - return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id]; -} - - -/* builds a trail from the top of the org tree to the node provide. - basically fleshes out 'my orgs' - Returns an array of [org0, org1, ..., myorg] */ -function orgNodeTrail(node) { - var na = new Array(); - while( node ) { - na.push(node); - node = findOrgUnit(node.parent_ou()); - } - return na.reverse(); -} - - -/* returns an array of sibling org units */ -function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); } -/* ------------------------------------------------------------------------------------------------------ */ - diff --git a/Open-ILS/web/opac/common/js/org_utils.js b/Open-ILS/web/opac/common/js/org_utils.js index 3a6b744fd1..a4a61074c6 100644 --- a/Open-ILS/web/opac/common/js/org_utils.js +++ b/Open-ILS/web/opac/common/js/org_utils.js @@ -39,6 +39,8 @@ function orgNodeTrail(node) { return na.reverse(); } +function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); } + var orgArraySearcher = {}; @@ -74,3 +76,6 @@ function _tree_killer () { orgArraySearcher = null; globalOrgTypes = null; } + + + diff --git a/Open-ILS/web/opac/common/js/utils.js b/Open-ILS/web/opac/common/js/utils.js index 499694bbe2..0956d7e3cc 100644 --- a/Open-ILS/web/opac/common/js/utils.js +++ b/Open-ILS/web/opac/common/js/utils.js @@ -236,32 +236,35 @@ function findNodeByName(root, nodeName) { function truncate(string, size) { if(string && size != null && size > -1 && string.length > size) - return string.substr(0, size) + "..."; + return string.substr(0, size) + "... "; return string; } /* style sheets must have a 'name' attribute for these functions to work */ -function setActiveStyleSheet(name) { +function setActivateStyleSheet(name) { var i, a, main; for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++) { if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("name")) { + a.disabled = true; if (a.getAttribute ("name").indexOf(name) != -1) a.disabled = false; } } } -function swapStyleSheet(newname, oldname) { - var i, a, main; - for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++) { - if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("name")) { - if (a.getAttribute ("name").indexOf(newsheet) != -1) - a.disabled = false; - if (a.getAttribute ("name").indexOf(oldsheet) != -1) - a.disabled = true; - } + +/* ----------------------------------------------------- */ +function scaleFonts(type) { + + var size = ""; + switch(type) { + case "large": size = "113%"; break; + case "small": size = "87%"; break; } + + document.body.style.fontSize = size; + for (i = 0; (a = document.getElementsByTagName ("table")[i]); i++) a.style.fontSize = size; } @@ -270,3 +273,4 @@ function swapStyleSheet(newname, oldname) { + -- 2.43.2