Mercurial > hg > OKFNAnnotator
comparison annotator_files/lib/plugin/filter.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.Filter = (function(_super) { | 6 Annotator.Plugin.Filter = (function(_super) { |
6 | 7 |
7 __extends(Filter, _super); | 8 __extends(Filter, _super); |
8 | 9 |
32 appendTo: 'body', | 33 appendTo: 'body', |
33 filters: [], | 34 filters: [], |
34 addAnnotationFilter: true, | 35 addAnnotationFilter: true, |
35 isFiltered: function(input, property) { | 36 isFiltered: function(input, property) { |
36 var keyword, _i, _len, _ref; | 37 var keyword, _i, _len, _ref; |
37 if (!(input && property)) return false; | 38 if (!(input && property)) { |
39 return false; | |
40 } | |
38 _ref = input.split(/\s*/); | 41 _ref = input.split(/\s*/); |
39 for (_i = 0, _len = _ref.length; _i < _len; _i++) { | 42 for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
40 keyword = _ref[_i]; | 43 keyword = _ref[_i]; |
41 if (property.indexOf(keyword) === -1) return false; | 44 if (property.indexOf(keyword) === -1) { |
45 return false; | |
46 } | |
42 } | 47 } |
43 return true; | 48 return true; |
44 } | 49 } |
45 }; | 50 }; |
46 | 51 |
47 function Filter(element, options) { | 52 function Filter(element, options) { |
48 this._onPreviousClick = __bind(this._onPreviousClick, this); | 53 this._onPreviousClick = __bind(this._onPreviousClick, this); |
54 | |
49 this._onNextClick = __bind(this._onNextClick, this); | 55 this._onNextClick = __bind(this._onNextClick, this); |
56 | |
50 this._onFilterKeyup = __bind(this._onFilterKeyup, this); | 57 this._onFilterKeyup = __bind(this._onFilterKeyup, this); |
58 | |
51 this._onFilterBlur = __bind(this._onFilterBlur, this); | 59 this._onFilterBlur = __bind(this._onFilterBlur, this); |
60 | |
52 this._onFilterFocus = __bind(this._onFilterFocus, this); | 61 this._onFilterFocus = __bind(this._onFilterFocus, this); |
53 this.updateHighlights = __bind(this.updateHighlights, this); element = $(this.html.element).appendTo(this.options.appendTo); | 62 |
63 this.updateHighlights = __bind(this.updateHighlights, this); | |
64 | |
65 var _base; | |
66 element = $(this.html.element).appendTo((options != null ? options.appendTo : void 0) || this.options.appendTo); | |
54 Filter.__super__.constructor.call(this, element, options); | 67 Filter.__super__.constructor.call(this, element, options); |
68 (_base = this.options).filters || (_base.filters = []); | |
55 this.filter = $(this.html.filter); | 69 this.filter = $(this.html.filter); |
56 this.filters = []; | 70 this.filters = []; |
57 this.current = 0; | 71 this.current = 0; |
58 } | 72 } |
59 | 73 |
103 var _i, _len, _ref, _results; | 117 var _i, _len, _ref, _results; |
104 _ref = this.filters; | 118 _ref = this.filters; |
105 _results = []; | 119 _results = []; |
106 for (_i = 0, _len = _ref.length; _i < _len; _i++) { | 120 for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
107 f = _ref[_i]; | 121 f = _ref[_i]; |
108 if (f.property === filter.property) _results.push(f); | 122 if (f.property === filter.property) { |
123 _results.push(f); | |
124 } | |
109 } | 125 } |
110 return _results; | 126 return _results; |
111 }).call(this)).length) { | 127 }).call(this)).length) { |
112 filter.id = 'annotator-filter-' + filter.property; | 128 filter.id = 'annotator-filter-' + filter.property; |
113 filter.annotations = []; | 129 filter.annotations = []; |
150 this.highlights = this.annotator.element.find('.annotator-hl:visible'); | 166 this.highlights = this.annotator.element.find('.annotator-hl:visible'); |
151 return this.filtered = this.highlights.not(this.classes.hl.hide); | 167 return this.filtered = this.highlights.not(this.classes.hl.hide); |
152 }; | 168 }; |
153 | 169 |
154 Filter.prototype.filterHighlights = function() { | 170 Filter.prototype.filterHighlights = function() { |
155 var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _len, _ref; | 171 var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _i, _len, _ref; |
156 activeFilters = $.grep(this.filters, function(filter) { | 172 activeFilters = $.grep(this.filters, function(filter) { |
157 return !!filter.annotations.length; | 173 return !!filter.annotations.length; |
158 }); | 174 }); |
159 filtered = ((_ref = activeFilters[0]) != null ? _ref.annotations : void 0) || []; | 175 filtered = ((_ref = activeFilters[0]) != null ? _ref.annotations : void 0) || []; |
160 if (activeFilters.length > 1) { | 176 if (activeFilters.length > 1) { |
171 return filtered.push(this); | 187 return filtered.push(this); |
172 } | 188 } |
173 }); | 189 }); |
174 } | 190 } |
175 highlights = this.highlights; | 191 highlights = this.highlights; |
176 for (index = 0, _len = filtered.length; index < _len; index++) { | 192 for (index = _i = 0, _len = filtered.length; _i < _len; index = ++_i) { |
177 annotation = filtered[index]; | 193 annotation = filtered[index]; |
178 highlights = highlights.not(annotation.highlights); | 194 highlights = highlights.not(annotation.highlights); |
179 } | 195 } |
180 highlights.addClass(this.classes.hl.hide); | 196 highlights.addClass(this.classes.hl.hide); |
181 this.filtered = this.highlights.not(this.classes.hl.hide); | 197 this.filtered = this.highlights.not(this.classes.hl.hide); |
205 }; | 221 }; |
206 | 222 |
207 Filter.prototype._onFilterKeyup = function(event) { | 223 Filter.prototype._onFilterKeyup = function(event) { |
208 var filter; | 224 var filter; |
209 filter = $(event.target).parent().data('filter'); | 225 filter = $(event.target).parent().data('filter'); |
210 if (filter) return this.updateFilter(filter); | 226 if (filter) { |
227 return this.updateFilter(filter); | |
228 } | |
211 }; | 229 }; |
212 | 230 |
213 Filter.prototype._findNextHighlight = function(previous) { | 231 Filter.prototype._findNextHighlight = function(previous) { |
214 var active, annotation, current, index, next, offset, operator, resetOffset; | 232 var active, annotation, current, index, next, offset, operator, resetOffset; |
215 if (!this.highlights.length) return this; | 233 if (!this.highlights.length) { |
234 return this; | |
235 } | |
216 offset = previous ? 0 : -1; | 236 offset = previous ? 0 : -1; |
217 resetOffset = previous ? -1 : 0; | 237 resetOffset = previous ? -1 : 0; |
218 operator = previous ? 'lt' : 'gt'; | 238 operator = previous ? 'lt' : 'gt'; |
219 active = this.highlights.not('.' + this.classes.hl.hide); | 239 active = this.highlights.not('.' + this.classes.hl.hide); |
220 current = active.filter('.' + this.classes.hl.active); | 240 current = active.filter('.' + this.classes.hl.active); |
221 if (!current.length) current = active.eq(offset); | 241 if (!current.length) { |
242 current = active.eq(offset); | |
243 } | |
222 annotation = current.data('annotation'); | 244 annotation = current.data('annotation'); |
223 index = active.index(current[0]); | 245 index = active.index(current[0]); |
224 next = active.filter(":" + operator + "(" + index + ")").not(annotation.highlights).eq(resetOffset); | 246 next = active.filter(":" + operator + "(" + index + ")").not(annotation.highlights).eq(resetOffset); |
225 if (!next.length) next = active.eq(resetOffset); | 247 if (!next.length) { |
248 next = active.eq(resetOffset); | |
249 } | |
226 return this._scrollToHighlight(next.data('annotation').highlights); | 250 return this._scrollToHighlight(next.data('annotation').highlights); |
227 }; | 251 }; |
228 | 252 |
229 Filter.prototype._onNextClick = function(event) { | 253 Filter.prototype._onNextClick = function(event) { |
230 return this._findNextHighlight(); | 254 return this._findNextHighlight(); |