我需要关于Annotator.js的例子

时间:2015-08-11 14:30:45

标签: javascript

如何使用Annotator脚本? 简单的例子 创建,更新,删除,检索。

$('#content').annotator('addPlugin', 'Store', {
  urls: {
    // These are the default URLs.
    create:  '/annotations',
    update:  '/annotations/:id',
    destroy: '/annotations/:id',
    search:  '/search'
  }
}):

1 个答案:

答案 0 :(得分:4)

这个例子展示了如何使用Annotator.js以及如何将它与两个插件相关联,"离线"和"触摸",用于永久离线存储注释并使其在触摸设备上工作:

<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8 />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Annotator Touch Plugin</title>
  <link rel="stylesheet" href="annotator.min.css" />
  <link rel="stylesheet" href="annotator.touch.css" />
  <style>body { font-size: 1.6em }</style>
</head>
<body>
<p>Current Connectivity: <span id="status"></span></p>
  <p><button id="clear-storage">Clear LocalStorage</button></p>
  <div id="content">
    <p>One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked.</p>

    <p>"What's happened to me?" he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer.</p>

    <p>Gregor then turned to look out the window at the dull weather. Drops of rain could be heard hitting the pane, which made him feel quite sad. "How about if I sleep a little bit longer and forget all this nonsense", he thought, but that was something he was unable to do because he was used to sleeping on his right, and in his present state couldn't get into that position. However hard he threw himself onto his right, he always rolled back to where he was. He must have tried it a hundred times, shut his eyes so that he wouldn't have to look at the floundering legs, and only stopped when he began to feel a mild, dull pain there that he had never felt before.</p>
  </div>
  <script src="jquery.js"></script>
  <script src="highlighter.js"></script>
  <script src="annotator-full.min.js"></script>
  <script src="annotator.touch.min.js"></script>
  <script src="annotator.offline.min.js"></script>
  <script>
    jQuery("#content").annotator().annotator('addPlugin', 'Touch', {
      force: location.search.indexOf('force') > -1,
      useHighlighter: location.search.indexOf('highlighter') > -1
    });

    jQuery("#content").annotator().annotator('addPlugin', 'Offline', {
      online:  function () {
        jQuery("#status").text("Online");
      },
      offline: function () {
        jQuery("#status").text("Offline");
      }    });

    jQuery("#clear-storage").click(function () {
      if (annotator) {
        annotator.plugins.Offline.store.clear()
      }
    });

    if (!Annotator.Plugin.Touch.isTouchDevice()) {
      if (location.search.indexOf('force') > -1) {
        jQuery("body").prepend('<p><a href="./index.html">Disable Plugin in Desktop Browser</a></p>');
      } else {
        jQuery("body").prepend('<p><a href="./index.html?force">Enable Plugin in Desktop Browser</a></p>');
      }
    }

    var annotator = jQuery("#content").data('annotator');
  </script>
</body>
</html>

请注意,所有这些文件必须存在于同一文件夹中:

CSS:

  • annotator.min.css
  • annotator.touch.css

JS:

  • jquery.js
  • highlighter.js
  • annotator-full.min.js
  • annotator.touch.min.js
  • annotator.offline.min.js

(highlighter.js位于annotator.touch插件的VENDOR文件夹中)