2021-02-28 08:05:36 +01:00
|
|
|
!function($){$.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,callback=settings.callback||function(){},onedit=settings.onedit||function(){},onsubmit=settings.onsubmit||function(){},onreset=settings.onreset||function(){},onerror=settings.onerror||reset;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),$(this).bind(settings.event,function(e){if(!0!==$(this).data("disabled.editable")&&!self.editing&&!1!==onedit.apply(this,[settings,self])){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).html(),$(self).html("");var form=$("<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));var input_content,input=element.apply(form,[settings,self]);if(settings.loadurl){var t=setTimeout(function(){input.disabled=!0,content.apply(form,[settings.loadtext,settings,self])},100),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){window.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;content.apply(form,[input_content,settings,self]),input.attr("name",settings.name),buttons.apply(form,[settings,self]),$(self).append(form),plugin.apply(form,[settings,self]),$(":input:visible:enabled:first",form).focus(),settings.select&&input.select(),input.keydown(function(e){27==e.keyCode&&(e.preventDefault(),reset.apply(form,[settings,self]))});"cancel"==settings.onblur?input.blur(function(e){t=setTimeout(function(){reset.apply(form,[settings,self])},500)}):"submit"==settings.onblur?input.blur(function(e){t=setTimeout(function(){form.submit()},200)}):$.isFunction(settings.onblur)?input.blur(function(e){settings.onblur.apply(self,[input.val(),settings])}):input.blur(function(e){}),form.submit(function(e){if(t&&clearTimeout(t),e.preventDefault(),!1!==onsubmit.apply(form,[settings,self])&&!1!==submit.apply(form,[settings,self]))if($.isFunction(settings.target)){var str=settings.target.apply(self,[input.val(),settings]);$(self).html(str),self.editing=!1,callback.apply(self,[self.innerHTML,settings]),$.trim($(self).html())||$(self).html(settings.placeholder)}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])):$.extend(submitdata,settings.submitdata),"PUT"==settings.method&&(submitdata._method="put"),$(self).html(settings.indicator);var ajaxoptions={type:"POST",data:submitdata,dataType:"html",url:settings.target,success:function(result,status){"html"==ajaxoptions.dataType&&$(self).html(result),self.editing=!1,callback.apply(self,[result,settings]),$
|