best_in_place 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -0
- data/lib/best_in_place/version.rb +1 -1
- data/public/javascripts/best_in_place.js +30 -15
- metadata +3 -3
data/README.md
CHANGED
@@ -45,6 +45,7 @@ Options:
|
|
45
45
|
- **:nil**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit".
|
46
46
|
If not defined it will show *"-"*.
|
47
47
|
- **:activator**: Is the DOM object that can activate the field. If not defined the user will making editable by clicking on it.
|
48
|
+
- **:sanitize**: True by default. If set to false the input/textarea will accept html tags.
|
48
49
|
|
49
50
|
|
50
51
|
I created a [test_app](https://github.com/bernat/best_in_place/tree/master/test_app) and a running demo in heroku to test the features.
|
@@ -160,6 +161,7 @@ In order to use the Rails 3 gem, just add the following line to the gemfile:
|
|
160
161
|
- v.0.1.5 **Attention: this release is not backwards compatible**. Changing params from list to option hash, helper's refactoring,
|
161
162
|
fixing bug with objects inside namespaces, adding feature for passing an external activator handler as param. Adding feature
|
162
163
|
of key ESCAPE for destroying changes before they are made permanent (in inputs and textarea).
|
164
|
+
- v.0.1.6-0.1.7 Avoiding request when the input is not modified and allowing the user to not sanitize input data.
|
163
165
|
|
164
166
|
##Authors, License and Stuff
|
165
167
|
|
@@ -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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernat Farrero
|