Changeset 2703
- Timestamp:
- 03/10/10 23:12:42 (2 years ago)
- 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 /** 2 Inspired on http://scripterlative.com?recoverscroll 3 */ 110 4 111 5 var RecoverScroll= 112 6 { 113 /*** Free Download with instructions: http://scripterlative.com?recoverscroll ***/7 timer:null, x:0, y:0, cookieId:"RecoverScroll", dataCode:0, 114 8 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() 118 11 { 119 12 var offsetData,sx=0,sy=0,then,dt = new Date(),now = dt.getTime(); 120 //keep for 60 mins121 dt.setDate(dt.getDate() + 60);122 //set tje cookie123 document.cookie = "scriptFreeload=" + (then || now) + ";expires="124 + dt.toGMTString();125 document.cookie = "dAlert=1";126 //this.cont();127 13 14 //establish if this is IE, FF or else 128 15 if( document.documentElement ) 129 16 this.dataCode=3; … … 134 21 if( typeof window.pageXOffset!='undefined' ) 135 22 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 139 25 this.addToHandler(window, 'onscroll', function(){ RecoverScroll.reset() }); 140 26 27 //scrolls to the previous scroll position as recovered from the cookie (if any) 141 28 if(window.location.hash == "" 142 29 && (offsetData=this.readCookie(this.cookieId)) != "" … … 144 31 && !isNaN(sx = Number(offsetData[1])) && !isNaN(sy = Number(offsetData[3]))) 145 32 { 146 if(!!window.SoftScroll && SoftScroll.scrollTo)147 { SoftScroll.init(); SoftScroll.scrollTo(sx, sy); }148 else149 33 window.scrollTo(sx, sy); 150 34 } 151 35 36 //get current scroll position 152 37 this.record(); 153 38 }, 154 39 40 //reset the scroll position to current 155 41 reset:function() 156 42 { … … 159 45 }, 160 46 47 //record current scroll position into cookie 161 48 record:function() 162 49 { … … 165 52 this.getScrollData(); 166 53 167 this.setTempCookie(this.cookieId, cStr='x|'+this.x+'|y|'+this.y);54 document.cookie=this.cookieId+"="+'x|'+this.x+'|y|'+this.y; 168 55 }, 169 56 170 setTempCookie:function(cName, cValue) 171 { 172 document.cookie=cName+"="+cValue; 173 }, 174 57 //reads the cookie value 175 58 readCookie:function(cookieName) 176 59 { … … 180 63 cValue=(cValue=document.cookie.match(new RegExp("(^|;|\\s)"+cookieName+'=([^;]+);?'))) ? cValue[2] : ""; 181 64 182 return this.bon?cValue:"";65 return cValue; 183 66 }, 184 67 68 //loads the scroll data (based on IE,FF, else) 185 69 getScrollData:function() 186 70 { … … 199 83 }, 200 84 85 //add event handler 201 86 addToHandler:function(obj, evt, func) 202 87 { … … 214 99 else 215 100 obj[evt]=func; 216 },217 218 sf:function( str )219 {220 return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});221 101 } 222 102 }
Note: See TracChangeset
for help on using the changeset viewer.