diff --git a/jquery.editable.js b/jquery.editable.js index b58244d..2d62418 100644 --- a/jquery.editable.js +++ b/jquery.editable.js @@ -1,66 +1,71 @@ -// jQuery.editable.js v1.1.2 +// jQuery.editable.js v1.1.3 // http://shokai.github.io/jQuery.editable // (c) 2012-2015 Sho Hashimoto +// +// Modified by Benjamin Van Ryseghem // The MIT License -(function($){ - var escape_html = function(str){ +(function($) { + var escape_html = function(str) { return str.replace(//gm, '>'); }; - var unescape_html = function(str){ + var unescape_html = function(str) { return str.replace(/</gm, '<').replace(/>/gm, '>'); }; - $.fn.editable = function(event, callback){ - if(typeof callback !== 'function') callback = function(){}; - if(typeof event === 'string'){ + $.fn.editable = function(event, callback) { + if (typeof callback !== 'function') callback = function() {}; + if (typeof event === 'string') { var trigger = this; var action = event; var type = 'input'; - } - else if(typeof event === 'object'){ + } else if (typeof event === 'object') { var trigger = event.trigger || this; - if(typeof trigger === 'string') trigger = $(trigger); + if (typeof trigger === 'string') trigger = $(trigger); var action = event.action || 'click'; var type = event.type || 'input'; - } - else{ - throw('Argument Error - jQuery.editable("click", function(){ ~~ })'); + } else { + throw ('Argument Error - jQuery.editable("click", function(){ ~~ })'); } var target = this; var edit = {}; - edit.start = function(e){ + edit.start = function(e) { trigger.unbind(action === 'clickhold' ? 'mousedown' : action); - if(trigger !== target) trigger.hide(); + if (trigger !== target) trigger.hide(); + var text = target.attr("editable-src") ? target.attr("editable-src") : target.text(); var old_value = ( type === 'textarea' ? - target.text().replace(//gm, '\n').replace(/>/gm, '>').replace(/</gm, '<') : - target.text() - ).replace(/^\s+/,'').replace(/\s+$/,''); + text.replace(//gm, '\n').replace(/>/gm, '>').replace(/</gm, '<') : + text + ).replace(/^\s+/, '').replace(/\s+$/, ''); var input = type === 'textarea' ? $('