source: proiecte/swift/trunk/lib/hoard-371/doc/skin/fontsize.js @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 3.0 KB
Line 
1/*
2* Copyright 2002-2004 The Apache Software Foundation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*     http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16function init() 
17{ //embedded in the doc
18  //ndeSetTextSize();
19}
20
21function checkBrowser(){
22  if (!document.getElementsByTagName){
23    return true;
24  }
25  else{
26    return false;
27  }
28}
29
30
31function ndeSetTextSize(chgsize,rs) 
32{
33  var startSize;
34  var newSize;
35
36  if (!checkBrowser)
37  {
38    return;
39  }
40
41  startSize = parseInt(ndeGetDocTextSize());
42
43  if (!startSize)
44  {
45    startSize = 16;
46  }
47
48  switch (chgsize)
49  {
50  case 'incr':
51    newSize = startSize + 2;
52    break;
53
54  case 'decr':
55    newSize = startSize - 2;
56    break;
57
58  case 'reset':
59    if (rs) {newSize = rs;} else {newSize = 16;}
60    break;
61
62  default:
63    try{
64      newSize = parseInt(ndeReadCookie("nde-textsize"));
65    }
66    catch(e){
67      alert(e);
68    }
69   
70    if (!newSize || newSize == 'NaN')
71    {
72      newSize = startSize;
73    }
74    break;
75
76  }
77
78  if (newSize < 10) 
79  {
80    newSize = 10;
81  }
82
83  newSize += 'px';
84
85  document.getElementsByTagName('html')[0].style.fontSize = newSize;
86  document.getElementsByTagName('body')[0].style.fontSize = newSize;
87
88  ndeCreateCookie("nde-textsize", newSize, 365);
89}
90
91function ndeGetDocTextSize() 
92{
93  if (!checkBrowser)
94  {
95    return 0;
96  }
97
98  var size = 0;
99  var body = document.getElementsByTagName('body')[0];
100
101  if (body.style && body.style.fontSize)
102  {
103    size = body.style.fontSize;
104  }
105  else if (typeof(getComputedStyle) != 'undefined')
106  {
107    size = getComputedStyle(body,'').getPropertyValue('font-size');
108  }
109  else if (body.currentStyle)
110  {
111   size = body.currentStyle.fontSize;
112  }
113
114  //fix IE bug
115  if( isNaN(size)){
116    if(size.substring(size.length-1)=="%"){
117      return
118    }
119
120  }
121
122  return size;
123
124}
125
126
127
128function ndeCreateCookie(name,value,days) 
129{
130  var cookie = name + "=" + value + ";";
131
132  if (days) 
133  {
134    var date = new Date();
135    date.setTime(date.getTime()+(days*24*60*60*1000));
136    cookie += " expires=" + date.toGMTString() + ";";
137  }
138  cookie += " path=/";
139
140  document.cookie = cookie;
141
142}
143
144function ndeReadCookie(name) 
145{
146  var nameEQ = name + "=";
147  var ca = document.cookie.split(';');
148
149 
150  for(var i = 0; i < ca.length; i++) 
151  {
152    var c = ca[i];
153    while (c.charAt(0) == ' ') 
154    {
155      c = c.substring(1, c.length);
156    }
157
158    ctest = c.substring(0,name.length);
159 
160    if(ctest == name){
161      return c.substring(nameEQ.length,c.length);
162    }
163  }
164  return null;
165}
Note: See TracBrowser for help on using the repository browser.