simple_update_field 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.1.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.3)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.6.5)
12
+ rake (0.9.2.2)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ rspec (2.8.0)
16
+ rspec-core (~> 2.8.0)
17
+ rspec-expectations (~> 2.8.0)
18
+ rspec-mocks (~> 2.8.0)
19
+ rspec-core (2.8.0)
20
+ rspec-expectations (2.8.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.8.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.1.0)
29
+ jeweler (~> 1.8.3)
30
+ rdoc (~> 3.12)
31
+ rspec (~> 2.8.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Curtis Schofield
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = simple_update_field
2
+
3
+ Rails text field helper for inplace-editing of text with keybindings
4
+ to move between each simple_update_field.
5
+
6
+ simple_update_field is implemented internally with jquery
7
+
8
+
9
+
10
+ == Contributing to simple_update_field
11
+
12
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
13
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
14
+ * Fork the project.
15
+ * Start a feature/bugfix branch.
16
+ * Commit and push until you are happy with your contribution.
17
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
18
+ * 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.
19
+
20
+ == Copyright
21
+ Authored by Curtis Schofield
22
+
23
+ Copyright (c) 2012 Blazing Cloud. See LICENSE.txt for
24
+ further details.
25
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "simple_update_field"
18
+ gem.homepage = "http://github.com/robotarmy/simple_update_field"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{turn a resource attribute into an inplace editable field}
21
+ gem.description = %Q{Your resources text attributes will gain inplace update ability with keybindings for quick editing}
22
+ gem.email = "curtis@ram9.cc"
23
+ gem.authors = ["Curtis Schofield"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "simple_update_field #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,5 @@
1
+ module SimpleUpdateField
2
+ class Engine < Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "simple_update_field"
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Curtis Schofield"]
12
+ s.date = "2012-03-07"
13
+ s.description = "Your resources text attributes will gain inplace update ability with keybindings for quick editing"
14
+ s.email = "curtis@ram9.cc"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/simple_update_field.rb",
29
+ "simple_update_field.gemspec",
30
+ "spec/simple_update_field_spec.rb",
31
+ "spec/spec_helper.rb",
32
+ "vendor/assets/javascripts/editable_list.js"
33
+ ]
34
+ s.homepage = "http://github.com/robotarmy/simple_update_field"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "turn a resource attribute into an inplace editable field"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
48
+ else
49
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
50
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SimpleUpdateField" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'simple_update_field'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,172 @@
1
+ //2hrs march 2nd
2
+ //1hrs march 2nd
3
+ //3hrs march 4th
4
+ //
5
+ Editable = function(selector) {
6
+ var self = this
7
+ self.selector = selector
8
+
9
+ var create_tag_with = function(tag_name,node) {
10
+ var elem = $('<'+tag_name+'/>');
11
+ var attributes = node.get(0).attributes
12
+ for(var i = attributes.length-1; i >=0;i--) {
13
+ elem.attr(attributes[i].nodeName, attributes[i].nodeValue)
14
+ }
15
+
16
+ elem.data(node.data())
17
+ elem.data('editable-was',node.get(0).tagName)
18
+
19
+ node.replaceWith(function() {
20
+ return elem
21
+ })
22
+ return elem
23
+ }
24
+
25
+ var replace_input_from = function(node) {
26
+ var element = create_tag_with('input',node)
27
+
28
+ element.data('original-text',node.text())
29
+ element.val(node.text().trim())
30
+
31
+ return element
32
+
33
+ }
34
+
35
+ self.begin_edit_event = function(event) {
36
+ var clicked_node = $(this);
37
+ var new_node = replace_input_from(clicked_node);
38
+ install_edit_complete_notions(new_node)
39
+ new_node.focus();
40
+ }
41
+ var is_rollback_changes = function() {
42
+ if (self.last_keydown_event) {
43
+ if (self.last_keydown_event.keyCode == Editable.ESC_KEY) {
44
+ return true
45
+ }
46
+ }
47
+ return false
48
+ }
49
+ var is_blur_tab_redirect = function () {
50
+ if (self.last_keydown_event) {
51
+ if (self.last_keydown_event.keyCode == Editable.TAB_KEY) {
52
+ return true
53
+ }
54
+ if (self.last_keydown_event.keyCode == Editable.ENTER_KEY) {
55
+ return true
56
+ }
57
+ }
58
+ return false
59
+ }
60
+ var move_to_next_sibling = function(element) {
61
+ if(element.attr('editable-index')) {
62
+ var next_position = parseInt(element.attr('editable-index')) +1
63
+ var next_editable = $(selector).filter('[editable-index='+next_position+']')
64
+ if (next_editable.size() == 0) {
65
+ next_editable = $(selector).filter('[editable-index=1]')
66
+ }
67
+ next_editable.trigger('click.editable')
68
+ }else {
69
+ throw 'Expected to be able to assign custom attribute editable-index'
70
+ }
71
+ }
72
+ self.rollback_edit_event = function(event) {
73
+ var finished_node = $(this)
74
+ var element = create_tag_with(finished_node.data('editable-was'),finished_node)
75
+ element.text(element.data('original-text'))
76
+ install_edit_notions(element)
77
+ }
78
+ self.commit_to_remote_resource = function(node) {
79
+ uri = node.attr('editable-resource-uri')
80
+ name = node.attr('editable-resource-model')
81
+ attribute = node.attr('editable-resource-attribute')
82
+ id = node.attr('editable-resource-id')
83
+ data = {}
84
+ data['id'] = id
85
+ data[name] = {}
86
+ data[name][attribute] = node.val().trim()
87
+ $.post(uri, data)
88
+ }
89
+ self.complete_edit_event = function(event) {
90
+
91
+ var finished_node = $(this)
92
+ commit_to_remote_resource(finished_node)
93
+ var element = create_tag_with(finished_node.data('editable-was'),finished_node)
94
+ element.text(finished_node.val())
95
+ install_edit_notions(element)
96
+
97
+ // If tab key was hit during the edit phase
98
+ // we want to redirect this blur to be a click on the next
99
+ // sibling
100
+ if(is_blur_tab_redirect()) {
101
+ move_to_next_sibling(element)
102
+ }
103
+
104
+ // Cleanup - cross event state
105
+ // there was no last keydown event
106
+ self.last_keydown_event = undefined;
107
+ }
108
+
109
+ var install_edit_notions = function(selector) {
110
+
111
+ $(selector).bind('click.editable',begin_edit_event)
112
+ $(selector).bind('mouseover.editable',function() {
113
+ $(this).addClass('editable-hover')
114
+ })
115
+
116
+ $(selector).bind('mouseout.editable',function() {
117
+ $(this).removeClass('editable-hover')
118
+ })
119
+ }
120
+
121
+ var install_edit_complete_notions = function (selector) {
122
+
123
+ $(selector).bind('keydown.editable',function(e) {
124
+ self.last_keydown_event = e
125
+ if(is_blur_tab_redirect()) {
126
+ $(this).trigger('blur.editable')
127
+ return false; // manually handle tab - no event propigation
128
+ }
129
+ if(is_rollback_changes()) {
130
+ $(this).trigger('rollback.editable')
131
+ return false;
132
+ }
133
+ return true // allow default propigation
134
+ })
135
+
136
+ $(selector).bind('blur.editable',self.complete_edit_event)
137
+ $(selector).bind('rollback.editable',self.rollback_edit_event)
138
+ }
139
+ var annotate_editable_with_position = function(selector) {
140
+ $(selector).each(function(i,el) {
141
+ $(el).attr('editable-index',i+1)
142
+ })
143
+ }
144
+
145
+ var annotate_with_resource_errors = function(selector) {
146
+ $(selector).each(function(i,el){
147
+ if (!($(el).attr('editable-resource-uri')) ||
148
+ $(el).attr('editable-resource-uri') == "") {
149
+ $(el).parent().append('<div class="editable-errors">expected editable-resource-uri attribute in form http://server/resource/id</div>')
150
+ }
151
+ if (!($(el).attr('editable-resource-model')) ||
152
+ $(el).attr('editable-resource-model') == "") {
153
+ $(el).parent().append('<div class="editable-errors">expected editable-resource-model attribute in underscorized-rails form</div>')
154
+ }
155
+ if (!($(el).attr('editable-resource-attribute')) ||
156
+ $(el).attr('editable-resource-attribute') == "") {
157
+ $(el).parent().append('<div class="editable-errors">expected editable-resource-attribute attribute in underscorized-rails form </div>')
158
+ }
159
+ })
160
+ }
161
+
162
+ var install = function() {
163
+ install_edit_notions(selector)
164
+ annotate_editable_with_position(selector)
165
+ annotate_with_resource_errors(selector)
166
+ $(selector).data('editable','installed')
167
+ }()
168
+ return self;
169
+ }
170
+ Editable.TAB_KEY = 9 // tab is #9
171
+ Editable.ENTER_KEY = 13 // enter is #13
172
+ Editable.ESC_KEY = 27 // enter is #13
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_update_field
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Curtis Schofield
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70217325079200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70217325079200
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &70217325078720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70217325078720
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70217325078180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.1.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70217325078180
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70217325077620 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70217325077620
58
+ description: Your resources text attributes will gain inplace update ability with
59
+ keybindings for quick editing
60
+ email: curtis@ram9.cc
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - .rspec
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - VERSION
75
+ - lib/simple_update_field.rb
76
+ - simple_update_field.gemspec
77
+ - spec/simple_update_field_spec.rb
78
+ - spec/spec_helper.rb
79
+ - vendor/assets/javascripts/editable_list.js
80
+ homepage: http://github.com/robotarmy/simple_update_field
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 468527135396484031
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.10
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: turn a resource attribute into an inplace editable field
108
+ test_files: []