text: !function(t,n,e,i){"use strict";function a(n,e){var i=this.element=t(n),a=this.elementOptions(i),c=a.activator||n;a.activator=t(c);var l=t.extend({},t.fn[o].defaults,e,a);this.opts=l,this.bindElement(l)}var o="jinplace",c=["type","url","data","loadurl","elementId","object","attribute","okButton","cancelButton","inputClass","activator","textOnly","placeholder","submitFunction"];a.prototype={elementOptions:function(n){function e(t){return"-"+t.toLowerCase()}function i(t){return"data-"+t.replace(/[A-Z]/g,e)}var a={};return t.each(c,function(t,e){a[e]=n.attr(i(e))}),a.elementId=n.attr("id"),a.textOnly&&(a.textOnly="false"!==a.textOnly),a},bindElement:function(n){n.activator.off("click.jip").on("click.jip",t.proxy(this.clickHandler,this));var e=this.element;""==t.trim(e.html())&&(e.html(n.placeholder),n.placeholder=e.html())},clickHandler:function(n){n.preventDefault(),n.stopPropagation(),t(n.currentTarget).off("click.jip").on("click.jip",function(t){t.preventDefault()});var e=this,a=e.opts,c=t.extend({},s,t.fn[o].editors[a.type]);e.origValue=e.element.html(),e.fetchData(a).done(function(t){var n=c.makeField(e.element,t);c.inputField||(c.inputField=n),n.addClass(a.inputClass);var o=u(a,n,c.buttonsAllowed);e.element.html(o),o.on("jip:submit submit",function(){return e.submit(c,a),!1}).on("jip:cancel",function(){return e.cancel(c),!1}).on("keyup",function(t){27==t.keyCode&&e.cancel(c)}),c.activate(o,n);var l=c.blurAction||(a.okButton?a.cancelButton?i:"jip:cancel":"submit");c.blurEvent(n,o,l)})},fetchData:function(n){var e;e=n.data?n.data:n.loadurl?n.loadFunction(n):t.trim(this.element.html());var i=function(t){return t==n.placeholder?"":t},a=t.when(e);return a.pipe?a.pipe(i):a.then(i)},cancel:function(t){var n=this;n.element.html(n.origValue),t.finish(),n.bindElement(n.opts)},submit:function(n,e){var a,o=this,c=t.Deferred().reject();try{a=e.submitFunction.call(i,e,n.value()),a===i&&(a=c)}catch(l){a=c}t.when(a).done(function(t){o.onUpdate(n,e,t)}).fail(function(){o.cancel(n)})},onUpdate:function(t,n,e){var i=this;i.setContent(e),t.finish(),i.element.trigger("jinplace:done",[e]),i.bindElement(n)},setContent:function(t){var n=this.element;return t?void(this.opts.textOnly?n.text(t):n.html(t)):void n.html(this.opts.placeholder)}};var l=function(n,e){var a={id:n.elementId,object:n.object,attribute:n.attribute};return t.isPlainObject(e)?t.extend(a,e):e!==i&&(a.value=e),a};t.fn[o]=function(n){return this.each(function(){t.data(this,"plugin_"+o)||t.data(this,"plugin_"+o,new a(this,n))})},t.fn[o].defaults={url:e.location.pathname,type:"input",textOnly:2,placeholder:"[ --- ]",submitFunction:function(n,e){return t.ajax(n.url,{type:"post",data:l(n,e),dataType:"text",headers:{"Cache-Control":"no-cache"}})},loadFunction:function(n){return t.ajax(n.loadurl,{data:l(n)})}};var u=function(n,e,i){var a=t("<form>").attr("style","display: inline;").attr("action","javascript:void(0);").append(e);return i&&r(a,n),a},r=function(n,e){var i=function(t,e){n.append(t),t.one("click",function(t){t.stopPropagation(),n.trigger(e)})},a=e.okButton;if(a){var o=t("<input>").attr("type","button").attr("value",a).addClass("jip-button jip-ok-button");i(o,"submit")}var c=e.cancelButton;c&&(o=t("<input>").attr("type","button").attr("value",c).addClass("jip-button jip-cancel-button"),i(o,"jip:cancel"))},s={makeField:function(n,e){return t("<input>").attr("type","text").val(e)},activate:function(t,n){n.focus()},value:function(){return this.inputField.val()},blurEvent:function(t,n,e){if(e&&"ignore"!=e){var i=function(){var i=setTimeout(function(){t.trigger(e)},300);n.on("click",function(){clearTimeout(i)})};t.on("blur",i)}},finish:function(){}};t.fn[o].editorBase=s,t.fn[o].editors={input:{buttonsAllowed:!0},textarea:{buttonsAllowed:!0,makeField:function(n,e){return t("<textarea>").css({"min-width":n.width(),"min-height":n.height()}).val(e)},activate:function(t,n){n.focus(),n.elastic&&n.elastic()}},select:{makeField:function(n,e){var i=t("<select>"),a=t.parseJSON(e),o=!1,c=null;return t.each(a,function(e,a){var l=t("<option>").val(a[0]).html(a[1]);a[2]&&(l.attr("selected","1"),o=!0),a[1]==n.text()&&(c=l),i.append(l)}),!o&&c&&c.attr("selected","1"),i},activate:function(t,n){n.focus(),n.on("change",function(){n.trigger("jip:submit")})}}}}(jQuery,window,document);