| 1 |
/**
|
| 2 |
* a jquery cache function
|
| 3 |
*
|
| 4 |
* works by creating a bunch of hidden text areas for later retrieval
|
| 5 |
* assumes, at this point, that value is a string which is properly encoded
|
| 6 |
*
|
| 7 |
* many solutions are bogged down by having to encode and decode cache values in larger
|
| 8 |
* from single large arrays stored in textareas, etc.
|
| 9 |
*
|
| 10 |
* Tested only on Windows IE7 and FireFox 1.5.x
|
| 11 |
*
|
| 12 |
* @todo do some checks of key and value
|
| 13 |
* @todo alternative use cookies/iframes for better XP persistance
|
| 14 |
*
|
| 15 |
* @author Jonathan Hendler (jonathan at civicactions dot com)
|
| 16 |
* @license AGPL http://www.affero.org/oagpl.html
|
| 17 |
* @version 0.1.0
|
| 18 |
*
|
| 19 |
* cacheCheck:
|
| 20 |
* cachePut:
|
| 21 |
* cacheGet:
|
| 22 |
* cacheRemove:
|
| 23 |
*
|
| 24 |
*/
|
| 25 |
|
| 26 |
jQuery.extend({
|
| 27 |
cacheCheck: function (key){
|
| 28 |
return jQuery('#'+key).size() > 0;
|
| 29 |
},
|
| 30 |
cachePut: function (key,value){
|
| 31 |
if (!jQuery.cacheCheck(key)){
|
| 32 |
jQuery('body').append('<textarea id="'+key+'" style="position: absolute; top: 0px; left: 0px; display: none; inline: none;"></textarea>');
|
| 33 |
}
|
| 34 |
//do some checks of key and value
|
| 35 |
jQuery('#'+key).val(value);
|
| 36 |
},
|
| 37 |
cacheGet: function (key){
|
| 38 |
if (jQuery.cacheCheck(key)){
|
| 39 |
return jQuery('#'+key).val();
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
return null;
|
| 43 |
}
|
| 44 |
},
|
| 45 |
cacheRemove: function (key){
|
| 46 |
if (jQuery.cacheCheck(key)){
|
| 47 |
jQuery('#'+key).remove();
|
| 48 |
return true;
|
| 49 |
}
|
| 50 |
else {
|
| 51 |
return false;
|
| 52 |
}
|
| 53 |
}
|
| 54 |
});
|