-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery.editable.js
61 lines (53 loc) · 1.87 KB
/
jquery.editable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
*
* jQuery Editables 1.0.1
*
* Date: Aug 11 2012
* Source: www.tectual.com.au, www.arashkarimzadeh.com
* Author: Arash Karimzadeh ([email protected])
*
* Copyright (c) 2012 Tectual Pty. Ltd.
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function($){
$.fn.editables = function(options){
var opts = $.extend( {}, $.fn.editables.options, options );
if(!$.isArray(opts.freezeOn)) opts.freezeOn = [opts.freezeOn];
if(!$.isArray(opts.editOn)) opts.editOn = [opts.editOn];
$('[data-type=editable]', this).each(
function(){
var $this = $(this);
var fn = function(ev){
var t = $($this.data('for'));
if(opts.beforeFreeze.call(t, $this, ev)==false) return;
t.hide();
$this.show();
t.trigger('onFreeze');
};
var evs= {};
$.each( opts.freezeOn, function(){ evs[this] = fn; } );
$($this.data('for')).hide().bind('onFreeze', opts.onFreeze).bind(evs);
var fn = function(ev){
var t = $($this.data('for'));
if(opts.beforeEdit.call($this, t, ev)==false) return;
$this.hide();
t.show().focus();
$this.trigger('onEdit');
}
var evs = {};
$.each( opts.editOn, function(){ evs[this] = fn; } );
$this.bind('onEdit', opts.onEdit).bind(evs);
}
);
return this;
}
$.fn.editables.options = {
editOn: 'click', /* Event, Array[Events]: All jquery events */
beforeEdit: $.noop, /* Function: It is called before conversion, you can stop it by returning false */
onEdit: $.noop, /* Function: This function bind to editable item as event */
freezeOn: 'blur', /* Event, Array[Events]: All jquery events */
beforeFreeze: $.noop, /* Function: It is called before conversion, you can stop it by returning false */
onFreeze: $.noop /* Function: This function bind to edit field as event */
}
})(jQuery);