Skip to content

Commit

Permalink
Cập nhật nút tạo slug phim nhanh
Browse files Browse the repository at this point in the history
Donateeeeeeeeeeeee đi ae -_-!
  • Loading branch information
apiiphim authored Aug 8, 2024
1 parent 8f222b4 commit a91fb5c
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions application/admin/view/vod/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@
</div>
</div>

<div class="layui-form-item ">
<div class="layui-form-item">
<label class="layui-form-label">{:lang('name')}:</label>
<div class="layui-input-inline w500">
<input type="text" class="layui-input" value="{$info.vod_name}" placeholder="" name="vod_name" id="vod_name">
</div>
<label class="layui-form-label">{:lang('sub')}:</label>
<div class="layui-input-inline ">
<div class="layui-input-inline" style="display: flex; align-items: center; width: 500px;">
<input type="text" class="layui-input" value="{$info.vod_sub}" placeholder="" name="vod_sub" id="vod_sub">
<button type="button" class="btn btn-primary" id="generate-vod-sub" style="margin-left: 5px; width: 120px;">Tạo Slug</button>
</div>
</div>


<div class="layui-form-item">
<label class="layui-form-label">{:lang('en')}:</label>
Expand Down Expand Up @@ -1197,8 +1199,48 @@
getExtend('{$info.type_id}')
},1000);
{/if}

$(document).ready(function() {
$('#generate-vod-sub').click(function() {
const name = $('#vod_name').val();
const slug = generateSlug(name);
$('#vod_sub').val(slug);
});

// Function to generate slug
function generateSlug(text) {
text = removeVietnameseTones(text);
text = text.replace(/[^a-zA-Z0-9\-\_]/g, '-');
text = text.replace(/-+/g, '-').replace(/^-+|-+$/g, '');
return text.toLowerCase();
}

function removeVietnameseTones(str) {
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
str = str.replace(/đ/g, "d");
str = str.replace(/À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ/g, "A");
str = str.replace(/È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ/g, "E");
str = str.replace(/Ì|Í|Ị|Ỉ|Ĩ/g, "I");
str = str.replace(/Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ/g, "O");
str = str.replace(/Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ/g, "U");
str = str.replace(/Ỳ|Ý|Ỵ|Ỷ|Ỹ/g, "Y");
str = str.replace(/Đ/g, "D");
str = str.replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, ""); // ̀ ́ ̃ ̉ ̣
str = str.replace(/\u02C6|\u0306|\u031B/g, ""); // ˆ ̆ ̛
str = str.replace(/ + /g, " ");
str = str.trim();
str = str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'|\"|\&|\#|\[|\]|~|\$|_|`|-|{|}|\||\\/g, " ");
return str;
}
});


</script>

</body>
</html>
</html>

0 comments on commit a91fb5c

Please sign in to comment.