Skip to content

Commit 829dee4

Browse files
author
Marco de Jongh
committed
added image support
link support
1 parent 152fad0 commit 829dee4

File tree

2 files changed

+77
-17
lines changed

2 files changed

+77
-17
lines changed

css/annotation.css

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@
2929
display: none;
3030
position: relative;
3131
}
32+
33+
.image-annotate-hoverimg {
34+
display:none;
35+
}
36+
3237
.image-annotate-area {
33-
border: 1px solid #000000;
3438
position: absolute;
3539
}
36-
.image-annotate-area div {
40+
41+
.image-annotate-area-border {
42+
border: 1px solid #000000;
43+
}
44+
45+
.image-annotate-area-border div {
3746
border: 1px solid #FFFFFF;
3847
display: block;
3948
}

js/jquery.annotate.js

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
this.deleteUrl = opts.deleteUrl;
1919
this.editable = opts.editable;
2020
this.useAjax = opts.useAjax;
21-
this.notes = opts.notes;
22-
21+
22+
this.notes = [];
23+
24+
for(var i=0;i<opts.notes.length;i++)
25+
{
26+
this.notes.push($.extend({}, $.fn.annotateImage.noteDefaults, opts.notes[i]))
27+
}
28+
2329
// Add the canvas
2430
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>');
2531
this.canvas.children('.image-annotate-edit').hide();
@@ -81,6 +87,19 @@
8187
useAjax: true,
8288
notes: new Array()
8389
};
90+
91+
$.fn.annotateImage.noteDefaults = {
92+
id : "new",
93+
top : 30,
94+
left : 30,
95+
width : 30,
96+
height : 30,
97+
text : "",
98+
url : null,
99+
target : '_self',
100+
image : null,
101+
hoverImage : null
102+
};
84103

85104
$.fn.annotateImage.clear = function(image) {
86105
/// <summary>
@@ -217,14 +236,7 @@
217236
if (note) {
218237
this.note = note;
219238
} else {
220-
var newNote = new Object();
221-
newNote.id = "new";
222-
newNote.top = 30;
223-
newNote.left = 30;
224-
newNote.width = 30;
225-
newNote.height = 30;
226-
newNote.text = "";
227-
this.note = newNote;
239+
this.note = $.fn.annotateImage.noteDefaults;
228240
}
229241

230242
// Set area
@@ -294,13 +306,27 @@
294306
this.note = note;
295307

296308
this.editable = (note.editable && image.editable);
297-
309+
310+
var img = null;
311+
312+
298313
// Add the area
299-
this.area = $('<div class="image-annotate-area' + (this.editable ? ' image-annotate-area-editable' : '') + '"><div></div></div>');
300-
image.canvas.children('.image-annotate-view').prepend(this.area);
314+
this.area = $('<div class="image-annotate-area ' + (note.image == null ? 'image-annotate-area-border' : '' ) + (this.editable ? ' image-annotate-area-editable' : '') + '"><div></div></div>');
315+
316+
//(note.image != null ? '<img style="height:' + note.height +'px; width:' + note.width + 'px;" src="' + note.image + '"/>' : '')
317+
318+
319+
image.canvas.children('.image-annotate-view').prepend(this.area);
301320

302321
// Add the note
303322
this.form = $('<div class="image-annotate-note">' + note.text + '</div>');
323+
324+
if(note.url != null)
325+
{
326+
$(this.area).click(function(){ window.open(note.url, note.target);});
327+
$(this.area).css('cursor','pointer');
328+
}
329+
304330
this.form.hide();
305331
image.canvas.children('.image-annotate-view').append(this.form);
306332
this.form.children('span.actions').hide();
@@ -329,8 +355,33 @@
329355
/// <summary>
330356
/// Sets the position of an annotation.
331357
/// </summary>
332-
this.area.children('div').height((parseInt(this.note.height) - 2) + 'px');
333-
this.area.children('div').width((parseInt(this.note.width) - 2) + 'px');
358+
var height = parseInt(this.note.height) - 2 + 'px';
359+
var width = (parseInt(this.note.width) - 2) + 'px';
360+
var img = null;
361+
var hoverImg = null;
362+
363+
this.area.children('div').height(height);
364+
this.area.children('div').width(width);
365+
366+
if(this.note.image != null)
367+
{
368+
img = $('<img id="dynamic">'); //Equivalent: $(document.createElement('img'))
369+
img.attr('src', this.note.image);
370+
$(img).css('height',height);
371+
$(img).css('width',width);
372+
img.appendTo(this.area.children('div'));
373+
}
374+
375+
if(this.note.hoverImage != null)
376+
{
377+
hoverImg = $('<img id="hoverImage" class="image-annotate-hoverimg">'); //Equivalent: $(document.createElement('img'))
378+
hoverImg.attr('src', this.note.hoverImage);
379+
$(hoverImg).css('height',height);
380+
$(hoverImg).css('width',width);
381+
$(this.area).hover(function(){$(hoverImage).show(); $(img).hide()},function(){$(hoverImage).hide(); $(img).show()})
382+
hoverImg.appendTo(this.area.children('div'));
383+
}
384+
334385
this.area.css('left', (this.note.left) + 'px');
335386
this.area.css('top', (this.note.top) + 'px');
336387
this.form.css('left', (this.note.left) + 'px');

0 commit comments

Comments
 (0)