From 358008fca7204b8236a85ccd3d47a19348372366 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 5 Jul 2017 15:56:00 +0200 Subject: [PATCH] alert is called in the resize function - so this is not to pulled into the master - its just to demonstrate the alert --- src/app.js | 1 + src/app/modal-dialog-alert.js | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/app/modal-dialog-alert.js diff --git a/src/app.js b/src/app.js index e3e48f78fc..e4034f42f3 100644 --- a/src/app.js +++ b/src/app.js @@ -31,6 +31,7 @@ var RighthandPanel = require('./app/righthand-panel') var examples = require('./app/example-contracts') // var Txlistener = require('./app/txListener') + var css = csjs` html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } diff --git a/src/app/modal-dialog-alert.js b/src/app/modal-dialog-alert.js new file mode 100644 index 0000000000..9b7144b5ab --- /dev/null +++ b/src/app/modal-dialog-alert.js @@ -0,0 +1,51 @@ +/* global FileReader, confirm, alert */ +var yo = require('yo-yo') +var csjs = require('csjs-inject') + +module.exports = (title, content, ok, cancel) => { + var okDiv = document.getElementById('modal-footer-ok') + var cancelDiv = document.getElementById('modal-footer-cancel') + okDiv.innerHTML = (ok && ok.label !== undefined) ? ok.label : 'OK' + cancelDiv.innerHTML = (cancel && cancel.label !== undefined) ? cancel.label : '' + + var modal = document.querySelector('.modal-body') + var modaltitle = document.querySelector('.modal-header h2') + + modaltitle.innerHTML = ' - ' + if (title) modaltitle.innerHTML = title + + modal.innerHTML = '' + //if (content) modal.appendChild(content) + if (content) modal.innerHTML = content + + var container = document.querySelector('.modal') + container.style.display = container.style.display === 'block' ? hide() : show() + + function okListenner () { + hide() + if (ok && ok.fn) ok.fn() + removeEventListener() + } + + function cancelListenner () { + hide() + if (cancel && cancel.fn) cancel.fn() + removeEventListener() + } + + function hide () { + container.style.display = 'none' + } + + function show () { + container.style.display = 'block' + } + + function removeEventListener () { + okDiv.removeEventListener('click', okListenner) + cancelDiv.removeEventListener('click', cancelListenner) + } + + okDiv.addEventListener('click', okListenner) + cancelDiv.addEventListener('click', cancelListenner) +} \ No newline at end of file