rest_in_place 2.1.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDA3N2Y3M2JmODg2OWI5YmExM2Q1ZDA0MzdkNTQ4OGFjODc2MzgxMw==
5
+ data.tar.gz: !binary |-
6
+ MTk3ZTc1YTgyOWQxODI5YmIwMjdiMGRhYThhOGNlYTAyNTU3OGViMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDE5ZWRmYWQ2ZWNmNzUzZmMyNGQ1ZTBhOTEwYzNhOWFhOTRhZTc0MmRkZjQ5
10
+ ZjM1YTcxMGQxY2IxMzk1MjdjNDZiYmJkZDQ2ZmJiZGFkYTUyYzU4OTlkYmEz
11
+ Mjk3YWNmZjBhNDQxOWFiMmVmNmM0OGFjYTdhNjEwOTU5MmQ5MDQ=
12
+ data.tar.gz: !binary |-
13
+ MDYzYTMwMWQ3ZjA3YmU5MzZhNTNhZmExYTQ4ZmZkY2U3NGQyODEwZjQzMmE0
14
+ MWJkOTM0YTU1NjRmN2Y3Yjc0OTRkNjkwOTE2MDJlNTMyNGY1YTAzN2YwZjUz
15
+ MDAwMmMyZTU0Y2E0MGFiOWRlZGI3ZmZiYmJmNTlmMjJkZjRmNGE=
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 [Jan Varwig]
1
+ Copyright (c) 2013 [Jan Varwig]
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -102,7 +102,7 @@ follows:
102
102
 
103
103
  - put attributes into the element, like this:
104
104
 
105
- <span class="rest-in-place" data-url="/users/1" data-object="user" data-attribute="name">
105
+ <span class="rest-in-place" data-url="/users/1" data-object="user" data-attribute="name" data-placeholder="Enter a name">
106
106
  <%= @user.name %>
107
107
  </span>
108
108
 
@@ -158,6 +158,8 @@ it's associated with:
158
158
  Triggering the event is the first thing that happens, before any processing
159
159
  and form building takes place. That means uou can use this event to modify
160
160
  the content of the element (for example to remove number/date formatting).
161
+ - `ready.rest-in-place` when the form has been built. This event can be used
162
+ e.g. to change the size of the field or textarea.
161
163
  - `success.rest-in-place` with the data retrieved from the server as an
162
164
  extra parameter after a successful save on the server.
163
165
  This event is triggered at the very latest moment, after the element has
@@ -187,9 +189,9 @@ Your app/controllers/users_controller.rb:
187
189
  class UsersController < ApplicationController
188
190
  def show
189
191
  @user = User.find params[:id]
190
- respond_to do |type|
191
- type.html
192
- type.json {render :json => @user}
192
+ respond_to do |format|
193
+ format.html
194
+ format.json {render :json => @user}
193
195
  end
194
196
  end
195
197
 
@@ -260,5 +262,5 @@ If you send pull requests be sure to also add tests and make sure the existing
260
262
  tests pass.
261
263
 
262
264
 
263
- ---
264
- Copyright (c) 2012 [Jan Varwig], released under the MIT license
265
+ Copyright (c) 2013 [Jan Varwig], released under the MIT license
266
+
@@ -1 +1 @@
1
- //= require ./rest_in_place.js
1
+ //= require ./rest_in_place
@@ -10,23 +10,25 @@ class RestInPlaceEditor
10
10
  @createClickHandler()
11
11
 
12
12
  @$element.click(@clickHandler)
13
+
14
+ @updateDisplayValue(@$element.text())
13
15
 
14
16
  # ## Public interface functions ############################################
15
17
 
16
18
  # Toggle the element associated with this editor from normal to a form field
17
19
  activate : ->
20
+ @oldValue = @elementHTML()
18
21
  @$element.trigger('activate.rest-in-place')
19
- @oldValue = @$element.html()
20
22
  @$element.addClass('rip-active')
21
23
  @$element.unbind('click', @clickHandler)
22
24
  @activateForm()
25
+ @$element.trigger('ready.rest-in-place')
23
26
 
24
27
  # Restore the element to its default state
25
28
  abort : ->
26
29
  @$element.trigger('abort.rest-in-place')
27
- @$element
28
- .html(@oldValue)
29
- .removeClass('rip-active')
30
+ @updateDisplayValue(@oldValue)
31
+ @$element.removeClass('rip-active')
30
32
  .click(@clickHandler)
31
33
 
32
34
  # Take the changes a user has made and send them to the server.
@@ -104,15 +106,17 @@ class RestInPlaceEditor
104
106
  @formType = @formType || $(parent).attr("data-formtype")
105
107
  @objectName = @objectName || $(parent).attr("data-object")
106
108
  @attributeName = @attributeName || $(parent).attr("data-attribute")
109
+ @placeholder = @placeholder || $(parent).attr("data-placeholder")
107
110
 
108
111
  @$element.parents().each (index, parent) =>
109
112
  @objectName = @objectName || res[1] if res = parent.id.match(/^(\w+)_(\d+)$/i)
110
113
 
