[ Index ] |
|
Code source de LifeType 1.2.4 |
1 /** 2 * functions for auto save 3 */ 4 5 // Before you change the following values, please make sure the total cookie size of the domain does not exceed 6 // your LimitRequestFieldsize value in Apache. Or you will get a ugly error message like this in your browser: 7 // 8 // [Bad Request: Size of a request header field exceeds server limit] 9 // 10 // The default LimitRequestFieldsize value of apache is 8192 bytes. 11 12 // In generally, the cookie size is 4096 bytes, So this number should be smaller then 4096 13 var maxBackupCookieLength = 3240; 14 15 // How many cookies we can use per postText and PostExtentedText 16 var maxBackupCookiesPerBlog = 1; 17 18 // It doesn't make sense just backup few characters, use this to control the minimal backup length 19 var minBackupLength = 9; 20 21 // The time interval between two post backup, the default is 5 seconds 22 var backupInterval = 5; 23 24 // Timer we used for post backup 25 var backupTimer; 26 27 // Cookies we used in auto save 28 var postNotSavedCookieName = LTCookieBaseName + "postNotSaved"; 29 var postTopicCookieName = LTCookieBaseName + "postTopic"; 30 var postTextCookieName = LTCookieBaseName + "postText"; 31 32 function deleteBackupPostFromCookie() 33 { 34 deleteCookie( postNotSavedCookieName ); 35 for( cookieNum = 0; cookieNum < maxBackupCookiesPerBlog; cookieNum++ ) 36 { 37 deleteCookie( postTopicCookieName + cookieNum ); 38 deleteCookie( postTextCookieName + cookieNum ); 39 } 40 } 41 42 function saveBackupPostToCookie( cookieName, content ) 43 { 44 // Clear old post, I know it stupid. But it seems the best way to keep the data clean. 45 // If we use mutiple cookies to compose a single post. 46 for( cookieNum = 0; cookieNum < maxBackupCookiesPerBlog; cookieNum++ ) 47 { 48 deleteCookie( cookieName + cookieNum ); 49 } 50 51 var dataIndex = 0; 52 var cookieNum = 0; 53 var data = escape( content ); 54 while ( ( dataIndex < data.length ) && ( cookieNum < maxBackupCookiesPerBlog ) ) { 55 var cookieData = data.substring(dataIndex, dataIndex + maxBackupCookieLength); 56 setCookie( cookieName + cookieNum, cookieData, 1); 57 dataIndex += maxBackupCookieLength; 58 cookieNum++; 59 } 60 } 61 62 function loadBackupPostFromCookie( cookieName ) 63 { 64 var content = ""; 65 for( cookieNum = 0; cookieNum < maxBackupCookiesPerBlog; cookieNum++ ) 66 { 67 data = getCookie( cookieName + cookieNum ); 68 if ( data ) 69 content += data; 70 else 71 break; 72 } 73 74 return unescape( content ); 75 } 76 77 function backupPost() 78 { 79 postTopic = $('postTopic').value; 80 81 if( htmlAreaEnabled ) 82 { 83 postText = tinyMCE.getInstanceById('postText').getBody().innerHTML; 84 } 85 else 86 { 87 postText = $('postText').value; 88 } 89 90 if( postTopic.length > minBackupLength ) 91 { 92 setCookie( postNotSavedCookieName, 1, 1); 93 saveBackupPostToCookie( postTopicCookieName, postTopic ); 94 } 95 96 if( postText.length > minBackupLength ) 97 { 98 setCookie( postNotSavedCookieName, 1, 1); 99 saveBackupPostToCookie( postTextCookieName, postText ); 100 } 101 } 102 103 function initialAutoSave() 104 { 105 postNotSaved = getCookie( postNotSavedCookieName ); 106 if ( postNotSaved == 1 ) 107 { 108 $('autoSaveMessage').innerHTML = msgAutoSaveMessage; 109 Element.show($('autoSaveMessage')); 110 } 111 else 112 { 113 deleteBackupPostFromCookie(); 114 } 115 } 116 117 function startAutoSave() { 118 backupTimer = setInterval('backupPost();', backupInterval * 1000 ); 119 } 120 121 function restartAutoSave() { 122 deleteBackupPostFromCookie(); 123 clearInterval( backupTimer ); 124 setTimeout( 'startAutoSave();', backupInterval * 1000 ); 125 } 126 127 function restoreAutoSave() 128 { 129 $('postTopic').value = loadBackupPostFromCookie( postTopicCookieName ); 130 131 if( htmlAreaEnabled ) 132 { 133 tinyMCE.getInstanceById('postText').getBody().innerHTML = loadBackupPostFromCookie( postTextCookieName ); 134 } 135 else 136 { 137 $('postText').value = loadBackupPostFromCookie( postTextCookieName ); 138 } 139 140 $('autoSaveMessage').innerHTML = ''; 141 Element.hide($('autoSaveMessage')); 142 } 143 144 function eraseAutoSave() 145 { 146 deleteBackupPostFromCookie(); 147 148 $('autoSaveMessage').innerHTML = ''; 149 Element.hide($('autoSaveMessage')); 150 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |