+ this.focusAnnotation($p);
+ return false;
+ }
+
+ /*
+ * Clicking outside of focused area doesn't unfocus by default
+ * - this greatly simplifies the whole click check
+ */
+
+ if( $e.hasClass('theme-ref') )
+ {
+ console.log($e);
+ this.selectTheme($e.attr('x-theme-class'));
+ }
+
+ /* 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)
+ {
+ console.log('Redundant unfocus');
+ return false;
+ }
+
+ if(this.currentOpen
+ && this.currentOpen.is("*[x-annotation-box]")
+ && this.currentOpen.parent()[0] == this.currentFocused[0])
+ {
+ console.log("Can't unfocus open box");
+ return false;
+ }
+
+ var $box = $("*[x-annotation-box]", this.currentFocused);
+ $box.css({'display': 'none'});
+ // this.currentFocused.removeAttr('x-focused');
+ // this.currentFocused.hide();
+ this.currentFocused = null;
+ },
+
+ focusAnnotation: function($e) {
+ this.currentFocused = $e;
+ var $box = $("*[x-annotation-box]", $e);
+ $box.css({'display': 'block'});
+
+ // $e.attr('x-focused', 'focused');
+ },
+
+ closeWithSave: function($e) {
+ var $edit = $e.data('edit-overlay');
+ var newText = $('textarea', $edit).val();
+
+ this.model.putXMLPart($e, newText, function($e, html) {
+ this.renderPart($e, html);
+ $edit.remove();
+ $e.removeAttr('x-open');
+ }.bind(this) );
+ this.currentOpen = null;
+ },
+
+ closeWithoutSave: function($e) {
+ var $edit = $e.data('edit-overlay');
+ $edit.remove();
+ $e.removeAttr('x-open');
+ this.currentOpen = null;
+ },
+
+ editableFor: function($button)
+ {
+ var $e = $button;
+ var n = 0;
+
+ while( ($e[0] != this.element[0]) && !($e.attr('x-editable')) && n < 50)