/** * Hide the "save" box when form fields are focused */ $('.input-group input, .input-group textarea').focus(function(){ $('.form-save').slideUp(); $('.form-save .text-url').val(''); $('.form-save .link-url').attr('href', ''); $('.form-save .email-url').attr('href', ''); }); /** * Generate save information */ $('.submit').click(function(e) { var to_email = 'your@email.address'; var email_subject = 'Saved form'; var email_msg = ''; var editor_url = window.location.href.slice( 0, window.location.href.indexOf('?') ) + '?'; e.preventDefault(); var query_string = ''; // get all the form values $('.form-group .input-group input').each(function() { var name = $(this).attr('name'); var value = $(this).val(); query_string += name + "=" + escape(value) + "&"; }); // generate link email_msg += "mailto:" + to_email; email_msg += '?subject=' + escape(email_subject); email_msg += '&body=' + escape(editor_url + query_string); // display link $('.form-save .text-url').val(editor_url + query_string); $('.form-save .link-url').attr('href', editor_url + query_string); $('.form-save .email-url').attr('href', email_msg); $('.form-save').slideDown(); }); /** * Revrieve querystring variables * Via: http://stackoverflow.com/questions/4656843/jquery-get-querystring-from-url */ function get_url_vars() { var vars = []; var hash; var hashes = window.location.href.slice( window.location.href.indexOf('?') + 1 ).split( '&' ); for ( var i=0; i < hashes.length; i++ ) { hash = hashes[i].split( '=' ); vars.push( hash[0] ); vars[hash[0]] = hash[1]; } return vars; } /** * Populate the form fields with qeuerystring variables */ function populate_form() { var qs_vars = []; // init qs_vars = get_url_vars(); if ( qs_vars.length > 0 ) { // populate the form with saved vars for ( var i=0; i