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
var MyXXX = { | |
get_age: function(age){ | |
switch(age) { | |
case 1: | |
return "below 20"; | |
break; | |
default: | |
return "above 20"; | |
} | |
}, | |
get_interests: function(interest){ | |
var lastIndex = interest.lastIndexOf(", "); | |
var s1 = interest.substring(0, lastIndex); | |
var s2 = interest.substring(lastIndex + 1); | |
return s1 + " and " + s2; | |
}, | |
get_newletter: function(newsletter){ | |
if (newsletter === "false") { | |
return "don't"; | |
} else { | |
return ""; | |
} | |
} | |
} | |
$(document).ready(function() { | |
$(document).on('keyup blur onload', '#user_interest', function(e) { | |
e.preventDefault(); | |
last_char = $(this).val()[$(this).val().length - 1]; | |
$('.interests').html(""); | |
tags = $(this).val().split(", ").filter(function(e){return e}); | |
$.each(tags,function(index, value){ | |
console.log(value); | |
$('.interests').append('<span class="label label-default">'+value.replace(',','')+'<span class="glyphicon glyphicon-remove glyphicon-white close-button"></span></span>\n'); | |
}); | |
}); | |
$(document).on('click', '.interests .close-button', function(event) { | |
event.preventDefault(); | |
text = $(this).parent().text(); | |
if(text.indexOf(' ') >= 0){ | |
text = text.replace(/\s+/, ""); | |
} else { | |
text = text.replace(/\s+/, "")+", "; | |
} | |
if ($('#user_interest').val().indexOf(',') >= 0) { | |
$('#user_interest').val($('#user_interest').val().replace(text, "")); | |
} else { | |
$('#user_interest').val(""); | |
} | |
$(this).parent().remove(); | |
}); | |
$(".btn-upload").on('click', function(e){ | |
e.preventDefault(); | |
$("#files:hidden").trigger('click'); | |
}); | |
$("#files").change(function(e) { | |
e.preventDefault(); | |
handleFileSelect(e); | |
}); | |
$('#user_address').change(function(event) { | |
if($(this).val()) { | |
$('.dynamic-fields').hide().slideDown(); | |
if($(this).val() === 'Home'){ | |
} | |
} else { | |
$('.dynamic-fields').slideUp(); | |
} | |
}); | |
"first_name" in localStorage && $("input[name='user[first_name]'").val(localStorage.getItem("first_name")); | |
"last_name" in localStorage && $("input[name='user[last_name]'").val(localStorage.getItem("last_name")); | |
"age" in localStorage && $("input[name='user[age]'").val(localStorage.getItem("age")); | |
$("form").submit(function(event) { | |
var first_name = $("input[name='user[first_name]'").val(); | |
var last_name = $("input[name='user[last_name]'").val(); | |
var age = $("input[name='user[age]'").val(); | |
localStorage.setItem("first_name", first_name); | |
localStorage.setItem("last_name", last_name); | |
localStorage.setItem("age", age); | |
}); | |
$(".full_name").html(localStorage.getItem("first_name")+" "+ localStorage.getItem("last_name")); | |
$(".age").html(localStorage.getItem("age")); | |
$(".email").html(localStorage.getItem("email")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment