changeset 4:6979313586cf

new version of annotator.
author casties
date Mon, 27 Aug 2012 19:05:38 +0200
parents 6356e78ccf5c
children 8365fc487252
files annotator_files/lib/annotator.js annotator_files/lib/class.js annotator_files/lib/console.js annotator_files/lib/editor.js annotator_files/lib/extensions.js annotator_files/lib/notification.js annotator_files/lib/plugin/annotateitpermissions.js annotator_files/lib/plugin/auth.js annotator_files/lib/plugin/filter.js annotator_files/lib/plugin/kitchensink.js annotator_files/lib/plugin/markdown.js annotator_files/lib/plugin/permissions.js annotator_files/lib/plugin/store.js annotator_files/lib/plugin/tags.js annotator_files/lib/plugin/unsupported.js annotator_files/lib/range.js annotator_files/lib/viewer.js annotator_files/lib/widget.js
diffstat 18 files changed, 576 insertions(+), 266 deletions(-) [+]
line wrap: on
line diff
--- a/annotator_files/lib/annotator.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/annotator.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,7 +1,8 @@
-var Annotator, util, _Annotator,
+// Generated by CoffeeScript 1.3.3
+var Annotator, g, util, _Annotator, _ref,
   __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; };
 
 util = {
   uuid: (function() {
@@ -16,6 +17,23 @@
       return this;
     })();
   },
+  maxZIndex: function($elements) {
+    var all, el;
+    all = (function() {
+      var _i, _len, _results;
+      _results = [];
+      for (_i = 0, _len = $elements.length; _i < _len; _i++) {
+        el = $elements[_i];
+        if ($(el).css('position') === 'static') {
+          _results.push(-1);
+        } else {
+          _results.push(parseInt($(el).css('z-index'), 10) || -1);
+        }
+      }
+      return _results;
+    })();
+    return Math.max.apply(Math, all);
+  },
   mousePosition: function(e, offsetEl) {
     var offset;
     offset = $(offsetEl).offset();
@@ -43,7 +61,6 @@
   };
 
   Annotator.prototype.html = {
-    hl: '<span class="annotator-hl"></span>',
     adder: '<div class="annotator-adder"><button>' + _t('Annotate') + '</button></div>',
     wrapper: '<div class="annotator-wrapper"></div>'
   };
@@ -68,29 +85,41 @@
 
   function Annotator(element, options) {
     this.onDeleteAnnotation = __bind(this.onDeleteAnnotation, this);
+
     this.onEditAnnotation = __bind(this.onEditAnnotation, this);
+
     this.onAdderClick = __bind(this.onAdderClick, this);
+
     this.onAdderMousedown = __bind(this.onAdderMousedown, this);
+
     this.onHighlightMouseover = __bind(this.onHighlightMouseover, this);
+
     this.checkForEndSelection = __bind(this.checkForEndSelection, this);
+
     this.checkForStartSelection = __bind(this.checkForStartSelection, this);
+
     this.clearViewerHideTimer = __bind(this.clearViewerHideTimer, this);
+
     this.startViewerHideTimer = __bind(this.startViewerHideTimer, this);
+
     this.showViewer = __bind(this.showViewer, this);
+
     this.onEditorSubmit = __bind(this.onEditorSubmit, this);
+
     this.onEditorHide = __bind(this.onEditorHide, this);
+
     this.showEditor = __bind(this.showEditor, this);
-    var name, src, _ref;
     Annotator.__super__.constructor.apply(this, arguments);
     this.plugins = {};
-    if (!Annotator.supported()) return this;
-    if (!this.options.readOnly) this._setupDocumentEvents();
+    if (!Annotator.supported()) {
+      return this;
+    }
+    if (!this.options.readOnly) {
+      this._setupDocumentEvents();
+    }
     this._setupWrapper()._setupViewer()._setupEditor();
-    _ref = this.html;
-    for (name in _ref) {
-      src = _ref[name];
-      if (name !== 'wrapper') this[name] = $(src).appendTo(this.wrapper).hide();
-    }
+    this._setupDynamicStyle();
+    this.adder = $(this.html.adder).appendTo(this.wrapper).hide();
   }
 
   Annotator.prototype._setupWrapper = function() {
@@ -146,6 +175,28 @@
     return this;
   };
 
