add option escape
, fixes #377
This commit is contained in:
parent
fff300e2bd
commit
1329e0ccf9
CHANGELOG.txt
src/inputs
test/unit
@ -3,6 +3,7 @@ X-editable changelog
|
|||||||
|
|
||||||
Version 1.5.0 wip
|
Version 1.5.0 wip
|
||||||
----------------------------
|
----------------------------
|
||||||
|
[enh #377] add bool option `escape` to allow html as content (vitalets)
|
||||||
[bug #344] fix determing empty for html content (vitalets)
|
[bug #344] fix determing empty for html content (vitalets)
|
||||||
[enh] update select2 to 3.4.3 (vitalets)
|
[enh] update select2 to 3.4.3 (vitalets)
|
||||||
[enh #343] Bootstrap 3 support (vitalets)
|
[enh #343] Bootstrap 3 support (vitalets)
|
||||||
|
@ -52,7 +52,7 @@ To create your own input you can inherit from this class.
|
|||||||
@param {DOMElement} element
|
@param {DOMElement} element
|
||||||
**/
|
**/
|
||||||
value2html: function(value, element) {
|
value2html: function(value, element) {
|
||||||
$(element).text($.trim(value));
|
$(element)[this.options.escape ? 'text' : 'html']($.trim(value));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,6 +194,19 @@ To create your own input you can inherit from this class.
|
|||||||
@default null
|
@default null
|
||||||
**/
|
**/
|
||||||
inputclass: null,
|
inputclass: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
If `true` - html will be escaped in content of element via $.text() method.
|
||||||
|
If `false` - html will not be escaped, $.html() used.
|
||||||
|
When you use own `display` function, this option has no influence.
|
||||||
|
|
||||||
|
@property escape
|
||||||
|
@type boolean
|
||||||
|
@since 1.5.0
|
||||||
|
@default true
|
||||||
|
**/
|
||||||
|
escape: true,
|
||||||
|
|
||||||
//scope for external methods (e.g. source defined as function)
|
//scope for external methods (e.g. source defined as function)
|
||||||
//for internal use only
|
//for internal use only
|
||||||
scope: null,
|
scope: null,
|
||||||
|
@ -100,10 +100,14 @@ $(function(){
|
|||||||
//collect text of checked boxes
|
//collect text of checked boxes
|
||||||
value2htmlFinal: function(value, element) {
|
value2htmlFinal: function(value, element) {
|
||||||
var html = [],
|
var html = [],
|
||||||
checked = $.fn.editableutils.itemsByValue(value, this.sourceData);
|
checked = $.fn.editableutils.itemsByValue(value, this.sourceData),
|
||||||
|
escape = this.options.escape;
|
||||||
|
|
||||||
if(checked.length) {
|
if(checked.length) {
|
||||||
$.each(checked, function(i, v) { html.push($.fn.editableutils.escape(v.text)); });
|
$.each(checked, function(i, v) {
|
||||||
|
var text = escape ? $.fn.editableutils.escape(v.text) : v.text;
|
||||||
|
html.push(text);
|
||||||
|
});
|
||||||
$(element).html(html.join('<br>'));
|
$(element).html(html.join('<br>'));
|
||||||
} else {
|
} else {
|
||||||
$(element).empty();
|
$(element).empty();
|
||||||
|
@ -88,7 +88,8 @@ $(function(){
|
|||||||
|
|
||||||
value2html: function(value, element) {
|
value2html: function(value, element) {
|
||||||
var text = value ? value.format(this.options.viewformat) : '';
|
var text = value ? value.format(this.options.viewformat) : '';
|
||||||
$(element).text(text);
|
//$(element).text(text);
|
||||||
|
Constructor.superclass.value2html.call(this, text, element);
|
||||||
},
|
},
|
||||||
|
|
||||||
html2value: function(html) {
|
html2value: function(html) {
|
||||||
|
@ -85,7 +85,7 @@ $(function(){
|
|||||||
|
|
||||||
value2html: function(value, element) {
|
value2html: function(value, element) {
|
||||||
var text = value ? this.dpg.formatDate(value, this.parsedViewFormat, this.options.datepicker.language) : '';
|
var text = value ? this.dpg.formatDate(value, this.parsedViewFormat, this.options.datepicker.language) : '';
|
||||||
Date.superclass.value2html(text, element);
|
Date.superclass.value2html.call(this, text, element);
|
||||||
},
|
},
|
||||||
|
|
||||||
html2value: function(html) {
|
html2value: function(html) {
|
||||||
|
@ -96,7 +96,7 @@ $(function(){
|
|||||||
//formatDate works with UTCDate!
|
//formatDate works with UTCDate!
|
||||||
var text = value ? this.dpg.formatDate(this.toUTC(value), this.parsedViewFormat, this.options.datetimepicker.language, this.options.formatType) : '';
|
var text = value ? this.dpg.formatDate(this.toUTC(value), this.parsedViewFormat, this.options.datetimepicker.language, this.options.formatType) : '';
|
||||||
if(element) {
|
if(element) {
|
||||||
DateTime.superclass.value2html(text, element);
|
DateTime.superclass.value2html.call(this, text, element);
|
||||||
} else {
|
} else {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ $(function(){
|
|||||||
|
|
||||||
value2html: function(value, element) {
|
value2html: function(value, element) {
|
||||||
var text = $.datepicker.formatDate(this.options.viewformat, value);
|
var text = $.datepicker.formatDate(this.options.viewformat, value);
|
||||||
DateUI.superclass.value2html(text, element);
|
DateUI.superclass.value2html.call(this, text, element);
|
||||||
},
|
},
|
||||||
|
|
||||||
html2value: function(html) {
|
html2value: function(html) {
|
||||||
|
@ -72,7 +72,8 @@ $(function(){
|
|||||||
text = items[0].text;
|
text = items[0].text;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(element).text(text);
|
//$(element).text(text);
|
||||||
|
$.fn.editabletypes.abstractinput.prototype.value2html.call(this, text, element);
|
||||||
},
|
},
|
||||||
|
|
||||||
autosubmit: function() {
|
autosubmit: function() {
|
||||||
|
6
src/inputs/select2/select2.js
vendored
6
src/inputs/select2/select2.js
vendored
@ -174,7 +174,8 @@ $(function(){
|
|||||||
} else if(this.sourceData) {
|
} else if(this.sourceData) {
|
||||||
data = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
|
data = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
|
||||||
} else {
|
} else {
|
||||||
//can not get list of possible values (e.g. autotext for select2 with ajax source)
|
//can not get list of possible values
|
||||||
|
//(e.g. autotext for select2 with ajax source)
|
||||||
}
|
}
|
||||||
|
|
||||||
//data may be array (when multiple values allowed)
|
//data may be array (when multiple values allowed)
|
||||||
@ -190,7 +191,8 @@ $(function(){
|
|||||||
|
|
||||||
text = $.isArray(text) ? text.join(this.options.viewseparator) : text;
|
text = $.isArray(text) ? text.join(this.options.viewseparator) : text;
|
||||||
|
|
||||||
$(element).text(text);
|
//$(element).text(text);
|
||||||
|
Constructor.superclass.value2html.call(this, text, element);
|
||||||
},
|
},
|
||||||
|
|
||||||
html2value: function(html) {
|
html2value: function(html) {
|
||||||
|
@ -71,10 +71,9 @@ $(function(){
|
|||||||
value2htmlFinal: function(value, element) {
|
value2htmlFinal: function(value, element) {
|
||||||
if(this.getIsObjects()) {
|
if(this.getIsObjects()) {
|
||||||
var items = $.fn.editableutils.itemsByValue(value, this.sourceData);
|
var items = $.fn.editableutils.itemsByValue(value, this.sourceData);
|
||||||
$(element).text(items.length ? items[0].text : '');
|
value = items.length ? items[0].text : '';
|
||||||
} else {
|
}
|
||||||
$(element).text(value);
|
$.fn.editabletypes.abstractinput.prototype.value2html.call(this, value, element);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
html2value: function (html) {
|
html2value: function (html) {
|
||||||
|
@ -437,12 +437,10 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("'display' returning html only (img)", function () {
|
test("'display' returning html only (img)", function () {
|
||||||
var c = 0,
|
var html = '<img src="../src/img/clear.png">',
|
||||||
html = '<img src="../src/img/clear.png">',
|
|
||||||
html_br = '<br>',
|
|
||||||
e = $('<a href="#" data-pk="1" data-type="text" data-name="text1">0</a>').appendTo('#qunit-fixture').editable({
|
e = $('<a href="#" data-pk="1" data-type="text" data-name="text1">0</a>').appendTo('#qunit-fixture').editable({
|
||||||
display: function(value, response) {
|
display: function(value, response) {
|
||||||
$(this).html(c == 0 ? html : html_br);
|
$(this).html(html);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -454,7 +452,7 @@ $(function () {
|
|||||||
p.find('input').val(1);
|
p.find('input').val(1);
|
||||||
p.find('form').submit();
|
p.find('form').submit();
|
||||||
|
|
||||||
equal(e.html(), $.fn.editable.defaults.emptytext, 'html br --> emptytext ok');
|
equal(e.html(), html, 'html again ok');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("password", function () {
|
test("password", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user