diff --git a/contributed/jquery.jeditable.ui-autocomplete.htm b/contributed/jquery.jeditable.ui-autocomplete.htm new file mode 100644 index 0000000..91670e9 --- /dev/null +++ b/contributed/jquery.jeditable.ui-autocomplete.htm @@ -0,0 +1,35 @@ +/* Autocomplete using jQueryUI1.8.16 [from rezeusor with love]*/ +/* This additional code needs to be inserted in your page for the multicomplete to work smoothly */ + + +function split( val ) { + return val.split( /,\s*/ ); +} +function extractLast( term ) { + return split( term ).pop(); +} +var listofstuff = ["0118","999","88199","9119","725","3"] ; +$('.importantNumbers').editable(function(value,settings){return save(this.id,value,this.revert);}, + {type:"autocomplete",autocomplete:{ + minLength: 0, + source: function( request, response ) { + response( $.ui.autocomplete.filter( analysts, extractLast( request.term ) ) ); + }, + focus: function() { + return false; + }, + select: function( event, ui ) { + var terms = split( this.value ); + terms.pop(); + terms.push( ui.item.value ); + terms.push( "" ); + // Set this to whatever you want to be + this.value = terms.join( ", " ); + return false; + } + }, + submit:'save', + cancel:'cancel', + onblur:'ignore' + } +); diff --git a/contributed/jquery.jeditable.ui-autocomplete.js b/contributed/jquery.jeditable.ui-autocomplete.js new file mode 100644 index 0000000..62111c4 --- /dev/null +++ b/contributed/jquery.jeditable.ui-autocomplete.js @@ -0,0 +1,21 @@ +/* Autocomplete using jQueryUI1.8.16 [from rezeusor with love] */ + +//Normal Autocomplete +$.editable.addInputType('autocomplete', { + element : $.editable.types.text.element, + plugin : function(settings, original) { + $('input', this).autocomplete(settings.autocomplete); + } +}); + +//Multiple Results Autocomplete +$.editable.addInputType('multicomplete', { + element : $.editable.types.text.element, + plugin : function(settings, original) { + $('input', this).bind( "keydown", function( event ) { + if ( event.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { + event.preventDefault(); + } + }).autocomplete(settings.autocomplete); + } +}); diff --git a/contributed/jquery.jeditable.wysihtml5.js b/contributed/jquery.jeditable.wysihtml5.js new file mode 100644 index 0000000..1e935e2 --- /dev/null +++ b/contributed/jquery.jeditable.wysihtml5.js @@ -0,0 +1,44 @@ +$.editable.addInputType('wysihtml5', { + element : function(settings, original) { + settings.wysihtml5 = new Array(); + settings.wysihtml5.editor = null; + settings.wysihtml5.uuid = Math.uuid(); + + var container = $('
'); + $(container).attr('id', settings.wysihtml5.uuid); + $(container).attr('class', 'wysihtml5'); + $(this).append(container); + + var toolbar = $('#wysihtml5-toolbar').clone(); + $(toolbar).attr('id', settings.wysihtml5.uuid + '-toolbar'); + $(toolbar).attr('class', 'wysihtml5-toolbar'); + $(container).append(toolbar); + + var textarea = $(''); + $(textarea).attr('id', settings.wysihtml5.uuid + '-textarea'); + if (settings.rows) { + textarea.attr('rows', settings.rows); + } else if (settings.height != "none") { + textarea.height(settings.height); + } + if (settings.cols) { + textarea.attr('cols', settings.cols); + } else if (settings.width != "none") { + textarea.width(settings.width); + } + $(container).append(textarea); + + return(container); + }, + plugin: function(settings, original) { + settings.wysihtml5.editor = new wysihtml5.Editor(settings.wysihtml5.uuid + '-textarea', { + toolbar: settings.wysihtml5.uuid + '-toolbar', + parserRules: wysihtml5ParserRules + }); + }, + get_data: function (settings, original) { + return { + value: settings.wysihtml5.editor.textarea.element.value + }; + } +}); \ No newline at end of file diff --git a/jquery.jeditable.autogrow.js b/jquery.jeditable.autogrow.js index 2057670..7f8855d 100644 --- a/jquery.jeditable.autogrow.js +++ b/jquery.jeditable.autogrow.js @@ -33,6 +33,6 @@ $.editable.addInputType('autogrow', { return(textarea); }, plugin : function(settings, original) { - $('textarea', this).autogrow(settings.autogrow); + $('textarea', this).autoGrow(settings.autogrow); } }); diff --git a/jquery.jeditable.js b/jquery.jeditable.js index eb8a911..6ceeefd 100644 --- a/jquery.jeditable.js +++ b/jquery.jeditable.js @@ -17,19 +17,19 @@ /** * Version 1.7.2-dev * - * ** means there is basic unit tests for this parameter. + * ** means there is basic unit tests for this parameter. * * @name Jeditable * @type jQuery * @param String target (POST) URL or function to send edited content to ** - * @param Hash options additional options + * @param Hash options additional options * @param String options[method] method to use to send edited content (POST or PUT) ** * @param Function options[callback] Function to run after submitting edited content ** * @param String options[name] POST parameter name of edited content * @param String options[id] POST parameter name of edited div id * @param Hash options[submitdata] Extra parameters to send when submitting edited content. * @param String options[type] text, textarea or select (or any 3rd party input type) ** - * @param Integer options[rows] number of rows if using textarea ** + * @param Integer options[rows] number of rows if using textarea ** * @param Integer options[cols] number of columns if using textarea ** * @param Mixed options[height] 'auto', 'none' or height in pixels ** * @param Mixed options[width] 'auto', 'none' or width in pixels ** @@ -48,19 +48,21 @@ * @param String options[select] true or false, when true text is highlighted ?? * @param String options[placeholder] Placeholder text or html to insert when element is empty. ** * @param String options[onblur] 'cancel', 'submit', 'ignore' or function ?? - * + * @param String options[size] the size of the text field + * @param String options[maxlength] the maximum number of character in the text field + * * @param Function options[onsubmit] function(settings, original) { ... } called before submit * @param Function options[onreset] function(settings, original) { ... } called before reset * @param Function options[onerror] function(settings, original, xhr) { ... } called on error - * + * * @param Hash options[ajaxoptions] jQuery Ajax options. See docs.jquery.com. - * + * */ (function($) { $.fn.editable = function(target, options) { - + if ('disable' == target) { $(this).data('disabled.editable', true); return; @@ -76,39 +78,46 @@ .removeData('event.editable'); return; } - + var settings = $.extend({}, $.fn.editable.defaults, {target:target}, options); - + /* setup some functions */ var plugin = $.editable.types[settings.type].plugin || function() { }; var submit = $.editable.types[settings.type].submit || function() { }; - var buttons = $.editable.types[settings.type].buttons + var get_data = $.editable.types[settings.type].get_data || function() { }; + var buttons = $.editable.types[settings.type].buttons || $.editable.types['defaults'].buttons; - var content = $.editable.types[settings.type].content + var content = $.editable.types[settings.type].content || $.editable.types['defaults'].content; - var element = $.editable.types[settings.type].element + var element = $.editable.types[settings.type].element || $.editable.types['defaults'].element; - var reset = $.editable.types[settings.type].reset + var reset = $.editable.types[settings.type].reset || $.editable.types['defaults'].reset; var callback = settings.callback || function() { }; - var onedit = settings.onedit || function() { }; + var intercept = settings.intercept || function(s) { return s; }; + var onedit = settings.onedit || function() { }; var onsubmit = settings.onsubmit || function() { }; var onreset = settings.onreset || function() { }; var onerror = settings.onerror || reset; - + + // selector name of the (div), where input/wysiwyg is embedded to + // fire save event when clicking outside of the container + // condition: onblur : submit + var containerName = settings.containerName; + /* Show tooltip. */ if (settings.tooltip) { $(this).attr('title', settings.tooltip); } - + settings.autowidth = 'auto' == settings.width; settings.autoheight = 'auto' == settings.height; - + return this.each(function() { - + /* Save this to self because this changes when scope changes. */ - var self = this; - + var self = this; + /* Inlined block elements lose their width and height after first edit. */ /* Save them for later use as workaround. */ var savedwidth = $(self).width(); @@ -116,38 +125,38 @@ /* Save so it can be later used by $.editable('destroy') */ $(this).data('event.editable', settings.event); - + /* If element is empty add something clickable (if requested) */ if (!$.trim($(this).html())) { $(this).html(settings.placeholder); } - + $(this).bind(settings.event, function(e) { - + /* Abort if element is disabled. */ if (true === $(this).data('disabled.editable')) { return; } - + /* Prevent throwing an exeption if edit field is clicked again. */ if (self.editing) { return; } - + /* Abort if onedit hook returns false. */ if (false === onedit.apply(this, [settings, self])) { return; } - + /* Prevent default action and bubbling. */ e.preventDefault(); e.stopPropagation(); - + /* Remove tooltip. */ if (settings.tooltip) { $(self).removeAttr('title'); } - + /* Figure out how wide and tall we are, saved width and height. */ /* Workaround for http://dev.jquery.com/ticket/2190 */ if (0 == $(self).width()) { @@ -155,28 +164,28 @@ settings.height = savedheight; } else { if (settings.width != 'none') { - settings.width = + settings.width = settings.autowidth ? $(self).width() : settings.width; } if (settings.height != 'none') { - settings.height = + settings.height = settings.autoheight ? $(self).height() : settings.height; } } - + /* Remove placeholder text, replace is here because of IE. */ - if ($(this).html().toLowerCase().replace(/(;|"|\/)/g, '') == + if ($(this).html().toLowerCase().replace(/(;|"|\/)/g, '') == settings.placeholder.toLowerCase().replace(/(;|"|\/)/g, '')) { $(this).html(''); } - + self.editing = true; self.revert = $(self).html(); $(self).html(''); /* Create the form object. */ var form = $(''); - + /* Apply css or style or both. */ if (settings.cssclass) { if ('inherit' == settings.cssclass) { @@ -190,7 +199,7 @@ if ('inherit' == settings.style) { form.attr('style', $(self).attr('style')); /* IE needs the second line or display wont be inherited. */ - form.css('display', $(self).css('display')); + form.css('display', $(self).css('display')); } else { form.attr('style', settings.style); } @@ -201,7 +210,7 @@ /* Set input content via POST, GET, given data or existing value. */ var input_content; - + if (settings.loadurl) { var t = setTimeout(function() { input.disabled = true; @@ -232,18 +241,18 @@ input_content = settings.data.apply(self, [self.revert, settings]); } } else { - input_content = self.revert; + input_content = self.revert; } content.apply(form, [input_content, settings, self]); input.attr('name', settings.name); - + /* Add buttons to the form. */ buttons.apply(form, [settings, self]); - + /* Add created form to self. */ $(self).append(form); - + /* Attach 3rd party plugin if requested. */ plugin.apply(form, [settings, self]); @@ -254,7 +263,7 @@ if (settings.select) { input.select(); } - + /* discard changes if pressing esc */ input.keydown(function(e) { if (e.keyCode == 27) { @@ -280,6 +289,17 @@ form.submit(); }, 200); }); + $('body').click(function() { + input.closest(settings.containerName).click(function(e) { + e.stopPropagation(); + }); + + t = setTimeout(function() { + form.submit(); + }, 200); + + }); + } else if ($.isFunction(settings.onblur)) { input.blur(function(e) { settings.onblur.apply(self, [input.val(), settings]); @@ -292,35 +312,50 @@ form.submit(function(e) { - if (t) { + if (t) { clearTimeout(t); } /* Do no submit. */ - e.preventDefault(); - + e.preventDefault(); + + // unbind click event on body to prevent reloading page after save + $('body').unbind('click'); + /* Call before submit hook. */ - /* If it returns false abort submitting. */ - if (false !== onsubmit.apply(form, [settings, self])) { + /* If it returns false abort submitting. */ + if (false !== onsubmit.apply(form, [settings, self])) { /* Custom inputs call before submit hook. */ /* If it returns false abort submitting. */ - if (false !== submit.apply(form, [settings, self])) { + if (false !== submit.apply(form, [settings, self])) { + + //strd. value + var id = self.id; + var value = input.val(); + + //value from plugin if available + var data = get_data.apply(form, [settings, self]); + if(data) + { + id = data.id; + value = data.value; + } /* Check if given target is function */ if ($.isFunction(settings.target)) { - var str = settings.target.apply(self, [input.val(), settings]); + var str = settings.target.apply(self, [value, settings]); $(self).html(str); self.editing = false; callback.apply(self, [self.innerHTML, settings]); - /* TODO: this is not dry */ + /* TODO: this is not dry */ if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } } else { /* Add edited content and id of edited element to POST. */ var submitdata = {}; - submitdata[settings.name] = input.val(); - submitdata[settings.id] = self.id; + submitdata[settings.name] = value; + submitdata[settings.id] = id; /* Add extra data to be POST:ed. */ if ($.isFunction(settings.submitdata)) { $.extend(submitdata, settings.submitdata.apply(self, [self.revert, settings])); @@ -335,7 +370,7 @@ /* Show the saving indicator. */ $(self).html(settings.indicator); - + /* Defaults for ajaxoptions. */ var ajaxoptions = { type : 'POST', @@ -343,11 +378,12 @@ dataType: 'html', url : settings.target, success : function(result, status) { + result = intercept.apply(self,[result]); if (ajaxoptions.dataType == 'html') { $(self).html(result); } self.editing = false; - callback.apply(self, [result, settings]); + callback.apply(self, [result, settings, submitdata]); if (!$.trim($(self).html())) { $(self).html(settings.placeholder); } @@ -356,28 +392,28 @@ onerror.apply(form, [settings, self, xhr]); } }; - + /* Override with what is given in settings.ajaxoptions. */ - $.extend(ajaxoptions, settings.ajaxoptions); - $.ajax(ajaxoptions); - + $.extend(ajaxoptions, settings.ajaxoptions); + $.ajax(ajaxoptions); + } } } - + /* Show tooltip again. */ $(self).attr('title', settings.tooltip); - + return false; }); }); - + /* Privileged methods */ this.reset = function(form) { /* Prevent calling reset twice when blurring. */ if (this.editing) { /* Before reset hook, if it returns false abort reseting. */ - if (false !== onreset.apply(form, [settings, self])) { + if (false !== onreset.apply(form, [settings, self])) { $(self).html(self.revert); self.editing = false; if (!$.trim($(self).html())) { @@ -385,11 +421,11 @@ } /* Show tooltip again. */ if (settings.tooltip) { - $(self).attr('title', settings.tooltip); + $(self).attr('title', settings.tooltip); } - } + } } - }; + }; }); }; @@ -399,7 +435,7 @@ types: { defaults: { element : function(settings, original) { - var input = $(''); + var input = $(''); $(this).append(input); return(input); }, @@ -422,7 +458,7 @@ /* Otherwise use button with given string as text. */ } else { var submit = $(''); - submit.html(settings.submit); + submit.html(settings.submit); } $(this).append(submit); } @@ -439,9 +475,9 @@ $(cancel).click(function(event) { if ($.isFunction($.editable.types[settings.type].reset)) { - var reset = $.editable.types[settings.type].reset; + var reset = $.editable.types[settings.type].reset; } else { - var reset = $.editable.types['defaults'].reset; + var reset = $.editable.types['defaults'].reset; } reset.apply(form, [settings, original]); return false; @@ -457,6 +493,14 @@ /* https://bugzilla.mozilla.org/show_bug.cgi?id=236791 */ //input[0].setAttribute('autocomplete','off'); input.attr('autocomplete','off'); + if (settings.size) { + input.attr('size', settings.size); + } + + if (settings.maxlength) { + input.attr('maxlength', settings.maxlength); + } + $(this).append(input); return(input); } @@ -486,7 +530,7 @@ }, content : function(data, settings, original) { /* If it is string assume it is json. */ - if (String == data.constructor) { + if (String == data.constructor) { eval ('var json = ' + data); } else { /* Otherwise assume it is a hash already. */ @@ -498,13 +542,13 @@ } if ('selected' == key) { continue; - } + } var option = $('').val(key).append(json[key]); - $('select', this).append(option); - } - /* Loop option again to set selected. IE needed this... */ + $('select', this).append(option); + } + /* Loop option again to set selected. IE needed this... */ $('select', this).children().each(function() { - if ($(this).val() == json['selected'] || + if ($(this).val() == json['selected'] || $(this).text() == $.trim(original.revert)) { $(this).attr('selected', 'selected'); } @@ -538,6 +582,7 @@ loadtype : 'GET', loadtext : 'Loading...', placeholder: 'Click to edit', + containerName : 'div.edit-container', loaddata : {}, submitdata : {}, ajaxoptions: {}