-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.editable.min.js
More file actions
9 lines (9 loc) · 4.02 KB
/
jquery.editable.min.js
File metadata and controls
9 lines (9 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
/*
* jQuery plugin that changes any element on your page
*
* @author Big Tiger
* @website https://github.com/bigtiger1/JQuery/
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 1.0
*/
!function(l,t){"use strict";function e(){var t=(new Date).getTime();t-b<250&&l(this).trigger(o),b=t}function a(t){if(27==t.keyCode)p(g,h.text());else if(13==t.keyCode&&t.data.closeOnEnter)g.editable("close");else if(t.data.toggleFontSize&&t.metaKey&&(38==t.keyCode||40==t.keyCode)){var e=parseInt(f.css("font-size"),10);return e+=40==t.keyCode?-1:1,f.css("font-size",e+"px"),!1}}function c(){f[0].scrollHeight!==parseInt(f.attr("data-scroll"),10)&&(f.css("height",f[0].scrollHeight+"px"),f.attr("data-scroll",f[0].scrollHeight))}function i(s,o){if(!s.is(":editing")){h=(g=s).clone(),s.attr("data-is-editing","1");var r=l.trim(s.html()),i=s.css("font-size"),t=1.4*s.height(),e="font-family: "+s.css("font-family")+"; font-size: "+s.css("font-size")+";font-weight: "+s.css("font-weight")+";";switch(o.lineBreaks&&(r=r.replace(/<br( |)(|\/)>/g,"\n")),o.type){case"text":f=l("<input>",{type:"text"});break;case"number":f=l("<input>",{type:"number"});break;case"date":f=l("<input>",{type:"date"});break;default:f=l("<textarea/>")}if(s.text(""),!1!==o.tinyMCE){var n="editable-area-"+(new Date).getTime();f.val(r).appendTo(s).attr("id",n),"object"!=typeof o.tinyMCE&&(o.tinyMCE={}),o.tinyMCE.mode="exact",o.tinyMCE.elements=n,o.tinyMCE.width=s.innerWidth(),o.tinyMCE.height=s.height()+200,o.tinyMCE.theme_advanced_resize_vertical=!0,o.tinyMCE.setup=function(t){t.onInit.add(function(e,t){var i=e.getWin(),n=!1,a=function(){var t=l(e.getDoc()).find("body").html();l(t).get(0).nodeName==s.get(0).nodeName&&(t=l(t).html()),p(s,t),e.remove(),f=!1,d.off("click",a),g=!1,"function"==typeof o.callback&&o.callback({content:!(t==r||!n)&&t,fontSize:!1,$el:s})};setTimeout(function(){d.on("click",a)},500),(f=l("<textarea/>")).on("blur",a),i.onkeydown=function(){n=!0},i.focus()})},tinyMCE.init(o.tinyMCE)}else(o.toggleFontSize||o.closeOnEnter)&&d.on("keydown",o,a),"textarea"===o.type&&d.on("keyup",c),f.val(r).blur(function(){g=!1;var t=l.trim(f.val()),e=f.css("font-size");o.lineBreaks&&(t=t.replace(new RegExp("\n","g"),"<br />")),t?(p(s,t),e!=i&&s.css("font-size",e),d.off("keydown",a),d.off("keyup",c),"function"==typeof o.callback&&o.callback({content:t!=r&&t,fontSize:e!=i&&e,$el:s})):p(s,h.text())}).addClass(o.cssClass).attr("style",e).appendTo(s).css({margin:0,padding:"2px",height:4+t+"px"}).focus().get(0).select(),c();s.trigger("edit",[f])}}function n(t){if(!1!==g){g.editable("close");var e=l(this);i(e,t.data)}else i(l(this),t.data);return!1}var d=l(t),f=!1,g=!1,h=!1,s="data-edit-event",o="dbltap",r="ontouchend"in t,y="tinyMCE"in t&&"function"==typeof t.tinyMCE.init,u=l.fn.is,b=0,p=function(t,e){t.removeAttr("data-is-editing"),t.html(e),f.remove()};l.fn.editable=function(t){if("string"==typeof t)if(this.is(":editable"))switch(t){case"open":this.is(":editing")||this.trigger(this.attr(s));break;case"close":this.is(":editing")&&f.trigger("blur");break;case"destroy":this.is(":editing")&&f.trigger("blur"),this.off(this.attr(s)),this.removeAttr(s);break;default:console.warn('Unknown command "'+t+'" for jquery.editable')}else console.error("Calling .editable() on an element that is not editable, call .editable() first");else this.is(":editable")&&(console.warn('Making an already editable element editable, call .editable("destroy") first'),this.editable("destroy")),!1===(t=l.extend({event:"dblclick",touch:!0,lineBreaks:!0,toggleFontSize:!0,closeOnEnter:!1,tinyMCE:!1,type:"textarea",cssClass:"editable--editing"},t)).tinyMCE||y||(console.warn("Trying to use tinyMCE as editor but id does not seem to be installed"),t.tinyMCE=!1),r&&t.touch?(t.event=o,this.off("touchend",e),this.on("touchend",e)):t.event+=".textEditor",this.on(t.event,t,n),this.attr(s,t.event);return this},l.fn.is=function(t){if("string"==typeof t&&0===t.indexOf(":")){if(":editable"==t)return void 0!==this.attr(s);if(":editing"==t)return void 0!==this.attr("data-is-editing")}return u.apply(this,arguments)}}(jQuery,window);