FEATURE: add lock to URL

This commit is contained in:
Michal Kváček
2016-07-26 14:39:27 +02:00
parent 5fc4393729
commit be4a136476
4 changed files with 74 additions and 10 deletions
+52 -2
View File
@@ -1,6 +1,40 @@
// initialize Foundation
$ (document).foundation ();
/**
* Makes slug from input string
*
* @param text
* @param trimSpaces
*
* @returns {string}
*/
function slugify(text, trimSpaces) {
text = text.toString ().toLowerCase ();
if (trimSpaces)
text = text.trim ();
return text.replace (/ /g, '-')
.replace (/[àáâãäå]/g, "a")
.replace (/[čç]/g, "c")
.replace (/[ěèéêë]/g, "e")
.replace (/[ùúûüů]/g, "u")
.replace (/[ìíîï]/g, "i")
.replace (/[ňńñ]/g, "n")
.replace (/[òóôõö]/g, "o")
.replace (/[ýÿ]/g, "y")
.replace (/œ/g, "oe")
.replace (/ď/g, "d")
.replace (/ř/g, "r")
.replace (/š/g, "s")
.replace (/ž/g, "z")
.replace (/ť/g, "t")
.replace (/æ/g, "ae")
.replace (/[^a-z0-9\-]+/g, '')
.replace (/\-\-+/g, '-');
}
// bind some custom methods
$ (document).ready (function () {
$ ('.confirm').click (function () {
@@ -11,8 +45,24 @@ $ (document).ready (function () {
confirmMessage = 'Really?';
}
var confirmation = confirm (confirmMessage);
return confirm (confirmMessage);
});
return confirmation;
$('#lockUrl').change(function () {
$ ('.slug-source').keyup ();
});
$ ('.slug-target').keyup (function () {
$ (this).val (slugify ($ (this).val (), false));
$('#lockUrl').prop('checked', true);
});
$ ('.slug-source').keyup (function () {
var source = $ (this);
var target = $ ('.slug-target');
var locked = $ ('#lockUrl');
if (!locked.is (':checked'))
target.val (slugify (source.val (), true));
});
});