{"size": 2223, "ext": "js", "max_stars_repo_path": "resources/assets/js/main.js", "max_stars_repo_name": "lucaswll/lucas-develop", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/assets/js/main.js", "max_issues_repo_name": "lucaswll/lucas-develop", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "resources/assets/js/main.js", "max_forks_repo_name": "lucaswll/lucas-develop", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.1097560976, "max_line_length": 134, "alphanum_fraction": 0.477282951}
$(document).ready(function() {
    
    $(".cpf").mask("999.999.999-99");
    $(".cnpj").mask("99.999.999/9999-99");

    $(".money").mask("#.##0,00", { reverse: true });
    $(".percent").mask("##0,00", { reverse: true });
    
    $(".datetime").mask("99/99/9999 99:99");

    // Limitar campos números com valores mínimos e/ou máximos
    $("input[min-value], input[max-value]").change(function() {

        var value = numberFormat($(this).val());
        if (value) {

            var min = numberFormat($(this).attr("min-value"));
            var max = numberFormat($(this).attr("max-value"));
            
            if (!isNaN(min) && value - min < 0) value = min;
            if (!isNaN(max) && value - max > 0) value = max;
            
            $(this).val(numberFormat(value, "br"));

        }

    });
    
    // Botão para remover um registro
	$(".btn-delete").click(function(e) {

	    e.preventDefault();

        var id = $(this).attr('data-id');
        var action = $(this).attr('href');
        var question = $(this).attr('data-question') || "Essa é uma ação <b>irrerversível</b>.<br/>Tem certeza que deseja continuar?";
        
        if (id && action) {
        	
        	
        	var $form = 
        	$('<form method="post" class="hide" action="'+action+'">'+
        		'<input class="hide" name="_method" value="DELETE"/>'+
        		'<input class="hide" name="_token" value="'+window.Laravel.token+'">'+
        		'<input name="id" value="'+id+'"/>'+
        	'</form>');
        	
        	$dialog.confirm(question, function() {
        		$("body").append($form);
        		$form.submit();
        	});
        }
	        
	});

});

/**
 * Formata um número para determinado formato
 * @param {*} value 
 * @param {*} format 
 */
function numberFormat(value, format) {

    format = format || "en";

    if (value) {

        if (format == "en") {
            return parseFloat(value.replace(".", "").replace(",", ".")).toFixed(2);

        } else if (format == "br") {

            var parts = value.toString().split(".");
            parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
            return parts.join(",");
        }

    } else {
        return false;
    }
}