From f368074d5bad129e8365acd20713a479c74d2851 Mon Sep 17 00:00:00 2001 From: david-binda Date: Mon, 19 Oct 2020 14:22:48 +0000 Subject: [PATCH] Make the plugin compatible with jQuery 3.x The `$.selector` and `$.context` were removed in latest versions of the jQuery. `$.bind`, `$.isFunction`, and `$.focus` were deprecated. This commit fixes the usage of removed and deprecated API. --- jquery.inlineedit.js | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/jquery.inlineedit.js b/jquery.inlineedit.js index 2d567df..781c17e 100644 --- a/jquery.inlineedit.js +++ b/jquery.inlineedit.js @@ -25,21 +25,15 @@ var namespace = '.inlineedit', // define inlineEdit method $.fn.inlineEdit = function( options ) { + var cbBindings = function( event ) { + bindings.apply( this, [event] ); + }; + this.each( function() { $.inlineEdit.getInstance( this, options ).initValue(); + $(this).on( events, cbBindings ); }); - var cbBindings = function( event ) { - bindings.apply( this, [event] ); - }; - - if ($.fn.on) { - $(this.context).on( events, this.selector, cbBindings ); - } else { - // legacy support - $(this).live( events, cbBindings ); - } - function bindings( event ) { var widget = $.inlineEdit.getInstance( this, options ), editableElement = widget.element.find( widget.options.control ), @@ -128,7 +122,8 @@ $.inlineEdit.prototype = { initValue: function() { - this.value( $.trim( this.element.data('original-content') || this.element.html() ) || this.options.value ); + var val = this.element.data('original-content') || this.element.html() || this.options.value; + this.value( val.trim() ); if ( !this.value() ) { this.element.html( $( this.placeholderHtml() ) ); @@ -148,21 +143,21 @@ $.inlineEdit.prototype = { .html( self.mutatedHtml( self.value() ) ) .addClass( self.options.editInProgress ) .find( '.save' ) - .bind( 'click', function( event ) { + .on( 'click', function( event ) { self.save( self.element, event ); self.change( self.element, event ); return false; }) .end() .find( '.cancel' ) - .bind( 'click', function( event ) { + .on( 'click', function( event ) { self.cancel( self.element, event ); self.change( self.element, event ); return false; }) .end() .find( self.options.control ) - .bind( 'blur', function( event ) { + .on( 'blur', function( event ) { if (self.options.cancelOnBlur === true) { self.cancel( self.element, event ); self.change( self.element, event ); @@ -171,7 +166,7 @@ $.inlineEdit.prototype = { self.change( self.element, event ); } }) - .bind( 'keyup', function( event ) { + .on( 'keyup', function( event ) { switch ( event.keyCode ) { case 13: // save on ENTER if (self.options.control !== 'textarea') { @@ -185,7 +180,7 @@ $.inlineEdit.prototype = { break; } }) - .focus() + .trigger( 'focus') .end(); // trigger mutate event on mutation (i.e. edit-in-progress) @@ -329,7 +324,7 @@ $.inlineEdit.prototype = { }, _callback: function( fn, args ) { - return ($.isFunction( this.options[fn] ) && this.options[fn].apply( this.element[0], args ) ) !== false || !this.options[fn]; + return ( typeof this.options[fn] === 'function' && this.options[fn].apply( this.element[0], args ) ) !== false || !this.options[fn]; }, _decodeHtml: function( encoded ) { @@ -340,4 +335,4 @@ $.inlineEdit.prototype = { }; -})); \ No newline at end of file +}));