<commit_before>OV.ShowSharingDialog = function (importer, viewerSettings, importSettings, camera)
{
    function AddCheckboxLine (parentDiv, text, id, onChange)
    {
        let line = $('<div>').addClass ('ov_dialog_table_row').appendTo (parentDiv);
        let check = $('<input>').attr ('type', 'checkbox').attr ('checked', 'true').addClass ('ov_dialog_checkradio').attr ('id', id).appendTo (line);
        $('<label>').attr ('for', id).html (text).appendTo (line);
        check.change (() => {
            onChange (check.prop ('checked'));
        });
    }

    function GetSharingLink (params)
    {
        let builder = OV.CreateUrlBuilder ();
        builder.AddModelUrls (params.files);
        builder.AddColor (params.color);
        let hashParameters = builder.GetParameterList ();
        return 'https://3dviewer.net#' + hashParameters;
    }

    function GetEmbeddingCode (params)
    {
        let builder = OV.CreateUrlBuilder ();
        builder.AddModelUrls (params.files);
        builder.AddCamera (params.camera);
        builder.AddBackground (params.background);
        builder.AddColor (params.color);
        let hashParameters = builder.GetParameterList ();

        let embeddingCode = '';
        embeddingCode += '<iframe';
        embeddingCode += ' width="640" height="480"';
        embeddingCode += ' style="border:1px solid #eeeeee;"';
        embeddingCode += ' src="https://3dviewer.net/embed.html#' + hashParameters + '">';
        embeddingCode += '</iframe>';
        return embeddingCode;
    }

    function AddCopyableTextInput (parentDiv, getText)
    {
        let copyText = 'copy';
        let copiedText = 'copied';
        let container = $('<div>').addClass ('ov_dialog_copyable_input').appendTo (parentDiv);
        let input = $('<input>').prop ('readonly', true).appendTo (container);
        let button = $('<div>').addClass ('button').html (copyText).appendTo (container);
        button.click (() => {
            OV.CopyToClipboard (getText ());
            button.fadeOut (200, () => {
                button.html (copiedText).fadeIn (200);
                setTimeout (() => {
                    button.fadeOut (200, () => {
                        button.html (copyText).fadeIn (200);
                    });
                }, 2000);
            });
        });
        return input;
    }

    function AddSharingLinkTab (parentDiv, importSettings, sharingLinkParams)
    {
        let section = $('<div>').addClass ('ov_dialog_section').appendTo (parentDiv);
        $('<div>').html ('Sharing Link').addClass ('ov_dialog_inner_title').appendTo (section);
        let optionsSection = null;
        if (OV.FeatureSet.SettingsPanel) {
            optionsSection = $('<div>').addClass ('ov_dialog_section').appendTo (section);
        }
        let sharingLinkInput = AddCopyableTextInput (section, () => {
            return GetSharingLink (sharingLinkParams);
        });
        // TODO: camera position in sharing link
        // TODO: background color in sharing link
        if (OV.FeatureSet.SettingsPanel) {
            AddCheckboxLine (optionsSection, 'Use overridden default color', 'share_color', (checked) => {
                sharingLinkParams.color = checked ? importSettings.defaultColor : null;
                sharingLinkInput.val (GetSharingLink (sharingLinkParams));
            });
            sharingLinkParams.color = importSettings.defaultColor;
        }        
        sharingLinkInput.val (GetSharingLink (sharingLinkParams));
    }

    function AddEmbeddingCodeTab (parentDiv, viewerSettings, importSettings, embeddingCodeParams)
    {
        let section = $('<div>').addClass ('ov_dialog_section').css ('margin-top', '20px').appendTo (parentDiv);
        $('<div>').html ('Embedding Code').addClass ('ov_dialog_inner_title').appendTo (section);
        let optionsSection = $('<div>').addClass ('ov_dialog_section').appendTo (section);
        let embeddingCodeInput = AddCopyableTextInput (section, () => {
            return GetEmbeddingCode (embeddingCodeParams);
        });
        AddCheckboxLine (optionsSection, 'Use current camera position', 'embed_camera', (checked) => {
            embeddingCodeParams.camera = checked ? camera : null;
            embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
        });
        if (OV.FeatureSet.SettingsPanel) {
            AddCheckboxLine (optionsSection, 'Use overridden background color', 'embed_background', (checked) => {
                embeddingCodeParams.background = checked ? viewerSettings.backgroundColor : null;
                embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
            });
            embeddingCodeParams.background = viewerSettings.backgroundColor;
            AddCheckboxLine (optionsSection, 'Use overridden default color', 'embed_color', (checked) => {
                embeddingCodeParams.color = checked ? importSettings.defaultColor : null;
                embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
            });
            embeddingCodeParams.color = importSettings.defaultColor;
        }
        embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
    }

    if (!importer.IsOnlyFileSource (OV.FileSource.Url)) {
        return OV.ShowMessageDialog (
            'Sharing Failed',
            'Sharing works only if you load files by url. Please upload your model files to a web server, open them by url, and try embedding again.',
            null
        );
    }
    
    let files = importer.GetFileList ().GetFiles ();
    let modelFiles = [];
    for (let fileIndex = 0; fileIndex < files.length; fileIndex++) {
        let file = files[fileIndex];
        modelFiles.push (file.fileUrl);
    }

    let sharingLinkParams = {
        files : modelFiles,
        color : null
    };

    let embeddingCodeParams = {
        files : modelFiles,
        camera : camera,
        background : null,
        color : null
    };

    let dialog = new OV.ButtonDialog ();
    let contentDiv = dialog.Init ('Share', [
        {
            name : 'Close',
            onClick () {
                dialog.Hide ();
            }
        }
    ]);

    AddSharingLinkTab (contentDiv, importSettings, sharingLinkParams);
    AddEmbeddingCodeTab (contentDiv, viewerSettings, importSettings, embeddingCodeParams);

    dialog.Show ();
    return dialog;
};<commit_msg>Remove default color from sharing link.<commit_after>OV.ShowSharingDialog = function (importer, viewerSettings, importSettings, camera)
{
    function AddCheckboxLine (parentDiv, text, id, onChange)
    {
        let line = $('<div>').addClass ('ov_dialog_table_row').appendTo (parentDiv);
        let check = $('<input>').attr ('type', 'checkbox').attr ('checked', 'true').addClass ('ov_dialog_checkradio').attr ('id', id).appendTo (line);
        $('<label>').attr ('for', id).html (text).appendTo (line);
        check.change (() => {
            onChange (check.prop ('checked'));
        });
    }

    function GetSharingLink (params)
    {
        let builder = OV.CreateUrlBuilder ();
        builder.AddModelUrls (params.files);
        let hashParameters = builder.GetParameterList ();
        return 'https://3dviewer.net#' + hashParameters;
    }

    function GetEmbeddingCode (params)
    {
        let builder = OV.CreateUrlBuilder ();
        builder.AddModelUrls (params.files);
        builder.AddCamera (params.camera);
        builder.AddBackground (params.background);
        builder.AddColor (params.color);
        let hashParameters = builder.GetParameterList ();

        let embeddingCode = '';
        embeddingCode += '<iframe';
        embeddingCode += ' width="640" height="480"';
        embeddingCode += ' style="border:1px solid #eeeeee;"';
        embeddingCode += ' src="https://3dviewer.net/embed.html#' + hashParameters + '">';
        embeddingCode += '</iframe>';
        return embeddingCode;
    }

    function AddCopyableTextInput (parentDiv, getText)
    {
        let copyText = 'copy';
        let copiedText = 'copied';
        let container = $('<div>').addClass ('ov_dialog_copyable_input').appendTo (parentDiv);
        let input = $('<input>').prop ('readonly', true).appendTo (container);
        let button = $('<div>').addClass ('button').html (copyText).appendTo (container);
        button.click (() => {
            OV.CopyToClipboard (getText ());
            button.fadeOut (200, () => {
                button.html (copiedText).fadeIn (200);
                setTimeout (() => {
                    button.fadeOut (200, () => {
                        button.html (copyText).fadeIn (200);
                    });
                }, 2000);
            });
        });
        return input;
    }

    function AddSharingLinkTab (parentDiv, sharingLinkParams)
    {
        let section = $('<div>').addClass ('ov_dialog_section').appendTo (parentDiv);
        $('<div>').html ('Sharing Link').addClass ('ov_dialog_inner_title').appendTo (section);
        let optionsSection = null;
        if (OV.FeatureSet.SettingsPanel) {
            optionsSection = $('<div>').addClass ('ov_dialog_section').appendTo (section);
        }
        let sharingLinkInput = AddCopyableTextInput (section, () => {
            return GetSharingLink (sharingLinkParams);
        }); 
        sharingLinkInput.val (GetSharingLink (sharingLinkParams));
    }

    function AddEmbeddingCodeTab (parentDiv, viewerSettings, importSettings, embeddingCodeParams)
    {
        let section = $('<div>').addClass ('ov_dialog_section').css ('margin-top', '20px').appendTo (parentDiv);
        $('<div>').html ('Embedding Code').addClass ('ov_dialog_inner_title').appendTo (section);
        let optionsSection = $('<div>').addClass ('ov_dialog_section').appendTo (section);
        let embeddingCodeInput = AddCopyableTextInput (section, () => {
            return GetEmbeddingCode (embeddingCodeParams);
        });
        AddCheckboxLine (optionsSection, 'Use current camera position', 'embed_camera', (checked) => {
            embeddingCodeParams.camera = checked ? camera : null;
            embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
        });
        if (OV.FeatureSet.SettingsPanel) {
            AddCheckboxLine (optionsSection, 'Use overridden background color', 'embed_background', (checked) => {
                embeddingCodeParams.background = checked ? viewerSettings.backgroundColor : null;
                embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
            });
            embeddingCodeParams.background = viewerSettings.backgroundColor;
            AddCheckboxLine (optionsSection, 'Use overridden default color', 'embed_color', (checked) => {
                embeddingCodeParams.color = checked ? importSettings.defaultColor : null;
                embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
            });
            embeddingCodeParams.color = importSettings.defaultColor;
        }
        embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams));
    }

    if (!importer.IsOnlyFileSource (OV.FileSource.Url)) {
        return OV.ShowMessageDialog (
            'Sharing Failed',
            'Sharing works only if you load files by url. Please upload your model files to a web server, open them by url, and try embedding again.',
            null
        );
    }
    
    let files = importer.GetFileList ().GetFiles ();
    let modelFiles = [];
    for (let fileIndex = 0; fileIndex < files.length; fileIndex++) {
        let file = files[fileIndex];
        modelFiles.push (file.fileUrl);
    }

    let sharingLinkParams = {
        files : modelFiles
    };

    let embeddingCodeParams = {
        files : modelFiles,
        camera : camera,
        background : null,
        color : null
    };

    let dialog = new OV.ButtonDialog ();
    let contentDiv = dialog.Init ('Share', [
        {
            name : 'Close',
            onClick () {
                dialog.Hide ();
            }
        }
    ]);

    AddSharingLinkTab (contentDiv, sharingLinkParams);
    AddEmbeddingCodeTab (contentDiv, viewerSettings, importSettings, embeddingCodeParams);

    dialog.Show ();
    return dialog;
};
{'fraction_non_alphanumeric': 0.128332653893192, 'fraction_numerical': 0.004565837749694252, 'mean_word_length': 2.5126002290950744, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 52, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '5912332', 'n_tokens_mistral': 3313, 'n_tokens_neox': 3182, 'n_words': 714}