1$(function(){ 2 if (!window.localStorage) return; 3 4 var $text = $('input[type=text], input[type=email], textarea'); 5 var $checkbox = $('input[type=checkbox]'); 6 var $radio = $('input[type=radio]'); 7 var $select = $('select'); 8 9 function init(){ 10 //text, textarea 11 $.each($text, function(){ 12 var inputName = $(this).attr('name'); 13 if(localStorage[inputName]){ 14 $(this).val(localStorage[inputName]); 15 } 16 }); 17 //checkbox 18 $.each($checkbox, function(){ 19 var inputName = $(this).attr('name'); 20 var inputValue = $(this).attr('value'); 21 var cbValues = JSON.parse(localStorage.getItem(inputName)); 22 if($.inArray(inputValue, cbValues) != -1){ 23 $(this).attr('checked','checked'); 24 } 25 }); 26 //radio 27 $.each($radio, function(){ 28 var inputName = $(this).attr('name'); 29 var inputValue = $(this).attr('value'); 30 if(localStorage[inputName]){ 31 if(inputValue == localStorage[inputName]){ 32 $(this).attr('checked','checked'); 33 } 34 } 35 }); 36 //select 37 $.each($select, function(){ 38 var inputName = $(this).attr('name'); 39 var optionValue = localStorage[inputName]; 40 $('[name="' + inputName + '"]').find('option[value="' + optionValue + '"]').attr('selected', true); 41 }); 42 43 bindEvent(); 44 }//init 45 46 init(); 47 48 function bindEvent(){ 49 //text, textarea, radio, select 50 // $($text, $radio, $select).change(function(){ 51 // localStorage[$(this).attr('name')] = $(this).val(); 52 // }); 53 $('input[type=text], input[type=email], textarea, input[type=radio], select').change(function(){ 54 localStorage.setItem($(this).attr('name'), $(this).val()); 55 }); 56 //checkbox 57 $checkbox.change(function(){ 58 var inputName = $(this).attr('name'); 59 var inputValue = $(this).attr('value'); 60 var cbValues = new Array; 61 $.each( $('[name="' + inputName + '"]'), function(){ 62 if( $(this).is(':checked') ){ 63 cbValues.push($(this).attr('value')); 64 } 65 }); 66 localStorage.setItem(inputName, JSON.stringify(cbValues)); 67 }); 68 $('input[type=reset]').click(function(){ 69 localStorage.clear(); 70 }); 71 } 72});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.