+  Annotator.prototype._setupDynamicStyle = function() {
+    var max, sel, style, x;
+    style = $('#annotator-dynamic-style');
+    if (!style.length) {
+      style = $('<style id="annotator-dynamic-style"></style>').appendTo(document.head);
+    }
+    sel = '*' + ((function() {
+      var _i, _len, _ref, _results;
+      _ref = ['adder', 'outer', 'notice', 'filter'];
+      _results = [];
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+        x = _ref[_i];
+        _results.push(":not(.annotator-" + x + ")");
+      }
+      return _results;
+    })()).join('');
+    max = util.maxZIndex($(document.body).find(sel));
+    max = Math.max(max, 1000);
+    style.text([".annotator-adder, .annotator-outer, .annotator-notice {", "  z-index: " + (max + 20) + ";", "}", ".annotator-filter {", "  z-index: " + (max + 10) + ";", "}"].join("\n"));
+    return this;
+  };
+
   Annotator.prototype.getSelectedRanges = function() {
     var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _i, _len;
     selection = util.getGlobal().getSelection();
@@ -153,13 +204,15 @@
     rangesToIgnore = [];
     if (!selection.isCollapsed) {
       ranges = (function() {
-        var _ref, _results;
+        var _i, _ref, _results;
         _results = [];
-        for (i = 0, _ref = selection.rangeCount; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
+        for (i = _i = 0, _ref = selection.rangeCount; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
           r = selection.getRangeAt(i);
           browserRange = new Range.BrowserRange(r);
           normedRange = browserRange.normalize().limit(this.wrapper[0]);
-          if (normedRange === null) rangesToIgnore.push(r);
+          if (normedRange === null) {
+            rangesToIgnore.push(r);
+          }
           _results.push(normedRange);
         }
         return _results;
@@ -171,7 +224,9 @@
       selection.addRange(r);
     }
     return $.grep(ranges, function(range) {
-      if (range) selection.addRange(range.toRange());
+      if (range) {
+        selection.addRange(range.toRange());
+      }
       return range;
     });
   };
@@ -184,36 +239,40 @@
   };
 
   Annotator.prototype.setupAnnotation = function(annotation, fireEvents) {
-    var normed, normedRanges, r, sniffed, _i, _len;
-    if (fireEvents == null) fireEvents = true;
+    var normed, normedRanges, r, root, _i, _j, _len, _len1, _ref;
+    if (fireEvents == null) {
+      fireEvents = true;
+    }
+    root = this.wrapper[0];
     annotation.ranges || (annotation.ranges = this.selectedRanges);
-    normedRanges = (function() {
-      var _i, _len, _ref, _results;
-      _ref = annotation.ranges;
-      _results = [];
-      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-        r = _ref[_i];
-        if (!(r != null)) continue;
-        sniffed = Range.sniff(r);
-        _results.push(sniffed.normalize(this.wrapper[0]));
+    normedRanges = [];
+    _ref = annotation.ranges;
+    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+      r = _ref[_i];
+      try {
+        normedRanges.push(Range.sniff(r).normalize(root));
+      } catch (e) {
+        if (e instanceof Range.RangeError) {
+          this.publish('rangeNormalizeFail', [annotation, r, e]);
+        } else {
+          throw e;
+        }
       }
-      return _results;
-    }).call(this);
-    normedRanges = $.grep(normedRanges, function(range) {
-      return range !== null;
-    });
+    }
     annotation.quote = [];
     annotation.ranges = [];
     annotation.highlights = [];
-    for (_i = 0, _len = normedRanges.length; _i < _len; _i++) {
-      normed = normedRanges[_i];
+    for (_j = 0, _len1 = normedRanges.length; _j < _len1; _j++) {
+      normed = normedRanges[_j];
       annotation.quote.push($.trim(normed.text()));
       annotation.ranges.push(normed.serialize(this.wrapper[0], '.annotator-hl'));
       $.merge(annotation.highlights, this.highlightRange(normed));
     }
     annotation.quote = annotation.quote.join(' / ');
     $(annotation.highlights).data('annotation', annotation);
-    if (fireEvents) this.publish('annotationCreated', [annotation]);
+    if (fireEvents) {
+      this.publish('annotationCreated', [annotation]);
+    }
     return annotation;
   };
 
@@ -237,10 +296,14 @@
   Annotator.prototype.loadAnnotations = function(annotations) {
     var clone, loader,
       _this = this;
-    if (annotations == null) annotations = [];
+    if (annotations == null) {
+      annotations = [];
+    }
     loader = function(annList) {
       var n, now, _i, _len;
-      if (annList == null) annList = [];
+      if (annList == null) {
+        annList = [];
+      }
       now = annList.splice(0, 10);
       for (_i = 0, _len = now.length; _i < _len; _i++) {
         n = now[_i];
@@ -249,13 +312,15 @@
       if (annList.length > 0) {
         return setTimeout((function() {
           return loader(annList);
-        }), 1);
+        }), 10);
       } else {
         return _this.publish('annotationsLoaded', [clone]);
       }
     };
     clone = annotations.slice();
-    if (annotations.length) loader(annotations);
+    if (annotations.length) {
+      loader(annotations);
+    }
     return this;
   };
 
@@ -267,20 +332,37 @@
     }
   };
 
