AnanthaKN / jquery-in-place-editor

Automatically exported from code.google.com/p/jquery-in-place-editor
Other
0 stars 0 forks source link

Feature: Function call on focus #114

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'd like a feature that assigns a function to be called before editing begins, 
to get a value for the text that might differ from what is being displayed.

Consider the web page text: "yolk and sugar"

The original text was: "i1 & i2" (where i1 and i2 represent yolk and sugar).

In other words, the text on the web page is an expansion of their original, 
abbreviated text. The only way to retrieve the original text is by sending a 
request to the server.

Original issue reported on code.google.com by dave.jar...@gmail.com on 14 May 2012 at 6:41

GoogleCodeExporter commented 8 years ago
Something like:

on_edit (function) default: null. Called before editing begins.

Original comment by dave.jar...@gmail.com on 14 May 2012 at 6:42

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Made a few changes to jquery.inline.js:

In function setInitialValue, around line 284 (before editor.val(initialValue)):

    if( this.settings.on_edit ) {
      initialValue = this.settings.on_edit( initialValue );
    }

And at the top of the source, around line 81:

  on_edit:      null, // function: called before editing begins

Then write a function:

function getEditValue( initialValue ) { 
  return "42 " + initialValue;
}

Seems to do the trick.

Original comment by dave.jar...@gmail.com on 14 May 2012 at 6:55

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
A full example:

  $('.span-class').editInPlace({
    url           : window.location.pathname,
    default_text  : '',
    hover_class   : 'inplace_hover',
    params        : 'command=update-instruction',
    on_edit       : get_instruction_value
  });

Then this line can become a bit more flexible:

  initialValue = this.settings.on_edit( this.dom, initialValue );

And then the <span> element (or whatever was DOM element was used) is passed 
along:

  function get_instruction_value( dom, initialValue ) {
    return "id: " + dom.attr("id") + " " + initialValue;
  }

Original comment by dave.jar...@gmail.com on 15 May 2012 at 12:00