473,378 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

pagewidth and component js resizer problem

2
hello,
first time here and for posting
i was researching some problems I was having with a resizer javascript
it uses window.onload which causes problems with some other flash and js on the page so I have modified it
however, this now causes the page to render first (using the standard settings) and then resize afterwards, so there is a flash of the original page size before I get the correct sizes
is there a way to maintain the page size as you browse from page to page ?
this is an external js called by the main index file

here is the original code

Expand|Select|Wrap|Line Numbers
  1. var prefsLoaded = false;
  2. var defaultFontSize = 76;
  3. var currentFontSize = defaultFontSize;
  4. var currentStyle = "Fixed";
  5.  
  6. function revertStyles(){
  7.  
  8.     currentFontSize = defaultFontSize;
  9.     changeFontSize(0);
  10.  
  11.  
  12. }
  13.  
  14. function switchFluid(){
  15.     if(currentStyle == "Fluid"){
  16.         setWidth("Fixed");
  17.     }
  18. }
  19. function switchFixed(){
  20.     if(currentStyle == "Fixed"){
  21.         setWidth("Fluid");
  22.     }
  23. }
  24.  
  25. function setWidth(width){
  26.     d=new Date();
  27.     flash=Math.round(Math.random()*d.getTime());
  28.     if(width != "Fixed"){
  29.         document.body.className = 'bodyfluid';
  30.         currentStyle = "Fluid";
  31.     }else{
  32.         document.body.className = '';
  33.         currentStyle = "Fixed";
  34.     }
  35. }
  36.  
  37. function changeFontSize(sizeDifference){
  38.     currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);
  39.  
  40.     if(currentFontSize > 100){
  41.         currentFontSize = 100;
  42.     }else if(currentFontSize < 60){
  43.         currentFontSize = 60;
  44.     }
  45.  
  46.     setFontSize(currentFontSize);
  47. };
  48.  
  49. function setFontSize(fontSize){
  50.     var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
  51.     document.body.style.fontSize = fontSize + '%';
  52.  
  53.     //alert (document.body.style.fontSize);
  54. };
  55.  
  56.  
  57. function createCookie(name,value,days) {
  58.   if (days) {
  59.     var date = new Date();
  60.     date.setTime(date.getTime()+(days*24*60*60*1000));
  61.     var expires = "; expires="+date.toGMTString();
  62.   }
  63.   else expires = "";
  64.   document.cookie = name+"="+value+expires+"; path=/";
  65. };
  66.  
  67. function readCookie(name) {
  68.   var nameEQ = name + "=";
  69.   var ca = document.cookie.split(';');
  70.   for(var i=0;i < ca.length;i++) {
  71.     var c = ca[i];
  72.     while (c.charAt(0)==' ') c = c.substring(1,c.length);
  73.     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  74.   }
  75.   return null;
  76. };
  77.  
  78. window.onload = setWidthFont;
  79.  
  80. function setWidthFont(){
  81.     if(!prefsLoaded){
  82.  
  83.         cookie = readCookie("fontSize");
  84.         currentFontSize = cookie ? cookie : defaultFontSize;
  85.         setFontSize(currentFontSize);
  86.  
  87.         cookie = readCookie("pageWidth");
  88.         currentStyle = cookie ? cookie : "Fixed";
  89.         setWidth(currentStyle);
  90.         prefsLoaded = true;
  91.     }
  92.  
  93. }
  94.  
  95. window.onunload = saveSettings;
  96.  
  97. function saveSettings()
  98. {
  99.   createCookie("fontSize", currentFontSize, 365);
  100.   createCookie("pageWidth", currentStyle, 365);
  101. }
here is the modified code

