Changeset 4:6979313586cf in OKFNAnnotator (for Zope) for annotator_files/lib
- Timestamp:
- Aug 27, 2012, 5:05:38 PM (12 years ago)
- Branch:
- default
- 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 2 var Annotator, g, util, _Annotator, _ref, 2 3 __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; }; 5 6 6 7 util = { … … 17 18 })(); 18 19 }, 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 }, 19 37 mousePosition: function(e, offsetEl) { 20 38 var offset; … … 44 62 45 63 Annotator.prototype.html = { 46 hl: '<span class="annotator-hl"></span>',47 64 adder: '<div class="annotator-adder"><button>' + _t('Annotate') + '</button></div>', 48 65 wrapper: '<div class="annotator-wrapper"></div>' … … 69 86 function Annotator(element, options) { 70 87 this.onDeleteAnnotation = __bind(this.onDeleteAnnotation, this); 88 71 89 this.onEditAnnotation = __bind(this.onEditAnnotation, this); 90 72 91 this.onAdderClick = __bind(this.onAdderClick, this); 92 73 93 this.onAdderMousedown = __bind(this.onAdderMousedown, this); 94 74 95 this.onHighlightMouseover = __bind(this.onHighlightMouseover, this); 96 75 97 this.checkForEndSelection = __bind(this.checkForEndSelection, this); 98 76 99 this.checkForStartSelection = __bind(this.checkForStartSelection, this); 100 77 101 this.clearViewerHideTimer = __bind(this.clearViewerHideTimer, this); 102 78 103 this.startViewerHideTimer = __bind(this.startViewerHideTimer, this); 104 79 105 this.showViewer = __bind(this.showViewer, this); 106 80 107 this.onEditorSubmit = __bind(this.onEditorSubmit, this); 108 81 109 this.onEditorHide = __bind(this.onEditorHide, this); 110 82 111 this.showEditor = __bind(this.showEditor, this); 83 var name, src, _ref;84 112 Annotator.__super__.constructor.apply(this, arguments); 85 113 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 } 88 120 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(); 94 123 } 95 124 … … 147 176 }; 148 177 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 149 200 Annotator.prototype.getSelectedRanges = function() { 150 201 var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _i, _len; … … 154 205 if (!selection.isCollapsed) { 155 206 ranges = (function() { 156 var _ ref, _results;207 var _i, _ref, _results; 157 208 _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) { 159 210 r = selection.getRangeAt(i); 160 211 browserRange = new Range.BrowserRange(r); 161 212 normedRange = browserRange.normalize().limit(this.wrapper[0]); 162 if (normedRange === null) rangesToIgnore.push(r); 213 if (normedRange === null) { 214 rangesToIgnore.push(r); 215 } 163 216 _results.push(normedRange); 164 217 } … … 172 225 } 173 226 return $.grep(ranges, function(range) { 174 if (range) selection.addRange(range.toRange()); 227 if (range) { 228 selection.addRange(range.toRange()); 229 } 175 230 return range; 176 231 }); … … 185 240 186 241 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]; 189 247 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 } 205 262 annotation.quote = []; 206 263 annotation.ranges = []; 207 264 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]; 210 267 annotation.quote.push($.trim(normed.text())); 211 268 annotation.ranges.push(normed.serialize(this.wrapper[0], '.annotator-hl')); … … 214 271 annotation.quote = annotation.quote.join(' / '); 215 272 $(annotation.highlights).data('annotation', annotation); 216 if (fireEvents) this.publish('annotationCreated', [annotation]); 273 if (fireEvents) { 274 this.publish('annotationCreated', [annotation]); 275 } 217 276 return annotation; 218 277 }; … … 238 297 var clone, loader, 239 298 _this = this; 240 if (annotations == null) annotations = []; 299 if (annotations == null) { 300 annotations = []; 301 } 241 302 loader = function(annList) { 242 303 var n, now, _i, _len; 243 if (annList == null) annList = []; 304 if (annList == null) { 305 annList = []; 306 } 244 307 now = annList.splice(0, 10); 245 308 for (_i = 0, _len = now.length; _i < _len; _i++) { … … 250 313 return setTimeout((function() { 251 314 return loader(annList); 252 }), 1 );315 }), 10); 253 316 } else { 254 317 return _this.publish('annotationsLoaded', [clone]); … … 256 319 }; 257 320 clone = annotations.slice(); 258 if (annotations.length) loader(annotations); 321 if (annotations.length) { 322 loader(annotations); 323 } 259 324 return this; 260 325 }; … … 268 333 }; 269 334 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 } 272 340 white = /^\s*$/; 341 hl = $("<span class='" + cssClass + "'></span>"); 273 342 _ref = normedRange.textNodes(); 274 343 _results = []; … … 276 345 node = _ref[_i]; 277 346 if (!white.test(node.nodeValue)) { 278 _results.push($(node).wrapAll( this.hl).parent().show()[0]);347 _results.push($(node).wrapAll(hl).parent().show()[0]); 279 348 } 280 349 } 281 350 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; 282 364 }; 283 365 … … 304 386 this.editor.element.css(location); 305 387 this.editor.load(annotation); 388 this.publish('annotationEditorShown', [this.editor, annotation]); 306 389 return this; 307 390 }; … … 348 431 var container, range, _i, _len, _ref; 349 432 this.mouseIsDown = false; 350 if (this.ignoreMouseup) return; 433 if (this.ignoreMouseup) { 434 return; 435 } 351 436 this.selectedRanges = this.getSelectedRanges(); 352 437 _ref = this.selectedRanges; … … 354 439 range = _ref[_i]; 355 440 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 } 357 447 } 358 448 if (event && this.selectedRanges.length) { … … 370 460 var annotations; 371 461 this.clearViewerHideTimer(); 372 if (this.mouseIsDown || this.viewer.isShown()) return false; 462 if (this.mouseIsDown || this.viewer.isShown()) { 463 return false; 464 } 373 465 annotations = $(event.target).parents('.annotator-hl').andSelf().map(function() { 374 466 return $(this).data("annotation"); … … 378 470 379 471 Annotator.prototype.onAdderMousedown = function(event) { 380 if (event != null) event.preventDefault(); 472 if (event != null) { 473 event.preventDefault(); 474 } 381 475 return this.ignoreMouseup = true; 382 476 }; 383 477 384 478 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 } 387 483 position = this.adder.position(); 388 484 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 } 389 507 return this.showEditor(this.createAnnotation(), position); 390 508 }; … … 420 538 })(Delegator); 421 539 540 g = util.getGlobal(); 541 542 if (!(((_ref = g.document) != null ? _ref.evaluate : void 0) != null)) { 543 $.getScript('http://assets.annotateit.org/vendor/xpath.min.js'); 544 } 545 546 if (!(g.getSelection != null)) { 547 $.getScript('http://assets.annotateit.org/vendor/ierange.min.js'); 548 } 549 550 if (!(g.JSON != null)) { 551 $.getScript('http://assets.annotateit.org/vendor/json2.min.js'); 552 } 553 422 554 Annotator.$ = $; 423 555 -
annotator_files/lib/class.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var Delegator, 2 __slice = Array.prototype.slice,3 __hasProp = Object.prototype.hasOwnProperty;3 __slice = [].slice, 4 __hasProp = {}.hasOwnProperty; 4 5 5 6 Delegator = (function() { … … 19 20 20 21 Delegator.prototype.addEvents = function() { 21 var event, functionName, sel, selector, _i, _ref, _ref 2, _results;22 var event, functionName, sel, selector, _i, _ref, _ref1, _results; 22 23 _ref = this.events; 23 24 _results = []; 24 25 for (sel in _ref) { 25 26 functionName = _ref[sel]; 26 _ref 2 = 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++]; 27 28 _results.push(this.addEvent(selector.join(' '), event, functionName)); 28 29 } … … 37 38 }; 38 39 isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === ''; 39 if (isBlankSelector) bindTo = this.element; 40 if (isBlankSelector) { 41 bindTo = this.element; 42 } 40 43 if (typeof bindTo === 'string') { 41 44 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 2 var fn, functions, _i, _j, _len, _len1, 3 __slice = [].slice; 3 4 4 5 functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"]; … … 10 11 }; 11 12 } 12 if (!(console.groupCollapsed != null)) console.groupCollapsed = console.group; 13 if (!(console.groupCollapsed != null)) { 14 console.groupCollapsed = console.group; 15 } 13 16 for (_i = 0, _len = functions.length; _i < _len; _i++) { 14 17 fn = functions[_i]; … … 21 24 } else { 22 25 this.console = {}; 23 for (_j = 0, _len 2 = functions.length; _j < _len2; _j++) {26 for (_j = 0, _len1 = functions.length; _j < _len1; _j++) { 24 27 fn = functions[_j]; 25 28 this.console[fn] = function() {}; -
annotator_files/lib/editor.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 4 5 5 6 Annotator.Editor = (function(_super) { … … 26 27 function Editor(options) { 27 28 this.onCancelButtonMouseover = __bind(this.onCancelButtonMouseover, this); 29 28 30 this.processKeypress = __bind(this.processKeypress, this); 31 29 32 this.submit = __bind(this.submit, this); 33 30 34 this.load = __bind(this.load, this); 35 31 36 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); 33 40 this.fields = []; 34 41 this.annotation = {}; … … 190 197 textarea.height(height + (diff.top * directionY)); 191 198 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 } 194 205 } else if (mousedown.element === controls[0]) { 195 206 editor.css({ -
annotator_files/lib/extensions.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var $, gettext, _gettext, _ref, _t; 2 3 … … 92 93 while (elem && elem.nodeType === 1 && elem !== relativeRoot) { 93 94 idx = $(elem.parentNode).children(elem.tagName).index(elem) + 1; 94 idx = idx > 1 ? "[" + idx + "]" : "";95 idx = "[" + idx + "]"; 95 96 path = "/" + elem.tagName.toLowerCase() + idx + path; 96 97 elem = elem.parentNode; … … 106 107 107 108 $.fn.escape = function(html) { 108 if (arguments.length) return this.html($.escape(html)); 109 if (arguments.length) { 110 return this.html($.escape(html)); 111 } 109 112 return this.html(); 110 113 }; 114 115 $.fn.reverse = [].reverse; -
annotator_files/lib/notification.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var Annotator, 2 3 __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; }; 5 6 6 7 Annotator = Annotator || {}; … … 26 27 function Notification(options) { 27 28 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); 29 32 } 30 33 31 34 Notification.prototype.show = function(message, status) { 32 if (status == null) status = Annotator.Notification.INFO; 35 if (status == null) { 36 status = Annotator.Notification.INFO; 37 } 33 38 $(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message || ""); 34 39 setTimeout(this.hide, 5000); -
annotator_files/lib/plugin/annotateitpermissions.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 5 6 6 7 Annotator.Plugin.AnnotateItPermissions = (function(_super) { 7 8 8 9 __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 } 9 21 10 22 AnnotateItPermissions.prototype.options = { … … 16 28 consumer: 'group:__consumer__' 17 29 }, 30 userId: function(user) { 31 return user.userId; 32 }, 18 33 userString: function(user) { 19 return user ;34 return user.userId; 20 35 }, 21 userAuthorize: function(action, annotation, user , consumer) {22 var action_field, permissions, _ref, _ref 2, _ref3, _ref4;36 userAuthorize: function(action, annotation, user) { 37 var action_field, permissions, _ref, _ref1, _ref2, _ref3; 23 38 permissions = annotation.permissions || {}; 24 39 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) { 29 44 return true; 30 } else if ( user === annotation.user && consumer === annotation.consumer) {45 } else if (_ref1 = this.groups.authenticated, __indexOf.call(action_field, _ref1) >= 0) { 31 46 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)) { 33 48 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)) { 35 50 return true; 36 } else if ( consumer === annotation.consumer && __indexOf.call(action_field, user) >= 0) {51 } else if (user.consumerKey === annotation.consumer && user.admin) { 37 52 return true; 38 53 } else { … … 41 56 } 42 57 }, 43 user: '',44 consumer: 'annotateit',45 58 permissions: { 46 59 'read': ['group:__world__'], … … 51 64 }; 52 65 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 78 66 AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) { 79 67 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 } 81 71 }; 82 72 … … 85 75 field = $(field).show(); 86 76 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 })) { 89 84 return input.attr('checked', 'checked'); 90 85 } else { … … 95 90 AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) { 96 91 var dataKey; 97 if (!annotation.permissions) annotation.permissions = this.options.permissions; 92 if (!annotation.permissions) { 93 annotation.permissions = this.options.permissions; 94 } 98 95 dataKey = type + '-permissions'; 99 96 if ($(field).find('input').is(':checked')) { … … 105 102 106 103 AnnotateItPermissions.prototype._setAuthFromToken = function(token) { 107 AnnotateItPermissions.__super__._setAuthFromToken.apply(this, arguments); 108 return this.setConsumer(token.consumerKey); 104 return this.setUser(token); 109 105 }; 110 106 -
annotator_files/lib/plugin/auth.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var 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; }; 4 5 5 6 createDateFromISO8601 = function(string) { … … 9 10 offset = 0; 10 11 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 } 17 30 if (d[14]) { 18 31 offset = (Number(d[16]) * 60) + Number(d[17]); … … 37 50 dec = ""; 38 51 tmp_arr = []; 39 if (!data) return data; 52 if (!data) { 53 return data; 54 } 40 55 data += ''; 41 56 while (i < data.length) { … … 61 76 62 77 base64UrlDecode = function(data) { 63 var i, m, _ ref;78 var i, m, _i, _ref; 64 79 m = data.length % 4; 65 80 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) { 67 82 data += '='; 68 83 } … … 176 191 177 192 Auth.prototype.withToken = function(callback) { 178 if (!(callback != null)) return; 193 if (!(callback != null)) { 194 return; 195 } 179 196 if (this.haveValidToken()) { 180 197 return callback(this._unsafeToken); 181 198 } else { 182 199 this.waitingForToken.push(callback); 183 if (!this.requestInProgress) return this.requestToken(); 200 if (!this.requestInProgress) { 201 return this.requestToken(); 202 } 184 203 } 185 204 }; -
annotator_files/lib/plugin/filter.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 4 5 5 6 Annotator.Plugin.Filter = (function(_super) { … … 35 36 isFiltered: function(input, property) { 36 37 var keyword, _i, _len, _ref; 37 if (!(input && property)) return false; 38 if (!(input && property)) { 39 return false; 40 } 38 41 _ref = input.split(/\s*/); 39 42 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 40 43 keyword = _ref[_i]; 41 if (property.indexOf(keyword) === -1) return false; 44 if (property.indexOf(keyword) === -1) { 45 return false; 46 } 42 47 } 43 48 return true; … … 47 52 function Filter(element, options) { 48 53 this._onPreviousClick = __bind(this._onPreviousClick, this); 54 49 55 this._onNextClick = __bind(this._onNextClick, this); 56 50 57 this._onFilterKeyup = __bind(this._onFilterKeyup, this); 58 51 59 this._onFilterBlur = __bind(this._onFilterBlur, this); 60 52 61 this._onFilterFocus = __bind(this._onFilterFocus, this); 53 this.updateHighlights = __bind(this.updateHighlights, this); element = $(this.html.element).appendTo(this.options.appendTo); 62 63 this.updateHighlights = __bind(this.updateHighlights, this); 64 65 var _base; 66 element = $(this.html.element).appendTo((options != null ? options.appendTo : void 0) || this.options.appendTo); 54 67 Filter.__super__.constructor.call(this, element, options); 68 (_base = this.options).filters || (_base.filters = []); 55 69 this.filter = $(this.html.filter); 56 70 this.filters = []; … … 106 120 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 107 121 f = _ref[_i]; 108 if (f.property === filter.property) _results.push(f); 122 if (f.property === filter.property) { 123 _results.push(f); 124 } 109 125 } 110 126 return _results; … … 153 169 154 170 Filter.prototype.filterHighlights = function() { 155 var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _ len, _ref;171 var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _i, _len, _ref; 156 172 activeFilters = $.grep(this.filters, function(filter) { 157 173 return !!filter.annotations.length; … … 174 190 } 175 191 highlights = this.highlights; 176 for (index = 0, _len = filtered.length; index < _len; index++) {192 for (index = _i = 0, _len = filtered.length; _i < _len; index = ++_i) { 177 193 annotation = filtered[index]; 178 194 highlights = highlights.not(annotation.highlights); … … 208 224 var filter; 209 225 filter = $(event.target).parent().data('filter'); 210 if (filter) return this.updateFilter(filter); 226 if (filter) { 227 return this.updateFilter(filter); 228 } 211 229 }; 212 230 213 231 Filter.prototype._findNextHighlight = function(previous) { 214 232 var active, annotation, current, index, next, offset, operator, resetOffset; 215 if (!this.highlights.length) return this; 233 if (!this.highlights.length) { 234 return this; 235 } 216 236 offset = previous ? 0 : -1; 217 237 resetOffset = previous ? -1 : 0; … … 219 239 active = this.highlights.not('.' + this.classes.hl.hide); 220 240 current = active.filter('.' + this.classes.hl.active); 221 if (!current.length) current = active.eq(offset); 241 if (!current.length) { 242 current = active.eq(offset); 243 } 222 244 annotation = current.data('annotation'); 223 245 index = active.index(current[0]); 224 246 next = active.filter(":" + operator + "(" + index + ")").not(annotation.highlights).eq(resetOffset); 225 if (!next.length) next = active.eq(resetOffset); 247 if (!next.length) { 248 next = active.eq(resetOffset); 249 } 226 250 return this._scrollToHighlight(next.data('annotation').highlights); 227 251 }; -
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 2 var __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; }; 3 4 4 5 Annotator.prototype.setupPlugins = function(config, options) { 5 6 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 } 8 13 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 } 11 18 uri = win.location.href.split(/#|\?/).shift() || ''; 12 19 pluginConfig = { … … 39 46 if (!__hasProp.call(options, name)) continue; 40 47 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 } 42 51 } 43 52 $.extend(true, pluginConfig, options); -
annotator_files/lib/plugin/markdown.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 4 5 5 6 Annotator.Plugin.Markdown = (function(_super) { … … 12 13 13 14 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) { 15 17 Markdown.__super__.constructor.apply(this, arguments); 16 18 this.converter = new Showdown.converter(); -
annotator_files/lib/plugin/permissions.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 4 5 5 6 Annotator.Plugin.Permissions = (function(_super) { … … 24 25 if (annotation.permissions) { 25 26 tokens = annotation.permissions[action] || []; 26 if (tokens.length === 0) return true; 27 if (tokens.length === 0) { 28 return true; 29 } 27 30 for (_i = 0, _len = tokens.length; _i < _len; _i++) { 28 31 token = tokens[_i]; 29 if (this.userId(user) === token) return true; 32 if (this.userId(user) === token) { 33 return true; 34 } 30 35 } 31 36 return false; … … 46 51 function Permissions(element, options) { 47 52 this._setAuthFromToken = __bind(this._setAuthFromToken, this); 53 48 54 this.updateViewer = __bind(this.updateViewer, this); 55 49 56 this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this); 57 50 58 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); 52 62 if (this.options.user) { 53 63 this.setUser(this.options.user); … … 59 69 var createCallback, self, 60 70 _this = this; 61 if (!Annotator.supported()) return; 71 if (!Annotator.supported()) { 72 return; 73 } 62 74 self = this; 63 75 createCallback = function(method, type) { … … 95 107 var keyword, _i, _len, _ref; 96 108 user = _this.options.userString(user); 97 if (!(input && user)) return false; 109 if (!(input && user)) { 110 return false; 111 } 98 112 _ref = input.split(/\s*/); 99 113 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 100 114 keyword = _ref[_i]; 101 if (user.indexOf(keyword) === -1) return false; 115 if (user.indexOf(keyword) === -1) { 116 return false; 117 } 102 118 } 103 119 return true; … … 114 130 if (annotation) { 115 131 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 } 117 135 } 118 136 }; 119 137 120 138 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 } 122 142 if (this.options.userAuthorize) { 123 143 return this.options.userAuthorize.call(this.options, action, annotation, user); … … 131 151 field = $(field).show(); 132 152 input = field.find('input').removeAttr('disabled'); 133 if (!this.authorize('admin', annotation)) field.hide(); 153 if (!this.authorize('admin', annotation)) { 154 field.hide(); 155 } 134 156 if (this.authorize(action, annotation || {}, null)) { 135 157 return input.attr('checked', 'checked'); … … 141 163 Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) { 142 164 var dataKey; 143 if (!annotation.permissions) annotation.permissions = this.options.permissions; 165 if (!annotation.permissions) { 166 annotation.permissions = this.options.permissions; 167 } 144 168 dataKey = type + '-permissions'; 145 169 if ($(field).find('input').is(':checked')) { … … 160 184 field.remove(); 161 185 } 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 } 164 192 }; 165 193 -
annotator_files/lib/plugin/store.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 5 6 6 7 Annotator.Plugin.Store = (function(_super) { … … 30 31 function Store(element, options) { 31 32 this._onError = __bind(this._onError, this); 33 32 34 this._onLoadAnnotationsFromSearch = __bind(this._onLoadAnnotationsFromSearch, this); 35 33 36 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); 35 40 this.annotations = []; 36 41 } 37 42 38 43 Store.prototype.pluginInit = function() { 39 if (!Annotator.supported()) return; 44 if (!Annotator.supported()) { 45 return; 46 } 40 47 if (this.annotator.plugins.Auth) { 41 48 return this.annotator.plugins.Auth.withToken(this._getAnnotations); … … 108 115 109 116 Store.prototype._onLoadAnnotations = function(data) { 110 if (data == null) data = []; 117 if (data == null) { 118 data = []; 119 } 111 120 this.annotations = data; 112 121 return this.annotator.loadAnnotations(data.slice()); … … 118 127 119 128 Store.prototype._onLoadAnnotationsFromSearch = function(data) { 120 if (data == null) data = {}; 129 if (data == null) { 130 data = {}; 131 } 121 132 return this._onLoadAnnotations(data.rows || []); 122 133 }; … … 193 204 $.extend(annotation, this.options.annotationData); 194 205 data = JSON.stringify(annotation); 195 if (highlights) annotation.highlights = highlights; 206 if (highlights) { 207 annotation.highlights = highlights; 208 } 196 209 return data; 197 210 }; -
annotator_files/lib/plugin/tags.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var __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; }; 4 5 5 6 Annotator.Plugin.Tags = (function(_super) { … … 9 10 function Tags() { 10 11 this.setAnnotationTags = __bind(this.setAnnotationTags, this); 12 11 13 this.updateField = __bind(this.updateField, this); 12 Tags.__super__.constructor.apply(this, arguments);14 return Tags.__super__.constructor.apply(this, arguments); 13 15 } 14 16 … … 18 20 string = $.trim(string); 19 21 tags = []; 20 if (string) tags = string.split(/\s+/); 22 if (string) { 23 tags = string.split(/\s+/); 24 } 21 25 return tags; 22 26 }, … … 31 35 32 36 Tags.prototype.pluginInit = function() { 33 if (!Annotator.supported()) return; 37 if (!Annotator.supported()) { 38 return; 39 } 34 40 this.field = this.annotator.editor.addField({ 35 41 label: Annotator._t('Add some tags here') + '\u2026', … … 61 67 var value; 62 68 value = ''; 63 if (annotation.tags) value = this.stringifyTags(annotation.tags); 69 if (annotation.tags) { 70 value = this.stringifyTags(annotation.tags); 71 } 64 72 return this.input.val(value); 65 73 }; … … 88 96 89 97 Annotator.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 } 92 102 matches = 0; 93 103 keywords = []; … … 97 107 keyword = keywords[_i]; 98 108 if (tags.length) { 99 for (_j = 0, _len 2 = tags.length; _j < _len2; _j++) {109 for (_j = 0, _len1 = tags.length; _j < _len1; _j++) { 100 110 tag = tags[_j]; 101 if (tag.indexOf(keyword) !== -1) matches += 1; 111 if (tag.indexOf(keyword) !== -1) { 112 matches += 1; 113 } 102 114 } 103 115 } -
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 2 var __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; }; 3 4 4 5 Annotator.Plugin.Unsupported = (function(_super) { … … 7 8 8 9 function Unsupported() { 9 Unsupported.__super__.constructor.apply(this, arguments);10 return Unsupported.__super__.constructor.apply(this, arguments); 10 11 } 11 12 -
annotator_files/lib/range.js
r3 r4 1 var Range; 1 // Generated by CoffeeScript 1.3.3 2 var 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; }; 2 5 3 6 Range = {}; … … 16 19 }; 17 20 21 Range.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 66 Range.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 18 81 Range.BrowserRange = (function() { 19 82 … … 41 104 node = this[p + 'Container']; 42 105 offset = this[p + 'Offset']; 43 if (!((node != null) && (offset != null))) return false; 106 if (!((node != null) && (offset != null))) { 107 return false; 108 } 44 109 if (node.nodeType === 1) { 45 110 it = node.childNodes[offset]; … … 64 129 nr.end = nr.start; 65 130 } 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 } 67 134 nr.end = r.end; 68 135 } … … 99 166 return node.parentNode === bounds || $.contains(bounds, node.parentNode); 100 167 }); 101 if (!nodes.length) return null; 168 if (!nodes.length) { 169 return null; 170 } 102 171 this.start = nodes[0]; 103 172 this.end = nodes[nodes.length - 1]; … … 189 258 } 190 259 191 SerializedRange.prototype. _nodeFromXPath = function(xpath) {192 var c ustomResolver, 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 } 202 271 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 } 254 274 length = 0; 255 _ref 3 = $(this._nodeFromXPath(parentXPath + this[p])).textNodes();256 for (_j = 0, _len 2 = _ref3.length; _j < _len2; _j++) {257 tn = _ref 3[_j];275 _ref1 = $(node).textNodes(); 276 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 277 tn = _ref1[_j]; 258 278 if (length + tn.nodeValue.length >= this[p + 'Offset']) { 259 279 range[p + 'Container'] = tn; … … 264 284 } 265 285 } 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 }); 267 301 return new Range.BrowserRange(range).normalize(root); 268 302 }; -
annotator_files/lib/viewer.js
r3 r4 1 // Generated by CoffeeScript 1.3.3 1 2 var LinkParser, 2 3 __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; }; 5 6 6 7 Annotator.Viewer = (function(_super) { … … 29 30 function Viewer(options) { 30 31 this.onDeleteClick = __bind(this.onDeleteClick, this); 32 31 33 this.onEditClick = __bind(this.onEditClick, this); 34 32 35 this.load = __bind(this.load, this); 36 33 37 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); 35 41 this.item = $(this.html.item)[0]; 36 42 this.fields = []; … … 61 67 62 68 Viewer.prototype.load = function(annotations) { 63 var annotation, controller, controls, del, edit, element, field, item, link, links, list, _i, _j, _len, _len 2, _ref, _ref2;69 var annotation, controller, controls, del, edit, element, field, item, link, links, list, _i, _j, _len, _len1, _ref, _ref1; 64 70 this.annotations = annotations || []; 65 71 list = this.element.find('ul:first').empty(); … … 99 105 }; 100 106 } 101 _ref 2= this.fields;102 for (_j = 0, _len 2 = _ref2.length; _j < _len2; _j++) {103 field = _ref 2[_j];107 _ref1 = this.fields; 108 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 109 field = _ref1[_j]; 104 110 element = $(field.element).clone().appendTo(item)[0]; 105 111 field.load(element, annotation, controller); … … 147 153 LinkParser.prototype.get = function(rel, cond) { 148 154 var d, k, keys, match, v, _i, _len, _ref, _results; 149 if (cond == null) cond = {}; 155 if (cond == null) { 156 cond = {}; 157 } 150 158 cond = $.extend({}, cond, { 151 159 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 2 var __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; }; 3 4 4 5 Annotator.Widget = (function(_super) { … … 33 34 right: offset.left + widget.width() 34 35 }; 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 } 37 42 return this; 38 43 };
Note: See TracChangeset
for help on using the changeset viewer.