simple_update_field 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.creole +49 -4
- data/VERSION +1 -1
- data/simple_update_field.gemspec +2 -2
- data/vendor/assets/javascripts/simple_update_field.js +35 -19
- metadata +11 -11
data/README.creole
CHANGED
@@ -5,6 +5,38 @@ to move between each simple_update_field.
|
|
5
5
|
|
6
6
|
simple_update_field is implemented internally with jquery
|
7
7
|
|
8
|
+
== Design Goals
|
9
|
+
|
10
|
+
Simple_update_field is designed to extend the browsers behaviour in a un-surprising manner.
|
11
|
+
|
12
|
+
== Styling Guide
|
13
|
+
|
14
|
+
Use CSS as you normaly would along with the following classes
|
15
|
+
|
16
|
+
|
17
|
+
{{{
|
18
|
+
.editable-input {
|
19
|
+
/*
|
20
|
+
this is the input that will be created
|
21
|
+
on click use this class to change it's style
|
22
|
+
*/
|
23
|
+
}
|
24
|
+
}}}
|
25
|
+
{{{
|
26
|
+
.editable-hover {
|
27
|
+
/*
|
28
|
+
this is the field that has a mouse-over
|
29
|
+
use this to tell the user the field is clickable
|
30
|
+
*/
|
31
|
+
}
|
32
|
+
|
33
|
+
}}}
|
34
|
+
|
35
|
+
It is recommended to put a min-width on the element which contains your editable
|
36
|
+
text. For example - if you use a span - if you remove all the text the element
|
37
|
+
will collapse. Simple Update Field will not take responsiblity for lack of styling
|
38
|
+
such an element as you have the power to adjust this via CSS!
|
39
|
+
|
8
40
|
== Installation Guide for Rails 3+
|
9
41
|
|
10
42
|
If you are using a version of rails before JQuery became the default - please integrate the gem 'jquery-rails'
|
@@ -26,7 +58,9 @@ based resource calls.
|
|
26
58
|
<div class='phrase'>
|
27
59
|
<span editable-resource-attribute="text"
|
28
60
|
editable-resource-model="<%=phrase.class.model_name.downcase%>"
|
29
|
-
editable-resource-uri="<%=
|
61
|
+
editable-resource-uri="<%=phrase_path(phrase,
|
62
|
+
:authenticity_token =>
|
63
|
+
form_authenticity_token)%>"
|
30
64
|
class="text">
|
31
65
|
<%= phrase.text %>
|
32
66
|
</span>
|
@@ -41,12 +75,16 @@ based resource calls.
|
|
41
75
|
*** this will be sent to the server as part of the post-variable ie: model_name_here[attribute_name_here]=VALUE
|
42
76
|
## editable-resource-uri
|
43
77
|
*** this is the destination to send the post-variable that is described by the above.
|
78
|
+
**** you will need to encode CRSF into this path if you are using typical rails protect_from_forgery
|
44
79
|
==== Example of all 3 attributes
|
45
80
|
* With resources 'Animals' (Model : Animal & Controller : AnimalsController) with the attribute 'name' and an instance of Animal 'animal'
|
46
81
|
{{{
|
47
82
|
<span editable-resource-attribute="name"
|
48
83
|
editable-resource-model="animal"
|
49
|
-
editable-resource-uri="<%=
|
84
|
+
editable-resource-uri="<%= animal_path(animal,
|
85
|
+
:authenticity_token =>
|
86
|
+
form_authenticity_token)
|
87
|
+
%>"
|
50
88
|
class="animal-name">
|
51
89
|
<%= animal.name %>
|
52
90
|
</span>
|
@@ -103,12 +141,15 @@ $(document).ready(function() {
|
|
103
141
|
|
104
142
|
|
105
143
|
== Roadmap
|
106
|
-
* Have it work for any element without modifying structure (ie needs no wrapper)
|
107
144
|
* form field helper
|
108
145
|
* error handling of ajax call
|
109
146
|
|
110
147
|
== Recent Changes
|
111
148
|
|
149
|
+
* Only commit changed fields to the remote-resource-uri
|
150
|
+
* Trim leading and trailng whitespace of entered data or original text data
|
151
|
+
* Have it work for any element without modifying structure (ie needs no wrapper)
|
152
|
+
* Reworked internal Design so that it can work without altering the layout done via css
|
112
153
|
* Left out test harness https://github.com/blazingcloud/simple_update_field-jasmine-harness
|
113
154
|
|
114
155
|
=== Contributing to simple_update_field
|
@@ -122,7 +163,11 @@ $(document).ready(function() {
|
|
122
163
|
# Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
123
164
|
|
124
165
|
=== Copyright
|
125
|
-
Authored by
|
166
|
+
Authored by
|
167
|
+
Curtis Schofield
|
168
|
+
|
169
|
+
Contributors
|
170
|
+
Judy Tuna
|
126
171
|
|
127
172
|
Copyright (c) 2012 Blazing Cloud. See LICENSE.txt for
|
128
173
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.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.1.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-
|
12
|
+
s.date = "2012-05-01"
|
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,11 @@
|
|
1
1
|
SimpleUpdateField = function(selector) {
|
2
2
|
var self = this
|
3
|
+
/*
|
4
|
+
* This is used internally to track what key has been
|
5
|
+
* pressed last in complete event form.
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
self.last_keydown_event = undefined;
|
3
9
|
self.selector = selector
|
4
10
|
self.current_input = function () {
|
5
11
|
var last_clicked = $(self.selector + ' > input')
|
@@ -21,13 +27,14 @@ SimpleUpdateField = function(selector) {
|
|
21
27
|
input_node.attr(attributes[i].nodeName, attributes[i].nodeValue)
|
22
28
|
}
|
23
29
|
}
|
24
|
-
input_node.data('original-text',node.text())
|
25
|
-
input_node.val(node.text().trim())
|
30
|
+
input_node.data('original-text',node.text().trim())
|
26
31
|
|
32
|
+
input_node.val(node.text().trim())
|
33
|
+
input_node.addClass('editable-input')
|
27
34
|
return input_node
|
28
35
|
}
|
29
36
|
|
30
|
-
|
37
|
+
var begin_edit_event = function(event) {
|
31
38
|
var clicked_node = $(this);
|
32
39
|
var input_node = create_input_from(clicked_node);
|
33
40
|
clicked_node.text("")
|
@@ -63,42 +70,51 @@ SimpleUpdateField = function(selector) {
|
|
63
70
|
}
|
64
71
|
next_editable.trigger('click.editable')
|
65
72
|
}else {
|
66
|
-
throw 'Expected to
|
73
|
+
throw 'Expected to find custom attribute editable-index'
|
67
74
|
}
|
68
75
|
}
|
69
|
-
|
76
|
+
var rollback_edit_event = function(event) {
|
70
77
|
var finished_input_node = $(this)
|
71
78
|
|
72
79
|
finished_input_node.parent().text(finished_input_node.data('original-text')) // the input we create had a memo about it's original text
|
73
80
|
finished_input_node.remove() // remove the input field that we created such that the node is unchanged
|
74
81
|
|
75
82
|
}
|
76
|
-
|
77
|
-
uri =
|
78
|
-
name =
|
79
|
-
attribute =
|
80
|
-
id =
|
83
|
+
var commit_to_remote_resource = function(input_node) {
|
84
|
+
uri = input_node.attr('editable-resource-uri')
|
85
|
+
name = input_node.attr('editable-resource-model')
|
86
|
+
attribute = input_node.attr('editable-resource-attribute')
|
87
|
+
id = input_node.attr('editable-resource-id')
|
81
88
|
data = {}
|
82
89
|
data['id'] = id
|
83
90
|
data[name] = {}
|
84
|
-
data[name][attribute] =
|
91
|
+
data[name][attribute] = input_node.val().trim()
|
85
92
|
$.ajax({url:uri,data:data,type:'PUT'})
|
86
93
|
}
|
87
94
|
|
88
|
-
|
95
|
+
var commit_if_changed = function(input_node) {
|
96
|
+
if(input_node.data('original-text') != input_node.val().trim()) {
|
97
|
+
commit_to_remote_resource(input_node)
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
var complete_edit_event = function(event) {
|
89
102
|
|
90
103
|
var finished_input_node = $(this)
|
91
104
|
var parent = finished_input_node.parent();
|
92
105
|
|
93
|
-
|
94
|
-
parent.text(finished_input_node.val()) // set the elements character data back to text
|
106
|
+
commit_if_changed(finished_input_node)
|
95
107
|
|
96
|
-
|
108
|
+
// set the elements character data back to text
|
109
|
+
parent.text(finished_input_node.val())
|
97
110
|
|
111
|
+
// remove the input field that we created
|
112
|
+
// such that the node is unchanged
|
113
|
+
finished_input_node.remove()
|
98
114
|
|
99
115
|
// If tab key was hit during the edit phase
|
100
|
-
// we want to redirect this blur to be a
|
101
|
-
// sibling
|
116
|
+
// we want to redirect this blur to be a
|
117
|
+
// click on the next sibling
|
102
118
|
if(is_blur_tab_redirect()) {
|
103
119
|
move_to_next_sibling(parent)
|
104
120
|
}
|
@@ -135,8 +151,8 @@ SimpleUpdateField = function(selector) {
|
|
135
151
|
return true // allow default propigation
|
136
152
|
})
|
137
153
|
|
138
|
-
$(selector).bind('blur.editable',
|
139
|
-
$(selector).bind('rollback.editable',
|
154
|
+
$(selector).bind('blur.editable',complete_edit_event)
|
155
|
+
$(selector).bind('rollback.editable',rollback_edit_event)
|
140
156
|
}
|
141
157
|
var annotate_editable_with_position = function(selector) {
|
142
158
|
$(selector).each(function(i,el) {
|
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.1.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-
|
12
|
+
date: 2012-05-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70265774286000 !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: *70265774286000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &70265774284540 !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: *70265774284540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70265774283080 !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: *70265774283080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70265774281220 !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: *70265774281220
|
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: 2183542009217822170
|
96
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|