<commit_before>/**************************************************************************
 * Popup dialog boxes for Bootstrap - http://www.bootpopup.tk
 * Copyright (C) 2016  rigon<<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *************************************************************************/


var bootpopupFormCounter = 0;

function bootpopup(options) {
    bootpopupFormCounter++;

    var opts = {
        title: "",
        showclose: true,
        content: [],
        buttons: ["close"],
        dismiss: function(data) {},
        close: function(data) {},
        ok: function(data) {},
        cancel: function(data) {},
        yes: function(data) {},
        no: function(data) {},
        complete: function(data) {},
    }

    
    var buttons = [];
    for(key in options) {
        if(key in opts)
            opts[key] = options[key];
        // If an event for a button is given, show the respective button
        if(["close", "ok", "cancel", "yes", "no"].indexOf(key) >= 0)
            buttons.push(key);
    }
    // Copy news buttons to opts.buttons
    if(buttons.length > 0) {
        // Clear default buttons if new are not given
        if(!("buttons" in options)) opts.buttons = [];
        buttons.forEach(function(item) {
            if(opts.buttons.indexOf(item) < 0) opts.buttons.push(item);
        });
    }


    var modalWindow = $('<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="bootpopup-title"></div>');
    var dialog = $('<div class="modal-dialog" role="document"></div>');
    var content = $('<div class="modal-content"></div>');
    dialog.append(content);
    modalWindow.append(dialog);
    
    // Header
    var header = $('<div class="modal-header"></div>');
    if(opts.showclose)
        header.append('<button type="button" class="bootpopup-button close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
    header.append('<h4 class="modal-title" id="bootpopup-title">' + opts.title + '</h4>');

    content.append(header);
    
    // Body
    var body = $('<div class="modal-body"></div>').appendTo(content);
    var form = $("<form></form>", { id: "bootpopup-form" + bootpopupFormCounter, class: "form-horizontal" }).appendTo(body);

    for(element in opts.content) {
        for(type in opts.content[element]) {
            var attrs = opts.content[element][type];
            
            switch(type) {
                /* // List of input types
                case "button": case "checkbox": case "color": case "date": case "datetime-local": 
                case "email": case "file": case "hidden": case "image": case "month": case "number":
                case "password": case "radio": case "range": case "reset": case "search":
                case "submit": case "tel": case "text": case "time": case "url": case "week": */
                case "button": case "text": case "submit": case "color": case "date": case "password": 
                case "hidden": case "file": case "number": case "email": case "reset":
                    attrs.type = type;
                    // Continue for input
                case "input":
                    attrs.id = (typeof attrs.id === "undefined" ? "bootpopup-form-input" + element : attrs.id);
                    attrs.class = (typeof attrs.class === "undefined" ? "form-control" : attrs.class);
                    attrs.type = (typeof attrs.type === "undefined" ? "text" : attrs.type);

                    // Form Group
                    var formGroup = $('<div class="form-group"></div>').appendTo(form);
                    // Label
                    $("<label></label>", { for: attrs.id, class: "col-sm-2 control-label", text: attrs.label}).appendTo(formGroup);
                    // Input and div to control width<commit_msg>URL input type support<commit_after>/**************************************************************************
 * Popup dialog boxes for Bootstrap - http://www.bootpopup.tk
 * Copyright (C) 2016  rigon<<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *************************************************************************/


var bootpopupFormCounter = 0;

function bootpopup(options) {
    bootpopupFormCounter++;

    var opts = {
        title: "",
        showclose: true,
        content: [],
        buttons: ["close"],
        dismiss: function(data) {},
        close: function(data) {},
        ok: function(data) {},
        cancel: function(data) {},
        yes: function(data) {},
        no: function(data) {},
        complete: function(data) {},
    }

    
    var buttons = [];
    for(key in options) {
        if(key in opts)
            opts[key] = options[key];
        // If an event for a button is given, show the respective button
        if(["close", "ok", "cancel", "yes", "no"].indexOf(key) >= 0)
            buttons.push(key);
    }
    // Copy news buttons to opts.buttons
    if(buttons.length > 0) {
        // Clear default buttons if new are not given
        if(!("buttons" in options)) opts.buttons = [];
        buttons.forEach(function(item) {
            if(opts.buttons.indexOf(item) < 0) opts.buttons.push(item);
        });
    }


    var modalWindow = $('<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="bootpopup-title"></div>');
    var dialog = $('<div class="modal-dialog" role="document"></div>');
    var content = $('<div class="modal-content"></div>');
    dialog.append(content);
    modalWindow.append(dialog);
    
    // Header
    var header = $('<div class="modal-header"></div>');
    if(opts.showclose)
        header.append('<button type="button" class="bootpopup-button close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
    header.append('<h4 class="modal-title" id="bootpopup-title">' + opts.title + '</h4>');

    content.append(header);
    
    // Body
    var body = $('<div class="modal-body"></div>').appendTo(content);
    var form = $("<form></form>", { id: "bootpopup-form" + bootpopupFormCounter, class: "form-horizontal" }).appendTo(body);

    for(element in opts.content) {
        for(type in opts.content[element]) {
            var attrs = opts.content[element][type];
            
            switch(type) {
                /* // List of input types
                case "button": case "checkbox": case "color": case "date": case "datetime-local": 
                case "email": case "file": case "hidden": case "image": case "month": case "number":
                case "password": case "radio": case "range": case "reset": case "search":
                case "submit": case "tel": case "text": case "time": case "url": case "week": */
                case "button": case "text": case "submit": case "color": case "url": case "password": 
                case "hidden": case "file": case "number": case "email": case "reset": case "date":
                    attrs.type = type;
                    // Continue for input
                case "input":
                    attrs.id = (typeof attrs.id === "undefined" ? "bootpopup-form-input" + element : attrs.id);
                    attrs.class = (typeof attrs.class === "undefined" ? "form-control" : attrs.class);
                    attrs.type = (typeof attrs.type === "undefined" ? "text" : attrs.type);

                    // Form Group
                    var formGroup = $('<div class="form-group"></div>').appendTo(form);
                    // Label
                    $("<label></label>", { for: attrs.id, class: "col-sm-2 control-label", text: attrs.label}).appendTo(formGroup);
                    // Input and div to control width
{'fraction_non_alphanumeric': 0.18133783024170883, 'fraction_numerical': 0.002922990444069702, 'mean_word_length': 2.5078864353312302, 'pattern_counts': {'":': 69, '<': 55, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2699176', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2327, 'n_words': 742}