Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocomplete and autocompleteAvailableTags options #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions demo-static-autocomplete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<html>
<head>
<title>Image Annotations</title>
<style type="text/css" media="all">@import "css/annotation.css";</style>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.8.17/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.17.js"></script>
<script type="text/javascript" src="js/jquery.annotate.js"></script>

<script language="javascript">
$(window).load(function() {
$("#toAnnotate").annotateImage({
editable: true,
useAjax: false,
notes: [ { "top": 286,
"left": 161,
"width": 52,
"height": 37,
"text": "Small people on the steps",
"id": "e69213d0-2eef-40fa-a04b-0ed998f9f1f5",
"editable": false },
{ "top": 134,
"left": 179,
"width": 68,
"height": 74,
"text": "National Gallery Dome",
"id": "e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe",
"editable": true } ],
autocomplete : true,
autocompleteAvailableTags : [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
]
});
});
</script>
</head>
<body>
<div>
<img id="toAnnotate" src="images/trafalgar-square-annotated.jpg" alt="Trafalgar Square" width="600" height="398" />
</div>
</body>
</html>
30 changes: 23 additions & 7 deletions js/jquery.annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
this.editable = opts.editable;
this.useAjax = opts.useAjax;
this.notes = opts.notes;
this.autocomplete = opts.autocomplete;
this.autocompleteAvailableTags = opts.autocompleteAvailableTags;

// Add the canvas
this.canvas = $('<div class="image-annotate-canvas"><div class="image-annotate-view"></div><div class="image-annotate-edit"><div class="image-annotate-edit-area"></div></div></div>');
Expand Down Expand Up @@ -85,7 +87,7 @@
$.fn.annotateImage.clear = function(image) {
/// <summary>
/// Clears all existing annotations from the image.
/// </summary>
/// </summary>
for (var i = 0; i < image.notes.length; i++) {
image.notes[image.notes[i]].destroy();
}
Expand Down Expand Up @@ -117,15 +119,15 @@
/// <summary>
/// Gets a count og the ticks for the current date.
/// This is used to ensure that URLs are always unique and not cached by the browser.
/// </summary>
/// </summary>
var now = new Date();
return now.getTime();
};

$.fn.annotateImage.add = function(image) {
/// <summary>
/// Adds a note to the image.
/// </summary>
/// </summary>
if (image.mode == 'view') {
image.mode = 'edit';

Expand Down Expand Up @@ -244,6 +246,11 @@
this.form = form;

$('body').append(this.form);

if (image.autocomplete && image.autocompleteAvailableTags.length) {
$.fn.annotateImage.autocomplete(image.autocompleteAvailableTags);
}

this.form.css('left', this.area.offset().left + 'px');
this.form.css('top', (parseInt(this.area.offset().top) + parseInt(this.area.height()) + 7) + 'px');

Expand Down Expand Up @@ -274,7 +281,7 @@
$.fn.annotateEdit.prototype.destroy = function() {
/// <summary>
/// Destroys an editable annotation area.
/// </summary>
/// </summary>
this.image.canvas.children('.image-annotate-edit').hide();
this.area.resizable('destroy');
this.area.draggable('destroy');
Expand Down Expand Up @@ -325,6 +332,15 @@
}
};


// Exec Autocomplete
$.fn.annotateImage.autocomplete = function (arrTags) {
$("#image-annotate-text").autocomplete({
source: arrTags
});
};


$.fn.annotateView.prototype.setPosition = function() {
/// <summary>
/// Sets the position of an annotation.
Expand Down Expand Up @@ -352,7 +368,7 @@
$.fn.annotateView.prototype.hide = function() {
/// <summary>
/// Removes the highlight from the annotation.
/// </summary>
/// </summary>
this.form.fadeOut(250);
this.area.removeClass('image-annotate-area-hover');
this.area.removeClass('image-annotate-area-editable-hover');
Expand All @@ -361,15 +377,15 @@
$.fn.annotateView.prototype.destroy = function() {
/// <summary>
/// Destroys the annotation.
/// </summary>
/// </summary>
this.area.remove();
this.form.remove();
}

$.fn.annotateView.prototype.edit = function() {
/// <summary>
/// Edits the annotation.
/// </summary>
/// </summary>
if (this.image.mode == 'view') {
this.image.mode = 'edit';
var annotation = this;
Expand Down
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Extract [this zip file][7] into a directory on your web server and navigate to `

To use the plugin you first need to reference the jQuery and jQuery UI libraries in your page. Add
the `jquery.annotate.js` and `annotation.css` files to enable the plugin.

```html
<style type="text/css" media="all">@import "css/annotation.css";</style>
<script type="text/javascript" src="dist/js/jquery.min.js"></script>
<script type="text/javascript" src="dist/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.annotate.js"></script>

```
Once you've added in the necessary scripts, hook up an image on the page by using the following syntax:

```html
<script language="javascript">
$(window).load(function() {
$("#toAnnotate").annotateImage({
Expand All @@ -40,13 +40,13 @@ Once you've added in the necessary scripts, hook up an image on the page by usin
});
});
</script>

```
It is important to use the `$(function() { ... });` function as this will fire once the page and
all it's images have loaded. Failing to do so will result in the plugin executing before the image
dimensions have been determined.

The HTML markup for the page looks like this:

```html
<html>
<head>
<title>Demo Page</title>
Expand All @@ -57,7 +57,7 @@ The HTML markup for the page looks like this:
</div>
</body>
</html>

```
A copy of all this code is included in the release.

### Build:
Expand Down