UNPKG

sunrize

Version:

Sunrize — A Multi-Platform X3D Editor

86 lines (64 loc) 2.18 kB
"use strict"; const $ = require ("jquery"), electron = require ("electron"), Editor = require ("../Undo/Editor"), _ = require ("../Application/GetText"); require ("./Popover"); require ("../Bits/Validate"); $.fn.exportNodePopover = function (node, oldExportedName, oldDescription = "") { // Create content. const scene = node .getExecutionContext (); const content = $("<div></div>"); $("<span></span>") .text ("Exported Name") .appendTo (content); const nameInput = $("<input></input>") .attr ("placeholder", _("Enter exported name")) .val (oldExportedName || scene .getUniqueExportName (node .getName ())) .appendTo (content); $("<span></span>") .text ("Description") .appendTo (content); const descriptionInput = $("<input></input>") .attr ("placeholder", _("Enter description")) .val (oldDescription) .appendTo (content); // Create tooltip. const tooltip = this .popover ({ content: content, extension: { wide: true, }, events: { show: (event, api) => { $(nameInput) .add (descriptionInput) .off (); nameInput .validate (Editor .Id, () => { electron .shell .beep (); nameInput .highlight (); }); $(nameInput) .add (descriptionInput) .on ("keydown.exportNodePopover", event => { if (event .key !== "Enter") return; event .preventDefault (); api .toggle (false); if (!nameInput .val ()) return; const exportedName = nameInput .val () !== oldExportedName ? scene .getUniqueExportName (nameInput .val ()) : oldExportedName, description = descriptionInput .val (); Editor .updateExportedNode (scene, exportedName, oldExportedName, node, description); }); setTimeout (() => nameInput .trigger ("select"), 1); }, }, }) return this; };