summaryrefslogtreecommitdiffstats
path: root/apps/samples/vrml/annotations.js
blob: b91ccfa5cf4c73fad32420e2c699bb704913bf4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function Annotations(element, params) {
		
	// private attributes
	var self = this;
	var dojo               = require("dojo");
	var domConst           = dojo.require('dojo/dom-construct');
	var xhr                = dojo.require("dojo/_base/xhr");

  if (typeof(element) === 'string') {
    element = dojo.byId(element);
  }

  // private instanceId
  if (!Annotations.instances)
  	Annotations.instances = 0;
  var instanceId = Annotations.instances++;
  
  // public attributes
  this.annotations = [];
  this.vrmlViewer = params.viewer;

  // establish our dom
	element.appendChild(domConst.toDom('\
    <div style="text-align: right"><div class="annotation" /></div><button type="button" class="annotate"></button></div>\
	  <div class="messages"></div>\
	'));
  
  this.annotationTextElem = dojo.query("div.annotation", element)[0];
	this.annotateButtonElem = dojo.query("button.annotate", element)[0];
	this.messagesElem = dojo.query("div.messages", element)[0];
	
	// privileged public methods
	this.annotate = function(text) {
    var pose = dojo.clone(self.vrmlViewer.pose);
    var imageURL = self.vrmlViewer.imageURL;
    var annoLink = document.createElement("a");
    var annoText = document.createTextNode(text + "\n");
    annoLink.setAttribute("href", "#");
    annoLink.appendChild(annoText);
    annoLink.onclick = function() {
      self.vrmlViewer.setPose(imageURL, pose);
    }
	  this.messagesElem.appendChild(annoLink);
	}

	require(["dijit/form/TextBox"], function(TextBox) {
  	self.annotationBox = new TextBox({
      name: "Annotation",
  		style: "width: 70%",
  		onKeyDown: function(e) {
        var code = e.keyCode || e.which;
        if( code === 13 ) {
          e.preventDefault();
    		  self.annotate(this.get("value"));
          return false; 
        }
  		},
  	}, self.annotationTextElem);
  });
  
  require(["dijit/form/Button"], function(Button) {
  	self.resetButton = new Button({
      label: "Annotate",
  		onClick: function(){
  		  self.annotate(self.annotationBox.get("value"));
  		}
  	}, self.annotateButtonElem);
  });
  
}