Skip to content

Commit

Permalink
Export workspace encode URL (bits-and-electrons#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
saich08 authored Feb 20, 2021
1 parent a3a727b commit f928da7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
10 changes: 8 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@
<div class="modal-content rounded-0">
<div class="modal-body">
<div>
<p>Link to current Bloch sphere state, custom gates and lambda gates.</p>
<label class="form-label">Link to current Bloch sphere state,
custom gates and lambda gates.</label>
<textarea id="export-workspace-textarea" class="form-control textarea-custom"
readonly></textarea>
</div>
<div class="form-check">
<input id="export-workspace-encode-url" class="form-check-input" type="checkbox">
<label class="form-label" for="export-workspace-encode-url">Encode URL</label>
</div>
<div>
<button id="export-workspace" class="btn btn-primary mt-2 btn-sharp">Copy to clipboard</button>
<button id="export-workspace" class="btn btn-primary mt-2 btn-sharp">
Copy to clipboard</button>
</div>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/event_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ var ExportWorkspaceEventsListeners = {
$("#export-workspace").click(function () {
ExportWorkspaceEvents.copyWorkspaceToClipboard();
});

$("#export-workspace-encode-url").change(function() {
if ($(this).is(':checked')) {
ExportWorkspaceEvents.updateWorkspaceURL(false);
}
else {
ExportWorkspaceEvents.updateWorkspaceURL(true);
}
});

$('#export-workspace-modal').on('hidden.bs.modal', function () {
// Reset Export Workspace Model
ExportWorkspaceEvents.resetExportWorkspaceModel();
});
},

startAllEventListeners: function () {
Expand Down
24 changes: 19 additions & 5 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ var ExportWorkspaceEvents = {
// Update URL Hash
window.location.hash = workspacePropertiesJson;

// Decode Location with Unsafe URL Characters
let location = decodeURIComponent(window.location);

// Update Export Workspace
$("#export-workspace-textarea").val(location);
// Update Workspace URL
ExportWorkspaceEvents.updateWorkspaceURL(true);
},

loadWorkspace: function () {
Expand Down Expand Up @@ -122,9 +119,26 @@ var ExportWorkspaceEvents = {
$("#azimuth-angle-content").html(`${workspaceProperties.lambdaGates.azimuthAngle}<span>&#176;</span>`);
},

updateWorkspaceURL: function (decoded) {
let location = window.location;

if (decoded)
{
// Decode Location with Unsafe URL Characters
location = decodeURIComponent(location);
}

// Update Export Workspace
$("#export-workspace-textarea").val(location);
},

copyWorkspaceToClipboard: function () {
$("#export-workspace-textarea").select();
document.execCommand("copy");
},

resetExportWorkspaceModel: function () {
$("#export-workspace-encode-url").prop('checked', false);
}
};

Expand Down

0 comments on commit f928da7

Please sign in to comment.