UNPKG

remix-ide

Version:

Minimalistic browser-based Solidity IDE

44 lines (40 loc) 1.2 kB
'use strict' var modalDialogCustom = require('../app/ui/modal-dialog-custom') // Allowing window to be overriden for testing function GistHandler (_window) { if (_window !== undefined) { modalDialogCustom = _window } this.handleLoad = function (params, cb) { if (!cb) cb = () => {} var loadingFromGist = false var gistId if (params['gist'] === '') { loadingFromGist = true modalDialogCustom.prompt('Load a Gist', 'Enter the ID of the Gist or URL you would like to load.', null, (target) => { if (target !== '') { gistId = getGistId(target) if (gistId) { cb(gistId) } else { modalDialogCustom.alert('Error while loading gist. Please provide a valid Gist ID or URL.') } } }) return loadingFromGist } else { gistId = params['gist'] loadingFromGist = !!gistId } if (loadingFromGist) { cb(gistId) } return loadingFromGist } function getGistId (str) { var idr = /[0-9A-Fa-f]{8,}/ var match = idr.exec(str) return match ? match[0] : null } } module.exports = GistHandler