mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Added 'camel' mode for inputpreset as per #325
This commit is contained in:
parent
b5d9916acd
commit
833c752bae
@ -7,7 +7,8 @@
|
||||
* - data-input-preset: specifies a CSS selector for a source input element
|
||||
* - data-input-preset-closest-parent: optional, specifies a CSS selector for a closest common parent
|
||||
* for the source and destination input elements.
|
||||
* - data-input-preset-type: specifies the conversion type. Supported values are: URL, file.
|
||||
* - data-input-preset-type: specifies the conversion type. Supported values are:
|
||||
* url, file, slug, camel.
|
||||
*
|
||||
* Example: <input type="text" id="name" value=""/>
|
||||
* <input type="text"
|
||||
@ -115,6 +116,12 @@
|
||||
AZERBAIJANI_MAP
|
||||
]
|
||||
|
||||
var removeList = [
|
||||
"a", "an", "as", "at", "before", "but", "by", "for", "from", "is",
|
||||
"in", "into", "like", "of", "off", "on", "onto", "per", "since",
|
||||
"than", "the", "this", "that", "to", "up", "via", "with"
|
||||
]
|
||||
|
||||
var InputPreset = function (element, options) {
|
||||
var $el = this.$el = $(element);
|
||||
this.options = options || {};
|
||||
@ -166,6 +173,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
function toCamel(slug, numChars) {
|
||||
|
||||
Downcoder.Initialize()
|
||||
slug = slug.replace(Downcoder.regex, function(m) {
|
||||
return Downcoder.map[m]
|
||||
})
|
||||
|
||||
var regex = new RegExp('\\b(' + removeList.join('|') + ')\\b', 'gi')
|
||||
slug = slug.replace(regex, '')
|
||||
slug = slug.toLowerCase()
|
||||
slug = slug.replace(/(\b|-)\w/g, function(m) {
|
||||
return m.toUpperCase();
|
||||
});
|
||||
slug = slug.replace(/[^-\w\s]/g, '')
|
||||
slug = slug.replace(/^\s+|\s+$/g, '')
|
||||
slug = slug.replace(/[-\s]+/g, '')
|
||||
slug = slug.substr(0, 1).toLowerCase() + slug.substr(1);
|
||||
return slug.substring(0, numChars)
|
||||
}
|
||||
|
||||
function slugify(slug, numChars) {
|
||||
|
||||
Downcoder.Initialize()
|
||||
@ -173,11 +200,6 @@
|
||||
return Downcoder.map[m]
|
||||
})
|
||||
|
||||
var removeList = [
|
||||
"a", "an", "as", "at", "before", "but", "by", "for", "from", "is",
|
||||
"in", "into", "like", "of", "off", "on", "onto", "per", "since",
|
||||
"than", "the", "this", "that", "to", "up", "via", "with"
|
||||
]
|
||||
var regex = new RegExp('\\b(' + removeList.join('|') + ')\\b', 'gi')
|
||||
slug = slug.replace(regex, '')
|
||||
slug = slug.replace(/[^-\w\s]/g, '')
|
||||
@ -215,12 +237,16 @@
|
||||
}
|
||||
|
||||
InputPreset.prototype.formatValue = function() {
|
||||
if (this.options.inputPresetType == 'camel')
|
||||
var value = toCamel(this.$src.val())
|
||||
else {
|
||||
var value = slugify(this.$src.val())
|
||||
}
|
||||
|
||||
if (this.options.inputPresetType == 'url')
|
||||
value = '/' + value
|
||||
|
||||
return value.toLowerCase().replace(/\s/gi, "-")
|
||||
return value.replace(/\s/gi, "-")
|
||||
}
|
||||
|
||||
InputPreset.DEFAULTS = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user