Expand|Select|Wrap|Line Numbers
  1. var defaultFontSize = 76;
  2. var currentFontSize = defaultFontSize;
  3. var currentStyle = "Fixed";
  4. var prefsLoaded = false;
  5.  
  6.  
  7. function revertStyles(){
  8.     currentFontSize = defaultFontSize;
  9.     changeFontSize(0);
  10. }
  11.  
  12. function switchFluid(){
  13.     if(currentStyle == "Fluid"){
  14.         setWidth("Fixed");
  15.     }
  16. }
  17.  
  18. function switchFixed(){
  19.     if(currentStyle == "Fixed"){
  20.         setWidth("Fluid");
  21.     }
  22. }
  23.  
  24. function setWidth(width){
  25.     d=new Date();
  26.     flash=Math.round(Math.random()*d.getTime());
  27.     if(width != "Fixed"){
  28.         document.body.className = 'bodyfluid';
  29.         currentStyle = "Fluid";
  30.     }else{
  31.         document.body.className = '';
  32.         currentStyle = "Fixed";
  33.     }
  34. }
  35.  
  36. function changeFontSize(sizeDifference){
  37.     currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);
  38.  
  39.     if(currentFontSize > 100){
  40.         currentFontSize = 100;
  41.     }else if(currentFontSize < 60){
  42.         currentFontSize = 60;
  43.     }
  44.     setFontSize(currentFontSize);
  45. };
  46.  
  47. function setFontSize(fontSize){
  48.     var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
  49.     document.body.style.fontSize = fontSize + '%';
  50.  
  51.     //alert (document.body.style.fontSize);
  52. };
  53.  
  54. function createCookie(name,value,days) {
  55.   if (days) {
  56.     var date = new Date();
  57.     date.setTime(date.getTime()+(days*24*60*60*1000));
  58.     var expires = "; expires="+date.toGMTString();
  59.   }
  60.   else expires = "";
  61.   document.cookie = name+"="+value+expires+"; path=/";
  62. };
  63.  
  64. function readCookie(name) {
  65.   var nameEQ = name + "=";
  66.   var ca = document.cookie.split(';');
  67.   for(var i=0;i < ca.length;i++) {
  68.     var c = ca[i];
  69.     while (c.charAt(0)==' ') c = c.substring(1,c.length);
  70.     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  71.   }
  72.   return null;
  73. }
  74.  
  75. function saveSettings()
  76. {
  77.   createCookie("fontSize", currentFontSize, 365);
  78.   createCookie("pageWidth", currentStyle, 365);
  79. }
  80.  
  81. function setWidthFont_init(){
  82.     if(!prefsLoaded){
  83.  
  84.         cookie = readCookie("fontSize");
  85.         currentFontSize = cookie ? cookie : defaultFontSize;
  86.         setFontSize(currentFontSize);
  87.  
  88.         cookie = readCookie("pageWidth");
  89.         currentStyle = cookie ? cookie : "Fixed";
  90.         setWidth(currentStyle);
  91.         prefsLoaded = true;
  92.     }
  93. };
  94.  
  95. // for Mozilla browsers
  96.  
  97. if (document.addEventListener) {
  98.     document.addEventListener("DOMContentLoaded", setWidthFont_init, false);
  99. }
  100.  
  101. // for Internet Explorer (using conditional comments)
  102. /*@cc_on @*/
  103. /*@if (@_win32)
  104. document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  105. var script = document.getElementById("__ie_onload");
  106. script.onreadystatechange = function() {
  107.     if (this.readyState == "complete") {
  108.         setWidthFont_init(); // call the onload handler
  109.     }
  110. };
  111. /*@end @*/
  112.  
  113. if (/WebKit/i.test(navigator.userAgent)) { // sniff
  114.     var _timer = setInterval(function() {
  115.         if (/loaded|complete/.test(document.readyState)) {
  116.             clearInterval(_timer);
  117.             setWidthFont_init(); // call the onload handler
  118.         }
  119.     }, 10);
  120. }
  121.  
  122. window.onunload = saveSettings;
  123. window.onload = setWidthFont_init;
Mar 21 '07 #1
3 1659
iam_clint
1,208 Expert 1GB
have you tried onbeforeload=""
Mar 21 '07 #2
mrhoo
428 256MB
You can read the cookie and document.write a custom styleSheet for your page in about a millisecond, long before the page and all it's resources have loaded.
Mar 21 '07 #3
nisiwi
2
both of those are great suggestions
I am a noob to javascript so there are probably loads of ways that I could be doing this better and faster
I will investigate them both further - i like the idea of rewrting the CSS as I effectively do this with PHP - depending on what conditions are met depends on what CSS file I generate
if I can do this with js as well that would be great

thanks for your greaet suggestions
Mar 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
0
by: Doug | last post by:
Hello, We are having a problem with a component in our system that uses publisher policy files. Whenever it gets modified and moved out to where our build processes reference components for other...
1
by: Wolfgang Draxinger | last post by:
Component systems with C++ are quite some challenge. Microsoft tried it with COM and it was not the big hit, there is CORBA, which isn't focused on C++ but only supports a limited set of value...
1
by: Peter Rilling | last post by:
I created a COM+ component (ServicedComponent) in .NET. The component has a single method Connect() which returns a reference to a SqlConnection object. This component works fine when the world is...
2
by: Poppa Pimp | last post by:
ImageResizer.php Image Resizer PLEASE HELP The URL of the page this is on in my site is http://poppa-pimps-wallpapers.com//ImageResizer.php You can click on browse and get image,but...
15
by: sparks | last post by:
We tried one years ago and it was slow, bulky and just plain bad. Now everyone is trying to use laptops with different rez and we can't make and format databases to fit 3 different rez...forget the...
1
by: vovan | last post by:
I need to make my VB 2005 Windows Form application resolution independent. I bought Klik resizer control. But it doesn't work with some Infragistics controls properly. Can anyone suggest any other...
1
anfetienne
by: anfetienne | last post by:
hi, im using the web resizer api to use as an online image editor for a project. i've got everything working up until the point where i need to save the images from the api server and i cant think of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.