|
18 | 18 | this.deleteUrl = opts.deleteUrl; |
19 | 19 | this.editable = opts.editable; |
20 | 20 | 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 | + |
23 | 29 | // Add the canvas |
24 | 30 | 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>'); |
25 | 31 | this.canvas.children('.image-annotate-edit').hide(); |
|
81 | 87 | useAjax: true, |
82 | 88 | notes: new Array() |
83 | 89 | }; |
| 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 | + }; |
84 | 103 |
|
85 | 104 | $.fn.annotateImage.clear = function(image) { |
86 | 105 | /// <summary> |
|
217 | 236 | if (note) { |
218 | 237 | this.note = note; |
219 | 238 | } 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; |
228 | 240 | } |
229 | 241 |
|
230 | 242 | // Set area |
|
294 | 306 | this.note = note; |
295 | 307 |
|
296 | 308 | this.editable = (note.editable && image.editable); |
297 | | - |
| 309 | + |
| 310 | + var img = null; |
| 311 | + |
| 312 | + |
298 | 313 | // 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); |
301 | 320 |
|
302 | 321 | // Add the note |
303 | 322 | 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 | + |
304 | 330 | this.form.hide(); |
305 | 331 | image.canvas.children('.image-annotate-view').append(this.form); |
306 | 332 | this.form.children('span.actions').hide(); |
|
329 | 355 | /// <summary> |
330 | 356 | /// Sets the position of an annotation. |
331 | 357 | /// </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 | + |
334 | 385 | this.area.css('left', (this.note.left) + 'px'); |
335 | 386 | this.area.css('top', (this.note.top) + 'px'); |
336 | 387 | this.form.css('left', (this.note.left) + 'px'); |
|
0 commit comments