diff --git a/sistertalk.js b/sistertalk.js index 0574726..7556731 100644 --- a/sistertalk.js +++ b/sistertalk.js @@ -1,3 +1,4 @@ + jQuery(document).ready(function($) { // Utility Functions @@ -114,4 +115,107 @@ jQuery(document).ready(function($) { }); } */ +======= +jQuery(document).ready(function($) { + + // Utility Functions + + function readFromLocal(localName){ + //console.log('getting item from local...'+localName); + var string = localStorage.getItem(localName); + //console.log('string from local: '+JSON.parse(string)); + return JSON.parse(string); + } + + // Sistertalk Functions + function saveAnswersToLocal(){ + $('.gform_wrapper input').each(function(index, element) { + var id = $(this).attr('id'); + if (this.type == 'radio' || this.type == 'checkbox'){ + var value = this.checked; + writeToLocal(id, value); + } else if (this.type == 'text'){ + var value = this.value; + writeToLocal(id, value); + } + }); + $('.gform_wrapper textarea').each(function(index, element) { + var id = $(this).attr('id'); + writeToLocal(id, this.value); + }); + $('.gform_button').after(''); + setTimeout(function(){$('.save-msg').fadeOut(200, function() { $(this).remove(); });}, 5000); + } + + + + // Go... + + loadAnswersFromLocal(); + + //$('.gform_save_link').text('Save').addClass('btn btn-primary'); + $('.gform_button').attr('value','Save').addClass('btn btn-primary'); + + $('.gform_button').click(function(e){ + e.preventDefault(); + saveAnswersToLocal(); + }); + + + + + + + + // on submit... + + // for each input... + + //type = text or text area + + // type = checkbox + + // type = radio + + + + + + + + /* + * + * debugging only + * + */ + function insertClearButton(){ + var button = $(''); + button.attr('href', '#') + button.attr('id', 'clear'); + button.attr('class', 'btn btn-xs btn-warning'); + button.html('Erase All Workbook Answers'); + button.click(function(e){ + e.preventDefault(); + console.log('clearing localStorage...'); + localStorage.clear(); + window.location.reload(); + }); + $('#uc-footer-links').append(button); + } + //insertClearButton(); + /* + if($('.resume_form_link').text().length > 0){ + writeToLocal($('.gform_wrapper').attr('id'), $('.resume_form_link').text()); + } + else{ + $('.gform_wrapper').each(function(index, element) { + var id = $(this).attr('id'); + var url = readFromLocal(id); + if(null != url && window.location != url){ + window.location.replace(readFromLocal(id)); + } + }); + } + */ + }); \ No newline at end of file