111
- @url = @$element.attr("data-url") || @url || document.location.pathname
112
- @formType = @$element.attr("data-formtype") || @formType || "input"
113
- @objectName = @$element.attr("data-object") || @objectName
114
- @attributeName = @$element.attr("data-attribute") || @attributeName
115
-
114
+ @url = @$element.attr("data-url") || @url || document.location.pathname
115
+ @formType = @$element.attr("data-formtype") || @formType || "input"
116
+ @objectName = @$element.attr("data-object") || @objectName
117
+ @attributeName = @$element.attr("data-attribute") || @attributeName
118
+ @placeholder = @$element.attr("data-placeholder") || @placeholder || ''
119
+
116
120
  # Overwrites formtype specific method implementations during initialization
117
121
  bindForm : ->
118
122
  @activateForm = RestInPlaceEditor.forms[@formType].activateForm
@@ -145,12 +149,26 @@ class RestInPlaceEditor
145
149
  data[@objectName][@attributeName]
146
150
  else
147
151
  data[@attributeName]
148
-
152
+
153
+ updateDisplayValue : (value) ->
154
+ if $.trim(value).length < 1
155
+ @$element.html(@placeholderHTML())
156
+ else
157
+ @$element.text(value)
158
+
159
+ placeholderHTML : ->
160
+ """<span class="rest-in-placeholder">#{@placeholder}</span>"""
161
+
162
+ elementHTML: ->
163
+ value = @$element.html()
164
+ value = '' if value == @placeholderHTML()
165
+ value
166
+
149
167
  # ## Handlers ##############################################################
150
168
 
151
169
  # Handles the successful response from the server
152
170
  loadSuccessCallback : (data) ->
153
- @$element.html(@extractAttributeFromData(data))
171
+ @updateDisplayValue(@extractAttributeFromData(data))
154
172
  @$element.click(@clickHandler)
155
173
  @$element.removeClass('rip-active')
156
174
  @$element.trigger('success.rest-in-place', data)
@@ -173,7 +191,11 @@ class RestInPlaceEditor
173
191
  RestInPlaceEditor.forms =
174
192
  "input" :
175
193
  activateForm : ->
176
- @$element.html("""<form action="javascript:void(0)" style="display:inline;"><input type="text" value="#{$.trim(@oldValue)}" class="rest-in-place-#{@attributeName}"></form>""")
194
+ value = $.trim(@elementHTML())
195
+ @$element.html("""<form action="javascript:void(0)" style="display:inline;">
196
+ <input type="text" class="rest-in-place-#{@attributeName}" placeholder="#{@placeholder}">
197
+ </form>""")
198
+ @$element.find('input').val(value)
177
199
  @$element.find('input')[0].select()
178
200
  @$element.find("form").submit =>
179
201
  @update()
@@ -187,7 +209,11 @@ RestInPlaceEditor.forms =
187
209
 
188
210
  "textarea" :
189
211
  activateForm : ->
190
- @$element.html("""<form action="javascript:void(0)" style="display:inline;"><textarea class="rest-in-place-#{@attributeName}">#{$.trim(@oldValue)}</textarea></form>""")
212
+ value = $.trim(@elementHTML())
213
+ @$element.html("""<form action="javascript:void(0)" style="display:inline;">
214
+ <textarea class="rest-in-place-#{@attributeName}" placeholder="#{@placeholder}"></textarea>
215
+ </form>""")
216
+ @$element.find('textarea').val(value)
191
217
  @$element.find('textarea')[0].select()
192
218
  @$element.find("textarea").keyup (e) =>
193
219
  @abort() if e.keyCode == ESC_KEY
@@ -1,3 +1,3 @@
1
1
  module RestInPlace
2
- VERSION = "2.1.1"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -5,7 +5,7 @@ require "rest_in_place/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rest_in_place"
7
7
  s.version = RestInPlace::VERSION
8
- s.date = '2012-07-25'
8
+ s.date = '2014-03-06'
9
9
  s.authors = ["Jan Varwig"]
10
10
  s.email = ["jan@varwig.org"]
11
11
  s.homepage = "http://jan.varwig.org"
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
5
- prerelease:
4
+ version: 2.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jan Varwig
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-25 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &70117724071400 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70117724071400
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
25
27
  description: REST in Place is an AJAX Inplace-Editor that talks to RESTful controllers.
26
28
  email:
27
29
  - jan@varwig.org
@@ -33,33 +35,32 @@ files:
33
35
  - README.markdown
34
36
  - rest_in_place.gemspec
35
37
  - lib/assets/javascripts/rest_in_place/index.js
36
- - lib/assets/javascripts/rest_in_place/rest_in_place.coffee.erb
38
+ - lib/assets/javascripts/rest_in_place/rest_in_place.js.coffee.erb
37
39
  - lib/rest_in_place/version.rb
38
40
  - lib/rest_in_place.rb
39
41
  homepage: http://jan.varwig.org
40
42
  licenses:
41
43
  - MIT
44
+ metadata: {}
42
45
  post_install_message:
43
46
  rdoc_options: []
44
47
  require_paths:
45
48
  - lib
46
49
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
50
  requirements:
49
51
  - - ! '>='
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
55
  requirements:
55
56
  - - ! '>='
56
57
  - !ruby/object:Gem::Version
57
58
  version: '0'
58
59
  requirements: []
59
60
  rubyforge_project:
60
- rubygems_version: 1.8.11
61
+ rubygems_version: 2.0.3
61
62
  signing_key:
62
- specification_version: 3
63
+ specification_version: 4
63
64
  summary: An AJAX Inplace-Editor for the Rails 3.1 asset pipeline.
64
65
  test_files: []
65
66
  has_rdoc: