example.html 2.34 KB
Newer Older
Tristan Cavelier's avatar
Tristan Cavelier committed
1 2 3 4 5 6 7 8 9 10
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jIO Example</title>
</head>
<body>
  <script type="text/javascript">
    <!--
var log = function (o) {
Tristan Cavelier's avatar
Tristan Cavelier committed
11 12 13
  var node = document.createElement ('div');
  node.textContent = o;
  document.getElementById('log').appendChild(node);
Tristan Cavelier's avatar
Tristan Cavelier committed
14 15 16 17 18
};
        //-->
  </script>
  <div id="log">
  </div>
Tristan Cavelier's avatar
Tristan Cavelier committed
19
  <script type="text/javascript" src="../lib/md5/md5.js"></script>
Tristan Cavelier's avatar
Tristan Cavelier committed
20
  <script type="text/javascript" src="../jio.js"></script>
Tristan Cavelier's avatar
Tristan Cavelier committed
21 22
  <script type="text/javascript" src="../src/jio.storage/localstorage.js">
  </script>
Tristan Cavelier's avatar
Tristan Cavelier committed
23 24 25
  <script type="text/javascript" src="../lib/jquery/jquery.min.js"></script>
  <script type="text/javascript">
    <!--
Tristan Cavelier's avatar
Tristan Cavelier committed
26
var jio_instance = null;
Tristan Cavelier's avatar
Tristan Cavelier committed
27

Tristan Cavelier's avatar
Tristan Cavelier committed
28 29
log('Welcome to the jIO example.html!')
log('-> Create jIO instance');
Tristan Cavelier's avatar
Tristan Cavelier committed
30

Tristan Cavelier's avatar
Tristan Cavelier committed
31 32 33 34
jio_instance = jIO.newJio({
  "type": 'local',
  "username": 'jIOtest',
  "applicationname": 'example'
Tristan Cavelier's avatar
Tristan Cavelier committed
35 36
});

Tristan Cavelier's avatar
Tristan Cavelier committed
37 38 39 40 41 42 43 44 45 46 47 48
// Careful! These are asynchronous methods!
log('-> post "video" document metadata to localStorage');

jio_instance.post({
  "_id": 'video',
  "title": 'My Video Title',
  "codec": 'vorbis',
  "language": 'en',
  "description": 'Image compilation'
}, function (response) {

  log('-> put "thumbnail" attachment to localStorage');
Tristan Cavelier's avatar
Tristan Cavelier committed
49

Tristan Cavelier's avatar
Tristan Cavelier committed
50 51 52 53 54 55
  jio_instance.putAttachment({
    "_id": "video",
    "_attachment": "thumb.jpg",
    "_data": "BASE64DATA",
    "_mimetype": 'image/jpeg'
  }, function (response) {
Tristan Cavelier's avatar
Tristan Cavelier committed
56

Tristan Cavelier's avatar
Tristan Cavelier committed
57
    log('-> put "video" attachment to localStorage');
Tristan Cavelier's avatar
Tristan Cavelier committed
58

Tristan Cavelier's avatar
Tristan Cavelier committed
59 60 61 62 63 64 65
    jio_instance.putAttachment({
      "_id":"video",
      "_attachment": "myvideo.ogg",
      "_data": "BASE64DATATOO",
      "_mimetype":'video/ogg'
    }, function (val) {
      log('Done! Refresh the page to see get and remove command.');
Tristan Cavelier's avatar
Tristan Cavelier committed
66
    }, function (err) {
Tristan Cavelier's avatar
Tristan Cavelier committed
67
      log('Error! '+ err.reason);
Tristan Cavelier's avatar
Tristan Cavelier committed
68 69
    });

Tristan Cavelier's avatar
Tristan Cavelier committed
70 71 72 73
  }, function (err) {
    log('Error! ' + err.reason);
  });

Tristan Cavelier's avatar
Tristan Cavelier committed
74
}, function (err) {
Tristan Cavelier's avatar
Tristan Cavelier committed
75

Tristan Cavelier's avatar
Tristan Cavelier committed
76 77 78 79
  log('Error! ' + err.reason);
  log('-> get "video" document metadata from localStorage');

  jio_instance.get('video', function (val) {
Tristan Cavelier's avatar
Tristan Cavelier committed
80

Tristan Cavelier's avatar
Tristan Cavelier committed
81 82
    log('Title is: "' + val["title"] + '"');
    log('-> remove "video" document from localStorage');
Tristan Cavelier's avatar
Tristan Cavelier committed
83

Tristan Cavelier's avatar
Tristan Cavelier committed
84 85
    jio_instance.remove({"_id":'video'}, function (val) {
      log('Done! Refresh the page to see post and putAttachment command.');
Tristan Cavelier's avatar
Tristan Cavelier committed
86
    }, function (err) {
Tristan Cavelier's avatar
Tristan Cavelier committed
87
      log('Error! ' + err.reason);
Tristan Cavelier's avatar
Tristan Cavelier committed
88
    });
Tristan Cavelier's avatar
Tristan Cavelier committed
89

Tristan Cavelier's avatar
Tristan Cavelier committed
90 91 92 93
  }, function (err) {
    log('Error! ' + err.reason);
  });

Tristan Cavelier's avatar
Tristan Cavelier committed
94 95
});

Tristan Cavelier's avatar
Tristan Cavelier committed
96 97 98 99
        //-->
  </script>
</body>
</html>