<commit_before>import tingle from 'tingle.js';
import { iframeResizer } from 'iframe-resizer';
import './style.css';

// Find script
const script = document.currentScript;
const url = script.getAttribute('data-url') || '';

// Generate id for this modal
const id = `widget-${Date.now()}`;

// Create modal
const modal = new tingle.modal({
  closeMethods: [],
  cssClass: ['mtk-widget'],
});
modal.setContent(`<iframe id="${id}" src="${url}" style="width: 100%"></iframe>`);

// Set up iframe resizer
iframeResizer({
  minHeight: 200,
  checkOrigin: false,
  heightCalculationMethod: 'taggedElement',
  messageCallback: ({ iframe, message }) => {
    if (message === 'MTK_SB_CLOSE') {
      modal.close();
    }
  },
}, `#${id}`);

// Create button
const button = document.createElement('button');
button.innerText = 'Open widget';
button.onclick = () => {
  modal.open();
};

// Add button to the page
script.parentNode.insertBefore(button, script);<commit_msg>Parameterise buttonLabel and other fix<commit_after>import tingle from 'tingle.js';
import { iframeResizer } from 'iframe-resizer';
import './style.css';

// Find script
const script = document.currentScript;

// Extract parameters
const url = script.getAttribute('data-url') || '';
const buttonLabel = script.getAttribute('data-label') || 'Open widget';

// Generate id for this modal
const id = `widget-${Date.now()}`;

// Create modal
const modal = new tingle.modal({
  closeMethods: [],
  cssClass: ['mtk-widget'],
});
modal.setContent(`<iframe id="${id}" src="${url}" style="width: 100%"></iframe>`);

// Set up iframe resizer
iframeResizer({
  minHeight: 200,
  checkOrigin: false,
  heightCalculationMethod: 'taggedElement',
  messageCallback: ({ message }) => {
    if (message === 'MTK_SB_CLOSE') {
      modal.close();
    }
  },
}, `#${id}`);

// Create button
const button = document.createElement('button');
button.innerText = buttonLabel;
button.onclick = () => {
  modal.open();
};

// Add button to the page
script.parentNode.insertBefore(button, script);
{'fraction_non_alphanumeric': 0.18061023622047245, 'fraction_numerical': 0.005905511811023622, 'mean_word_length': 4.494594594594594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '6364074', 'n_tokens_mistral': 656, 'n_tokens_neox': 634, 'n_words': 160}