comparison annotator_files/lib/plugin/tags.js @ 4:6979313586cf

new version of annotator.
author casties
date Mon, 27 Aug 2012 19:05:38 +0200
parents 6356e78ccf5c
children
comparison
equal deleted inserted replaced
3:6356e78ccf5c 4:6979313586cf
1 // Generated by CoffeeScript 1.3.3
1 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 2 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
2 __hasProp = Object.prototype.hasOwnProperty, 3 __hasProp = {}.hasOwnProperty,
3 __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; }; 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; };
4 5
5 Annotator.Plugin.Tags = (function(_super) { 6 Annotator.Plugin.Tags = (function(_super) {
6 7
7 __extends(Tags, _super); 8 __extends(Tags, _super);
8 9
9 function Tags() { 10 function Tags() {
10 this.setAnnotationTags = __bind(this.setAnnotationTags, this); 11 this.setAnnotationTags = __bind(this.setAnnotationTags, this);
12
11 this.updateField = __bind(this.updateField, this); 13 this.updateField = __bind(this.updateField, this);
12 Tags.__super__.constructor.apply(this, arguments); 14 return Tags.__super__.constructor.apply(this, arguments);
13 } 15 }
14 16
15 Tags.prototype.options = { 17 Tags.prototype.options = {
16 parseTags: function(string) { 18 parseTags: function(string) {
17 var tags; 19 var tags;
18 string = $.trim(string); 20 string = $.trim(string);
19 tags = []; 21 tags = [];
20 if (string) tags = string.split(/\s+/); 22 if (string) {
23 tags = string.split(/\s+/);
24 }
21 return tags; 25 return tags;
22 }, 26 },
23 stringifyTags: function(array) { 27 stringifyTags: function(array) {
24 return array.join(" "); 28 return array.join(" ");
25 } 29 }
28 Tags.prototype.field = null; 32 Tags.prototype.field = null;
29 33
30 Tags.prototype.input = null; 34 Tags.prototype.input = null;
31 35
32 Tags.prototype.pluginInit = function() { 36 Tags.prototype.pluginInit = function() {
33 if (!Annotator.supported()) return; 37 if (!Annotator.supported()) {
38 return;
39 }
34 this.field = this.annotator.editor.addField({ 40 this.field = this.annotator.editor.addField({
35 label: Annotator._t('Add some tags here') + '\u2026', 41 label: Annotator._t('Add some tags here') + '\u2026',
36 load: this.updateField, 42 load: this.updateField,
37 submit: this.setAnnotationTags 43 submit: this.setAnnotationTags
38 }); 44 });
58 }; 64 };
59 65
60 Tags.prototype.updateField = function(field, annotation) { 66 Tags.prototype.updateField = function(field, annotation) {
61 var value; 67 var value;
62 value = ''; 68 value = '';
63 if (annotation.tags) value = this.stringifyTags(annotation.tags); 69 if (annotation.tags) {
70 value = this.stringifyTags(annotation.tags);
71 }
64 return this.input.val(value); 72 return this.input.val(value);
65 }; 73 };
66 74
67 Tags.prototype.setAnnotationTags = function(field, annotation) { 75 Tags.prototype.setAnnotationTags = function(field, annotation) {
68 return annotation.tags = this.parseTags(this.input.val()); 76 return annotation.tags = this.parseTags(this.input.val());
85 return Tags; 93 return Tags;
86 94
87 })(Annotator.Plugin); 95 })(Annotator.Plugin);
88 96
89 Annotator.Plugin.Tags.filterCallback = function(input, tags) { 97 Annotator.Plugin.Tags.filterCallback = function(input, tags) {
90 var keyword, keywords, matches, tag, _i, _j, _len, _len2; 98 var keyword, keywords, matches, tag, _i, _j, _len, _len1;
91 if (tags == null) tags = []; 99 if (tags == null) {
100 tags = [];
101 }
92 matches = 0; 102 matches = 0;
93 keywords = []; 103 keywords = [];
94 if (input) { 104 if (input) {
95 keywords = input.split(/\s+/g); 105 keywords = input.split(/\s+/g);
96 for (_i = 0, _len = keywords.length; _i < _len; _i++) { 106 for (_i = 0, _len = keywords.length; _i < _len; _i++) {
97 keyword = keywords[_i]; 107 keyword = keywords[_i];
98 if (tags.length) { 108 if (tags.length) {
99 for (_j = 0, _len2 = tags.length; _j < _len2; _j++) { 109 for (_j = 0, _len1 = tags.length; _j < _len1; _j++) {
100 tag = tags[_j]; 110 tag = tags[_j];
101 if (tag.indexOf(keyword) !== -1) matches += 1; 111 if (tag.indexOf(keyword) !== -1) {
112 matches += 1;
113 }
102 } 114 }
103 } 115 }
104 } 116 }
105 } 117 }
106 return matches === keywords.length; 118 return matches === keywords.length;