-  Annotator.prototype.highlightRange = function(normedRange) {
-    var node, white, _i, _len, _ref, _results;
+  Annotator.prototype.highlightRange = function(normedRange, cssClass) {
+    var hl, node, white, _i, _len, _ref, _results;
+    if (cssClass == null) {
+      cssClass = 'annotator-hl';
+    }
     white = /^\s*$/;
+    hl = $("<span class='" + cssClass + "'></span>");
     _ref = normedRange.textNodes();
     _results = [];
     for (_i = 0, _len = _ref.length; _i < _len; _i++) {
       node = _ref[_i];
       if (!white.test(node.nodeValue)) {
-        _results.push($(node).wrapAll(this.hl).parent().show()[0]);
+        _results.push($(node).wrapAll(hl).parent().show()[0]);
       }
     }
     return _results;
   };
 
+  Annotator.prototype.highlightRanges = function(normedRanges, cssClass) {
+    var highlights, r, _i, _len;
+    if (cssClass == null) {
+      cssClass = 'annotator-hl';
+    }
+    highlights = [];
+    for (_i = 0, _len = normedRanges.length; _i < _len; _i++) {
+      r = normedRanges[_i];
+      $.merge(highlights, this.highlightRange(r, cssClass));
+    }
+    return highlights;
+  };
+
   Annotator.prototype.addPlugin = function(name, options) {
     var klass, _base;
     if (this.plugins[name]) {
@@ -303,6 +385,7 @@
   Annotator.prototype.showEditor = function(annotation, location) {
     this.editor.element.css(location);
     this.editor.load(annotation);
+    this.publish('annotationEditorShown', [this.editor, annotation]);
     return this;
   };
 
@@ -347,13 +430,20 @@
   Annotator.prototype.checkForEndSelection = function(event) {
     var container, range, _i, _len, _ref;
     this.mouseIsDown = false;
-    if (this.ignoreMouseup) return;
+    if (this.ignoreMouseup) {
+      return;
+    }
     this.selectedRanges = this.getSelectedRanges();
     _ref = this.selectedRanges;
     for (_i = 0, _len = _ref.length; _i < _len; _i++) {
       range = _ref[_i];
       container = range.commonAncestor;
-      if (this.isAnnotator(container)) return;
+      if ($(container).hasClass('annotator-hl')) {
+        container = $(container).parents('[class^=annotator-hl]')[0];
+      }
+      if (this.isAnnotator(container)) {
+        return;
+      }
     }
     if (event && this.selectedRanges.length) {
       return this.adder.css(util.mousePosition(event, this.wrapper[0])).show();
@@ -369,7 +459,9 @@
   Annotator.prototype.onHighlightMouseover = function(event) {
     var annotations;
     this.clearViewerHideTimer();
-    if (this.mouseIsDown || this.viewer.isShown()) return false;
+    if (this.mouseIsDown || this.viewer.isShown()) {
+      return false;
+    }
     annotations = $(event.target).parents('.annotator-hl').andSelf().map(function() {
       return $(this).data("annotation");
     });
@@ -377,15 +469,41 @@
   };
 
   Annotator.prototype.onAdderMousedown = function(event) {
-    if (event != null) event.preventDefault();
+    if (event != null) {
+      event.preventDefault();
+    }
     return this.ignoreMouseup = true;
   };
 
   Annotator.prototype.onAdderClick = function(event) {
-    var position;
-    if (event != null) event.preventDefault();
+    var highlights, position, r, ranges;
+    if (event != null) {
+      event.preventDefault();
+    }
     position = this.adder.position();
     this.adder.hide();
+    if (this.selectedRanges && this.selectedRanges.length) {
+      ranges = (function() {
+        var _i, _len, _ref, _results;
+        _ref = this.selectedRanges;
+        _results = [];
+        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+          r = _ref[_i];
+          _results.push(Range.sniff(r).normalize());
+        }
+        return _results;
+      }).call(this);
+      highlights = this.highlightRanges(ranges, 'annotator-hl annotator-hl-temporary');
+      this.editor.element.one('hide', function() {
+        var h, _i, _len, _results;
+        _results = [];
+        for (_i = 0, _len = highlights.length; _i < _len; _i++) {
+          h = highlights[_i];
+          _results.push($(h).replaceWith(h.childNodes));
+        }
+        return _results;
+      });
+    }
     return this.showEditor(this.createAnnotation(), position);
   };
 
@@ -419,6 +537,20 @@
 
 })(Delegator);
 
+g = util.getGlobal();
+
+if (!(((_ref = g.document) != null ? _ref.evaluate : void 0) != null)) {
+  $.getScript('http://assets.annotateit.org/vendor/xpath.min.js');
+}
+
+if (!(g.getSelection != null)) {
+  $.getScript('http://assets.annotateit.org/vendor/ierange.min.js');
+}
+
+if (!(g.JSON != null)) {
+  $.getScript('http://assets.annotateit.org/vendor/json2.min.js');
+}
+
 Annotator.$ = $;
 
 Annotator.Delegator = Delegator;
--- a/annotator_files/lib/class.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/class.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,6 +1,7 @@
+// Generated by CoffeeScript 1.3.3
 var Delegator,
-  __slice = Array.prototype.slice,
-  __hasProp = Object.prototype.hasOwnProperty;
+  __slice = [].slice,
+  __hasProp = {}.hasOwnProperty;
 
 Delegator = (function() {
 
@@ -18,12 +19,12 @@
   }
 
   Delegator.prototype.addEvents = function() {
-    var event, functionName, sel, selector, _i, _ref, _ref2, _results;
+    var event, functionName, sel, selector, _i, _ref, _ref1, _results;
     _ref = this.events;
     _results = [];
     for (sel in _ref) {
       functionName = _ref[sel];
-      _ref2 = sel.split(' '), selector = 2 <= _ref2.length ? __slice.call(_ref2, 0, _i = _ref2.length - 1) : (_i = 0, []), event = _ref2[_i++];
+      _ref1 = sel.split(' '), selector = 2 <= _ref1.length ? __slice.call(_ref1, 0, _i = _ref1.length - 1) : (_i = 0, []), event = _ref1[_i++];
       _results.push(this.addEvent(selector.join(' '), event, functionName));
     }
     return _results;
@@ -36,7 +37,9 @@
       return _this[functionName].apply(_this, arguments);
     };
     isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === '';
-    if (isBlankSelector) bindTo = this.element;
+    if (isBlankSelector) {
+      bindTo = this.element;
+    }
     if (typeof bindTo === 'string') {
       this.element.delegate(bindTo, event, closure);
     } else {
--- a/annotator_files/lib/console.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/console.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,5 +1,6 @@
-var fn, functions, _i, _j, _len, _len2,
-  __slice = Array.prototype.slice;
+// Generated by CoffeeScript 1.3.3
+var fn, functions, _i, _j, _len, _len1,
+  __slice = [].slice;
 
 functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"];
 
@@ -9,7 +10,9 @@
       return console.log("GROUP: ", name);
     };
   }
-  if (!(console.groupCollapsed != null)) console.groupCollapsed = console.group;
+  if (!(console.groupCollapsed != null)) {
+    console.groupCollapsed = console.group;
+  }
   for (_i = 0, _len = functions.length; _i < _len; _i++) {
     fn = functions[_i];
     if (!(console[fn] != null)) {
@@ -20,7 +23,7 @@
   }
 } else {
   this.console = {};
-  for (_j = 0, _len2 = functions.length; _j < _len2; _j++) {
+  for (_j = 0, _len1 = functions.length; _j < _len1; _j++) {
     fn = functions[_j];
     this.console[fn] = function() {};
   }
--- a/annotator_files/lib/editor.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/editor.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.Editor = (function(_super) {
 
@@ -25,11 +26,17 @@
 
   function Editor(options) {
     this.onCancelButtonMouseover = __bind(this.onCancelButtonMouseover, this);
+
     this.processKeypress = __bind(this.processKeypress, this);
+
     this.submit = __bind(this.submit, this);
+
     this.load = __bind(this.load, this);
+
     this.hide = __bind(this.hide, this);
-    this.show = __bind(this.show, this);    Editor.__super__.constructor.call(this, $(this.html)[0], options);
+
+    this.show = __bind(this.show, this);
+    Editor.__super__.constructor.call(this, $(this.html)[0], options);
     this.fields = [];
     this.annotation = {};
   }
@@ -189,8 +196,12 @@
           directionY = editor.hasClass(classes.invert.y) ? 1 : -1;
           textarea.height(height + (diff.top * directionY));
           textarea.width(width + (diff.left * directionX));
-          if (textarea.outerHeight() !== height) mousedown.top = event.pageY;
-          if (textarea.outerWidth() !== width) mousedown.left = event.pageX;
+          if (textarea.outerHeight() !== height) {
+            mousedown.top = event.pageY;
+          }
+          if (textarea.outerWidth() !== width) {
+            mousedown.left = event.pageX;
+          }
         } else if (mousedown.element === controls[0]) {
           editor.css({
             top: parseInt(editor.css('top'), 10) + diff.top,
--- a/annotator_files/lib/extensions.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/extensions.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
 var $, gettext, _gettext, _ref, _t;
 
 gettext = null;
@@ -91,7 +92,7 @@
     elem = this;
     while (elem && elem.nodeType === 1 && elem !== relativeRoot) {
       idx = $(elem.parentNode).children(elem.tagName).index(elem) + 1;
-      idx = idx > 1 ? "[" + idx + "]" : "";
+      idx = "[" + idx + "]";
       path = "/" + elem.tagName.toLowerCase() + idx + path;
       elem = elem.parentNode;
     }
@@ -105,6 +106,10 @@
 };
 
 $.fn.escape = function(html) {
-  if (arguments.length) return this.html($.escape(html));
+  if (arguments.length) {
+    return this.html($.escape(html));
+  }
   return this.html();
 };
+
+$.fn.reverse = [].reverse;
--- a/annotator_files/lib/notification.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/notification.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,7 +1,8 @@
+// Generated by CoffeeScript 1.3.3
 var Annotator,
   __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 = Annotator || {};
 
@@ -25,11 +26,15 @@
 
   function Notification(options) {
     this.hide = __bind(this.hide, this);
-    this.show = __bind(this.show, this);    Notification.__super__.constructor.call(this, $(this.options.html).appendTo(document.body)[0], options);
+
+    this.show = __bind(this.show, this);
+    Notification.__super__.constructor.call(this, $(this.options.html).appendTo(document.body)[0], options);
   }
 
   Notification.prototype.show = function(message, status) {
-    if (status == null) status = Annotator.Notification.INFO;
+    if (status == null) {
+      status = Annotator.Notification.INFO;
+    }
     $(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message || "");
     setTimeout(this.hide, 5000);
     return this;
--- a/annotator_files/lib/plugin/annotateitpermissions.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/annotateitpermissions.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,12 +1,24 @@
+// 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; },
-  __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+  __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; },
+  __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
 
 Annotator.Plugin.AnnotateItPermissions = (function(_super) {
 
   __extends(AnnotateItPermissions, _super);
 
+  function AnnotateItPermissions() {
+    this._setAuthFromToken = __bind(this._setAuthFromToken, this);
+
+    this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
+
+    this.updatePermissionsField = __bind(this.updatePermissionsField, this);
+
+    this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
+    return AnnotateItPermissions.__super__.constructor.apply(this, arguments);
+  }
+
   AnnotateItPermissions.prototype.options = {
     showViewPermissionsCheckbox: true,
     showEditPermissionsCheckbox: true,
@@ -15,33 +27,34 @@
       authenticated: 'group:__authenticated__',
       consumer: 'group:__consumer__'
     },
-    userString: function(user) {
-      return user;
+    userId: function(user) {
+      return user.userId;
     },
-    userAuthorize: function(action, annotation, user, consumer) {
-      var action_field, permissions, _ref, _ref2, _ref3, _ref4;
+    userString: function(user) {
+      return user.userId;
+    },
+    userAuthorize: function(action, annotation, user) {
+      var action_field, permissions, _ref, _ref1, _ref2, _ref3;
       permissions = annotation.permissions || {};
       action_field = permissions[action] || [];
-      if (!(user && consumer)) {
-        return _ref = this.groups.world, __indexOf.call(action_field, _ref) >= 0;
-      } else {
-        if (_ref2 = this.groups.world, __indexOf.call(action_field, _ref2) >= 0) {
+      if (_ref = this.groups.world, __indexOf.call(action_field, _ref) >= 0) {
+        return true;
+      } else if ((user != null) && (user.userId != null) && (user.consumerKey != null)) {
+        if (user.userId === annotation.user && user.consumerKey === annotation.consumer) {
           return true;
-        } else if (user === annotation.user && consumer === annotation.consumer) {
+        } else if (_ref1 = this.groups.authenticated, __indexOf.call(action_field, _ref1) >= 0) {
           return true;
-        } else if (_ref3 = this.groups.authenticated, __indexOf.call(action_field, _ref3) >= 0) {
+        } else if (user.consumerKey === annotation.consumer && (_ref2 = this.groups.consumer, __indexOf.call(action_field, _ref2) >= 0)) {
           return true;
-        } else if (consumer === annotation.consumer && (_ref4 = this.groups.consumer, __indexOf.call(action_field, _ref4) >= 0)) {
+        } else if (user.consumerKey === annotation.consumer && (_ref3 = user.userId, __indexOf.call(action_field, _ref3) >= 0)) {
           return true;
-        } else if (consumer === annotation.consumer && __indexOf.call(action_field, user) >= 0) {
+        } else if (user.consumerKey === annotation.consumer && user.admin) {
           return true;
         } else {
           return false;
         }
       }
     },
-    user: '',
-    consumer: 'annotateit',
     permissions: {
       'read': ['group:__world__'],
       'update': [],
@@ -50,42 +63,24 @@
     }
   };
 
-  function AnnotateItPermissions(element, options) {
-    this._setAuthFromToken = __bind(this._setAuthFromToken, this);
-    this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
-    this.updatePermissionsField = __bind(this.updatePermissionsField, this);
-    this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);    AnnotateItPermissions.__super__.constructor.apply(this, arguments);
-    if (this.options.consumer) {
-      this.setConsumer(this.options.consumer);
-      delete this.options.consumer;
-    }
-  }
-
-  AnnotateItPermissions.prototype.setConsumer = function(consumer) {
-    return this.consumer = consumer;
-  };
-
-  AnnotateItPermissions.prototype.authorize = function(action, annotation, user, consumer) {
-    if (user === void 0) user = this.user;
-    if (consumer === void 0) consumer = this.consumer;
-    if (this.options.userAuthorize) {
-      return this.options.userAuthorize.call(this.options, action, annotation, user, consumer);
-    } else {
-      return true;
-    }
-  };
-
   AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) {
     AnnotateItPermissions.__super__.addFieldsToAnnotation.apply(this, arguments);
-    if (annotation && this.consumer) return annotation.consumer = this.consumer;
+    if (annotation && this.user) {
+      return annotation.consumer = this.user.consumerKey;
+    }
   };
 
   AnnotateItPermissions.prototype.updatePermissionsField = function(action, field, annotation) {
     var input;
     field = $(field).show();
     input = field.find('input').removeAttr('disabled');
-    if (!this.authorize('admin', annotation)) field.hide();
-    if (this.authorize(action, annotation || {}, '__nonexistentuser__')) {
+    if (!this.authorize('admin', annotation)) {
+      field.hide();
+    }
+    if (this.user && this.authorize(action, annotation || {}, {
+      userId: '__nonexistentuser__',
+      consumerKey: this.user.consumerKey
+    })) {
       return input.attr('checked', 'checked');
     } else {
       return input.removeAttr('checked');
@@ -94,7 +89,9 @@
 
   AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
     var dataKey;
-    if (!annotation.permissions) annotation.permissions = this.options.permissions;
+    if (!annotation.permissions) {
+      annotation.permissions = this.options.permissions;
+    }
     dataKey = type + '-permissions';
     if ($(field).find('input').is(':checked')) {
       return annotation.permissions[type] = [type === 'read' ? this.options.groups.world : this.options.groups.consumer];
@@ -104,8 +101,7 @@
   };
 
   AnnotateItPermissions.prototype._setAuthFromToken = function(token) {
-    AnnotateItPermissions.__super__._setAuthFromToken.apply(this, arguments);
-    return this.setConsumer(token.consumerKey);
+    return this.setUser(token);
   };
 
   return AnnotateItPermissions;
--- a/annotator_files/lib/plugin/auth.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/auth.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,6 +1,7 @@
+// Generated by CoffeeScript 1.3.3
 var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken,
-  __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; };
 
 createDateFromISO8601 = function(string) {
   var d, date, offset, regexp, time, _ref;
@@ -8,12 +9,24 @@
   d = string.match(new RegExp(regexp));
   offset = 0;
   date = new Date(d[1], 0, 1);
-  if (d[3]) date.setMonth(d[3] - 1);
-  if (d[5]) date.setDate(d[5]);
-  if (d[7]) date.setHours(d[7]);
-  if (d[8]) date.setMinutes(d[8]);
-  if (d[10]) date.setSeconds(d[10]);
-  if (d[12]) date.setMilliseconds(Number("0." + d[12]) * 1000);
+  if (d[3]) {
+    date.setMonth(d[3] - 1);
+  }
+  if (d[5]) {
+    date.setDate(d[5]);
+  }
+  if (d[7]) {
+    date.setHours(d[7]);
+  }
+  if (d[8]) {
+    date.setMinutes(d[8]);
+  }
+  if (d[10]) {
+    date.setSeconds(d[10]);
+  }
+  if (d[12]) {
+    date.setMilliseconds(Number("0." + d[12]) * 1000);
+  }
   if (d[14]) {
     offset = (Number(d[16]) * 60) + Number(d[17]);
     offset *= (_ref = d[15] === '-') != null ? _ref : {
@@ -36,7 +49,9 @@
     ac = 0;
     dec = "";
     tmp_arr = [];
-    if (!data) return data;
+    if (!data) {
+      return data;
+    }
     data += '';
     while (i < data.length) {
       h1 = b64.indexOf(data.charAt(i++));
@@ -60,10 +75,10 @@
 };
 
 base64UrlDecode = function(data) {
-  var i, m, _ref;
+  var i, m, _i, _ref;
   m = data.length % 4;
   if (m !== 0) {
-    for (i = 0, _ref = 4 - m; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
+    for (i = _i = 0, _ref = 4 - m; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
       data += '=';
     }
   }
@@ -175,12 +190,16 @@
   };
 
   Auth.prototype.withToken = function(callback) {
-    if (!(callback != null)) return;
+    if (!(callback != null)) {
+      return;
+    }
     if (this.haveValidToken()) {
       return callback(this._unsafeToken);
     } else {
       this.waitingForToken.push(callback);
-      if (!this.requestInProgress) return this.requestToken();
+      if (!this.requestInProgress) {
+        return this.requestToken();
+      }
     }
   };
 
--- 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);
   };
 
--- a/annotator_files/lib/plugin/kitchensink.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/kitchensink.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,13 +1,20 @@
-var __hasProp = Object.prototype.hasOwnProperty,
-  __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+// Generated by CoffeeScript 1.3.3
+var __hasProp = {}.hasOwnProperty,
+  __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
 
 Annotator.prototype.setupPlugins = function(config, options) {
   var name, opts, pluginConfig, plugins, uri, win, _i, _len, _results;
-  if (config == null) config = {};
-  if (options == null) options = {};
+  if (config == null) {
+    config = {};
+  }
+  if (options == null) {
+    options = {};
+  }
   win = util.getGlobal();
-  plugins = ['Unsupported', 'Auth', 'Tags', 'Filter', 'Store', 'Permissions'];
-  if (win.Showdown) plugins.push('Markdown');
+  plugins = ['Unsupported', 'Auth', 'Tags', 'Filter', 'Store', 'AnnotateItPermissions'];
+  if (win.Showdown) {
+    plugins.push('Markdown');
+  }
   uri = win.location.href.split(/#|\?/).shift() || '';
   pluginConfig = {
     Tags: {},
@@ -38,7 +45,9 @@
   for (name in options) {
     if (!__hasProp.call(options, name)) continue;
     opts = options[name];
-    if (__indexOf.call(plugins, name) < 0) plugins.push(name);
+    if (__indexOf.call(plugins, name) < 0) {
+      plugins.push(name);
+    }
   }
   $.extend(true, pluginConfig, options);
   _results = [];
--- a/annotator_files/lib/plugin/markdown.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/markdown.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.Markdown = (function(_super) {
 
@@ -11,7 +12,8 @@
   };
 
   function Markdown(element, options) {
-    this.updateTextField = __bind(this.updateTextField, this);    if ((typeof Showdown !== "undefined" && Showdown !== null ? Showdown.converter : void 0) != null) {
+    this.updateTextField = __bind(this.updateTextField, this);
+    if ((typeof Showdown !== "undefined" && Showdown !== null ? Showdown.converter : void 0) != null) {
       Markdown.__super__.constructor.apply(this, arguments);
       this.converter = new Showdown.converter();
     } else {
--- a/annotator_files/lib/plugin/permissions.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/permissions.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.Permissions = (function(_super) {
 
@@ -23,10 +24,14 @@
       var token, tokens, _i, _len;
       if (annotation.permissions) {
         tokens = annotation.permissions[action] || [];
-        if (tokens.length === 0) return true;
+        if (tokens.length === 0) {
+          return true;
+        }
         for (_i = 0, _len = tokens.length; _i < _len; _i++) {
           token = tokens[_i];
-          if (this.userId(user) === token) return true;
+          if (this.userId(user) === token) {
+            return true;
+          }
         }
         return false;
       } else if (annotation.user) {
@@ -45,10 +50,15 @@
 
   function Permissions(element, options) {
     this._setAuthFromToken = __bind(this._setAuthFromToken, this);
+
     this.updateViewer = __bind(this.updateViewer, this);
+
     this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
+
     this.updatePermissionsField = __bind(this.updatePermissionsField, this);
-    this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);    Permissions.__super__.constructor.apply(this, arguments);
+
+    this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
+    Permissions.__super__.constructor.apply(this, arguments);
     if (this.options.user) {
       this.setUser(this.options.user);
       delete this.options.user;
@@ -58,7 +68,9 @@
   Permissions.prototype.pluginInit = function() {
     var createCallback, self,
       _this = this;
-    if (!Annotator.supported()) return;
+    if (!Annotator.supported()) {
+      return;
+    }
     self = this;
     createCallback = function(method, type) {
       return function(field, annotation) {
@@ -94,11 +106,15 @@
         isFiltered: function(input, user) {
           var keyword, _i, _len, _ref;
           user = _this.options.userString(user);
-          if (!(input && user)) return false;
+          if (!(input && user)) {
+            return false;
+          }
           _ref = input.split(/\s*/);
           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
             keyword = _ref[_i];
-            if (user.indexOf(keyword) === -1) return false;
+            if (user.indexOf(keyword) === -1) {
+              return false;
+            }
           }
           return true;
         }
@@ -113,12 +129,16 @@
   Permissions.prototype.addFieldsToAnnotation = function(annotation) {
     if (annotation) {
       annotation.permissions = this.options.permissions;
-      if (this.user) return annotation.user = this.user;
+      if (this.user) {
+        return annotation.user = this.user;
+      }
     }
   };
 
   Permissions.prototype.authorize = function(action, annotation, user) {
-    if (user === void 0) user = this.user;
+    if (user === void 0) {
+      user = this.user;
+    }
     if (this.options.userAuthorize) {
       return this.options.userAuthorize.call(this.options, action, annotation, user);
     } else {
@@ -130,7 +150,9 @@
     var input;
     field = $(field).show();
     input = field.find('input').removeAttr('disabled');
-    if (!this.authorize('admin', annotation)) field.hide();
+    if (!this.authorize('admin', annotation)) {
+      field.hide();
+    }
     if (this.authorize(action, annotation || {}, null)) {
       return input.attr('checked', 'checked');
     } else {
@@ -140,7 +162,9 @@
 
   Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
     var dataKey;
-    if (!annotation.permissions) annotation.permissions = this.options.permissions;
+    if (!annotation.permissions) {
+      annotation.permissions = this.options.permissions;
+    }
     dataKey = type + '-permissions';
     if ($(field).find('input').is(':checked')) {
       return annotation.permissions[type] = [];
@@ -159,8 +183,12 @@
     } else {
       field.remove();
     }
-    if (!this.authorize('update', annotation)) controls.hideEdit();
-    if (!this.authorize('delete', annotation)) return controls.hideDelete();
+    if (!this.authorize('update', annotation)) {
+      controls.hideEdit();
+    }
+    if (!this.authorize('delete', annotation)) {
+      return controls.hideDelete();
+    }
   };
 
   Permissions.prototype._setAuthFromToken = function(token) {
--- a/annotator_files/lib/plugin/store.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/store.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,7 +1,8 @@
+// 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; },
-  __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+  __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; },
+  __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
 
 Annotator.Plugin.Store = (function(_super) {
 
@@ -29,14 +30,20 @@
 
   function Store(element, options) {
     this._onError = __bind(this._onError, this);
+
     this._onLoadAnnotationsFromSearch = __bind(this._onLoadAnnotationsFromSearch, this);
+
     this._onLoadAnnotations = __bind(this._onLoadAnnotations, this);
-    this._getAnnotations = __bind(this._getAnnotations, this);    Store.__super__.constructor.apply(this, arguments);
+
+    this._getAnnotations = __bind(this._getAnnotations, this);
+    Store.__super__.constructor.apply(this, arguments);
     this.annotations = [];
   }
 
   Store.prototype.pluginInit = function() {
-    if (!Annotator.supported()) return;
+    if (!Annotator.supported()) {
+      return;
+    }
     if (this.annotator.plugins.Auth) {
       return this.annotator.plugins.Auth.withToken(this._getAnnotations);
     } else {
@@ -107,7 +114,9 @@
   };
 
   Store.prototype._onLoadAnnotations = function(data) {
-    if (data == null) data = [];
+    if (data == null) {
+      data = [];
+    }
     this.annotations = data;
     return this.annotator.loadAnnotations(data.slice());
   };
@@ -117,7 +126,9 @@
   };
 
   Store.prototype._onLoadAnnotationsFromSearch = function(data) {
-    if (data == null) data = {};
+    if (data == null) {
+      data = {};
+    }
     return this._onLoadAnnotations(data.rows || []);
   };
 
@@ -192,7 +203,9 @@
     delete annotation.highlights;
     $.extend(annotation, this.options.annotationData);
     data = JSON.stringify(annotation);
-    if (highlights) annotation.highlights = highlights;
+    if (highlights) {
+      annotation.highlights = highlights;
+    }
     return data;
   };
 
--- a/annotator_files/lib/plugin/tags.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/tags.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.Tags = (function(_super) {
 
@@ -8,8 +9,9 @@
 
   function Tags() {
     this.setAnnotationTags = __bind(this.setAnnotationTags, this);
+
     this.updateField = __bind(this.updateField, this);
-    Tags.__super__.constructor.apply(this, arguments);
+    return Tags.__super__.constructor.apply(this, arguments);
   }
 
   Tags.prototype.options = {
@@ -17,7 +19,9 @@
       var tags;
       string = $.trim(string);
       tags = [];
-      if (string) tags = string.split(/\s+/);
+      if (string) {
+        tags = string.split(/\s+/);
+      }
       return tags;
     },
     stringifyTags: function(array) {
@@ -30,7 +34,9 @@
   Tags.prototype.input = null;
 
   Tags.prototype.pluginInit = function() {
-    if (!Annotator.supported()) return;
+    if (!Annotator.supported()) {
+      return;
+    }
     this.field = this.annotator.editor.addField({
       label: Annotator._t('Add some tags here') + '\u2026',
       load: this.updateField,
@@ -60,7 +66,9 @@
   Tags.prototype.updateField = function(field, annotation) {
     var value;
     value = '';
-    if (annotation.tags) value = this.stringifyTags(annotation.tags);
+    if (annotation.tags) {
+      value = this.stringifyTags(annotation.tags);
+    }
     return this.input.val(value);
   };
 
@@ -87,8 +95,10 @@
 })(Annotator.Plugin);
 
 Annotator.Plugin.Tags.filterCallback = function(input, tags) {
-  var keyword, keywords, matches, tag, _i, _j, _len, _len2;
-  if (tags == null) tags = [];
+  var keyword, keywords, matches, tag, _i, _j, _len, _len1;
+  if (tags == null) {
+    tags = [];
+  }
   matches = 0;
   keywords = [];
   if (input) {
@@ -96,9 +106,11 @@
     for (_i = 0, _len = keywords.length; _i < _len; _i++) {
       keyword = keywords[_i];
       if (tags.length) {
-        for (_j = 0, _len2 = tags.length; _j < _len2; _j++) {
+        for (_j = 0, _len1 = tags.length; _j < _len1; _j++) {
           tag = tags[_j];
-          if (tag.indexOf(keyword) !== -1) matches += 1;
+          if (tag.indexOf(keyword) !== -1) {
+            matches += 1;
+          }
         }
       }
     }
--- a/annotator_files/lib/plugin/unsupported.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/plugin/unsupported.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,12 +1,13 @@
-var __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; };
+// Generated by CoffeeScript 1.3.3
+var __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.Unsupported = (function(_super) {
 
   __extends(Unsupported, _super);
 
   function Unsupported() {
-    Unsupported.__super__.constructor.apply(this, arguments);
+    return Unsupported.__super__.constructor.apply(this, arguments);
   }
 
   Unsupported.prototype.options = {
--- a/annotator_files/lib/range.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/range.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,4 +1,7 @@
-var Range;
+// Generated by CoffeeScript 1.3.3
+var Range,
+  __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; };
 
 Range = {};
 
@@ -15,6 +18,66 @@
   }
 };
 
+Range.nodeFromXPath = function(xpath, root) {
+  var customResolver, evaluateXPath, namespace, node, segment;
+  if (root == null) {
+    root = document;
+  }
+  evaluateXPath = function(xp, nsResolver) {
+    if (nsResolver == null) {
+      nsResolver = null;
+    }
+    return document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+  };
+  if (!$.isXMLDoc(document.documentElement)) {
+    return evaluateXPath(xpath);
+  } else {
+    customResolver = document.createNSResolver(document.ownerDocument === null ? document.documentElement : document.ownerDocument.documentElement);
+    node = evaluateXPath(xpath, customResolver);
+    if (!node) {
+      xpath = ((function() {
+        var _i, _len, _ref, _results;
+        _ref = xpath.split('/');
+        _results = [];
+        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+          segment = _ref[_i];
+          if (segment && segment.indexOf(':') === -1) {
+            _results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
+          } else {
+            _results.push(segment);
+          }
+        }
+        return _results;
+      })()).join('/');
+      namespace = document.lookupNamespaceURI(null);
+      customResolver = function(ns) {
+        if (ns === 'xhtml') {
+          return namespace;
+        } else {
+          return document.documentElement.getAttribute('xmlns:' + ns);
+        }
+      };
+      node = evaluateXPath(xpath, customResolver);
+    }
+    return node;
+  }
+};
+
+Range.RangeError = (function(_super) {
+
+  __extends(RangeError, _super);
+
+  function RangeError(type, message, parent) {
+    this.type = type;
+    this.message = message;
+    this.parent = parent != null ? parent : null;
+    RangeError.__super__.constructor.call(this, this.message);
+  }
+
+  return RangeError;
+
+})(Error);
+
 Range.BrowserRange = (function() {
 
   function BrowserRange(obj) {
@@ -40,7 +103,9 @@
       p = _ref[_i];
       node = this[p + 'Container'];
       offset = this[p + 'Offset'];
-      if (!((node != null) && (offset != null))) return false;
+      if (!((node != null) && (offset != null))) {
+        return false;
+      }
       if (node.nodeType === 1) {
         it = node.childNodes[offset];
         node = it || node.childNodes[offset - 1];
@@ -63,7 +128,9 @@
       }
       nr.end = nr.start;
     } else {
-      if (r.endOffset < r.end.nodeValue.length) r.end.splitText(r.endOffset);
+      if (r.endOffset < r.end.nodeValue.length) {
+        r.end.splitText(r.endOffset);
+      }
       nr.end = r.end;
     }
     nr.commonAncestor = this.commonAncestorContainer;
@@ -98,7 +165,9 @@
     nodes = $.grep(this.textNodes(), function(node) {
       return node.parentNode === bounds || $.contains(bounds, node.parentNode);
     });
-    if (!nodes.length) return null;
+    if (!nodes.length) {
+      return null;
+    }
     this.start = nodes[0];
     this.end = nodes[nodes.length - 1];
     startParents = $(this.start).parents();
@@ -188,73 +257,24 @@
     this.endOffset = obj.endOffset;
   }
 
-  SerializedRange.prototype._nodeFromXPath = function(xpath) {
-    var customResolver, evaluateXPath, namespace, node, segment;
-    evaluateXPath = function(xp, nsResolver) {
-      if (nsResolver == null) nsResolver = null;
-      return document.evaluate(xp, document, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
-    };
-    if (!$.isXMLDoc(document.documentElement)) {
-      return evaluateXPath(xpath);
-    } else {
-      customResolver = document.createNSResolver(document.ownerDocument === null ? document.documentElement : document.ownerDocument.documentElement);
-      node = evaluateXPath(xpath, customResolver);
+  SerializedRange.prototype.normalize = function(root) {
+    var contains, length, node, p, range, tn, _i, _j, _len, _len1, _ref, _ref1;
+    range = {};
+    _ref = ['start', 'end'];
+    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+      p = _ref[_i];
+      try {
+        node = Range.nodeFromXPath(this[p], root);
+      } catch (e) {
+        throw new Range.RangeError(p, ("Error while finding " + p + " node: " + this[p] + ": ") + e, e);
+      }
       if (!node) {
-        xpath = ((function() {
-          var _i, _len, _ref, _results;
-          _ref = xpath.split('/');
-          _results = [];
-          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-            segment = _ref[_i];
-            if (segment && segment.indexOf(':') === -1) {
-              _results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
-            } else {
-              _results.push(segment);
-            }
-          }
-          return _results;
-        })()).join('/');
-        namespace = document.lookupNamespaceURI(null);
-        customResolver = function(ns) {
-          if (ns === 'xhtml') {
-            return namespace;
-          } else {
-            return document.documentElement.getAttribute('xmlns:' + ns);
-          }
-        };
-        node = evaluateXPath(xpath, customResolver);
+        throw new Range.RangeError(p, "Couldn't find " + p + " node: " + this[p]);
       }
-      return node;
-    }
-  };
-
-  SerializedRange.prototype.normalize = function(root) {
-    var cacXPath, common, endAncestry, i, length, p, parentXPath, range, startAncestry, tn, _i, _j, _len, _len2, _ref, _ref2, _ref3;
-    parentXPath = $(root).xpath()[0];
-    startAncestry = this.start.split("/");
-    endAncestry = this.end.split("/");
-    common = [];
-    range = {};
-    for (i = 0, _ref = startAncestry.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
-      if (startAncestry[i] === endAncestry[i]) {
-        common.push(startAncestry[i]);
-      } else {
-        break;
-      }
-    }
-    cacXPath = parentXPath + common.join("/");
-    range.commonAncestorContainer = this._nodeFromXPath(cacXPath);
-    if (!range.commonAncestorContainer) {
-      console.error(_t("Error deserializing range: can't find XPath '") + cacXPath + _t("'. Is this the right document?"));
-      return null;
-    }
-    _ref2 = ['start', 'end'];
-    for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
-      p = _ref2[_i];
       length = 0;
-      _ref3 = $(this._nodeFromXPath(parentXPath + this[p])).textNodes();
-      for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
-        tn = _ref3[_j];
+      _ref1 = $(node).textNodes();
+      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+        tn = _ref1[_j];
         if (length + tn.nodeValue.length >= this[p + 'Offset']) {
           range[p + 'Container'] = tn;
           range[p + 'Offset'] = this[p + 'Offset'] - length;
@@ -263,7 +283,21 @@
           length += tn.nodeValue.length;
         }
       }
+      if (!(range[p + 'Offset'] != null)) {
+        throw new Range.RangeError("" + p + "offset", "Couldn't find offset " + this[p + 'Offset'] + " in element " + this[p]);
+      }
     }
+    contains = !(document.compareDocumentPosition != null) ? function(a, b) {
+      return a.contains(b);
+    } : function(a, b) {
+      return a.compareDocumentPosition(b) & 16;
+    };
+    $(range.startContainer).parents().reverse().each(function() {
+      if (contains(this, range.endContainer)) {
+        range.commonAncestorContainer = this;
+        return false;
+      }
+    });
     return new Range.BrowserRange(range).normalize(root);
   };
 
--- a/annotator_files/lib/viewer.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/viewer.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,7 +1,8 @@
+// Generated by CoffeeScript 1.3.3
 var LinkParser,
   __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.Viewer = (function(_super) {
 
@@ -28,10 +29,15 @@
 
   function Viewer(options) {
     this.onDeleteClick = __bind(this.onDeleteClick, this);
+
     this.onEditClick = __bind(this.onEditClick, this);
+
     this.load = __bind(this.load, this);
+
     this.hide = __bind(this.hide, this);
-    this.show = __bind(this.show, this);    Viewer.__super__.constructor.call(this, $(this.html.element)[0], options);
+
+    this.show = __bind(this.show, this);
+    Viewer.__super__.constructor.call(this, $(this.html.element)[0], options);
     this.item = $(this.html.item)[0];
     this.fields = [];
     this.annotations = [];
@@ -60,7 +66,7 @@
   };
 
   Viewer.prototype.load = function(annotations) {
-    var annotation, controller, controls, del, edit, element, field, item, link, links, list, _i, _j, _len, _len2, _ref, _ref2;
+    var annotation, controller, controls, del, edit, element, field, item, link, links, list, _i, _j, _len, _len1, _ref, _ref1;
     this.annotations = annotations || [];
     list = this.element.find('ul:first').empty();
     _ref = this.annotations;
@@ -98,9 +104,9 @@
           }
         };
       }
-      _ref2 = this.fields;
-      for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
-        field = _ref2[_j];
+      _ref1 = this.fields;
+      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
+        field = _ref1[_j];
         element = $(field.element).clone().appendTo(item)[0];
         field.load(element, annotation, controller);
       }
@@ -146,7 +152,9 @@
 
   LinkParser.prototype.get = function(rel, cond) {
     var d, k, keys, match, v, _i, _len, _ref, _results;
-    if (cond == null) cond = {};
+    if (cond == null) {
+      cond = {};
+    }
     cond = $.extend({}, cond, {
       rel: rel
     });
--- a/annotator_files/lib/widget.js	Thu Apr 05 19:37:27 2012 +0200
+++ b/annotator_files/lib/widget.js	Mon Aug 27 19:05:38 2012 +0200
@@ -1,5 +1,6 @@
-var __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; };
+// Generated by CoffeeScript 1.3.3
+var __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.Widget = (function(_super) {
 
@@ -32,8 +33,12 @@
       top: offset.top,
       right: offset.left + widget.width()
     };
-    if ((current.top - viewport.top) < 0) this.invertY();
-    if ((current.right - viewport.right) > 0) this.invertX();
+    if ((current.top - viewport.top) < 0) {
+      this.invertY();
+    }
+    if ((current.right - viewport.right) > 0) {
+      this.invertX();
+    }
     return this;
   };