-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggleForm.min.js
More file actions
1 lines (1 loc) · 1.87 KB
/
toggleForm.min.js
File metadata and controls
1 lines (1 loc) · 1.87 KB
1
;(function(e){var t={className:"ui-toggleForm",edit:"button.edit",cancel:"button.cancel",data:".data",form:".form",close:"close",hideOtherForms:true};var n={init:function(r){return this.each(function(i){function h(){c.add(l).hide();f.add(u).fadeIn("fast")}function p(t){f.add(u).hide();c.add(e(t)).fadeIn("fast");d()}function d(){if(e(window).width()<768){setTimeout(function(){e(window).scrollTop(o.offset().top)},250)}}var s=e.extend({},t);if(r){s=e.extend(s,r)}var o=e(this);o.data("toggleForm-settings",s);var u=o.find(s.edit),a=o.find(s.cancel),f=o.find(s.data),l=o.find(s.form);if(!o.data("toggleForm-toggled")){o.addClass(s.className);var c=e("<button>",{type:"button","class":s.close,html:"×"}).appendTo(o);u.on("click",function(t){t.preventDefault();var r=e(this).data("toggle");if(s.hideOtherForms){n.showData.apply(e("."+s.className))}p(r)});c.on("click",function(){h()});a.on("click",function(e){e.preventDefault();h();d()});o.data("toggleForm-toggled",true)}else{var c=o.find("button."+s.close)}h()})},showForm:function(){return this.each(function(){var t=e(this),n=t.data("toggleForm-settings");if(n){t.find(n.data+", "+n.edit).hide();t.find("button."+n.close+", "+n.form).show()}})},showData:function(){return this.each(function(){var t=e(this),n=t.data("toggleForm-settings");if(n){t.find("button."+n.close+", "+n.form).hide();t.find(n.data+", "+n.edit).show()}})},destroy:function(){return this.each(function(){var t=e(this),n=t.data("toggleForm-settings");if(n){t.find(n.data+", "+n.form+", "+n.edit).show();t.find(n.edit+", "+n.cancel).off("click");t.find("button."+n.close).remove();t.data("toggleForm-toggled",false);t.removeClass(n.className)}})}};e.fn.toggleForm=function(t){if(n[t]){return n[t].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof t==="object"||!t){return n.init.apply(this,arguments)}else{e.error("Method "+t+" does not exist on toggleForm")}}})(jQuery);