best_in_place 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
data/lib/best_in_place.rb
CHANGED
@@ -21,15 +21,16 @@ module BestInPlace
|
|
21
21
|
collection = opts[:collection].to_json
|
22
22
|
end
|
23
23
|
out = "<span class='best_in_place'"
|
24
|
-
out
|
25
|
-
out
|
26
|
-
out
|
27
|
-
out
|
28
|
-
out
|
29
|
-
out
|
30
|
-
out
|
31
|
-
out
|
32
|
-
out
|
24
|
+
out << " id='best_in_place_#{object.class.to_s.gsub("::", "_").underscore}_#{field}'"
|
25
|
+
out << " data-url='#{opts[:path].blank? ? url_for(object).to_s : url_for(opts[:path])}'"
|
26
|
+
out << " data-object='#{object.class.to_s.gsub("::", "_").underscore}'"
|
27
|
+
out << " data-collection='#{collection}'" unless collection.blank?
|
28
|
+
out << " data-attribute='#{field}'"
|
29
|
+
out << " data-activator='#{opts[:activator]}'" unless opts[:activator].blank?
|
30
|
+
out << " data-sanitize='#{!!opts[:sanitize]}'" unless opts[:sanitize].nil?
|
31
|
+
out << " data-type='#{opts[:type].to_s}'>"
|
32
|
+
out << value.to_s
|
33
|
+
out << "</span>"
|
33
34
|
raw(out)
|
34
35
|
end
|
35
36
|
end
|
@@ -38,7 +38,6 @@
|
|
38
38
|
<td>Country</td>
|
39
39
|
<td>
|
40
40
|
<%= best_in_place @user, :country, {:type => :select, :collection => @countries} %>
|
41
|
-
<!-- <%= @countries.inspect %> -->
|
42
41
|
</td>
|
43
42
|
</tr>
|
44
43
|
<tr>
|
@@ -50,7 +49,7 @@
|
|
50
49
|
<tr>
|
51
50
|
<td>User description</td>
|
52
51
|
<td>
|
53
|
-
<%= best_in_place @user, :description, :type => :textarea %>
|
52
|
+
<%= best_in_place @user, :description, :type => :textarea, :sanitize => false %>
|
54
53
|
</td>
|
55
54
|
</table>
|
56
55
|
<br />
|
@@ -43,6 +43,12 @@ BestInPlaceEditor.prototype = {
|
|
43
43
|
|
44
44
|
update : function() {
|
45
45
|
var editor = this
|
46
|
+
if (this.formType in {"input":1, "textarea":1} && this.getValue() == this.oldValue)
|
47
|
+
{ // Avoid request if no change is made
|
48
|
+
editor.element.html(this.getValue())
|
49
|
+
$(this.activator).bind('click', {editor: this}, this.clickHandler)
|
50
|
+
return true
|
51
|
+
}
|
46
52
|
editor.ajax({
|
47
53
|
"type" : "post",
|
48
54
|
"dataType" : "text",
|
@@ -74,6 +80,7 @@ BestInPlaceEditor.prototype = {
|
|
74
80
|
self.objectName = self.objectName || jQuery(this).attr("data-object")
|
75
81
|
self.attributeName = self.attributeName || jQuery(this).attr("data-attribute")
|
76
82
|
})
|
83
|
+
|
77
84
|
// Try Rails-id based if parents did not explicitly supply something
|
78
85
|
self.element.parents().each(function(){
|
79
86
|
var res
|
@@ -83,12 +90,16 @@ BestInPlaceEditor.prototype = {
|
|
83
90
|
})
|
84
91
|
|
85
92
|
// Load own attributes (overrides all others)
|
86
|
-
self.url = self.element.attr("data-url")
|
87
|
-
self.collection = self.element.attr("data-collection")
|
88
|
-
self.formType = self.element.attr("data-type")
|
89
|
-
self.objectName = self.element.attr("data-object")
|
90
|
-
self.attributeName = self.element.attr("data-attribute")
|
91
|
-
self.activator = self.element.attr("data-activator")
|
93
|
+
self.url = self.element.attr("data-url") || self.url || document.location.pathname
|
94
|
+
self.collection = self.element.attr("data-collection") || self.collection
|
95
|
+
self.formType = self.element.attr("data-type") || self.formtype || "input"
|
96
|
+
self.objectName = self.element.attr("data-object") || self.objectName
|
97
|
+
self.attributeName = self.element.attr("data-attribute") || self.attributeName
|
98
|
+
self.activator = self.element.attr("data-activator") || self.element
|
99
|
+
|
100
|
+
if (!self.element.attr("data-sanitize")) self.sanitize = true
|
101
|
+
else self.sanitize = (self.element.attr("data-sanitize") == "true")
|
102
|
+
|
92
103
|
|
93
104
|
if ((self.formType == "select" || self.formType == "checkbox") && self.collection != null)
|
94
105
|
{
|
@@ -106,10 +117,14 @@ BestInPlaceEditor.prototype = {
|
|
106
117
|
},
|
107
118
|
|
108
119
|
// Trim and Strips HTML from text
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
120
|
+
sanitizeValue : function(s) {
|
121
|
+
if (this.sanitize)
|
122
|
+
{
|
123
|
+
var tmp = document.createElement("DIV")
|
124
|
+
tmp.innerHTML = s
|
125
|
+
s = tmp.textContent || tmp.innerText
|
126
|
+
}
|
127
|
+
return jQuery.trim(s)
|
113
128
|
},
|
114
129
|
|
115
130
|
/* Generate the data sent in the POST request */
|
@@ -162,7 +177,7 @@ BestInPlaceEditor.prototype = {
|
|
162
177
|
BestInPlaceEditor.forms = {
|
163
178
|
"input" : {
|
164
179
|
activateForm : function() {
|
165
|
-
var form = '<form class="form_in_place" action="javascript:void(0)" style="display:inline;"><input type="text" value="' + this.
|
180
|
+
var form = '<form class="form_in_place" action="javascript:void(0)" style="display:inline;"><input type="text" value="' + this.sanitizeValue(this.oldValue) + '"></form>'
|
166
181
|
this.element.html(form)
|
167
182
|
this.element.find('input')[0].select()
|
168
183
|
this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.input.submitHandler)
|
@@ -171,7 +186,7 @@ BestInPlaceEditor.forms = {
|
|
171
186
|
},
|
172
187
|
|
173
188
|
getValue : function() {
|
174
|
-
return this.
|
189
|
+
return this.sanitizeValue(this.element.find("input").val())
|
175
190
|
},
|
176
191
|
|
177
192
|
inputBlurHandler : function(event) {
|
@@ -202,7 +217,7 @@ BestInPlaceEditor.forms = {
|
|
202
217
|
},
|
203
218
|
|
204
219
|
getValue : function() {
|
205
|
-
return this.
|
220
|
+
return this.sanitizeValue(this.element.find("select").val())
|
206
221
|
},
|
207
222
|
|
208
223
|
blurHandler : function(event) {
|
@@ -225,14 +240,14 @@ BestInPlaceEditor.forms = {
|
|
225
240
|
|
226
241
|
"textarea" : {
|
227
242
|
activateForm : function() {
|
228
|
-
this.element.html('<form action="javascript:void(0)" style="display:inline;"><textarea>' + this.
|
243
|
+
this.element.html('<form action="javascript:void(0)" style="display:inline;"><textarea>' + this.sanitizeValue(this.oldValue) + '</textarea></form>')
|
229
244
|
this.element.find('textarea')[0].select()
|
230
245
|
this.element.find("textarea").bind('blur', {editor: this}, BestInPlaceEditor.forms.textarea.blurHandler)
|
231
246
|
this.element.find("textarea").bind('keyup', {editor: this}, BestInPlaceEditor.forms.textarea.keyupHandler)
|
232
247
|
},
|
233
248
|
|
234
249
|
getValue : function() {
|
235
|
-
return this.
|
250
|
+
return this.sanitizeValue(this.element.find("textarea").val())
|
236
251
|
},
|
237
252
|
|
238
253
|
blurHandler : function(event) {
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: best_in_place
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernat Farrero
|