Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Dialog to open other examples. Persists last loaded.

  • Loading branch information...
commit 5f65b3a30523954f6a6ce3165daad0039ca55112 1 parent 2f98b4e
Joe Walnes authored
Showing with 47 additions and 10 deletions.
  1. +19 −0 web/index.html
  2. +28 −10 web/viewer.js
View
19 web/index.html
@@ -33,6 +33,7 @@
<div class="container">
<span class="brand" href="#">GCode Viewer</span>
<ul class="nav">
+ <li><a href="javascript:openDialog()">Load Model</a></li>
<li><a href="javascript:about()">About</a></li>
</ul>
<ul class="nav pull-right">
@@ -46,6 +47,24 @@
<!-- WebGL rendering area -->
<div id="renderArea"></div>
+ <div class="modal" id="openModal" style="display: none">
+ <div class="modal-header">
+ <a class="close" data-dismiss="modal">&times;</a>
+ <h3>Open GCode</h3>
+ </div>
+ <div class="modal-body">
+ <h4>Examples</h4>
+ <ul>
+ <li><a href="javascript:openGCode('examples/15mm_cube.gcode')">15mm_cube.gcode</a></li>
+ <li><a href="javascript:openGCode('examples/octocat.gcode')">octocat.gcode</a></li>
+ <li><a href="javascript:openGCode('examples/part.gcode')">part.gcode</a></li>
+ </ul>
+ </div>
+ <div class="modal-footer">
+ <a class="btn" data-dismiss="modal">Cancel</a>
+ </div>
+ </div>
+
<!-- 'About' dialog'-->
<div class="modal fade" id="aboutModal" style="display: none">
<div class="modal-header">
View
38 web/viewer.js
@@ -203,6 +203,25 @@ function about() {
$('#aboutModal').modal();
}
+function openDialog() {
+ $('#openModal').modal();
+}
+
+var scene = null;
+var object = null;
+
+function openGCode(path) {
+ $('#openModal').modal('hide');
+ if (object) {
+ scene.remove(object);
+ }
+ loadFile(path, function(gcode) {
+ object = createObjectFromGCode(gcode);
+ scene.add(object);
+ localStorage.setItem('last-loaded', path);
+ });
+}
+
$(function() {
if (!Modernizr.webgl) {
@@ -210,19 +229,18 @@ $(function() {
return;
}
+ if (!Modernizr.localstorage) {
+ alert("Man, your browser is ancient. I can't work with this. Please upgrade.");
+ return;
+ }
+
// Show 'About' dialog for first time visits.
- if (Modernizr.localstorage) {
- if (!localStorage.getItem("not-first-visit")) {
- localStorage.setItem("not-first-visit", true);
- setTimeout(about, 500);
- }
- } else {
+ if (!localStorage.getItem("not-first-visit")) {
+ localStorage.setItem("not-first-visit", true);
setTimeout(about, 500);
}
- var scene = createScene($('#renderArea'));
- loadFile('./examples/octocat.gcode', function(gcode) {
- scene.add(createObjectFromGCode(gcode));
- });
+ scene = createScene($('#renderArea'));
+ openGCode(localStorage.getItem('last-loaded') || 'examples/octocat.gcode');
});
Please sign in to comment.
Something went wrong with that request. Please try again.