Skip to content

Commit 2e7fced

Browse files
committed
Extend service with method to set color properties.
Add documentation to all methods of the service. Version bump.
1 parent 286e66c commit 2e7fced

3 files changed

Lines changed: 177 additions & 6 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-annotorious",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"author": {
55
"name": "Igor Lino",
66
"url": "http://igorlino.github.io/angular-annotorious/"

js/angular-annotorious.js

Lines changed: 175 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*global anno:false */
12
(function () {
23
'use strict';
34

@@ -18,6 +19,7 @@
1819
activateSelector: activateSelector,//(opt_item_url_or_callback, opt_callback)
1920
addAnnotation: addAnnotation,//(annotation, opt_replace)
2021

22+
setProperties: setProperties, //(opt_options)
2123
addHandler: addHandler, //(type, handler)
2224
addPlugin: addPlugin, //(pluginName, opt_config_options)
2325
destroy: destroy, //(opt_item_url)
@@ -40,6 +42,34 @@
4042
return anno;
4143
}
4244

45+
/**
46+
* Sets the color properties for the annotation canvas.
47+
* NOTE: The text dialogs are out-of-scope and per CSS customizable.
48+
* The following properties can be changed:
49+
*
50+
* {
51+
* outline: '#00f',
52+
* stroke: '#ff0000',
53+
* fill: 'rgba(255, 0, 0, 0.3)',
54+
* hi_stroke: '#00ff00',
55+
* hi_fill: 'rgba(0, 255, 0, 0.3)'
56+
* }
57+
*
58+
* @param props
59+
*/
60+
function setProperties(props) {
61+
getAnnotorious().setProperties(props);
62+
}
63+
64+
/**
65+
* Creates and registers a plugin.
66+
*
67+
* @param pluginId
68+
* @param opt_config_options
69+
* @param pluginFunc
70+
* @param initFunc
71+
* @param annotatorFunc
72+
*/
4373
function createPlugin(pluginId, opt_config_options, pluginFunc, initFunc, annotatorFunc) {
4474
if (!opt_config_options) {
4575
opt_config_options = {};
@@ -71,66 +101,207 @@
71101
addPlugin(pluginId, opt_config_options);
72102
}
73103

104+
105+
/**
106+
* NOTE: this method is currently only relevant for the OpenLayers module.
107+
* Feel free to ignore in case you are only using the standard image annotation features of Annotorious.
108+
* Manually actives the selector. The selector can be activated on a specific
109+
* item or globally, on all items (which serves mainly as a shortcut for pages where
110+
* there is only one annotatable item). The function can take a callback function as parameter,
111+
* which will be called when the selector is deactivated again.
112+
*
113+
* @param opt_item_url_or_callback
114+
* @param opt_callback
115+
* @returns {*}
116+
*/
74117
function activateSelector(opt_item_url_or_callback, opt_callback) {
75118
return getAnnotorious().activateSelector(opt_item_url_or_callback, opt_callback);
76119
}
77120

121+
/**
122+
* Adds a new annotation, or replaces an existing annotation with a new annotation.
123+
* (In the latter case, the parameter opt_replace must be the existing annotation.)
124+
*
125+
* @param annotation
126+
* @param opt_replace
127+
* @returns {*}
128+
*/
78129
function addAnnotation(annotation, opt_replace) {
79130
return getAnnotorious().addAnnotation(annotation, opt_replace);
80131
}
81132

133+
/**
134+
* Adds an event handler function.
135+
*
136+
Annotorious issues the following events:
137+
138+
onMouseOverItem(event) - fired when the mouse enters an annotatable item
139+
onMouseOutOfItem(event) - fired when the mouse leaves an annotatable item
140+
onMouseOverAnnotation(event) - fired when the mouse enters an annotation
141+
onMouseOutOfAnnotation(event) - fired when the mouse leaves an annotation
142+
onSelectionStarted(event) - fired when the user starts a selection
143+
onSelectionCanceled(event) - fired when the user cancels a selection (not available on all selection tools)
144+
onSelectionCompleted(event) - fired when the user completes a selection
145+
onSelectionChanged(event) - fired when the user changed a selection
146+
beforePopupHide(popup) - fired just before the annotation info popup window hides
147+
beforeAnnotationRemoved(annotation) - fired before an annotation is removed (Note: it is possible to prevent annotation removal by returning false from the handler method!)
148+
onAnnotationRemoved(annotation) - fired when an annotation is removed from an imgae
149+
onAnnotationCreated(annotation) - fired when an annotation was created
150+
onAnnotationUpdated(annotation) - fired when an existing annotation was edited/updated
151+
*
152+
* @param type
153+
* @param handler
154+
* @returns {*}
155+
*/
82156
function addHandler(type, handler) {
83157
return getAnnotorious().addHandler(type, handler);
84158
}
85159

160+
/**
161+
* Registers a plugin. For more information,
162+
* see the Plugins Wiki page https://github.com/annotorious/annotorious/wiki/Plugins.
163+
*
164+
* @param pluginName
165+
* @param opt_config_options
166+
* @returns {*}
167+
*/
86168
function addPlugin(pluginName, opt_config_options) {
87169
return getAnnotorious().addPlugin(pluginName, opt_config_options);
88170
}
89171

172+
/**
173+
* Destroys annotation functionality on a specific item, or on all items on the page.
174+
* Note that this method differs from anno.reset() (see below) insofar as destroy does not
175+
* re-evaluate the annotatable CSS attributes. What is destroyed, stays destroyed.
176+
* (Until re-enabled through anno.makeAnnotatable()).
177+
*
178+
* @param opt_item_url
179+
* @returns {*}
180+
*/
90181
function destroy(opt_item_url) {
91182
return getAnnotorious().destroy(opt_item_url);
92183
}
93184

185+
/**
186+
* Returns the current annotations. opt_item_url is optional. If omitted,
187+
* the method call will return all annotations, on all annotatable items on the page.
188+
* If set to a specific item URL, only the annotations on that item will be returned.
189+
*
190+
* @param opt_item_url
191+
* @returns {*}
192+
*/
94193
function getAnnotations(opt_item_url) {
95194
return getAnnotorious().getAnnotations(opt_item_url);
96195
}
97196

197+
/**
198+
* Hides existing annotations on all, or a specific item.
199+
*
200+
* @param opt_item_url
201+
* @returns {*}
202+
*/
98203
function hideAnnotations(opt_item_url) {
99204
return getAnnotorious().hideAnnotations(opt_item_url);
100205
}
101206

207+
/**
208+
* Disables the selection widget (the small tooltip in the upper left corner which
209+
* says "Click and Drag to Annotate"), thus preventing users from creating new annotations
210+
* altogether. The typical use case for this is 'read-only' annotated images.
211+
* I.e. if you want to add some pre-defined annotations using anno.addAnnotation without the
212+
* user being able to add or change anything.
213+
*
214+
* The selection widget can be hidden on a specific item or globally, on all annotatable items on the page.
215+
*
216+
* @param opt_item_url
217+
* @returns {*}
218+
*/
102219
function hideSelectionWidget(opt_item_url) {
103220
return getAnnotorious().hideSelectionWidget(opt_item_url);
104221
}
105222

223+
/**
224+
* Highlights the specified annotation, just as if the mouse pointer was hovering over it.
225+
* The annotation will remain highlighted until one of these conditions is met:
226+
*
227+
* -The user moves the mouse into, and out of the annotation
228+
* -The user moves the mouse over another annotation
229+
* -The highlight is removed by calling this method with an empty parameter, e.g. anno.highlightAnnotation() or anno.highlightAnnotation(undefined)
230+
* -Another annotation is highlighted via anno.highlightAnnotation
231+
*
232+
* @param annotation
233+
* @returns {*}
234+
*/
106235
function highlightAnnotation(annotation) {
107236
return getAnnotorious().highlightAnnotation(annotation);
108237
}
109238

239+
/**
240+
* Makes an item on the screen annotatable (if there is a module available supporting the item format).
241+
* You can use this method as an alternative to CSS-based activation. It works just the same way,
242+
* and is simply there for convenience, and to prepare for (future) item formats that technically
243+
* don't support CSS-based activation (such as Web maps).
244+
*
245+
* @param item
246+
* @returns {*}
247+
*/
110248
function makeAnnotatable(item) {
111249
return getAnnotorious().makeAnnotatable(item);
112250
}
113251

252+
/**
253+
* Removes all annotations. If the optional parameter opt_item_url is set, only the annotations on the
254+
* specified item will be removed. Otherwise all annotations on all items on the page will be removed.
255+
*
256+
* @param opt_item_url
257+
* @returns {*}
258+
*/
114259
function removeAll(opt_item_url) {
115260
return getAnnotorious().removeAll(opt_item_url);
116261
}
117262

263+
/**
264+
* Removes an annotation from the page.
265+
*
266+
* @param annotation
267+
* @returns {*}
268+
*/
118269
function removeAnnotation(annotation) {
119270
return getAnnotorious().removeAnnotation(annotation);
120271
}
121272

122-
/*
123-
reset Annotorious
124-
Annotorious will destroy the current annotation canvas, and create a new one
273+
/**
274+
* Performs a 'hard reset' on Annotorious. This means all annotation features will be removed,
275+
* and the page will be re-scanned for items with the 'annotatable' CSS class. (Note: this method
276+
* could be handy in case you are working with JavaScript image carousels. Just make sure
277+
* the images have 'annotatable' set, then reset Annotorious after each page flip.)
278+
*
279+
* NOTE: Annotorious will destroy the current annotation canvas, and create a new one
280+
*
281+
* @returns {*}
125282
*/
126283
function reset() {
127284
return getAnnotorious().reset();
128285
}
129286

287+
/**
288+
* Shows existing annotations on all, or a specific item (if they were hidden using anno.hideAnnotations).
289+
*
290+
* @param opt_item_url
291+
* @returns {*}
292+
*/
130293
function showAnnotations(opt_item_url) {
131294
return getAnnotorious().showAnnotations(opt_item_url);
132295
}
133296

297+
/**
298+
* Enables the selection widget (the small tooltip in the upper left corner which says
299+
* "Click and Drag to Annotate"), thus enabling users to creating new annotations.
300+
* (Per default, the selection widget is enabled.)
301+
*
302+
* @param opt_item_url
303+
* @returns {*}
304+
*/
134305
function showSelectionWidget(opt_item_url) {
135306
return getAnnotorious().showSelectionWidget(opt_item_url);
136307
}
@@ -153,7 +324,7 @@
153324
if ($attributes.src) {
154325
annotoriousService.makeAnnotatable($element[0]);
155326
} else {
156-
$element.bind('load', function() {
327+
$element.bind('load', function () {
157328
$scope.$apply(function () {
158329
annotoriousService.makeAnnotatable($element[0]);
159330
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-annotorious",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"title": "Angular Annotorious",
55
"description": "Angular directive for Annotorius to start drawing and commenting to images on your Web page.",
66
"keywords": [

0 commit comments

Comments
 (0)