app/jquery/jquery-in-place-edit.js
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 12 Sep 2009 00:36:49 +0200
changeset 2898 ac5f77cd6046
parent 2892 d7a19ac73f22
permissions -rw-r--r--
Fix 500 when saving /site/edit without email When saving /site/edit with no no_reply_email set, a 500 error page would be returned due to an empty value being passed as value to the datastore (which is not allowed for email fields).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2892
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     1
/*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     2
* jquery-in-place-edit plugin
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     3
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     4
* Copyright (c) 2008 Christian Hellsten
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     5
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     6
* Plugin homepage:
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     7
*  http://aktagon.com/projects/jquery/in-place-edit/
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     8
*  http://github.com/christianhellsten/jquery-in-place-edit/
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
     9
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    10
* Examples:
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    11
*  http://aktagon.com/projects/jquery/in-place-edit/examples/
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    12
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    13
* Repository:
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    14
*  git://github.com/christianhellsten/jquery-in-place-edit.git
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    15
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    16
* Version 1.0.2
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    17
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    18
* Tested with:
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    19
*  Windows:  Firefox 2, Firefox 3, Internet Explorer 6, Internet Explorer 7
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    20
*  Linux:    Firefox 2, Firefox 3, Opera
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    21
*  Mac:      Firefox 2, Firefox 3, Opera
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    22
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    23
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    24
* Licensed under the MIT license:
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    25
* http://www.opensource.org/licenses/mit-license.php
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    26
*
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    27
*/
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    28
(function($) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    29
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    30
  $.fn.inPlaceEdit = function(options) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    31
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    32
    // Add click handler to all matching elements
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    33
    return this.each(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    34
      // Use default options, if necessary
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    35
      var settings = $.extend({}, $.fn.inPlaceEdit.defaults, options);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    36
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    37
      var element = $(this);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    38
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    39
      element.click(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    40
        element.data('skipBlur', false)
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    41
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    42
        // Prevent multiple clicks, and check if inplace editing is disabled
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    43
        if (element.hasClass("editing") || element.hasClass("disabled")) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    44
            return;
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    45
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    46
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    47
        element.addClass("editing");
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    48
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    49
        element.old_value = element.html();          // Store old HTML so we can revert to it later
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    50
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    51
        if(typeof(settings.html) == 'string') {     // There are two types of form templates: strings and DOM elements
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    52
          element.html(settings.html);              // Replace current HTML with given HTML
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    53
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    54
        else {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    55
          element.html('');                         // Replace current HTML with given object's HTML
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    56
          var form_template = settings.html.children(':first').clone(true);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    57
          form_template.appendTo(element);          // Clone event handlers too
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    58
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    59
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    60
        $('.field', element).val(element.old_value); // Set field value to old HTML
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    61
        $('.field', element).focus();               // Set focus to input field
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    62
        $('.field', element).select();              // Select all text in field
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    63
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    64
        // On blur: cancel action
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    65
        if(settings.onBlurDisabled == false) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    66
          $('.field', element).blur(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    67
            // Prevent cancel from being triggered when clicking Save & Cancel button
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    68
            var skipBlur = element.data('skipBlur')
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    69
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    70
            if(skipBlur != true) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    71
              element.timeout = setTimeout(cancel, 50);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    72
            }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    73
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    74
            element.data('skipBlur', false)
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    75
          });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    76
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    77
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    78
        // On save: revert to old HTML and submit
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    79
        $('.save-button', element).click(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    80
          return submit();
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    81
        });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    82
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    83
        $('.save-button', element).mousedown(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    84
          element.data('skipBlur', true)
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    85
        });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    86
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    87
        $('.cancel-button', element).mousedown(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    88
          element.data('skipBlur', true)
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    89
        });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    90
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    91
        // On cancel: revert to old HTML
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    92
        $('.cancel-button', element).click(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    93
          return cancel();
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    94
        });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    95
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    96
        // On keyup: submit (ESC) or cancel (enter)
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    97
        if(settings.onKeyupDisabled == false) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    98
          $('.field', element).keyup(function(event) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
    99
            var keycode = event.which;
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   100
            var type = this.tagName.toLowerCase();
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   101
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   102
            if(keycode == 27 && settings.escapeKeyDisabled == false)  {      // escape
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   103
              return cancel();
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   104
            }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   105
            else if(keycode == 13) { // enter
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   106
              // Don't submit on enter if this is a textarea
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   107
              if(type != "textarea") {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   108
                return submit();
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   109
              }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   110
            }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   111
            return true;
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   112
          });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   113
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   114
      });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   115
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   116
      // Add hover class on mouseover
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   117
      element.mouseover(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   118
        element.addClass("hover");
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   119
      });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   120
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   121
      // Remove hover class on mouseout
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   122
      element.mouseout(function() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   123
        element.removeClass("hover");
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   124
      });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   125
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   126
      function cancel() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   127
        element.html(element.old_value);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   128
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   129
        element.removeClass("hover editing");
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   130
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   131
        if(options.cancel) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   132
          options.cancel.apply(element, [element]);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   133
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   134
        return false; // Stop propagation
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   135
      };
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   136
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   137
      function submit() {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   138
        clearTimeout(element.timeout);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   139
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   140
        var id = element.attr('id');
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   141
        var value = $('.field', element).val();
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   142
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   143
        if(options.submit) {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   144
          options.submit.apply(element, [element, id, value, element.old_value]);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   145
        }
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   146
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   147
        element.removeClass("hover editing");
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   148
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   149
        element.html(value);
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   150
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   151
        return false; // Stop propagation
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   152
      };
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   153
    });
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   154
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   155
  };
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   156
 
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   157
  // Default (overridable) settings
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   158
  $.fn.inPlaceEdit.defaults = {
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   159
    onBlurDisabled  : false,
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   160
    onKeyupDisabled : false,
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   161
    escapeKeyDisabled : false,
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   162
    html : ' \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   163
          <div class="inplace-edit"> \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   164
            <input type="text" value="" class="field" /> \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   165
            <div class="buttons"> \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   166
              <input type="button" value="Save" class="save-button" /> \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   167
              <input type="button" value="Cancel" class="cancel-button" /> \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   168
            </div> \
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   169
          </div>'
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   170
  };
d7a19ac73f22 Added jquery in-place-edit.
Madhusudan.C.S <madhusudancs@gamil.com>
parents:
diff changeset
   171
})(jQuery);