1. Rufus Pollock
  2. commentonit

Commits

Rufus Pollock  committed eea6ca6

[annotator/store][s]: tabs for spaces and some very minor tweaks to try and get this more compatible with couch.

  • Participants
  • Parent commits 5a66359
  • Branches couchdb

Comments (0)

Files changed (1)

File vendor/annotator/_attachments/storecouchdb.js

View file
  • Ignore whitespace
 ;(function($){
 
 function apiRequest (opts) {
-  opts = $.extend({
+	opts = $.extend({
 	contentType: 'application/json',
-    success: function () {}
-  }, opts)
+		success: function () {}
+	}, opts)
 
-  return $.ajax(opts)
+	return $.ajax(opts)
 }
 
-Annotator.Plugins.Store = DelegatorClass.extend({
-  events: {
-    'annotationCreated': 'annotationCreated',
-    'annotationDeleted': 'annotationDeleted',
-    'annotationUpdated': 'annotationUpdated'
-  },
+Annotator.Plugins.StoreCouchdb = DelegatorClass.extend({
+	events: {
+		'annotationCreated': 'annotationCreated',
+		'annotationDeleted': 'annotationDeleted',
+		'annotationUpdated': 'annotationUpdated'
+	},
 
-  options: {
-    prefix: '/store',
+	options: {
+		prefix: '/store',
 
-    annotationData: {},
+		annotationData: {},
 
-    // If loadFromSearch is set, then we load the first batch of
-    // annotations from 'prefix/search(options=loadFromSearch)'
-    // instead of the registry path 'prefix/read'.
-    //
-    //     loadFromSearch: {
-    //       'limit': 0,
-    //       'all_fields': 1
-    //       'uri': 'http://this/document/only'
-    //     }
-    loadFromSearch: false,
+		// If loadFromSearch is set, then we load the first batch of
+		// annotations from 'prefix/search(options=loadFromSearch)'
+		// instead of the registry path 'prefix/read'.
+		//
+		//		 loadFromSearch: {
+		//			 'limit': 0,
+		//			 'all_fields': 1
+		//			 'uri': 'http://this/document/only'
+		//		 }
 
-    urls: {
-      'create':  '/annotations',     // POST
-      'read':    '/annotations/:id', // GET
-      'update':  '/annotations/:id', // PUT (since idempotent)
-      'destroy': '/annotations/:id', // DELETE
-      'search':  '/search'
-    }
-  },
+		urls: {
+			'create':	'/annotations',		 // POST
+			'read':		'/annotations/:id', // GET
+			'update':	'/annotations/:id', // PUT (since idempotent)
+			'destroy': '/annotations/:id', // DELETE
+			'search':	'/search'
+		}
+	},
 
-  init: function (options, element) {
-    this.options = $.extend(this.options, options)
+	init: function (options, element) {
+		this.options = $.extend(this.options, options)
 
-    this.options.annotator = $(element).data('annotator')
+		this.options.annotator = $(element).data('annotator')
 
-    this.element = element
-    this.annotations = []
+		this.element = element
+		this.annotations = []
 
-    if (this.options.loadFromSearch) {
-      this.loadAnnotationsFromSearch(this.options.loadFromSearch)
-    } else {
-      this.loadAnnotations()
-    }
+		// disable initial load for the time being ...
+		// this.loadAnnotationsFromSearch(this.options.loadFromSearch)
 
-    this._super()
-  },
+		this._super()
+	},
 
-  annotationCreated: function (e, annotation) {
-    var self = this
+	annotationCreated: function (e, annotation) {
+		var self = this
 
-    // Pre-register the annotation so as to save the list of highlight
-    // elements.
-    if (this.annotations.indexOf(annotation) === -1) {
-      this.registerAnnotation(annotation)
+		// Pre-register the annotation so as to save the list of highlight
+		// elements.
+		if (this.annotations.indexOf(annotation) === -1) {
+			this.registerAnnotation(annotation)
 
-      apiRequest({
-        url: this._urlFor('create'),
-        data: this._dataFor(annotation).json,
-        type: 'POST',
-        success: function (data) {
-          // Update with (e.g.) ID from server.
-          if (!("id" in data)) { console.warn("Warning: No ID returned from server for annotation ", annotation) }
-          self.updateAnnotation(annotation, data)
-        }
-      })
+			apiRequest({
+				url: this._urlFor('create'),
+				data: this._dataFor(annotation).json,
+				type: 'POST',
+				success: function (data) {
+					// Update with (e.g.) ID from server.
+					if (!("id" in data)) { console.warn("Warning: No ID returned from server for annotation ", annotation) }
+					self.updateAnnotation(annotation, data)
+				}
+			})
 
-    } else {
-      // This is called to update annotations created at load time with
-      // the highlight elements created by Annotator.
-      this.updateAnnotation(annotation, {})
-    }
-  },
+		} else {
+			// This is called to update annotations created at load time with
+			// the highlight elements created by Annotator.
+			this.updateAnnotation(annotation, {})
+		}
+	},
 
-  annotationDeleted: function (e, annotation) {
-    var self = this
+	annotationDeleted: function (e, annotation) {
+		var self = this
 
-    if ($.inArray(annotation, this.annotations) !== -1) {
-      apiRequest({
-        url: this._urlFor('destroy', annotation.id),
-        type: 'DELETE',
-        success: function () { self.unregisterAnnotation(annotation) }
-      })
-    }
-  },
+		if ($.inArray(annotation, this.annotations) !== -1) {
+			apiRequest({
+				url: this._urlFor('destroy', annotation.id),
+				type: 'DELETE',
+				success: function () { self.unregisterAnnotation(annotation) }
+			})
+		}
+	},
 
-  annotationUpdated: function (e, annotation) {
-    var self = this
+	annotationUpdated: function (e, annotation) {
+		var self = this
 
-    if ($.inArray(annotation, this.annotations) !== -1) {
-      apiRequest({
-        url: this._urlFor('update', annotation.id),
-        type: 'PUT',
-        data: this._dataFor(annotation),
-        success: function () { self.updateAnnotation(annotation) }
-      })
-    }
-  },
+		if ($.inArray(annotation, this.annotations) !== -1) {
+			apiRequest({
+				url: this._urlFor('update', annotation.id),
+				type: 'PUT',
+				data: this._dataFor(annotation),
+				success: function () { self.updateAnnotation(annotation) }
+			})
+		}
+	},
 
-  // NB: registerAnnotation and unregisterAnnotation do no error-checking/
-  // duplication avoidance of their own. Use with care.
-  registerAnnotation: function (annotation) {
+	// NB: registerAnnotation and unregisterAnnotation do no error-checking/
+	// duplication avoidance of their own. Use with care.
+	registerAnnotation: function (annotation) {
 	console.log(this)
 	console.log(this.annotations)
-    this.annotations.push(annotation)
-  },
+		this.annotations.push(annotation)
+	},
 
-  unregisterAnnotation: function (annotation) {
-    this.annotations.splice(this.annotations.indexOf(annotation), 1)
-  },
+	unregisterAnnotation: function (annotation) {
+		this.annotations.splice(this.annotations.indexOf(annotation), 1)
+	},
 
-  updateAnnotation: function (annotation, data) {
-    if ($.inArray(annotation, this.annotations) === -1) {
-      console.error("Trying to update unregistered annotation!")
-    } else {
-      $.extend(annotation, data)
-    }
+	updateAnnotation: function (annotation, data) {
+		if ($.inArray(annotation, this.annotations) === -1) {
+			console.error("Trying to update unregistered annotation!")
+		} else {
+			$.extend(annotation, data)
+		}
 
-    // Update the elements with our copies of the annotation objects (e.g.
-    // with ids from the server).
-    $(annotation.highlights).data('annotation', annotation)
-  },
+		// Update the elements with our copies of the annotation objects (e.g.
+		// with ids from the server).
+		$(annotation.highlights).data('annotation', annotation)
+	},
 
-  loadAnnotations: function () {
-    var self = this
+	loadAnnotations: function () {
+		var self = this
 
-    apiRequest({
-      url: this._urlFor('read'),
-      type: 'GET',
-      success: function (data) {
-        self.annotations = data
-        self.options.annotator.loadAnnotations(self.annotations)
-      }
-    })
-  },
+		apiRequest({
+			url: this._urlFor('read'),
+			type: 'GET',
+			success: function (data) {
+				self.annotations = data
+				self.options.annotator.loadAnnotations(self.annotations)
+			}
+		})
+	},
 
-  loadAnnotationsFromSearch: function (searchOptions) {
-    var self = this
-    apiRequest({
-      url: this._urlFor('search'),
-      type: 'GET',
-      data: searchOptions,
-      success: function (data) {
-        self.annotations = data.results
-        self.options.annotator.loadAnnotations(self.annotations)
-      }
-    })
-  },
+	loadAnnotationsFromSearch: function (searchOptions) {
+		var self = this
+		apiRequest({
+			url: this._urlFor('search'),
+			type: 'GET',
+			data: searchOptions,
+			success: function (data) {
+				self.annotations = data.results
+				self.options.annotator.loadAnnotations(self.annotations)
+			}
+		})
+	},
 
-  _urlFor: function (action, id) {
-    var url = this.options.prefix || '';
-    url += this.options.urls[action].replace(/\/:id/, id ? '/' + id : '')
-    return url
-  },
+	_urlFor: function (action, id) {
+		var url = this.options.prefix || '';
+		url += this.options.urls[action].replace(/\/:id/, id ? '/' + id : '')
+		return url
+	},
 
-  _dataFor: function (annotation) {
-    // Store a reference to the highlights array. We can't serialize
-    // a list of HTML Element objects.
-    var highlights = annotation.highlights
+	_dataFor: function (annotation) {
+		// Store a reference to the highlights array. We can't serialize
+		// a list of HTML Element objects.
+		var highlights = annotation.highlights
 
-    delete annotation.highlights
+		delete annotation.highlights
 
-    // Preload with extra data.
-    $.extend(annotation, this.options.annotationData)
-    var data = { json: $.toJSON(annotation) }
+		// Preload with extra data.
+		$.extend(annotation, this.options.annotationData)
+		var data = { json: $.toJSON(annotation) }
 
-    // Restore the highlights array.
-    annotation.highlights = highlights
+		// Restore the highlights array.
+		annotation.highlights = highlights
 
-    return data
-  }
+		return data
+	}
 })
 
 })(jQuery)