This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.inplace.min.js
6 lines (6 loc) · 1.9 KB
/
jquery.inplace.min.js
1
2
3
4
5
6
/**********
* Name : Inplace Title Plugin
* Author : Mojtaba Kianifar
* Version : 1.00
**********/
(function(e,t,n,r){function i(t,n){this.$element=e(t);this.options=n;this.title=this.$element.text();this.$input=null;this.has_actions=false;this.$element.bind("complete",this.options.oncomplete);this.init()}i.prototype={init:function(){this.$element.wrapInner('<span class="dp-inplace-value"></span>');this.$edit=e('<button class="dp-edit-handel">').prependTo(this.$element);this.$value=this.$element.find(".dp-inplace-value");this.$input=e('<input type="text">').appendTo(this.$element).hide();this.$save=e("<button class='dp-action-save'></button>").appendTo(this.$element).hide();this.$cancel=e("<button class='dp-action-cancel'></button>").appendTo(this.$element).hide();this.$cancel.bind("click",e.proxy(function(e){e.stopPropagation();this.cancel()},this));this.$save.bind("click",e.proxy(function(e){e.stopPropagation();this.save()},this));this.$edit.bind("click",e.proxy(function(){this._showActions()},this));this.$input.bind("keypress",e.proxy(function(e){if(e.which==13){this.save()}},this))},_showActions:function(){var e=this.title==" "?"":this.title;this.$input.val(e).show().focus();this.$save.show();this.$cancel.show();this.$value.hide()},_hideActions:function(){this.$input.hide();this.$save.hide();this.$cancel.hide();this.$value.show()},cancel:function(){this._hideActions()},save:function(){this.title=this.$input.val()==""?" ":this.$input.val();this.$value.html(this.title);this._hideActions();this.$element.trigger("complete")}};e.fn.inplace=function(t){if(typeof t=="string"){var n=this.data("inplace");if(n){var r=n[t].apply(n,Array.prototype.slice.call(arguments,1));if(r)return r}return this}t=e.extend({},e.fn.inplace.defaults,t);return this.each(function(){var n=e.data(this,"inplace");if(!n){n=new i(this,t);e.data(this,"inplace",n)}})};e.fn.inplace.defaults={oncomplete:null}})(jQuery,window,document)