Mercurial > hg > OKFNAnnotator
diff 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 |
line wrap: on
line diff
--- a/annotator_files/lib/plugin/filter.js Thu Apr 05 19:37:27 2012 +0200 +++ b/annotator_files/lib/plugin/filter.js Mon Aug 27 19:05:38 2012 +0200 @@ -1,6 +1,7 @@ +// Generated by CoffeeScript 1.3.3 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = Object.prototype.hasOwnProperty, - __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; }; + __hasProp = {}.hasOwnProperty, + __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; }; Annotator.Plugin.Filter = (function(_super) { @@ -34,11 +35,15 @@ addAnnotationFilter: true, isFiltered: function(input, property) { var keyword, _i, _len, _ref; - if (!(input && property)) return false; + if (!(input && property)) { + return false; + } _ref = input.split(/\s*/); for (_i = 0, _len = _ref.length; _i < _len; _i++) { keyword = _ref[_i]; - if (property.indexOf(keyword) === -1) return false; + if (property.indexOf(keyword) === -1) { + return false; + } } return true; } @@ -46,12 +51,21 @@ function Filter(element, options) { this._onPreviousClick = __bind(this._onPreviousClick, this); + this._onNextClick = __bind(this._onNextClick, this); + this._onFilterKeyup = __bind(this._onFilterKeyup, this); + this._onFilterBlur = __bind(this._onFilterBlur, this); + this._onFilterFocus = __bind(this._onFilterFocus, this); - this.updateHighlights = __bind(this.updateHighlights, this); element = $(this.html.element).appendTo(this.options.appendTo); + + this.updateHighlights = __bind(this.updateHighlights, this); + + var _base; + element = $(this.html.element).appendTo((options != null ? options.appendTo : void 0) || this.options.appendTo); Filter.__super__.constructor.call(this, element, options); + (_base = this.options).filters || (_base.filters = []); this.filter = $(this.html.filter); this.filters = []; this.current = 0; @@ -105,7 +119,9 @@ _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { f = _ref[_i]; - if (f.property === filter.property) _results.push(f); + if (f.property === filter.property) { + _results.push(f); + } } return _results; }).call(this)).length) { @@ -152,7 +168,7 @@ }; Filter.prototype.filterHighlights = function() { - var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _len, _ref; + var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _i, _len, _ref; activeFilters = $.grep(this.filters, function(filter) { return !!filter.annotations.length; }); @@ -173,7 +189,7 @@ }); } highlights = this.highlights; - for (index = 0, _len = filtered.length; index < _len; index++) { + for (index = _i = 0, _len = filtered.length; _i < _len; index = ++_i) { annotation = filtered[index]; highlights = highlights.not(annotation.highlights); } @@ -207,22 +223,30 @@ Filter.prototype._onFilterKeyup = function(event) { var filter; filter = $(event.target).parent().data('filter'); - if (filter) return this.updateFilter(filter); + if (filter) { + return this.updateFilter(filter); + } }; Filter.prototype._findNextHighlight = function(previous) { var active, annotation, current, index, next, offset, operator, resetOffset; - if (!this.highlights.length) return this; + if (!this.highlights.length) { + return this; + } offset = previous ? 0 : -1; resetOffset = previous ? -1 : 0; operator = previous ? 'lt' : 'gt'; active = this.highlights.not('.' + this.classes.hl.hide); current = active.filter('.' + this.classes.hl.active); - if (!current.length) current = active.eq(offset); + if (!current.length) { + current = active.eq(offset); + } annotation = current.data('annotation'); index = active.index(current[0]); next = active.filter(":" + operator + "(" + index + ")").not(annotation.highlights).eq(resetOffset); - if (!next.length) next = active.eq(resetOffset); + if (!next.length) { + next = active.eq(resetOffset); + } return this._scrollToHighlight(next.data('annotation').highlights); };