+ if($e.hasClass('annotation'))
+ {
+ var $box = $e.parent();
+
+ if(this.currentFocused)
+ {
+ if($box[0] == this.currentFocused[0]) {
+ console.log('unfocus of current');
+ this.unfocusAnnotation();
+ return false;
+ }
+
+ console.log('switch unfocus');
+ this.unfocusAnnotation();
+ }
+
+ this.focusAnnotation($box);
+ return false;
+ }
+
+ /*
+ * Clicking outside of focused area doesn't unfocus by default
+ * - this greatly simplifies the whole click check
+ */
+
+ /* other buttons */
+ if($e.hasClass('edit-button'))
+ this.openForEdit( this.editableFor($e) );
+
+ if($e.hasClass('accept-button'))
+ this.closeWithSave( this.editableFor($e) );
+
+ if($e.hasClass('reject-button'))
+ this.closeWithoutSave( this.editableFor($e) );
+ },
+
+ unfocusAnnotation: function() {
+ if(!this.currentFocused)
+ return false;
+
+ if(this.currentOpen
+ && this.currentOpen.is("*[x-annotation-box]")
+ && this.currentOpen.parent()[0] == this.currentFocused[0])
+ return false;
+
+ this.currentFocused.removeAttr('x-focused');
+ this.currentFocused = null;
+ },
+
+ focusAnnotation: function($e) {
+ this.currentFocused = $e;
+ $e.attr('x-focused', 'focused');
+ },