simple_update_field 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.creole +26 -1
- data/VERSION +1 -1
- data/simple_update_field.gemspec +2 -2
- data/vendor/assets/javascripts/simple_update_field.js +43 -26
- metadata +11 -11
data/README.creole
CHANGED
@@ -8,6 +8,30 @@ simple_update_field is implemented internally with jquery
|
|
8
8
|
== Design Goals
|
9
9
|
|
10
10
|
Simple_update_field is designed to extend the browsers behaviour in a un-surprising manner.
|
11
|
+
== Callback Guide
|
12
|
+
|
13
|
+
You may wish to be able to change the rules around when to, or when not to do an update.
|
14
|
+
|
15
|
+
A callback named 'before_update' is provided - you can install it when you invoke SimpleUpdateField.
|
16
|
+
|
17
|
+
For example you may wish to have a confirmation dialog:
|
18
|
+
|
19
|
+
{{{
|
20
|
+
|
21
|
+
var my_confirm_handler = function() {
|
22
|
+
var input = this
|
23
|
+
return confirm("Update the database with " + input.value +" ?")
|
24
|
+
}
|
25
|
+
|
26
|
+
$(document).ready(function() {
|
27
|
+
SimpleUpdateField('.phrase .text'
|
28
|
+
,{
|
29
|
+
before_update:my_confirm_handler
|
30
|
+
})
|
31
|
+
|
32
|
+
})
|
33
|
+
|
34
|
+
}}}
|
11
35
|
|
12
36
|
== Styling Guide
|
13
37
|
|
@@ -145,7 +169,7 @@ $(document).ready(function() {
|
|
145
169
|
* error handling of ajax call
|
146
170
|
|
147
171
|
== Recent Changes
|
148
|
-
|
172
|
+
* before_update callback - return true to continue , false to stop
|
149
173
|
* Only commit changed fields to the remote-resource-uri
|
150
174
|
* Trim leading and trailng whitespace of entered data or original text data
|
151
175
|
* Have it work for any element without modifying structure (ie needs no wrapper)
|
@@ -168,6 +192,7 @@ Curtis Schofield
|
|
168
192
|
|
169
193
|
Contributors
|
170
194
|
Judy Tuna
|
195
|
+
Hollin Wilkins
|
171
196
|
|
172
197
|
Copyright (c) 2012 Blazing Cloud. See LICENSE.txt for
|
173
198
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
data/simple_update_field.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "simple_update_field"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Curtis Schofield"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-09"
|
13
13
|
s.description = "Your resources text attributes will gain inplace update ability with keybindings for quick editing"
|
14
14
|
s.email = "curtis@ram9.cc"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,5 +1,5 @@
|
|
1
1
|
//1
|
2
|
-
SimpleUpdateField = function(selector) {
|
2
|
+
SimpleUpdateField = function(selector, options) {
|
3
3
|
var self = this
|
4
4
|
/*
|
5
5
|
* This is used internally to track what key has been
|
@@ -52,7 +52,7 @@ SimpleUpdateField = function(selector) {
|
|
52
52
|
}
|
53
53
|
return false
|
54
54
|
}
|
55
|
-
var
|
55
|
+
var is_tab_redirect = function () {
|
56
56
|
if (self.last_keydown_event) {
|
57
57
|
if (self.last_keydown_event.keyCode == SimpleUpdateField.TAB_KEY) {
|
58
58
|
return true
|
@@ -87,45 +87,62 @@ SimpleUpdateField = function(selector) {
|
|
87
87
|
$.ajax({url:uri,data:data,type:'PUT'})
|
88
88
|
}
|
89
89
|
|
90
|
-
|
90
|
+
self.commit_if_changed = function(input_node) {
|
91
91
|
if(input_node.data('original-text') != input_node.val().trim()) {
|
92
92
|
commit_to_remote_resource(input_node)
|
93
93
|
}
|
94
94
|
}
|
95
95
|
|
96
|
-
var
|
97
|
-
|
98
|
-
|
96
|
+
var commit_if_callback_true = function(original_element,finished_input_node) {
|
97
|
+
var continue_commit = true
|
98
|
+
if (options && options.before_update)
|
99
|
+
continue_commit = options.before_update.apply(finished_input_node.get(0))
|
100
|
+
if (continue_commit) {
|
101
|
+
commit_if_changed(finished_input_node)
|
102
|
+
}
|
103
|
+
return continue_commit
|
99
104
|
}
|
100
105
|
|
101
|
-
var
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
editable_restoration(parent,finished_input_node.data('original-text')) // the input we create had a memo about it's original text
|
106
|
+
var editable_restoration = function(original_element,text_value) {
|
107
|
+
original_element.text(text_value)
|
108
|
+
install_edit_notions(original_element)
|
106
109
|
}
|
107
110
|
|
108
|
-
var
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
commit_if_changed(finished_input_node)
|
114
|
-
|
115
|
-
editable_restoration(parent,finished_input_node.val())
|
111
|
+
var rollback_edit_event = function(event) {
|
112
|
+
var parent = $(this).parent();
|
113
|
+
rollback_edit(parent, $(this))
|
114
|
+
}
|
116
115
|
|
116
|
+
var rollback_edit = function(original_element, finished_input_node) {
|
117
|
+
editable_restoration(original_element, finished_input_node.data('original-text'))
|
118
|
+
}
|
119
|
+
|
120
|
+
var complete_edit = function(original_element,finished_input_node) {
|
121
|
+
if(commit_if_callback_true(original_element,finished_input_node) ) {
|
122
|
+
editable_restoration(original_element,finished_input_node.val())
|
123
|
+
}
|
124
|
+
else {
|
125
|
+
editable_restoration(original_element, finished_input_node.data('original-text'))
|
126
|
+
}
|
117
127
|
// If tab key was hit during the edit phase
|
118
|
-
// we want to redirect this
|
128
|
+
// we want to redirect this to be a
|
119
129
|
// click on the next sibling
|
120
|
-
if(
|
121
|
-
move_to_next_sibling(
|
130
|
+
if(is_tab_redirect()) {
|
131
|
+
move_to_next_sibling(original_element)
|
122
132
|
}
|
123
|
-
|
124
133
|
// Cleanup - cross event state
|
125
134
|
// there was no last keydown event
|
126
135
|
self.last_keydown_event = undefined;
|
127
136
|
}
|
128
137
|
|
138
|
+
var complete_edit_event = function(event) {
|
139
|
+
|
140
|
+
var finished_input_node = $(this)
|
141
|
+
var original_element = finished_input_node.parent();
|
142
|
+
|
143
|
+
complete_edit(original_element,finished_input_node)
|
144
|
+
}
|
145
|
+
|
129
146
|
var install_edit_notions = function(selector) {
|
130
147
|
|
131
148
|
$(selector).bind('click.editable',begin_edit_event)
|
@@ -148,8 +165,8 @@ SimpleUpdateField = function(selector) {
|
|
148
165
|
|
149
166
|
$(selector).bind('keydown.editable',function(e) {
|
150
167
|
self.last_keydown_event = e
|
151
|
-
if(
|
152
|
-
$(this).trigger('
|
168
|
+
if(is_tab_redirect()) {
|
169
|
+
$(this).trigger('complete.editable')
|
153
170
|
return false; // manually handle tab - no event propigation
|
154
171
|
}
|
155
172
|
if(is_rollback_changes()) {
|
@@ -159,7 +176,7 @@ SimpleUpdateField = function(selector) {
|
|
159
176
|
return true // allow default propigation
|
160
177
|
})
|
161
178
|
|
162
|
-
$(selector).bind('
|
179
|
+
$(selector).bind('complete.editable',complete_edit_event)
|
163
180
|
$(selector).bind('rollback.editable',rollback_edit_event)
|
164
181
|
}
|
165
182
|
var annotate_editable_with_position = function(selector) {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_update_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70104163814740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.8.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70104163814740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &70104163813460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.12'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70104163813460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70104163812080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.1.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70104163812080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70104163810880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.8.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70104163810880
|
58
58
|
description: Your resources text attributes will gain inplace update ability with
|
59
59
|
keybindings for quick editing
|
60
60
|
email: curtis@ram9.cc
|
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash:
|
95
|
+
hash: 4112278823148699834
|
96
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|