Changeset 4:6979313586cf in OKFNAnnotator (for Zope)


Ignore:
Timestamp:
Aug 27, 2012, 5:05:38 PM (12 years ago)
Author:
casties
Branch:
default
Message:

new version of annotator.

Location:
annotator_files/lib
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • annotator_files/lib/annotator.js

    r3 r4  
    1 var Annotator, util, _Annotator,
     1// Generated by CoffeeScript 1.3.3
     2var Annotator, g, util, _Annotator, _ref,
    23  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    3   __hasProp = Object.prototype.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; };
     4  __hasProp = {}.hasOwnProperty,
     5  __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; };
    56
    67util = {
     
    1718    })();
    1819  },
     20  maxZIndex: function($elements) {
     21    var all, el;
     22    all = (function() {
     23      var _i, _len, _results;
     24      _results = [];
     25      for (_i = 0, _len = $elements.length; _i < _len; _i++) {
     26        el = $elements[_i];
     27        if ($(el).css('position') === 'static') {
     28          _results.push(-1);
     29        } else {
     30          _results.push(parseInt($(el).css('z-index'), 10) || -1);
     31        }
     32      }
     33      return _results;
     34    })();
     35    return Math.max.apply(Math, all);
     36  },
    1937  mousePosition: function(e, offsetEl) {
    2038    var offset;
     
    4462
    4563  Annotator.prototype.html = {
    46     hl: '<span class="annotator-hl"></span>',
    4764    adder: '<div class="annotator-adder"><button>' + _t('Annotate') + '</button></div>',
    4865    wrapper: '<div class="annotator-wrapper"></div>'
     
    6986  function Annotator(element, options) {
    7087    this.onDeleteAnnotation = __bind(this.onDeleteAnnotation, this);
     88
    7189    this.onEditAnnotation = __bind(this.onEditAnnotation, this);
     90
    7291    this.onAdderClick = __bind(this.onAdderClick, this);
     92
    7393    this.onAdderMousedown = __bind(this.onAdderMousedown, this);
     94
    7495    this.onHighlightMouseover = __bind(this.onHighlightMouseover, this);
     96
    7597    this.checkForEndSelection = __bind(this.checkForEndSelection, this);
     98
    7699    this.checkForStartSelection = __bind(this.checkForStartSelection, this);
     100
    77101    this.clearViewerHideTimer = __bind(this.clearViewerHideTimer, this);
     102
    78103    this.startViewerHideTimer = __bind(this.startViewerHideTimer, this);
     104
    79105    this.showViewer = __bind(this.showViewer, this);
     106
    80107    this.onEditorSubmit = __bind(this.onEditorSubmit, this);
     108
    81109    this.onEditorHide = __bind(this.onEditorHide, this);
     110
    82111    this.showEditor = __bind(this.showEditor, this);
    83     var name, src, _ref;
    84112    Annotator.__super__.constructor.apply(this, arguments);
    85113    this.plugins = {};
    86     if (!Annotator.supported()) return this;
    87     if (!this.options.readOnly) this._setupDocumentEvents();
     114    if (!Annotator.supported()) {
     115      return this;
     116    }
     117    if (!this.options.readOnly) {
     118      this._setupDocumentEvents();
     119    }
    88120    this._setupWrapper()._setupViewer()._setupEditor();
    89     _ref = this.html;
    90     for (name in _ref) {
    91       src = _ref[name];
    92       if (name !== 'wrapper') this[name] = $(src).appendTo(this.wrapper).hide();
    93     }
     121    this._setupDynamicStyle();
     122    this.adder = $(this.html.adder).appendTo(this.wrapper).hide();
    94123  }
    95124
     
    147176  };
    148177
     178  Annotator.prototype._setupDynamicStyle = function() {
     179    var max, sel, style, x;
     180    style = $('#annotator-dynamic-style');
     181    if (!style.length) {
     182      style = $('<style id="annotator-dynamic-style"></style>').appendTo(document.head);
     183    }
     184    sel = '*' + ((function() {
     185      var _i, _len, _ref, _results;
     186      _ref = ['adder', 'outer', 'notice', 'filter'];
     187      _results = [];
     188      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     189        x = _ref[_i];
     190        _results.push(":not(.annotator-" + x + ")");
     191      }
     192      return _results;
     193    })()).join('');
     194    max = util.maxZIndex($(document.body).find(sel));
     195    max = Math.max(max, 1000);
     196    style.text([".annotator-adder, .annotator-outer, .annotator-notice {", "  z-index: " + (max + 20) + ";", "}", ".annotator-filter {", "  z-index: " + (max + 10) + ";", "}"].join("\n"));
     197    return this;
     198  };
     199
    149200  Annotator.prototype.getSelectedRanges = function() {
    150201    var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _i, _len;
     
    154205    if (!selection.isCollapsed) {
    155206      ranges = (function() {
    156         var _ref, _results;
     207        var _i, _ref, _results;
    157208        _results = [];
    158         for (i = 0, _ref = selection.rangeCount; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
     209        for (i = _i = 0, _ref = selection.rangeCount; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
    159210          r = selection.getRangeAt(i);
    160211          browserRange = new Range.BrowserRange(r);
    161212          normedRange = browserRange.normalize().limit(this.wrapper[0]);
    162           if (normedRange === null) rangesToIgnore.push(r);
     213          if (normedRange === null) {
     214            rangesToIgnore.push(r);
     215          }
    163216          _results.push(normedRange);
    164217        }
     
    172225    }
    173226    return $.grep(ranges, function(range) {
    174       if (range) selection.addRange(range.toRange());
     227      if (range) {
     228        selection.addRange(range.toRange());
     229      }
    175230      return range;
    176231    });
     
    185240
    186241  Annotator.prototype.setupAnnotation = function(annotation, fireEvents) {
    187     var normed, normedRanges, r, sniffed, _i, _len;
    188     if (fireEvents == null) fireEvents = true;
     242    var normed, normedRanges, r, root, _i, _j, _len, _len1, _ref;
     243    if (fireEvents == null) {
     244      fireEvents = true;
     245    }
     246    root = this.wrapper[0];
    189247    annotation.ranges || (annotation.ranges = this.selectedRanges);
    190     normedRanges = (function() {
    191       var _i, _len, _ref, _results;
    192       _ref = annotation.ranges;
    193       _results = [];
    194       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    195         r = _ref[_i];
    196         if (!(r != null)) continue;
    197         sniffed = Range.sniff(r);
    198         _results.push(sniffed.normalize(this.wrapper[0]));
    199       }
    200       return _results;
    201     }).call(this);
    202     normedRanges = $.grep(normedRanges, function(range) {
    203       return range !== null;
    204     });
     248    normedRanges = [];
     249    _ref = annotation.ranges;
     250    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     251      r = _ref[_i];
     252      try {
     253        normedRanges.push(Range.sniff(r).normalize(root));
     254      } catch (e) {
     255        if (e instanceof Range.RangeError) {
     256          this.publish('rangeNormalizeFail', [annotation, r, e]);
     257        } else {
     258          throw e;
     259        }
     260      }
     261    }
    205262    annotation.quote = [];
    206263    annotation.ranges = [];
    207264    annotation.highlights = [];
    208     for (_i = 0, _len = normedRanges.length; _i < _len; _i++) {
    209       normed = normedRanges[_i];
     265    for (_j = 0, _len1 = normedRanges.length; _j < _len1; _j++) {
     266      normed = normedRanges[_j];
    210267      annotation.quote.push($.trim(normed.text()));
    211268      annotation.ranges.push(normed.serialize(this.wrapper[0], '.annotator-hl'));
     
    214271    annotation.quote = annotation.quote.join(' / ');
    215272    $(annotation.highlights).data('annotation', annotation);
    216     if (fireEvents) this.publish('annotationCreated', [annotation]);
     273    if (fireEvents) {
     274      this.publish('annotationCreated', [annotation]);
     275    }
    217276    return annotation;
    218277  };
     
    238297    var clone, loader,
    239298      _this = this;
    240     if (annotations == null) annotations = [];
     299    if (annotations == null) {
     300      annotations = [];
     301    }
    241302    loader = function(annList) {
    242303      var n, now, _i, _len;
    243       if (annList == null) annList = [];
     304      if (annList == null) {
     305        annList = [];
     306      }
    244307      now = annList.splice(0, 10);
    245308      for (_i = 0, _len = now.length; _i < _len; _i++) {
     
    250313        return setTimeout((function() {
    251314          return loader(annList);
    252         }), 1);
     315        }), 10);
    253316      } else {
    254317        return _this.publish('annotationsLoaded', [clone]);
     
    256319    };
    257320    clone = annotations.slice();
    258     if (annotations.length) loader(annotations);
     321    if (annotations.length) {
     322      loader(annotations);
     323    }
    259324    return this;
    260325  };
     
    268333  };
    269334
    270   Annotator.prototype.highlightRange = function(normedRange) {
    271     var node, white, _i, _len, _ref, _results;
     335  Annotator.prototype.highlightRange = function(normedRange, cssClass) {
     336    var hl, node, white, _i, _len, _ref, _results;
     337    if (cssClass == null) {
     338      cssClass = 'annotator-hl';
     339    }
    272340    white = /^\s*$/;
     341    hl = $("<span class='" + cssClass + "'></span>");
    273342    _ref = normedRange.textNodes();
    274343    _results = [];
     
    276345      node = _ref[_i];
    277346      if (!white.test(node.nodeValue)) {
    278         _results.push($(node).wrapAll(this.hl).parent().show()[0]);
     347        _results.push($(node).wrapAll(hl).parent().show()[0]);
    279348      }
    280349    }
    281350    return _results;
     351  };
     352
     353  Annotator.prototype.highlightRanges = function(normedRanges, cssClass) {
     354    var highlights, r, _i, _len;
     355    if (cssClass == null) {
     356      cssClass = 'annotator-hl';
     357    }
     358    highlights = [];
     359    for (_i = 0, _len = normedRanges.length; _i < _len; _i++) {
     360      r = normedRanges[_i];
     361      $.merge(highlights, this.highlightRange(r, cssClass));
     362    }
     363    return highlights;
    282364  };
    283365
     
    304386    this.editor.element.css(location);
    305387    this.editor.load(annotation);
     388    this.publish('annotationEditorShown', [this.editor, annotation]);
    306389    return this;
    307390  };
     
    348431    var container, range, _i, _len, _ref;
    349432    this.mouseIsDown = false;
    350     if (this.ignoreMouseup) return;
     433    if (this.ignoreMouseup) {
     434      return;
     435    }
    351436    this.selectedRanges = this.getSelectedRanges();
    352437    _ref = this.selectedRanges;
     
    354439      range = _ref[_i];
    355440      container = range.commonAncestor;
    356       if (this.isAnnotator(container)) return;
     441      if ($(container).hasClass('annotator-hl')) {
     442        container = $(container).parents('[class^=annotator-hl]')[0];
     443      }
     444      if (this.isAnnotator(container)) {
     445        return;
     446      }
    357447    }
    358448    if (event && this.selectedRanges.length) {
     
    370460    var annotations;
    371461    this.clearViewerHideTimer();
    372     if (this.mouseIsDown || this.viewer.isShown()) return false;
     462    if (this.mouseIsDown || this.viewer.isShown()) {
     463      return false;
     464    }
    373465    annotations = $(event.target).parents('.annotator-hl').andSelf().map(function() {
    374466      return $(this).data("annotation");
     
    378470
    379471  Annotator.prototype.onAdderMousedown = function(event) {
    380     if (event != null) event.preventDefault();
     472    if (event != null) {
     473      event.preventDefault();
     474    }
    381475    return this.ignoreMouseup = true;
    382476  };
    383477
    384478  Annotator.prototype.onAdderClick = function(event) {
    385     var position;
    386     if (event != null) event.preventDefault();
     479    var highlights, position, r, ranges;
     480    if (event != null) {
     481      event.preventDefault();
     482    }
    387483    position = this.adder.position();
    388484    this.adder.hide();
     485    if (this.selectedRanges && this.selectedRanges.length) {
     486      ranges = (function() {
     487        var _i, _len, _ref, _results;
     488        _ref = this.selectedRanges;
     489        _results = [];
     490        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     491          r = _ref[_i];
     492          _results.push(Range.sniff(r).normalize());
     493        }
     494        return _results;
     495      }).call(this);
     496      highlights = this.highlightRanges(ranges, 'annotator-hl annotator-hl-temporary');
     497      this.editor.element.one('hide', function() {
     498        var h, _i, _len, _results;
     499        _results = [];
     500        for (_i = 0, _len = highlights.length; _i < _len; _i++) {
     501          h = highlights[_i];
     502          _results.push($(h).replaceWith(h.childNodes));
     503        }
     504        return _results;
     505      });
     506    }
    389507    return this.showEditor(this.createAnnotation(), position);
    390508  };
     
    420538})(Delegator);
    421539
     540g = util.getGlobal();
     541
     542if (!(((_ref = g.document) != null ? _ref.evaluate : void 0) != null)) {
     543  $.getScript('http://assets.annotateit.org/vendor/xpath.min.js');
     544}
     545
     546if (!(g.getSelection != null)) {
     547  $.getScript('http://assets.annotateit.org/vendor/ierange.min.js');
     548}
     549
     550if (!(g.JSON != null)) {
     551  $.getScript('http://assets.annotateit.org/vendor/json2.min.js');
     552}
     553
    422554Annotator.$ = $;
    423555
  • annotator_files/lib/class.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var Delegator,
    2   __slice = Array.prototype.slice,
    3   __hasProp = Object.prototype.hasOwnProperty;
     3  __slice = [].slice,
     4  __hasProp = {}.hasOwnProperty;
    45
    56Delegator = (function() {
     
    1920
    2021  Delegator.prototype.addEvents = function() {
    21     var event, functionName, sel, selector, _i, _ref, _ref2, _results;
     22    var event, functionName, sel, selector, _i, _ref, _ref1, _results;
    2223    _ref = this.events;
    2324    _results = [];
    2425    for (sel in _ref) {
    2526      functionName = _ref[sel];
    26       _ref2 = sel.split(' '), selector = 2 <= _ref2.length ? __slice.call(_ref2, 0, _i = _ref2.length - 1) : (_i = 0, []), event = _ref2[_i++];
     27      _ref1 = sel.split(' '), selector = 2 <= _ref1.length ? __slice.call(_ref1, 0, _i = _ref1.length - 1) : (_i = 0, []), event = _ref1[_i++];
    2728      _results.push(this.addEvent(selector.join(' '), event, functionName));
    2829    }
     
    3738    };
    3839    isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === '';
    39     if (isBlankSelector) bindTo = this.element;
     40    if (isBlankSelector) {
     41      bindTo = this.element;
     42    }
    4043    if (typeof bindTo === 'string') {
    4144      this.element.delegate(bindTo, event, closure);
  • annotator_files/lib/console.js

    r3 r4  
    1 var fn, functions, _i, _j, _len, _len2,
    2   __slice = Array.prototype.slice;
     1// Generated by CoffeeScript 1.3.3
     2var fn, functions, _i, _j, _len, _len1,
     3  __slice = [].slice;
    34
    45functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"];
     
    1011    };
    1112  }
    12   if (!(console.groupCollapsed != null)) console.groupCollapsed = console.group;
     13  if (!(console.groupCollapsed != null)) {
     14    console.groupCollapsed = console.group;
     15  }
    1316  for (_i = 0, _len = functions.length; _i < _len; _i++) {
    1417    fn = functions[_i];
     
    2124} else {
    2225  this.console = {};
    23   for (_j = 0, _len2 = functions.length; _j < _len2; _j++) {
     26  for (_j = 0, _len1 = functions.length; _j < _len1; _j++) {
    2427    fn = functions[_j];
    2528    this.console[fn] = function() {};
  • annotator_files/lib/editor.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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; };
     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; };
    45
    56Annotator.Editor = (function(_super) {
     
    2627  function Editor(options) {
    2728    this.onCancelButtonMouseover = __bind(this.onCancelButtonMouseover, this);
     29
    2830    this.processKeypress = __bind(this.processKeypress, this);
     31
    2932    this.submit = __bind(this.submit, this);
     33
    3034    this.load = __bind(this.load, this);
     35
    3136    this.hide = __bind(this.hide, this);
    32     this.show = __bind(this.show, this);    Editor.__super__.constructor.call(this, $(this.html)[0], options);
     37
     38    this.show = __bind(this.show, this);
     39    Editor.__super__.constructor.call(this, $(this.html)[0], options);
    3340    this.fields = [];
    3441    this.annotation = {};
     
    190197          textarea.height(height + (diff.top * directionY));
    191198          textarea.width(width + (diff.left * directionX));
    192           if (textarea.outerHeight() !== height) mousedown.top = event.pageY;
    193           if (textarea.outerWidth() !== width) mousedown.left = event.pageX;
     199          if (textarea.outerHeight() !== height) {
     200            mousedown.top = event.pageY;
     201          }
     202          if (textarea.outerWidth() !== width) {
     203            mousedown.left = event.pageX;
     204          }
    194205        } else if (mousedown.element === controls[0]) {
    195206          editor.css({
  • annotator_files/lib/extensions.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var $, gettext, _gettext, _ref, _t;
    23
     
    9293    while (elem && elem.nodeType === 1 && elem !== relativeRoot) {
    9394      idx = $(elem.parentNode).children(elem.tagName).index(elem) + 1;
    94       idx = idx > 1 ? "[" + idx + "]" : "";
     95      idx = "[" + idx + "]";
    9596      path = "/" + elem.tagName.toLowerCase() + idx + path;
    9697      elem = elem.parentNode;
     
    106107
    107108$.fn.escape = function(html) {
    108   if (arguments.length) return this.html($.escape(html));
     109  if (arguments.length) {
     110    return this.html($.escape(html));
     111  }
    109112  return this.html();
    110113};
     114
     115$.fn.reverse = [].reverse;
  • annotator_files/lib/notification.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var Annotator,
    23  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    3   __hasProp = Object.prototype.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; };
     4  __hasProp = {}.hasOwnProperty,
     5  __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; };
    56
    67Annotator = Annotator || {};
     
    2627  function Notification(options) {
    2728    this.hide = __bind(this.hide, this);
    28     this.show = __bind(this.show, this);    Notification.__super__.constructor.call(this, $(this.options.html).appendTo(document.body)[0], options);
     29
     30    this.show = __bind(this.show, this);
     31    Notification.__super__.constructor.call(this, $(this.options.html).appendTo(document.body)[0], options);
    2932  }
    3033
    3134  Notification.prototype.show = function(message, status) {
    32     if (status == null) status = Annotator.Notification.INFO;
     35    if (status == null) {
     36      status = Annotator.Notification.INFO;
     37    }
    3338    $(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message || "");
    3439    setTimeout(this.hide, 5000);
  • annotator_files/lib/plugin/annotateitpermissions.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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   __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; };
     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  __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; };
    56
    67Annotator.Plugin.AnnotateItPermissions = (function(_super) {
    78
    89  __extends(AnnotateItPermissions, _super);
     10
     11  function AnnotateItPermissions() {
     12    this._setAuthFromToken = __bind(this._setAuthFromToken, this);
     13
     14    this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
     15
     16    this.updatePermissionsField = __bind(this.updatePermissionsField, this);
     17
     18    this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
     19    return AnnotateItPermissions.__super__.constructor.apply(this, arguments);
     20  }
    921
    1022  AnnotateItPermissions.prototype.options = {
     
    1628      consumer: 'group:__consumer__'
    1729    },
     30    userId: function(user) {
     31      return user.userId;
     32    },
    1833    userString: function(user) {
    19       return user;
     34      return user.userId;
    2035    },
    21     userAuthorize: function(action, annotation, user, consumer) {
    22       var action_field, permissions, _ref, _ref2, _ref3, _ref4;
     36    userAuthorize: function(action, annotation, user) {
     37      var action_field, permissions, _ref, _ref1, _ref2, _ref3;
    2338      permissions = annotation.permissions || {};
    2439      action_field = permissions[action] || [];
    25       if (!(user && consumer)) {
    26         return _ref = this.groups.world, __indexOf.call(action_field, _ref) >= 0;
    27       } else {
    28         if (_ref2 = this.groups.world, __indexOf.call(action_field, _ref2) >= 0) {
     40      if (_ref = this.groups.world, __indexOf.call(action_field, _ref) >= 0) {
     41        return true;
     42      } else if ((user != null) && (user.userId != null) && (user.consumerKey != null)) {
     43        if (user.userId === annotation.user && user.consumerKey === annotation.consumer) {
    2944          return true;
    30         } else if (user === annotation.user && consumer === annotation.consumer) {
     45        } else if (_ref1 = this.groups.authenticated, __indexOf.call(action_field, _ref1) >= 0) {
    3146          return true;
    32         } else if (_ref3 = this.groups.authenticated, __indexOf.call(action_field, _ref3) >= 0) {
     47        } else if (user.consumerKey === annotation.consumer && (_ref2 = this.groups.consumer, __indexOf.call(action_field, _ref2) >= 0)) {
    3348          return true;
    34         } else if (consumer === annotation.consumer && (_ref4 = this.groups.consumer, __indexOf.call(action_field, _ref4) >= 0)) {
     49        } else if (user.consumerKey === annotation.consumer && (_ref3 = user.userId, __indexOf.call(action_field, _ref3) >= 0)) {
    3550          return true;
    36         } else if (consumer === annotation.consumer && __indexOf.call(action_field, user) >= 0) {
     51        } else if (user.consumerKey === annotation.consumer && user.admin) {
    3752          return true;
    3853        } else {
     
    4156      }
    4257    },
    43     user: '',
    44     consumer: 'annotateit',
    4558    permissions: {
    4659      'read': ['group:__world__'],
     
    5164  };
    5265
    53   function AnnotateItPermissions(element, options) {
    54     this._setAuthFromToken = __bind(this._setAuthFromToken, this);
    55     this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
    56     this.updatePermissionsField = __bind(this.updatePermissionsField, this);
    57     this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);    AnnotateItPermissions.__super__.constructor.apply(this, arguments);
    58     if (this.options.consumer) {
    59       this.setConsumer(this.options.consumer);
    60       delete this.options.consumer;
    61     }
    62   }
    63 
    64   AnnotateItPermissions.prototype.setConsumer = function(consumer) {
    65     return this.consumer = consumer;
    66   };
    67 
    68   AnnotateItPermissions.prototype.authorize = function(action, annotation, user, consumer) {
    69     if (user === void 0) user = this.user;
    70     if (consumer === void 0) consumer = this.consumer;
    71     if (this.options.userAuthorize) {
    72       return this.options.userAuthorize.call(this.options, action, annotation, user, consumer);
    73     } else {
    74       return true;
    75     }
    76   };
    77 
    7866  AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) {
    7967    AnnotateItPermissions.__super__.addFieldsToAnnotation.apply(this, arguments);
    80     if (annotation && this.consumer) return annotation.consumer = this.consumer;
     68    if (annotation && this.user) {
     69      return annotation.consumer = this.user.consumerKey;
     70    }
    8171  };
    8272
     
    8575    field = $(field).show();
    8676    input = field.find('input').removeAttr('disabled');
    87     if (!this.authorize('admin', annotation)) field.hide();
    88     if (this.authorize(action, annotation || {}, '__nonexistentuser__')) {
     77    if (!this.authorize('admin', annotation)) {
     78      field.hide();
     79    }
     80    if (this.user && this.authorize(action, annotation || {}, {
     81      userId: '__nonexistentuser__',
     82      consumerKey: this.user.consumerKey
     83    })) {
    8984      return input.attr('checked', 'checked');
    9085    } else {
     
    9590  AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
    9691    var dataKey;
    97     if (!annotation.permissions) annotation.permissions = this.options.permissions;
     92    if (!annotation.permissions) {
     93      annotation.permissions = this.options.permissions;
     94    }
    9895    dataKey = type + '-permissions';
    9996    if ($(field).find('input').is(':checked')) {
     
    105102
    106103  AnnotateItPermissions.prototype._setAuthFromToken = function(token) {
    107     AnnotateItPermissions.__super__._setAuthFromToken.apply(this, arguments);
    108     return this.setConsumer(token.consumerKey);
     104    return this.setUser(token);
    109105  };
    110106
  • annotator_files/lib/plugin/auth.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken,
    2   __hasProp = Object.prototype.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; };
     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; };
    45
    56createDateFromISO8601 = function(string) {
     
    910  offset = 0;
    1011  date = new Date(d[1], 0, 1);
    11   if (d[3]) date.setMonth(d[3] - 1);
    12   if (d[5]) date.setDate(d[5]);
    13   if (d[7]) date.setHours(d[7]);
    14   if (d[8]) date.setMinutes(d[8]);
    15   if (d[10]) date.setSeconds(d[10]);
    16   if (d[12]) date.setMilliseconds(Number("0." + d[12]) * 1000);
     12  if (d[3]) {
     13    date.setMonth(d[3] - 1);
     14  }
     15  if (d[5]) {
     16    date.setDate(d[5]);
     17  }
     18  if (d[7]) {
     19    date.setHours(d[7]);
     20  }
     21  if (d[8]) {
     22    date.setMinutes(d[8]);
     23  }
     24  if (d[10]) {
     25    date.setSeconds(d[10]);
     26  }
     27  if (d[12]) {
     28    date.setMilliseconds(Number("0." + d[12]) * 1000);
     29  }
    1730  if (d[14]) {
    1831    offset = (Number(d[16]) * 60) + Number(d[17]);
     
    3750    dec = "";
    3851    tmp_arr = [];
    39     if (!data) return data;
     52    if (!data) {
     53      return data;
     54    }
    4055    data += '';
    4156    while (i < data.length) {
     
    6176
    6277base64UrlDecode = function(data) {
    63   var i, m, _ref;
     78  var i, m, _i, _ref;
    6479  m = data.length % 4;
    6580  if (m !== 0) {
    66     for (i = 0, _ref = 4 - m; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
     81    for (i = _i = 0, _ref = 4 - m; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
    6782      data += '=';
    6883    }
     
    176191
    177192  Auth.prototype.withToken = function(callback) {
    178     if (!(callback != null)) return;
     193    if (!(callback != null)) {
     194      return;
     195    }
    179196    if (this.haveValidToken()) {
    180197      return callback(this._unsafeToken);
    181198    } else {
    182199      this.waitingForToken.push(callback);
    183       if (!this.requestInProgress) return this.requestToken();
     200      if (!this.requestInProgress) {
     201        return this.requestToken();
     202      }
    184203    }
    185204  };
  • annotator_files/lib/plugin/filter.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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; };
     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; };
    45
    56Annotator.Plugin.Filter = (function(_super) {
     
    3536    isFiltered: function(input, property) {
    3637      var keyword, _i, _len, _ref;
    37       if (!(input && property)) return false;
     38      if (!(input && property)) {
     39        return false;
     40      }
    3841      _ref = input.split(/\s*/);
    3942      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    4043        keyword = _ref[_i];
    41         if (property.indexOf(keyword) === -1) return false;
     44        if (property.indexOf(keyword) === -1) {
     45          return false;
     46        }
    4247      }
    4348      return true;
     
    4752  function Filter(element, options) {
    4853    this._onPreviousClick = __bind(this._onPreviousClick, this);
     54
    4955    this._onNextClick = __bind(this._onNextClick, this);
     56
    5057    this._onFilterKeyup = __bind(this._onFilterKeyup, this);
     58
    5159    this._onFilterBlur = __bind(this._onFilterBlur, this);
     60
    5261    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);
    5467    Filter.__super__.constructor.call(this, element, options);
     68    (_base = this.options).filters || (_base.filters = []);
    5569    this.filter = $(this.html.filter);
    5670    this.filters = [];
     
    106120      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    107121        f = _ref[_i];
    108         if (f.property === filter.property) _results.push(f);
     122        if (f.property === filter.property) {
     123          _results.push(f);
     124        }
    109125      }
    110126      return _results;
     
    153169
    154170  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;
    156172    activeFilters = $.grep(this.filters, function(filter) {
    157173      return !!filter.annotations.length;
     
    174190    }
    175191    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) {
    177193      annotation = filtered[index];
    178194      highlights = highlights.not(annotation.highlights);
     
    208224    var filter;
    209225    filter = $(event.target).parent().data('filter');
    210     if (filter) return this.updateFilter(filter);
     226    if (filter) {
     227      return this.updateFilter(filter);
     228    }
    211229  };
    212230
    213231  Filter.prototype._findNextHighlight = function(previous) {
    214232    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    }
    216236    offset = previous ? 0 : -1;
    217237    resetOffset = previous ? -1 : 0;
     
    219239    active = this.highlights.not('.' + this.classes.hl.hide);
    220240    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    }
    222244    annotation = current.data('annotation');
    223245    index = active.index(current[0]);
    224246    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    }
    226250    return this._scrollToHighlight(next.data('annotation').highlights);
    227251  };
  • annotator_files/lib/plugin/kitchensink.js

    r3 r4  
    1 var __hasProp = Object.prototype.hasOwnProperty,
    2   __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; };
     1// Generated by CoffeeScript 1.3.3
     2var __hasProp = {}.hasOwnProperty,
     3  __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; };
    34
    45Annotator.prototype.setupPlugins = function(config, options) {
    56  var name, opts, pluginConfig, plugins, uri, win, _i, _len, _results;
    6   if (config == null) config = {};
    7   if (options == null) options = {};
     7  if (config == null) {
     8    config = {};
     9  }
     10  if (options == null) {
     11    options = {};
     12  }
    813  win = util.getGlobal();
    9   plugins = ['Unsupported', 'Auth', 'Tags', 'Filter', 'Store', 'Permissions'];
    10   if (win.Showdown) plugins.push('Markdown');
     14  plugins = ['Unsupported', 'Auth', 'Tags', 'Filter', 'Store', 'AnnotateItPermissions'];
     15  if (win.Showdown) {
     16    plugins.push('Markdown');
     17  }
    1118  uri = win.location.href.split(/#|\?/).shift() || '';
    1219  pluginConfig = {
     
    3946    if (!__hasProp.call(options, name)) continue;
    4047    opts = options[name];
    41     if (__indexOf.call(plugins, name) < 0) plugins.push(name);
     48    if (__indexOf.call(plugins, name) < 0) {
     49      plugins.push(name);
     50    }
    4251  }
    4352  $.extend(true, pluginConfig, options);
  • annotator_files/lib/plugin/markdown.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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; };
     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; };
    45
    56Annotator.Plugin.Markdown = (function(_super) {
     
    1213
    1314  function Markdown(element, options) {
    14     this.updateTextField = __bind(this.updateTextField, this);    if ((typeof Showdown !== "undefined" && Showdown !== null ? Showdown.converter : void 0) != null) {
     15    this.updateTextField = __bind(this.updateTextField, this);
     16    if ((typeof Showdown !== "undefined" && Showdown !== null ? Showdown.converter : void 0) != null) {
    1517      Markdown.__super__.constructor.apply(this, arguments);
    1618      this.converter = new Showdown.converter();
  • annotator_files/lib/plugin/permissions.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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; };
     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; };
    45
    56Annotator.Plugin.Permissions = (function(_super) {
     
    2425      if (annotation.permissions) {
    2526        tokens = annotation.permissions[action] || [];
    26         if (tokens.length === 0) return true;
     27        if (tokens.length === 0) {
     28          return true;
     29        }
    2730        for (_i = 0, _len = tokens.length; _i < _len; _i++) {
    2831          token = tokens[_i];
    29           if (this.userId(user) === token) return true;
     32          if (this.userId(user) === token) {
     33            return true;
     34          }
    3035        }
    3136        return false;
     
    4651  function Permissions(element, options) {
    4752    this._setAuthFromToken = __bind(this._setAuthFromToken, this);
     53
    4854    this.updateViewer = __bind(this.updateViewer, this);
     55
    4956    this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
     57
    5058    this.updatePermissionsField = __bind(this.updatePermissionsField, this);
    51     this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);    Permissions.__super__.constructor.apply(this, arguments);
     59
     60    this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
     61    Permissions.__super__.constructor.apply(this, arguments);
    5262    if (this.options.user) {
    5363      this.setUser(this.options.user);
     
    5969    var createCallback, self,
    6070      _this = this;
    61     if (!Annotator.supported()) return;
     71    if (!Annotator.supported()) {
     72      return;
     73    }
    6274    self = this;
    6375    createCallback = function(method, type) {
     
    95107          var keyword, _i, _len, _ref;
    96108          user = _this.options.userString(user);
    97           if (!(input && user)) return false;
     109          if (!(input && user)) {
     110            return false;
     111          }
    98112          _ref = input.split(/\s*/);
    99113          for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    100114            keyword = _ref[_i];
    101             if (user.indexOf(keyword) === -1) return false;
     115            if (user.indexOf(keyword) === -1) {
     116              return false;
     117            }
    102118          }
    103119          return true;
     
    114130    if (annotation) {
    115131      annotation.permissions = this.options.permissions;
    116       if (this.user) return annotation.user = this.user;
     132      if (this.user) {
     133        return annotation.user = this.user;
     134      }
    117135    }
    118136  };
    119137
    120138  Permissions.prototype.authorize = function(action, annotation, user) {
    121     if (user === void 0) user = this.user;
     139    if (user === void 0) {
     140      user = this.user;
     141    }
    122142    if (this.options.userAuthorize) {
    123143      return this.options.userAuthorize.call(this.options, action, annotation, user);
     
    131151    field = $(field).show();
    132152    input = field.find('input').removeAttr('disabled');
    133     if (!this.authorize('admin', annotation)) field.hide();
     153    if (!this.authorize('admin', annotation)) {
     154      field.hide();
     155    }
    134156    if (this.authorize(action, annotation || {}, null)) {
    135157      return input.attr('checked', 'checked');
     
    141163  Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
    142164    var dataKey;
    143     if (!annotation.permissions) annotation.permissions = this.options.permissions;
     165    if (!annotation.permissions) {
     166      annotation.permissions = this.options.permissions;
     167    }
    144168    dataKey = type + '-permissions';
    145169    if ($(field).find('input').is(':checked')) {
     
    160184      field.remove();
    161185    }
    162     if (!this.authorize('update', annotation)) controls.hideEdit();
    163     if (!this.authorize('delete', annotation)) return controls.hideDelete();
     186    if (!this.authorize('update', annotation)) {
     187      controls.hideEdit();
     188    }
     189    if (!this.authorize('delete', annotation)) {
     190      return controls.hideDelete();
     191    }
    164192  };
    165193
  • annotator_files/lib/plugin/store.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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   __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; };
     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  __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; };
    56
    67Annotator.Plugin.Store = (function(_super) {
     
    3031  function Store(element, options) {
    3132    this._onError = __bind(this._onError, this);
     33
    3234    this._onLoadAnnotationsFromSearch = __bind(this._onLoadAnnotationsFromSearch, this);
     35
    3336    this._onLoadAnnotations = __bind(this._onLoadAnnotations, this);
    34     this._getAnnotations = __bind(this._getAnnotations, this);    Store.__super__.constructor.apply(this, arguments);
     37
     38    this._getAnnotations = __bind(this._getAnnotations, this);
     39    Store.__super__.constructor.apply(this, arguments);
    3540    this.annotations = [];
    3641  }
    3742
    3843  Store.prototype.pluginInit = function() {
    39     if (!Annotator.supported()) return;
     44    if (!Annotator.supported()) {
     45      return;
     46    }
    4047    if (this.annotator.plugins.Auth) {
    4148      return this.annotator.plugins.Auth.withToken(this._getAnnotations);
     
    108115
    109116  Store.prototype._onLoadAnnotations = function(data) {
    110     if (data == null) data = [];
     117    if (data == null) {
     118      data = [];
     119    }
    111120    this.annotations = data;
    112121    return this.annotator.loadAnnotations(data.slice());
     
    118127
    119128  Store.prototype._onLoadAnnotationsFromSearch = function(data) {
    120     if (data == null) data = {};
     129    if (data == null) {
     130      data = {};
     131    }
    121132    return this._onLoadAnnotations(data.rows || []);
    122133  };
     
    193204    $.extend(annotation, this.options.annotationData);
    194205    data = JSON.stringify(annotation);
    195     if (highlights) annotation.highlights = highlights;
     206    if (highlights) {
     207      annotation.highlights = highlights;
     208    }
    196209    return data;
    197210  };
  • annotator_files/lib/plugin/tags.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    2   __hasProp = Object.prototype.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; };
     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; };
    45
    56Annotator.Plugin.Tags = (function(_super) {
     
    910  function Tags() {
    1011    this.setAnnotationTags = __bind(this.setAnnotationTags, this);
     12
    1113    this.updateField = __bind(this.updateField, this);
    12     Tags.__super__.constructor.apply(this, arguments);
     14    return Tags.__super__.constructor.apply(this, arguments);
    1315  }
    1416
     
    1820      string = $.trim(string);
    1921      tags = [];
    20       if (string) tags = string.split(/\s+/);
     22      if (string) {
     23        tags = string.split(/\s+/);
     24      }
    2125      return tags;
    2226    },
     
    3135
    3236  Tags.prototype.pluginInit = function() {
    33     if (!Annotator.supported()) return;
     37    if (!Annotator.supported()) {
     38      return;
     39    }
    3440    this.field = this.annotator.editor.addField({
    3541      label: Annotator._t('Add some tags here') + '\u2026',
     
    6167    var value;
    6268    value = '';
    63     if (annotation.tags) value = this.stringifyTags(annotation.tags);
     69    if (annotation.tags) {
     70      value = this.stringifyTags(annotation.tags);
     71    }
    6472    return this.input.val(value);
    6573  };
     
    8896
    8997Annotator.Plugin.Tags.filterCallback = function(input, tags) {
    90   var keyword, keywords, matches, tag, _i, _j, _len, _len2;
    91   if (tags == null) tags = [];
     98  var keyword, keywords, matches, tag, _i, _j, _len, _len1;
     99  if (tags == null) {
     100    tags = [];
     101  }
    92102  matches = 0;
    93103  keywords = [];
     
    97107      keyword = keywords[_i];
    98108      if (tags.length) {
    99         for (_j = 0, _len2 = tags.length; _j < _len2; _j++) {
     109        for (_j = 0, _len1 = tags.length; _j < _len1; _j++) {
    100110          tag = tags[_j];
    101           if (tag.indexOf(keyword) !== -1) matches += 1;
     111          if (tag.indexOf(keyword) !== -1) {
     112            matches += 1;
     113          }
    102114        }
    103115      }
  • annotator_files/lib/plugin/unsupported.js

    r3 r4  
    1 var __hasProp = Object.prototype.hasOwnProperty,
    2   __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; };
     1// Generated by CoffeeScript 1.3.3
     2var __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; };
    34
    45Annotator.Plugin.Unsupported = (function(_super) {
     
    78
    89  function Unsupported() {
    9     Unsupported.__super__.constructor.apply(this, arguments);
     10    return Unsupported.__super__.constructor.apply(this, arguments);
    1011  }
    1112
  • annotator_files/lib/range.js

    r3 r4  
    1 var Range;
     1// Generated by CoffeeScript 1.3.3
     2var Range,
     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; };
    25
    36Range = {};
     
    1619};
    1720
     21Range.nodeFromXPath = function(xpath, root) {
     22  var customResolver, evaluateXPath, namespace, node, segment;
     23  if (root == null) {
     24    root = document;
     25  }
     26  evaluateXPath = function(xp, nsResolver) {
     27    if (nsResolver == null) {
     28      nsResolver = null;
     29    }
     30    return document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
     31  };
     32  if (!$.isXMLDoc(document.documentElement)) {
     33    return evaluateXPath(xpath);
     34  } else {
     35    customResolver = document.createNSResolver(document.ownerDocument === null ? document.documentElement : document.ownerDocument.documentElement);
     36    node = evaluateXPath(xpath, customResolver);
     37    if (!node) {
     38      xpath = ((function() {
     39        var _i, _len, _ref, _results;
     40        _ref = xpath.split('/');
     41        _results = [];
     42        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     43          segment = _ref[_i];
     44          if (segment && segment.indexOf(':') === -1) {
     45            _results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
     46          } else {
     47            _results.push(segment);
     48          }
     49        }
     50        return _results;
     51      })()).join('/');
     52      namespace = document.lookupNamespaceURI(null);
     53      customResolver = function(ns) {
     54        if (ns === 'xhtml') {
     55          return namespace;
     56        } else {
     57          return document.documentElement.getAttribute('xmlns:' + ns);
     58        }
     59      };
     60      node = evaluateXPath(xpath, customResolver);
     61    }
     62    return node;
     63  }
     64};
     65
     66Range.RangeError = (function(_super) {
     67
     68  __extends(RangeError, _super);
     69
     70  function RangeError(type, message, parent) {
     71    this.type = type;
     72    this.message = message;
     73    this.parent = parent != null ? parent : null;
     74    RangeError.__super__.constructor.call(this, this.message);
     75  }
     76
     77  return RangeError;
     78
     79})(Error);
     80
    1881Range.BrowserRange = (function() {
    1982
     
    41104      node = this[p + 'Container'];
    42105      offset = this[p + 'Offset'];
    43       if (!((node != null) && (offset != null))) return false;
     106      if (!((node != null) && (offset != null))) {
     107        return false;
     108      }
    44109      if (node.nodeType === 1) {
    45110        it = node.childNodes[offset];
     
    64129      nr.end = nr.start;
    65130    } else {
    66       if (r.endOffset < r.end.nodeValue.length) r.end.splitText(r.endOffset);
     131      if (r.endOffset < r.end.nodeValue.length) {
     132        r.end.splitText(r.endOffset);
     133      }
    67134      nr.end = r.end;
    68135    }
     
    99166      return node.parentNode === bounds || $.contains(bounds, node.parentNode);
    100167    });
    101     if (!nodes.length) return null;
     168    if (!nodes.length) {
     169      return null;
     170    }
    102171    this.start = nodes[0];
    103172    this.end = nodes[nodes.length - 1];
     
    189258  }
    190259
    191   SerializedRange.prototype._nodeFromXPath = function(xpath) {
    192     var customResolver, evaluateXPath, namespace, node, segment;
    193     evaluateXPath = function(xp, nsResolver) {
    194       if (nsResolver == null) nsResolver = null;
    195       return document.evaluate(xp, document, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    196     };
    197     if (!$.isXMLDoc(document.documentElement)) {
    198       return evaluateXPath(xpath);
    199     } else {
    200       customResolver = document.createNSResolver(document.ownerDocument === null ? document.documentElement : document.ownerDocument.documentElement);
    201       node = evaluateXPath(xpath, customResolver);
     260  SerializedRange.prototype.normalize = function(root) {
     261    var contains, length, node, p, range, tn, _i, _j, _len, _len1, _ref, _ref1;
     262    range = {};
     263    _ref = ['start', 'end'];
     264    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
     265      p = _ref[_i];
     266      try {
     267        node = Range.nodeFromXPath(this[p], root);
     268      } catch (e) {
     269        throw new Range.RangeError(p, ("Error while finding " + p + " node: " + this[p] + ": ") + e, e);
     270      }
    202271      if (!node) {
    203         xpath = ((function() {
    204           var _i, _len, _ref, _results;
    205           _ref = xpath.split('/');
    206           _results = [];
    207           for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    208             segment = _ref[_i];
    209             if (segment && segment.indexOf(':') === -1) {
    210               _results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
    211             } else {
    212               _results.push(segment);
    213             }
    214           }
    215           return _results;
    216         })()).join('/');
    217         namespace = document.lookupNamespaceURI(null);
    218         customResolver = function(ns) {
    219           if (ns === 'xhtml') {
    220             return namespace;
    221           } else {
    222             return document.documentElement.getAttribute('xmlns:' + ns);
    223           }
    224         };
    225         node = evaluateXPath(xpath, customResolver);
    226       }
    227       return node;
    228     }
    229   };
    230 
    231   SerializedRange.prototype.normalize = function(root) {
    232     var cacXPath, common, endAncestry, i, length, p, parentXPath, range, startAncestry, tn, _i, _j, _len, _len2, _ref, _ref2, _ref3;
    233     parentXPath = $(root).xpath()[0];
    234     startAncestry = this.start.split("/");
    235     endAncestry = this.end.split("/");
    236     common = [];
    237     range = {};
    238     for (i = 0, _ref = startAncestry.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
    239       if (startAncestry[i] === endAncestry[i]) {
    240         common.push(startAncestry[i]);
    241       } else {
    242         break;
    243       }
    244     }
    245     cacXPath = parentXPath + common.join("/");
    246     range.commonAncestorContainer = this._nodeFromXPath(cacXPath);
    247     if (!range.commonAncestorContainer) {
    248       console.error(_t("Error deserializing range: can't find XPath '") + cacXPath + _t("'. Is this the right document?"));
    249       return null;
    250     }
    251     _ref2 = ['start', 'end'];
    252     for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
    253       p = _ref2[_i];
     272        throw new Range.RangeError(p, "Couldn't find " + p + " node: " + this[p]);
     273      }
    254274      length = 0;
    255       _ref3 = $(this._nodeFromXPath(parentXPath + this[p])).textNodes();
    256       for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
    257         tn = _ref3[_j];
     275      _ref1 = $(node).textNodes();
     276      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
     277        tn = _ref1[_j];
    258278        if (length + tn.nodeValue.length >= this[p + 'Offset']) {
    259279          range[p + 'Container'] = tn;
     
    264284        }
    265285      }
    266     }
     286      if (!(range[p + 'Offset'] != null)) {
     287        throw new Range.RangeError("" + p + "offset", "Couldn't find offset " + this[p + 'Offset'] + " in element " + this[p]);
     288      }
     289    }
     290    contains = !(document.compareDocumentPosition != null) ? function(a, b) {
     291      return a.contains(b);
     292    } : function(a, b) {
     293      return a.compareDocumentPosition(b) & 16;
     294    };
     295    $(range.startContainer).parents().reverse().each(function() {
     296      if (contains(this, range.endContainer)) {
     297        range.commonAncestorContainer = this;
     298        return false;
     299      }
     300    });
    267301    return new Range.BrowserRange(range).normalize(root);
    268302  };
  • annotator_files/lib/viewer.js

    r3 r4  
     1// Generated by CoffeeScript 1.3.3
    12var LinkParser,
    23  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    3   __hasProp = Object.prototype.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; };
     4  __hasProp = {}.hasOwnProperty,
     5  __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; };
    56
    67Annotator.Viewer = (function(_super) {
     
    2930  function Viewer(options) {
    3031    this.onDeleteClick = __bind(this.onDeleteClick, this);
     32
    3133    this.onEditClick = __bind(this.onEditClick, this);
     34
    3235    this.load = __bind(this.load, this);
     36
    3337    this.hide = __bind(this.hide, this);
    34     this.show = __bind(this.show, this);    Viewer.__super__.constructor.call(this, $(this.html.element)[0], options);
     38
     39    this.show = __bind(this.show, this);
     40    Viewer.__super__.constructor.call(this, $(this.html.element)[0], options);
    3541    this.item = $(this.html.item)[0];
    3642    this.fields = [];
     
    6167
    6268  Viewer.prototype.load = function(annotations) {
    63     var annotation, controller, controls, del, edit, element, field, item, link, links, list, _i, _j, _len, _len2, _ref, _ref2;
     69    var annotation, controller, controls, del, edit, element, field, item, link, links, list, _i, _j, _len, _len1, _ref, _ref1;
    6470    this.annotations = annotations || [];
    6571    list = this.element.find('ul:first').empty();
     
    99105        };
    100106      }
    101       _ref2 = this.fields;
    102       for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
    103         field = _ref2[_j];
     107      _ref1 = this.fields;
     108      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
     109        field = _ref1[_j];
    104110        element = $(field.element).clone().appendTo(item)[0];
    105111        field.load(element, annotation, controller);
     
    147153  LinkParser.prototype.get = function(rel, cond) {
    148154    var d, k, keys, match, v, _i, _len, _ref, _results;
    149     if (cond == null) cond = {};
     155    if (cond == null) {
     156      cond = {};
     157    }
    150158    cond = $.extend({}, cond, {
    151159      rel: rel
  • annotator_files/lib/widget.js

    r3 r4  
    1 var __hasProp = Object.prototype.hasOwnProperty,
    2   __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; };
     1// Generated by CoffeeScript 1.3.3
     2var __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; };
    34
    45Annotator.Widget = (function(_super) {
     
    3334      right: offset.left + widget.width()
    3435    };
    35     if ((current.top - viewport.top) < 0) this.invertY();
    36     if ((current.right - viewport.right) > 0) this.invertX();
     36    if ((current.top - viewport.top) < 0) {
     37      this.invertY();
     38    }
     39    if ((current.right - viewport.right) > 0) {
     40      this.invertX();
     41    }
    3742    return this;
    3843  };
Note: See TracChangeset for help on using the changeset viewer.