Skip to content

Commit

Permalink
v1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sam committed May 14, 2019
2 parents 4840e60 + 4b8e138 commit 458b70a
Show file tree
Hide file tree
Showing 4 changed files with 676 additions and 422 deletions.
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function electronPrompt(options, parentWindow) {
useContentSize: true,
modal: Boolean(parentWindow),
title: opts.title,
icon: opts.icon
icon: opts.icon,
webPreferences: {
nodeIntegration: true
}
});

promptWindow.setMenu(null);
Expand Down
24 changes: 14 additions & 10 deletions lib/page/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const promptError = e => {
if (e instanceof Error) {
e = e.message;
}

ipcRenderer.sendSync('prompt-error:' + promptId, e);
};

Expand All @@ -17,7 +18,7 @@ const promptCancel = () => {
};

const promptSubmit = () => {
const dataEl = document.getElementById('data');
const dataEl = document.querySelector('#data');
let data = null;

if (promptOptions.type === 'input') {
Expand All @@ -29,6 +30,7 @@ const promptSubmit = () => {
data = dataEl.value;
}
}

ipcRenderer.sendSync('prompt-post-data:' + promptId, data);
};

Expand All @@ -48,9 +50,9 @@ docReady(() => {
}

if (promptOptions.useHtmlLabel) {
document.getElementById('label').innerHTML = promptOptions.label;
document.querySelector('#label').innerHTML = promptOptions.label;
} else {
document.getElementById('label').textContent = promptOptions.label;
document.querySelector('#label').textContent = promptOptions.label;
}

try {
Expand All @@ -59,18 +61,18 @@ docReady(() => {
if (customStyleContent) {
const customStyle = document.createElement('style');
customStyle.setAttribute('rel', 'stylesheet');
customStyle.appendChild(document.createTextNode(customStyleContent));
document.head.appendChild(customStyle);
customStyle.append(document.createTextNode(customStyleContent));
document.head.append(customStyle);
}
}
} catch (error) {
return promptError(error);
}

document.getElementById('ok').addEventListener('click', () => promptSubmit());
document.getElementById('cancel').addEventListener('click', () => promptCancel());
document.querySelector('#ok').addEventListener('click', () => promptSubmit());
document.querySelector('#cancel').addEventListener('click', () => promptCancel());

const dataContainerEl = document.getElementById('data-container');
const dataContainerEl = document.querySelector('#data-container');

let dataEl;
if (promptOptions.type === 'input') {
Expand Down Expand Up @@ -98,6 +100,7 @@ docReady(() => {
if (e.which === 13) {
promptSubmit();
}

if (e.which === 27) {
promptCancel();
}
Expand All @@ -117,11 +120,12 @@ docReady(() => {
if (k === promptOptions.value) {
optionEl.setAttribute('selected', 'selected');
}
dataEl.appendChild(optionEl);

dataEl.append(optionEl);
}
}

dataContainerEl.appendChild(dataEl);
dataContainerEl.append(dataEl);
dataEl.setAttribute('id', 'data');

dataEl.focus();
Expand Down
Loading

0 comments on commit 458b70a

Please sign in to comment.