Skip to content

Commit

Permalink
Merge pull request #13 from foliosus/master
Browse files Browse the repository at this point in the history
Adding CSS class "rip-active" to active form field and a small jQuery noConflict fix.
  • Loading branch information
janv committed May 24, 2011
2 parents a25b412 + 64a78a0 commit c1d9b00
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions javascripts/jquery.rest_in_place.js
Expand Up @@ -10,14 +10,16 @@ RestInPlaceEditor.prototype = {
// Public Interface Functions //////////////////////////////////////////////

activate : function() {
this.oldValue = this.element.html();
this.oldValue = this.element.html();
this.element.addClass('rip-active');
this.element.unbind('click', this.clickHandler)
this.activateForm();
},

abort : function() {
this.element
.html(this.oldValue)
.removeClass('rip-active')
.bind('click', {editor: this}, this.clickHandler);
},

Expand All @@ -31,6 +33,7 @@ RestInPlaceEditor.prototype = {
"dataType" : 'json',
"success" : function(data){ editor.loadSuccessCallback(data) }
});
editor.element.removeClass('rip-active');
}
});
editor.element.html("saving...");
Expand Down Expand Up @@ -102,14 +105,14 @@ RestInPlaceEditor.prototype = {
clickHandler : function(event) {
event.data.editor.activate();
}
}
};


RestInPlaceEditor.forms = {
"input" : {
/* is bound to the editor and called to replace the element's content with a form for editing data */
activateForm : function() {
this.element.html('<form action="javascript:void(0)" style="display:inline;"><input type="text" value="' + $.trim(this.oldValue) + '"></form>');
this.element.html('<form action="javascript:void(0)" style="display:inline;"><input type="text" value="' + jQuery.trim(this.oldValue) + '"></form>');
this.element.find('input')[0].select();
this.element.find("form")
.bind('submit', {editor: this}, RestInPlaceEditor.forms.input.submitHandler);
Expand All @@ -134,7 +137,7 @@ RestInPlaceEditor.forms = {
"textarea" : {
/* is bound to the editor and called to replace the element's content with a form for editing data */
activateForm : function() {
this.element.html('<form action="javascript:void(0)" style="display:inline;"><textarea>' + $.trim(this.oldValue) + '</textarea></form>');
this.element.html('<form action="javascript:void(0)" style="display:inline;"><textarea>' + jQuery.trim(this.oldValue) + '</textarea></form>');
this.element.find('textarea')[0].select();
this.element.find("textarea")
.bind('blur', {editor: this}, RestInPlaceEditor.forms.textarea.blurHandler);
Expand All @@ -149,11 +152,11 @@ RestInPlaceEditor.forms = {
}

}
}
};

jQuery.fn.rest_in_place = function() {
this.each(function(){
jQuery(this).data('restInPlaceEditor', new RestInPlaceEditor(this));
})
return this;
}
};

0 comments on commit c1d9b00

Please sign in to comment.