Mercurial > hg > OKFNAnnotator
comparison annotator_files/lib/plugin/store.js @ 4:6979313586cf
new version of annotator.
author | casties |
---|---|
date | Mon, 27 Aug 2012 19:05:38 +0200 |
parents | 6356e78ccf5c |
children |
comparison
equal
deleted
inserted
replaced
3:6356e78ccf5c | 4:6979313586cf |
---|---|
1 // Generated by CoffeeScript 1.3.3 | |
1 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | 2 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, |
2 __hasProp = Object.prototype.hasOwnProperty, | 3 __hasProp = {}.hasOwnProperty, |
3 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, | 4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
4 __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; }; | 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 Annotator.Plugin.Store = (function(_super) { | 7 Annotator.Plugin.Store = (function(_super) { |
7 | 8 |
8 __extends(Store, _super); | 9 __extends(Store, _super); |
9 | 10 |
27 } | 28 } |
28 }; | 29 }; |
29 | 30 |
30 function Store(element, options) { | 31 function Store(element, options) { |
31 this._onError = __bind(this._onError, this); | 32 this._onError = __bind(this._onError, this); |
33 | |
32 this._onLoadAnnotationsFromSearch = __bind(this._onLoadAnnotationsFromSearch, this); | 34 this._onLoadAnnotationsFromSearch = __bind(this._onLoadAnnotationsFromSearch, this); |
35 | |
33 this._onLoadAnnotations = __bind(this._onLoadAnnotations, this); | 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 this.annotations = []; | 40 this.annotations = []; |
36 } | 41 } |
37 | 42 |
38 Store.prototype.pluginInit = function() { | 43 Store.prototype.pluginInit = function() { |
39 if (!Annotator.supported()) return; | 44 if (!Annotator.supported()) { |
45 return; | |
46 } | |
40 if (this.annotator.plugins.Auth) { | 47 if (this.annotator.plugins.Auth) { |
41 return this.annotator.plugins.Auth.withToken(this._getAnnotations); | 48 return this.annotator.plugins.Auth.withToken(this._getAnnotations); |
42 } else { | 49 } else { |
43 return this._getAnnotations(); | 50 return this._getAnnotations(); |
44 } | 51 } |
105 Store.prototype.loadAnnotations = function() { | 112 Store.prototype.loadAnnotations = function() { |
106 return this._apiRequest('read', null, this._onLoadAnnotations); | 113 return this._apiRequest('read', null, this._onLoadAnnotations); |
107 }; | 114 }; |
108 | 115 |
109 Store.prototype._onLoadAnnotations = function(data) { | 116 Store.prototype._onLoadAnnotations = function(data) { |
110 if (data == null) data = []; | 117 if (data == null) { |
118 data = []; | |
119 } | |
111 this.annotations = data; | 120 this.annotations = data; |
112 return this.annotator.loadAnnotations(data.slice()); | 121 return this.annotator.loadAnnotations(data.slice()); |
113 }; | 122 }; |
114 | 123 |
115 Store.prototype.loadAnnotationsFromSearch = function(searchOptions) { | 124 Store.prototype.loadAnnotationsFromSearch = function(searchOptions) { |
116 return this._apiRequest('search', searchOptions, this._onLoadAnnotationsFromSearch); | 125 return this._apiRequest('search', searchOptions, this._onLoadAnnotationsFromSearch); |
117 }; | 126 }; |
118 | 127 |
119 Store.prototype._onLoadAnnotationsFromSearch = function(data) { | 128 Store.prototype._onLoadAnnotationsFromSearch = function(data) { |
120 if (data == null) data = {}; | 129 if (data == null) { |
130 data = {}; | |
131 } | |
121 return this._onLoadAnnotations(data.rows || []); | 132 return this._onLoadAnnotations(data.rows || []); |
122 }; | 133 }; |
123 | 134 |
124 Store.prototype.dumpAnnotations = function() { | 135 Store.prototype.dumpAnnotations = function() { |
125 var ann, _i, _len, _ref, _results; | 136 var ann, _i, _len, _ref, _results; |
190 var data, highlights; | 201 var data, highlights; |
191 highlights = annotation.highlights; | 202 highlights = annotation.highlights; |
192 delete annotation.highlights; | 203 delete annotation.highlights; |
193 $.extend(annotation, this.options.annotationData); | 204 $.extend(annotation, this.options.annotationData); |
194 data = JSON.stringify(annotation); | 205 data = JSON.stringify(annotation); |
195 if (highlights) annotation.highlights = highlights; | 206 if (highlights) { |
207 annotation.highlights = highlights; | |
208 } | |
196 return data; | 209 return data; |
197 }; | 210 }; |
198 | 211 |
199 Store.prototype._onError = function(xhr) { | 212 Store.prototype._onError = function(xhr) { |
200 var action, message; | 213 var action, message; |