jQuery, / - :
- :
(function( $ ){
var methods = {
init : function( options ) {
return this.each(function() {
var $this = $(this).hide();
var div = $('<div>'+$this.val()+'</div>').show().insertAfter($this).data('input',$this);
$this.data('div',div);
div.dblclick(function(){
$(this).hide();
$(this).data('input').val($(this).text()).show();
});
$this.blur(function(){
$(this).hide();
$(this).data('div').html($(this).val()).show();
});
},
value : function( str ) {
return this.each(function(){
$(this).val(str);
$(this).data('div').html($(this).val());
});
}
};
$.fn.editable = function( method ) {
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.editable' );
}
};
})( jQuery );
:
$('#editable').editable('new value that will sync the related div');
// instead of `$('#editable').value('...')`
Plugins/Authoring - Namespacing jQuery.
UPDATE . Since I made a mistake understanding this question, I came up with the following proposed solutions. This is not the best way to do this.
I highly recommend that you review your plugin design because it is not available in my personal opinion.
But since I don't see the whole script, the following code snippet will do the trick
(function() {
var $$val = $.fn.val;
$.fn.val = function(s) {
$(this).editable('change');
return $$val.apply(this, Array.prototype.slice.call(arguments));
};
})
NTN
source
share