Changeset 2703


Ignore:
Timestamp:
03/10/10 23:12:42 (2 years ago)
Author:
mswertz
Message:

cleaned and simplified the code, removing specific things from the script provider

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molgenis/3.3/src/org/molgenis/framework/ui/res/scripts/recoverscroll.js

    r2702 r2703  
    1  
    2 /**  (C)Scripterlative.com 
    3  
    4 -- R e c o v e r S c r o l l -- 
    5  
    6 Description 
    7 ~~~~~~~~~~~ 
    8  Preserves a document's scrolled x & y position between consecutive page reloads (in the same session). 
    9  
    10  *Uses session cookies* 
    11  
    12  NOTE - This script is configured not to operate when the URL contains a querystring parameter, 
    13         i.e. http://www.mysite.com?goto=abc 
    14  
    15  Info: http://scripterlative.com?recoverscroll 
    16  
    17  These instructions may be removed but not the above text. 
    18  
    19  Please notify any suspected errors in this text or code, however minor. 
    20  
    21 THIS IS A SUPPORTED SCRIPT 
    22 ~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    23 It's in everyone's interest that every download of our code leads to a successful installation. 
    24 To this end we undertake to provide a reasonable level of email-based support, to anyone  
    25 experiencing difficulties directly associated with the installation and configuration of the 
    26 application. 
    27  
    28 Before requesting assistance via the Feedback link, we ask that you take the following steps: 
    29  
    30 1) Ensure that the instructions have been followed accurately. 
    31  
    32 2) Ensure that either: 
    33    a) The browser's error console ( Ideally in FireFox ) does not show any related error messages. 
    34    b) You notify us of any error messages that you cannot interpret. 
    35  
    36 3) Validate your document's markup at: http://validator.w3.org or any equivalent site.    
    37     
    38 4) Provide a URL to a test document that demonstrates the problem. 
    39   
    40 Installation 
    41 ~~~~~~~~~~~~ 
    42  Save this text/file as 'recoverscroll.js', and place it in a folder associated with your web pages. 
    43  
    44  Insert the following tags in the <head> section of the document to be scrolled: 
    45  
    46  <script type='text/javascript' src='recoverscroll.js'></script> 
    47  
    48  (If recoverscroll.js resides in a different folder, include the relative path) 
    49  
    50 Configuration 
    51 ~~~~~~~~~~~~~ 
    52  The script is initialised by calling the function RecoverScroll.init(), using the onload event. 
    53  Provided that you have no other script that uses the onload event, either of the following two 
    54  methods can be used: 
    55  
    56   <body onload='RecoverScroll.init()'> 
    57  
    58   <script type='text/javascript'> 
    59    window.onload=function(){RecoverScroll.init()} 
    60   </script> 
    61  
    62  IMPORTANT - If you have (or suspect you have) other scripts that use the onload event, you must 
    63  prevent a conflict by using the following alternative initialisation. This code should be located 
    64  at any point below the installation of the other scripts. 
    65  
    66   <script type='text/javascript'> 
    67    RecoverScroll.addToHandler(window,'onload',function(){RecoverScroll.init()}); 
    68   </script> 
    69  
    70  When installing on multiple pages, on each page you must provide a /unique/ name as a quoted 
    71  parameter to the init function. This applies to whichever initialisation method is used, i.e.: 
    72  
    73  <body onload="RecoverScroll.init('homePage')" > 
    74  
    75  -OR- 
    76  
    77  <script type='text/javascript'> 
    78    window.onload=function(){RecoverScroll.init('homePage')} 
    79  </script> 
    80  
    81  -OR- 
    82  
    83  <script type='text/javascript'> 
    84    RecoverScroll.addToHandler(window,'onload',function(){RecoverScroll.init('homePage')}); 
    85  </script> 
    86  
    87  
    88  NOTE. This script also uses the onscroll event. If any other installed scripts are known use this 
    89        event, they should be initialised ealier. 
    90  
    91 Combining with SoftScroll 
    92 ~~~~~~~~~~~~~~~~~~~~~~~~~ 
    93 To combine RecoverScroll with SoftScroll, simply install 'softscroll.js' by placing these tags 
    94 /prior/ to the RecoverScroll <script> tags: 
    95  
    96 <script type='text/javascript' src='softscroll.js'></script> 
    97  
    98 GratuityWare 
    99 ~~~~~~~~~~~~ 
    100 This code is supplied on condition that all website owners/developers using it anywhere, 
    101 recognise the effort that went into producing it, by making a PayPal donation OF THEIR CHOICE 
    102 to the authors. This will ensure the incentive to provide support and the continued authoring 
    103 of new scripts. 
    104  
    105 YOUR USE OF THE CODE IS UNDERSTOOD TO MEAN THAT YOU AGREE WITH THIS PRINCIPLE. 
    106  
    107 You may donate at www.scripterlative.com, stating the URL to which the donation applies. 
    108  
    109 ** DO NOT EDIT BELOW THIS LINE **/ 
     1/** 
     2Inspired on http://scripterlative.com?recoverscroll 
     3*/ 
    1104 
    1115var RecoverScroll= 
    1126{ 
    113  /*** Free Download with instructions: http://scripterlative.com?recoverscroll ***/ 
     7 timer:null, x:0, y:0, cookieId:"RecoverScroll", dataCode:0, 
    1148 
    115  timer:null, x:0, y:0, bon:0xf, cookieId:"RecoverScroll", dataCode:0, logged:0, 
    116  
    117  init:function(pageName) 
     9 //body.onLoad 
     10 init:function() 
    11811 { 
    11912  var offsetData,sx=0,sy=0,then,dt = new Date(),now = dt.getTime(); 
    120   //keep for 60 mins 
    121   dt.setDate(dt.getDate() + 60); 
    122   //set tje cookie 
    123   document.cookie = "scriptFreeload=" + (then || now) + ";expires=" 
    124         + dt.toGMTString(); 
    125   document.cookie = "dAlert=1"; 
    126   //this.cont(); 
    12713 
     14  //establish if this is IE, FF or else 
    12815  if( document.documentElement ) 
    12916   this.dataCode=3; 
     
    13421    if( typeof window.pageXOffset!='undefined' ) 
    13522     this.dataCode=1; 
    136  
    137   if(pageName) 
    138    this.cookieId = pageName.replace(/[\s\=\;\,]/g,'_'); 
     23   
     24  //register a handler that puts every scroll action into the cookie 
    13925  this.addToHandler(window, 'onscroll', function(){ RecoverScroll.reset() }); 
    14026 
     27  //scrolls to the previous scroll position as recovered from the cookie (if any) 
    14128  if(window.location.hash == "" 
    14229     && (offsetData=this.readCookie(this.cookieId)) != "" 
     
    14431     && !isNaN(sx = Number(offsetData[1])) && !isNaN(sy = Number(offsetData[3]))) 
    14532   { 
    146     if(!!window.SoftScroll && SoftScroll.scrollTo) 
    147     { SoftScroll.init(); SoftScroll.scrollTo(sx, sy); } 
    148     else 
    14933     window.scrollTo(sx, sy); 
    15034   } 
    15135 
     36  //get current scroll position 
    15237  this.record(); 
    15338 }, 
    15439 
     40 //reset the scroll position to current 
    15541 reset:function() 
    15642 { 
     
    15945 }, 
    16046 
     47 //record current scroll position into cookie 
    16148 record:function() 
    16249 { 
     
    16552  this.getScrollData(); 
    16653 
    167   this.setTempCookie(this.cookieId, cStr='x|'+this.x+'|y|'+this.y); 
     54  document.cookie=this.cookieId+"="+'x|'+this.x+'|y|'+this.y; 
    16855 }, 
    16956 
    170  setTempCookie:function(cName, cValue) 
    171  { 
    172   document.cookie=cName+"="+cValue; 
    173  }, 
    174  
     57 //reads the cookie value 
    17558 readCookie:function(cookieName) 
    17659 { 
     
    18063   cValue=(cValue=document.cookie.match(new RegExp("(^|;|\\s)"+cookieName+'=([^;]+);?'))) ? cValue[2] : ""; 
    18164 
    182   return this.bon?cValue:""; 
     65  return cValue; 
    18366 }, 
    18467 
     68 //loads the scroll data (based on IE,FF, else) 
    18569 getScrollData:function() 
    18670 { 
     
    19983 }, 
    20084 
     85 //add event handler 
    20186 addToHandler:function(obj, evt, func) 
    20287 { 
     
    21499  else 
    215100   obj[evt]=func; 
    216  }, 
    217   
    218  sf:function( str ) 
    219  { 
    220    return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;}); 
    221101 } 
    222102} 
Note: See TracChangeset for help on using the changeset viewer.