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

Implemented new functionalities #16

Open
wants to merge 1 commit 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
28 changes: 28 additions & 0 deletions demo-with-events.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
<title>Image Annotations</title>
<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>

<script language="javascript">
$(window).load(function() {
$("#toAnnotate").annotateImage({
editable: true,
useAjax: false,
onCreate: function(){ console.log('Event: On Create') },
onUpdate: function(){ console.log('Event: On Update') },
onDelete: function(){ console.log('Event: On Delete') },
onChange: function(){ console.log(this.notes) },
notes: []
});
});
</script>
</head>
<body>
<div>
<img id="toAnnotate" src="images/trafalgar-square-annotated.jpg" alt="Trafalgar Square" width="600" height="398" />
</div>
</body>
</html>
35 changes: 33 additions & 2 deletions js/jquery.annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
this.editable = opts.editable;
this.useAjax = opts.useAjax;
this.notes = opts.notes;
this.onCreate = opts.onCreate != null ? opts.onCreate : function() {}
this.onUpdate = opts.onUpdate != null ? opts.onUpdate : function() {}
this.onDelete = opts.onDelete != null ? opts.onDelete : function() {}
this.onChange = opts.onChange != null ? opts.onChange : function() {}

// 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 @@ -167,11 +171,15 @@
// Add to canvas
if (note) {
note.resetPosition(editable, text);
image.onUpdate()
image.onChange()
} else {
editable.note.editable = true;
note = new $.fn.annotateView(image, editable.note)
note.resetPosition(editable, text);
image.notes.push(editable.note);
image.onCreate()
image.onChange()
}

editable.destroy();
Expand Down Expand Up @@ -214,11 +222,19 @@
/// </summary>
this.image = image;

// generate randomic guid
function guidGenerator() {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}

if (note) {
this.note = note;
} else {
var newNote = new Object();
newNote.id = "new";
newNote.id = guidGenerator();
newNote.top = 30;
newNote.left = 30;
newNote.width = 30;
Expand Down Expand Up @@ -366,7 +382,10 @@
this.form.remove();
}

$.fn.annotateView.prototype.edit = function() {
$.fn.annotateView.prototype.edit = function(img) {

var selfNote = this.note

/// <summary>
/// Edits the annotation.
/// </summary>
Expand All @@ -382,6 +401,15 @@
// Add the delete button
var del = $('<a class="image-annotate-edit-delete">Delete</a>');
del.click(function() {

let aux = []
img.notes.forEach(function(value,index){
if ( value.id != selfNote.id ) {
aux.push(img.notes[index])
}
})
img.notes = aux

var form = $('#image-annotate-edit-form form');

$.fn.annotateImage.appendPosition(form, editable)
Expand All @@ -394,6 +422,9 @@
});
}

annotation.image.onDelete()
annotation.image.onChange()

annotation.image.mode = 'view';
editable.destroy();
annotation.destroy();
Expand Down