forked from weblab/sistertalk
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Styling for Local Storage Save
- Loading branch information
briandunnigan
authored and
briandunnigan
committed
Jan 5, 2016
1 parent
09e6f68
commit 2ea83c5
Showing
4 changed files
with
152 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,119 @@ | ||
jQuery(document).ready(function($) { | ||
|
||
// Utility Functions | ||
function writeToLocal(localName, value){ | ||
//console.log('writing to local...'+localName); | ||
var string = JSON.stringify(value); | ||
//console.log('string to local: '+string); | ||
localStorage.setItem(localName, string) | ||
} | ||
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('<div class="alert alert-success" role="alert">Answers saved, you may now close this window.</div>'); | ||
} | ||
function loadAnswersFromLocal(){ | ||
$('.gform_wrapper input').each(function(index, element) { | ||
var id = $(this).attr('id'); | ||
if (this.type == 'radio' || this.type == 'checkbox'){ | ||
this.checked = readFromLocal(id); | ||
} else if (this.type == 'text'){ | ||
this.value = readFromLocal(id); | ||
} | ||
}); | ||
$('.gform_wrapper textarea').each(function(index, element) { | ||
var id = $(this).attr('id'); | ||
this.value = readFromLocal(id); | ||
}); | ||
} | ||
|
||
|
||
// 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 = $('<a>'); | ||
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)); | ||
} | ||
}); | ||
} | ||
*/ | ||
jQuery(document).ready(function($) { | ||
|
||
// Utility Functions | ||
function writeToLocal(localName, value){ | ||
//console.log('writing to local...'+localName); | ||
var string = JSON.stringify(value); | ||
//console.log('string to local: '+string); | ||
localStorage.setItem(localName, string) | ||
} | ||
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('<div class="alert alert-success" role="alert"><strong>Answers saved.</strong><br /> You may now continue on to the next section or close this window.</div>'); | ||
} | ||
function loadAnswersFromLocal(){ | ||
$('.gform_wrapper input').each(function(index, element) { | ||
var id = $(this).attr('id'); | ||
if (this.type == 'radio' || this.type == 'checkbox'){ | ||
this.checked = readFromLocal(id); | ||
} else if (this.type == 'text'){ | ||
this.value = readFromLocal(id); | ||
} | ||
}); | ||
$('.gform_wrapper textarea').each(function(index, element) { | ||
var id = $(this).attr('id'); | ||
this.value = readFromLocal(id); | ||
}); | ||
} | ||
|
||
|
||
// 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 = $('<a>'); | ||
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)); | ||
} | ||
}); | ||
} | ||
*/ | ||
}); |