index.html 2.96 KB
Newer Older
Adam Procter's avatar
Adam Procter committed
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
<!DOCTYPE html>
<html>
<head>
  <title>Vue 8 app</title>
  <script type="text/javascript" src="http://fast.fonts.net/jsapi/123daa36-b737-45e7-87de-86581d6755c3.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/deepstream.io-client-js/2.1.1/deepstream.js"></script>
  
  <script src="js/vue.js"></script>
  <script src="js/marked.js"></script>
  <script src="js/lodash.js"></script>
  <script src="js/main.js"></script>
  <script src="js/snap.svg-min.js"></script>
  
 <link rel="stylesheet" href="css/main.css" type="text/css" media="screen" />

	
</head>
<body>
	<div id="app">
		<h1>NINE - SVG (snap.js) + Vue.js + Deepstream</h1>
	
		
		<div class="group connectionState">
		     Connection-State is: <em id="connection-state">{{connectionState}}</em>
		   </div>
		   <my-record :ds="ds"></my-record>
		
		
	</div>
	
	<script>
		// Start of VUE + deepstream
	
const Record = {
    
    template:'',
    props: ['ds'],
    data: function() {
        return {
         xpos:'',
         ypos:'',
        }
    },
    created: function() {
      
        this.record = this.ds.record.getRecord('vue_nine/datarecord_nine');

        this.record.subscribe(values => {
           this.xpos = values.positionData.xpos;
           this.ypos = values.positionData.ypos;
           
        })
    },
    
            methods: {
                               
                  handlePOSUpdate: function() {
                      this.record.set({
                        positionData: {
                          xpos: this.xpos,
                          ypos: this.ypos
                        },
                                     	
                      });
                  },
                       
               	
           
            }
    
    
};

		
	 new Vue({
	        el: '#app',
	        components: {
	          'my-record': Record,
	                      },
	        data: {
	          ds: null,
	          connectionState: 'INITIAL'
	        },
	        created: function() {
	            this.ds = deepstream('wss://154.deepstreamhub.com?apiKey=0c6811b0-afa5-40df-93c8-c71d6f1cc0b5')
	            .login()
	            .on('connectionStateChanged', connectionState => {
	               this.connectionState =  connectionState;
	            });
	        },
	        methods: {
	          
	        }
	  })

// Start of SNAP SVG Animation
		  var lx = 0, ly = 0, ox = 0, oy = 0;
		  var thisBox;

		  
		  moveFnc = function(dx, dy, x, y) {
		     thisBox = this.getBBox();
		     
		      lx = dx + ox;
		      ly = dy + oy;
		      this.transform('t' + lx + ',' + ly);
				      
		  }
		  
		  startFnc = function(x, y, e) {  
		  
		  }
		  		  
		  endFnc = function() {
		      ox = lx;
		      oy = ly;  
		      handlePOSUpdate();  
		  };
		
		
		var s = Snap();
		var sheet = s.rect(10, 10, 50, 65);
	
		sheet.attr({
			fill:"#bada55",
			stroke:"#000",
			strokeWidth: 3
		});
		
			
		sheet.drag(moveFnc, startFnc, endFnc);
		
	// end of SNAP	
	
		
	</script>

 </body>
</html>