source: OKFNAnnotator (for Zope)/annotator_files/lib/plugin/tags.js @ 4:6979313586cf

Last change on this file since 4:6979313586cf was 4:6979313586cf, checked in by casties, 12 years ago

new version of annotator.

File size: 3.3 KB
Line 
1// Generated by CoffeeScript 1.3.3
2var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
3  __hasProp = {}.hasOwnProperty,
4  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
5
6Annotator.Plugin.Tags = (function(_super) {
7
8  __extends(Tags, _super);
9
10  function Tags() {
11    this.setAnnotationTags = __bind(this.setAnnotationTags, this);
12
13    this.updateField = __bind(this.updateField, this);
14    return Tags.__super__.constructor.apply(this, arguments);
15  }
16
17  Tags.prototype.options = {
18    parseTags: function(string) {
19      var tags;
20      string = $.trim(string);
21      tags = [];
22      if (string) {
23        tags = string.split(/\s+/);
24      }
25      return tags;
26    },
27    stringifyTags: function(array) {
28      return array.join(" ");
29    }
30  };
31
32  Tags.prototype.field = null;
33
34  Tags.prototype.input = null;
35
36  Tags.prototype.pluginInit = function() {
37    if (!Annotator.supported()) {
38      return;
39    }
40    this.field = this.annotator.editor.addField({
41      label: Annotator._t('Add some tags here') + '\u2026',
42      load: this.updateField,
43      submit: this.setAnnotationTags
44    });
45    this.annotator.viewer.addField({
46      load: this.updateViewer
47    });
48    if (this.annotator.plugins.Filter) {
49      this.annotator.plugins.Filter.addFilter({
50        label: Annotator._t('Tag'),
51        property: 'tags',
52        isFiltered: Annotator.Plugin.Tags.filterCallback
53      });
54    }
55    return this.input = $(this.field).find(':input');
56  };
57
58  Tags.prototype.parseTags = function(string) {
59    return this.options.parseTags(string);
60  };
61
62  Tags.prototype.stringifyTags = function(array) {
63    return this.options.stringifyTags(array);
64  };
65
66  Tags.prototype.updateField = function(field, annotation) {
67    var value;
68    value = '';
69    if (annotation.tags) {
70      value = this.stringifyTags(annotation.tags);
71    }
72    return this.input.val(value);
73  };
74
75  Tags.prototype.setAnnotationTags = function(field, annotation) {
76    return annotation.tags = this.parseTags(this.input.val());
77  };
78
79  Tags.prototype.updateViewer = function(field, annotation) {
80    field = $(field);
81    if (annotation.tags && $.isArray(annotation.tags) && annotation.tags.length) {
82      return field.addClass('annotator-tags').html(function() {
83        var string;
84        return string = $.map(annotation.tags, function(tag) {
85          return '<span class="annotator-tag">' + Annotator.$.escape(tag) + '</span>';
86        }).join(' ');
87      });
88    } else {
89      return field.remove();
90    }
91  };
92
93  return Tags;
94
95})(Annotator.Plugin);
96
97Annotator.Plugin.Tags.filterCallback = function(input, tags) {
98  var keyword, keywords, matches, tag, _i, _j, _len, _len1;
99  if (tags == null) {
100    tags = [];
101  }
102  matches = 0;
103  keywords = [];
104  if (input) {
105    keywords = input.split(/\s+/g);
106    for (_i = 0, _len = keywords.length; _i < _len; _i++) {
107      keyword = keywords[_i];
108      if (tags.length) {
109        for (_j = 0, _len1 = tags.length; _j < _len1; _j++) {
110          tag = tags[_j];
111          if (tag.indexOf(keyword) !== -1) {
112            matches += 1;
113          }
114        }
115      }
116    }
117  }
118  return matches === keywords.length;
119};
Note: See TracBrowser for help on using the repository browser.