diff --git a/dist/jquery.jeditable.min.js b/dist/jquery.jeditable.min.js index 60076e7..4c63df8 100644 --- a/dist/jquery.jeditable.min.js +++ b/dist/jquery.jeditable.min.js @@ -1,3 +1,3 @@ /*! jquery-jeditable https://github.com/NicolasCARPi/jquery_jeditable#readme */ -!function($){"use strict";$.fn.editableAriaShim=function(){return this.attr({role:"button",tabindex:0}),this},$.fn.editable=function(target,options){if("disable"!==target)if("enable"!==target){if("destroy"!==target){var settings=$.extend({},$.fn.editable.defaults,{target:target},options),plugin=$.editable.types[settings.type].plugin||function(){},submit=$.editable.types[settings.type].submit||function(){},buttons=$.editable.types[settings.type].buttons||$.editable.types.defaults.buttons,content=$.editable.types[settings.type].content||$.editable.types.defaults.content,element=$.editable.types[settings.type].element||$.editable.types.defaults.element,reset=$.editable.types[settings.type].reset||$.editable.types.defaults.reset,destroy=$.editable.types[settings.type].destroy||$.editable.types.defaults.destroy,callback=settings.callback||function(){},intercept=settings.intercept||function(s){return s},onedit=settings.onedit||function(){},onsubmit=settings.onsubmit||function(){},onreset=settings.onreset||function(){},onerror=settings.onerror||reset;settings.before;return settings.tooltip&&$(this).attr("title",settings.tooltip),this.each(function(){var self=this;$(this).data("event.editable",settings.event),$.trim($(this).html())||$(this).html(settings.placeholder),"destroy"!==target?($(this).on(settings.event,function(e){if(!0!==$(this).data("disabled.editable")&&9!==e.which&&!self.editing&&!1!==onedit.apply(this,[settings,self,e])){if(settings.before&&jQuery.isFunction(settings.before))settings.before(e);else if(settings.before&&!jQuery.isFunction(settings.before))throw"The 'before' option needs to be provided as a function!";e.preventDefault(),e.stopPropagation(),settings.tooltip&&$(self).removeAttr("title"),$(this).html().toLowerCase().replace(/(;|"|\/)/g,"")===settings.placeholder.toLowerCase().replace(/(;|"|\/)/g,"")&&$(this).html(""),self.editing=!0,self.revert=$(self).text(),$(self).html("");var form=$("
");settings.cssclass&&("inherit"===settings.cssclass?form.attr("class",$(self).attr("class")):form.attr("class",settings.cssclass)),settings.style&&("inherit"===settings.style?(form.attr("style",$(self).attr("style")),form.css("display",$(self).css("display"))):form.attr("style",settings.style)),settings.label&&form.append(""),settings.formid&&form.attr("id",settings.formid);var input_content,t,input=element.apply(form,[settings,self]);settings.inputcssclass&&("inherit"===settings.inputcssclass?input.attr("class",$(self).attr("class")):input.attr("class",settings.inputcssclass));var isSubmitting=!1;if(settings.loadurl){t=self.setTimeout(function(){input.disabled=!0},100),$(self).html(settings.loadtext);var loaddata={};loaddata[settings.id]=self.id,$.isFunction(settings.loaddata)?$.extend(loaddata,settings.loaddata.apply(self,[self.revert,settings])):$.extend(loaddata,settings.loaddata),$.ajax({type:settings.loadtype,url:settings.loadurl,data:loaddata,async:!1,cache:!1,success:function(result){self.clearTimeout(t),input_content=result,input.disabled=!1}})}else settings.data?(input_content=settings.data,$.isFunction(settings.data)&&(input_content=settings.data.apply(self,[self.revert,settings]))):input_content=self.revert;if(content.apply(form,[input_content,settings,self]),input.attr("name",settings.name),"none"!==settings.width){var adj_width=settings.width-(input.outerWidth(!0)-settings.width);input.width(adj_width)}buttons.apply(form,[settings,self]),settings.showfn&&$.isFunction(settings.showfn)&&form.hide(),$(self).html(""),$(self).append(form),settings.showfn&&$.isFunction(settings.showfn)&&settings.showfn(form),plugin.apply(form,[settings,self]),form.find(":input:visible:enabled:first").focus(),settings.select&&input.select(),$(this).keydown(function(e){27===e.which&&(e.preventDefault(),reset.apply(form,[settings,self]))}),"cancel"===settings.onblur?input.blur(function(e){t=self.setTimeout(function(){reset.apply(form,[settings,self])},500)}):"submit"===settings.onblur?input.blur(function(e){t=self.setTimeout(function(){form.submit()},200)}):$.isFunction(settings.onblur)&&input.blur(function(e){!1===settings.onblur.apply(self,[input.val(),settings,form])&&reset.apply(form,[settings,self])}),form.submit(function(e){if(e.preventDefault(),e.stopPropagation(),isSubmitting)return!1;if(isSubmitting=!0,t&&self.clearTimeout(t),(isSubmitting=!1!==onsubmit.apply(form,[settings,self]))&&(isSubmitting=!1!==submit.apply(form,[settings,self])))if($.isFunction(settings.target)){var responseHandler=function(value,complete){isSubmitting=!1,!1!==complete&&($(self).html(value),self.editing=!1,callback.apply(self,[self.innerHTML,settings]),$.trim($(self).html())||$(self).html(settings.placeholder))},userTarget=settings.target.apply(self,[input.val(),settings,responseHandler]);!1!==userTarget&&void 0!==userTarget&&responseHandler(userTarget,userTarget)}else{var submitdata={};submitdata[settings.name]=input.val(),submitdata[settings.id]=self.id,$.isFunction(settings.submitdata)?$.extend(submitdata,settings.submitdata.apply(self,[self.revert,settings,submitdata])):$.extend(submitdata,settings.submitdata),"PUT"===settings.method&&(submitdata._method="put"),$(self).html(settings.indicator);var ajaxoptions={type:"POST",complete:function(xhr,status){isSubmitting=!1},data:submitdata,dataType:"html",url:settings.target,success:function(result,status){result=intercept.apply(self,[result,status]),"html"===ajaxoptions.dataType&&$(self).html(result),self.editing=!1,callback.apply(self,[result,settings,submitdata]),$.trim($(self).html())||$(self).html(settings.placeholder)},error:function(xhr,status,error){onerror.apply(form,[settings,self,xhr])}};$.extend(ajaxoptions,settings.ajaxoptions),$.ajax(ajaxoptions)}return $(self).attr("title",settings.tooltip),!1})}}),self.reset=function(form){self.editing&&!1!==onreset.apply(form,[settings,self])&&($(self).text(self.revert),self.editing=!1,$.trim($(self).html())||$(self).html(settings.placeholder),settings.tooltip&&$(self).attr("title",settings.tooltip))},self.destroy=function(form){$(self).unbind($(self).data("event.editable")).removeData("disabled.editable").removeData("event.editable"),self.clearTimeouts(),self.editing&&reset.apply(form,[settings,self])},self.clearTimeout=function(t){var timeouts=$(self).data("timeouts");if(clearTimeout(t),timeouts){var i=timeouts.indexOf(t);i>-1?(timeouts.splice(i,1),timeouts.length<=0&&$(self).removeData("timeouts")):console.warn("jeditable clearTimeout could not find timeout "+t)}},self.clearTimeouts=function(){var timeouts=$(self).data("timeouts");if(timeouts){for(var i=0,n=timeouts.length;i');return $(this).append(input),input},content:function(string,settings,original){$(this).find(":input:first").val(string)},reset:function(settings,original){original.reset(this)},destroy:function(settings,original){original.destroy(this)},buttons:function(settings,original){var submit,cancel,form=this;(settings.submit&&(settings.submit.match(/>$/)?submit=$(settings.submit).on("click",function(){"submit"!==submit.attr("type")&&form.submit()}):((submit=$('