mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Pass element's maxlength to slugify and toCamel to respect field definition (#762)
This commit is contained in:
parent
8f2d2c7f53
commit
aa78d658a6
@ -35,12 +35,12 @@
|
||||
'U', 'Ứ': 'U', 'Ừ': 'U', 'Ử': 'U', 'Ữ': 'U', 'Ự': 'U', 'Ý': 'Y', 'Ỳ': 'Y',
|
||||
'Ỷ': 'Y', 'Ỹ': 'Y', 'Ỵ': 'Y', 'á': 'a', 'à': 'a', 'ã': 'a', 'ả': 'a', 'ạ':
|
||||
'a', 'ắ': 'a', 'ằ': 'a', 'ẵ': 'a', 'ẳ': 'a', 'ặ': 'a', 'ấ': 'a', 'ầ': 'a',
|
||||
'ẫ': 'a', 'ẩ': 'a', 'ậ': 'a', 'đ': 'd', 'é': 'e', 'è': 'e', 'ẽ': 'e', 'ẻ':
|
||||
'e', 'ẹ': 'e', 'ế': 'e', 'ề': 'e', 'ễ': 'e', 'ể': 'e', 'ệ': 'e', 'ó': 'o',
|
||||
'ò': 'o', 'ỏ': 'o', 'õ': 'o', 'ọ': 'o', 'ố': 'o', 'ồ': 'o', 'ổ': 'o', 'ỗ':
|
||||
'o', 'ộ': 'o', 'ơ': 'o', 'ớ': 'o', 'ờ': 'o', 'ở': 'o', 'ỡ': 'o', 'ợ': 'o',
|
||||
'í': 'i', 'ì': 'i', 'ỉ': 'i', 'ĩ': 'i', 'ị': 'i', 'ú': 'u', 'ù': 'u', 'ủ':
|
||||
'u', 'ũ': 'u', 'ụ': 'u', 'ư': 'u', 'ứ': 'u', 'ừ': 'u', 'ử': 'u', 'ữ': 'u',
|
||||
'ẫ': 'a', 'ẩ': 'a', 'ậ': 'a', 'đ': 'd', 'é': 'e', 'è': 'e', 'ẽ': 'e', 'ẻ':
|
||||
'e', 'ẹ': 'e', 'ế': 'e', 'ề': 'e', 'ễ': 'e', 'ể': 'e', 'ệ': 'e', 'ó': 'o',
|
||||
'ò': 'o', 'ỏ': 'o', 'õ': 'o', 'ọ': 'o', 'ố': 'o', 'ồ': 'o', 'ổ': 'o', 'ỗ':
|
||||
'o', 'ộ': 'o', 'ơ': 'o', 'ớ': 'o', 'ờ': 'o', 'ở': 'o', 'ỡ': 'o', 'ợ': 'o',
|
||||
'í': 'i', 'ì': 'i', 'ỉ': 'i', 'ĩ': 'i', 'ị': 'i', 'ú': 'u', 'ù': 'u', 'ủ':
|
||||
'u', 'ũ': 'u', 'ụ': 'u', 'ư': 'u', 'ứ': 'u', 'ừ': 'u', 'ử': 'u', 'ữ': 'u',
|
||||
'ự': 'u', 'ý': 'y', 'ỳ': 'y', 'ỷ': 'y', 'ỹ': 'y', 'ỵ': 'y'
|
||||
},
|
||||
LATIN_MAP = {
|
||||
@ -195,7 +195,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var InputPreset = function (element, options) {
|
||||
var $el = this.$el = $(element)
|
||||
@ -222,26 +222,26 @@
|
||||
|
||||
this.$src = $(options.inputPreset, parent)
|
||||
|
||||
this.$src.on('input paste', function(event) {
|
||||
if (self.cancelled)
|
||||
return
|
||||
|
||||
var timeout = event.type === 'paste' ? 100 : 0
|
||||
var updateValue = function(self, el, prefix) {
|
||||
this.$src.on('input paste', function(event) {
|
||||
if (self.cancelled)
|
||||
return
|
||||
|
||||
var timeout = event.type === 'paste' ? 100 : 0
|
||||
var updateValue = function(self, el, prefix) {
|
||||
if (el.data('update') === false) {
|
||||
return
|
||||
}
|
||||
el
|
||||
.val(prefix + self.formatValue())
|
||||
.trigger('oc.inputPreset.afterUpdate')
|
||||
}
|
||||
|
||||
var src = $(this)
|
||||
setTimeout(function() {
|
||||
$el.trigger('oc.inputPreset.beforeUpdate', [src])
|
||||
setTimeout(updateValue, 100, self, $el, prefix)
|
||||
}, timeout)
|
||||
})
|
||||
el
|
||||
.val(prefix + self.formatValue())
|
||||
.trigger('oc.inputPreset.afterUpdate')
|
||||
}
|
||||
|
||||
var src = $(this)
|
||||
setTimeout(function() {
|
||||
$el.trigger('oc.inputPreset.beforeUpdate', [src])
|
||||
setTimeout(updateValue, 100, self, $el, prefix)
|
||||
}, timeout)
|
||||
})
|
||||
|
||||
this.$el.on('change', function() {
|
||||
self.cancelled = true
|
||||
@ -263,10 +263,10 @@
|
||||
}
|
||||
|
||||
if (this.options.inputPresetType == 'camel') {
|
||||
var value = this.toCamel(this.$src.val())
|
||||
var value = this.toCamel(this.$src.val(), this.$el.attr('maxlength'))
|
||||
}
|
||||
else {
|
||||
var value = this.slugify(this.$src.val())
|
||||
var value = this.slugify(this.$src.val(), this.$el.attr('maxlength'))
|
||||
}
|
||||
|
||||
if (this.options.inputPresetType == 'url') {
|
||||
|
2
modules/system/assets/ui/storm-min.js
vendored
2
modules/system/assets/ui/storm-min.js
vendored
@ -2562,7 +2562,7 @@ setTimeout(updateValue,100,self,$el,prefix)},timeout)})
|
||||
this.$el.on('change',function(){self.cancelled=true})}
|
||||
InputPreset.prototype.formatNamespace=function(){var value=this.toCamel(this.$src.val())
|
||||
return value.substr(0,1).toUpperCase()+value.substr(1)}
|
||||
InputPreset.prototype.formatValue=function(){if(this.options.inputPresetType=='exact'){return this.$src.val();}else if(this.options.inputPresetType=='namespace'){return this.formatNamespace()}if(this.options.inputPresetType=='camel'){var value=this.toCamel(this.$src.val())}else{var value=this.slugify(this.$src.val())}if(this.options.inputPresetType=='url'){value='/'+value}return value.replace(/\s/gi,"-")}
|
||||
InputPreset.prototype.formatValue=function(){if(this.options.inputPresetType=='exact'){return this.$src.val();}else if(this.options.inputPresetType=='namespace'){return this.formatNamespace()}if(this.options.inputPresetType=='camel'){var value=this.toCamel(this.$src.val(),this.$el.attr('maxlength'))}else{var value=this.slugify(this.$src.val(),this.$el.attr('maxlength'))}if(this.options.inputPresetType=='url'){value='/'+value}return value.replace(/\s/gi,"-")}
|
||||
InputPreset.prototype.toCamel=function(slug,numChars){Downcoder.Initialize()
|
||||
slug=slug.replace(Downcoder.regex,function(m){return Downcoder.map[m]})
|
||||
slug=this.removeStopWords(slug);slug=slug.toLowerCase()
|
||||
|
Loading…
x
Reference in New Issue
Block a user