2016-02-13 06:50:49 +01:00
|
|
|
<script>
|
|
|
|
|
|
|
|
function insertTag() {
|
|
|
|
|
|
|
|
var newTag = $("#jstagInput").val();
|
|
|
|
|
|
|
|
if(newTag.trim()=="") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-14 01:15:19 +01:00
|
|
|
var findTag = $("span[data-tag]").filter(function() {
|
2016-02-25 02:50:27 +01:00
|
|
|
return $(this).attr('data-tag').toLowerCase() == newTag.toLowerCase();
|
2016-02-14 01:15:19 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if( findTag.length > 0 ) {
|
|
|
|
findTag.removeClass("unselect").addClass("select");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$("#jstagList").append("<span data-tag=\""+newTag+"\" class=\"select\">"+newTag+"</span>");
|
|
|
|
}
|
2016-02-13 06:50:49 +01:00
|
|
|
|
|
|
|
// Clean the input.
|
|
|
|
$("#jstagInput").val("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
// Click on tag unselected.
|
|
|
|
$(document).on("click", ".unselect", function() {
|
|
|
|
$(this).removeClass("unselect").addClass("select");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Click on tag selected.
|
|
|
|
$(document).on("click", ".select", function() {
|
|
|
|
$(this).removeClass("select").addClass("unselect");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Insert tag when click on the button "add".
|
|
|
|
$(document).on("click", "#jstagAdd", function(e) {
|
|
|
|
|
|
|
|
// Prevent forum submit.
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
insertTag();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// Insert tag when press enter key.
|
|
|
|
$("#jstagInput").keypress(function(e) {
|
|
|
|
|
|
|
|
if(e.which == 13) {
|
|
|
|
insertTag();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// Before form submit.
|
|
|
|
$("form").submit(function(e) {
|
|
|
|
|
|
|
|
// For each span.select make an array then implode with comma glue.
|
|
|
|
var list = $("#jstagList > span.select").map(function() {
|
|
|
|
return $(this).html();
|
|
|
|
}).get().join(",");
|
|
|
|
|
|
|
|
// Insert the tags separated by comma in the input hiden field.
|
|
|
|
$("#jstags").val( list );
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|