simple_update_field 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.creole +3 -2
- data/VERSION +1 -1
- data/simple_update_field.gemspec +2 -2
- data/vendor/assets/javascripts/simple_update_field.js +43 -37
- metadata +11 -11
data/README.creole
CHANGED
@@ -21,7 +21,7 @@ based resource calls.
|
|
21
21
|
}}}
|
22
22
|
* You will need to re-start a running server for the Gemfile change to take effect
|
23
23
|
=== View Side
|
24
|
-
* There are 3 custom attributes that will be used. An Example follows
|
24
|
+
* There are 3 custom attributes on a *span* that will be used. An Example follows
|
25
25
|
{{{
|
26
26
|
<div class='phrase'>
|
27
27
|
<span editable-resource-attribute="text"
|
@@ -86,6 +86,7 @@ There are 2 steps to integration with javascript.
|
|
86
86
|
//= require simple_update_field
|
87
87
|
}}}
|
88
88
|
* The second step is to invoke the the Simple Update Field on the appropriate elements
|
89
|
+
** this can be done in application.js aswell or in a new file in the app/assets/javascript directory
|
89
90
|
** A CSS selector of the jQuery style is assumed.
|
90
91
|
## For the above Phrase view code this could work :
|
91
92
|
{{{
|
@@ -102,7 +103,7 @@ $(document).ready(function() {
|
|
102
103
|
|
103
104
|
|
104
105
|
== Roadmap
|
105
|
-
|
106
|
+
* Have it work for any element without modifying structure (ie needs no wrapper)
|
106
107
|
* form field helper
|
107
108
|
* error handling of ajax call
|
108
109
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.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 = "
|
8
|
+
s.version = "2.0.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-04-
|
12
|
+
s.date = "2012-04-27"
|
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,38 +1,39 @@
|
|
1
1
|
SimpleUpdateField = function(selector) {
|
2
2
|
var self = this
|
3
3
|
self.selector = selector
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
self.current_input = function () {
|
5
|
+
var last_clicked = $(self.selector + ' > input')
|
6
|
+
if (last_clicked.size() == 0) {
|
7
|
+
return null
|
8
|
+
} else {
|
9
|
+
return last_clicked
|
10
10
|
}
|
11
|
-
|
12
|
-
elem.data(node.data())
|
13
|
-
elem.data('editable-was',node.get(0).tagName)
|
14
|
-
|
15
|
-
node.replaceWith(function() {
|
16
|
-
return elem
|
17
|
-
})
|
18
|
-
return elem
|
19
11
|
}
|
12
|
+
// Given a node with text() create an input that has the nodes text as it's value
|
13
|
+
// and record a memo about what the original-text is
|
14
|
+
//
|
15
|
+
var create_input_from = function(node) {
|
20
16
|
|
21
|
-
|
22
|
-
var
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
var input_node = $("<input/>")
|
18
|
+
var attributes = node.get(0).attributes
|
19
|
+
for(var i = attributes.length-1; i >=0; i--) {
|
20
|
+
if(attributes[i].nodeName.indexOf('editable') == 0) {
|
21
|
+
input_node.attr(attributes[i].nodeName, attributes[i].nodeValue)
|
22
|
+
}
|
23
|
+
}
|
24
|
+
input_node.data('original-text',node.text())
|
25
|
+
input_node.val(node.text().trim())
|
28
26
|
|
27
|
+
return input_node
|
29
28
|
}
|
30
29
|
|
31
30
|
self.begin_edit_event = function(event) {
|
32
31
|
var clicked_node = $(this);
|
33
|
-
var
|
34
|
-
|
35
|
-
|
32
|
+
var input_node = create_input_from(clicked_node);
|
33
|
+
clicked_node.text("")
|
34
|
+
clicked_node.append(input_node)
|
35
|
+
install_edit_complete_notions(input_node)
|
36
|
+
input_node.focus();
|
36
37
|
}
|
37
38
|
var is_rollback_changes = function() {
|
38
39
|
if (self.last_keydown_event) {
|
@@ -66,10 +67,11 @@ SimpleUpdateField = function(selector) {
|
|
66
67
|
}
|
67
68
|
}
|
68
69
|
self.rollback_edit_event = function(event) {
|
69
|
-
var
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
var finished_input_node = $(this)
|
71
|
+
|
72
|
+
finished_input_node.parent().text(finished_input_node.data('original-text')) // the input we create had a memo about it's original text
|
73
|
+
finished_input_node.remove() // remove the input field that we created such that the node is unchanged
|
74
|
+
|
73
75
|
}
|
74
76
|
self.commit_to_remote_resource = function(node) {
|
75
77
|
uri = node.attr('editable-resource-uri')
|
@@ -82,26 +84,30 @@ SimpleUpdateField = function(selector) {
|
|
82
84
|
data[name][attribute] = node.val().trim()
|
83
85
|
$.ajax({url:uri,data:data,type:'PUT'})
|
84
86
|
}
|
87
|
+
|
85
88
|
self.complete_edit_event = function(event) {
|
86
|
-
|
87
|
-
var
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
|
90
|
+
var finished_input_node = $(this)
|
91
|
+
var parent = finished_input_node.parent();
|
92
|
+
|
93
|
+
commit_to_remote_resource(finished_input_node)
|
94
|
+
parent.text(finished_input_node.val()) // set the elements character data back to text
|
95
|
+
|
96
|
+
finished_input_node.remove() // remove the input field that we created such that the node is unchanged
|
97
|
+
|
98
|
+
|
93
99
|
// If tab key was hit during the edit phase
|
94
100
|
// we want to redirect this blur to be a click on the next
|
95
101
|
// sibling
|
96
102
|
if(is_blur_tab_redirect()) {
|
97
|
-
move_to_next_sibling(
|
103
|
+
move_to_next_sibling(parent)
|
98
104
|
}
|
99
105
|
|
100
106
|
// Cleanup - cross event state
|
101
107
|
// there was no last keydown event
|
102
108
|
self.last_keydown_event = undefined;
|
103
109
|
}
|
104
|
-
|
110
|
+
|
105
111
|
var install_edit_notions = function(selector) {
|
106
112
|
|
107
113
|
$(selector).bind('click.editable',begin_edit_event)
|
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:
|
4
|
+
version: 2.0.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-04-
|
12
|
+
date: 2012-04-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70219322332160 !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: *70219322332160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &70219322329300 !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: *70219322329300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70219322306340 !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: *70219322306340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70219322304760 !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: *70219322304760
|
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: 2017553997290528289
|
96
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|