Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, June 29, 2017

Convert string to slug(link for website)

function string_to_slug(str) {
    str = str.replace(/^\s+|\s+$/g, ''); // trim 
    str = str.toLowerCase();

    // remove accents, swap ñ for n, etc 
    var from = "ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđßÆa·/_,:;";
    var to   = "AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa------";
    for (var i=0, l=from.length ; i<l ; i++) {
        str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
    }

    str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars         
         .replace(/\s+/g, '-') // collapse whitespace and replace by - 
         .replace(/-+/g, '-'); // collapse dashes
    return str;
}

Wednesday, June 8, 2016

Đổi format datepicker

Trong trường hợp bạn muốn đổi dịnh dạng ngày hay thay đổi option của datepicker trực tiếp bằng js mà ko load lại trang web, bạn hãy thử cách sau
Dùng bootstrap-datepicker:

$('.datepicker').datepicker('remove');
$("#datepicker").datepicker( {
    format: "mm-yyyy",
    viewMode: "months", 
    minViewMode: "months"
}); 
$('.datepicker').datepicker('update'); 
Dùng datepicker jQuery Ui:
$('.datepicker').datepicker('destroy');
$('.datepicker').datepicker("option",{changeYear:true, changeMonth:true,numberOfMonths:[1, 3]});

Sunday, May 22, 2016

tạo nút like share mạng xã hội cho sản phẩm bài viết




Thêm đoạn HTML sau vào trang của bạn:
 
<div class="post-block post-share">
                            <h3 class="heading-primary"><i class="fa fa-share"></i>Share this post</h3>

                            <!-- AddThis Button BEGIN -->
                            <div class="addthis_toolbox addthis_default_style ">
                                <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                                <a class="addthis_button_tweet"></a>
                                <a class="addthis_button_pinterest_pinit"></a>
                                <a class="addthis_counter addthis_pill_style"></a>
                            </div>
                            <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-50faf75173aadc53"></script>
                            <!-- AddThis Button END -->

                        </div>


 =======================kết quả=============================


Saturday, May 9, 2015

JavaScript Scope


Local JavaScript Variables

// code here can not use carName
function myFunction() {
    var carName = "Volvo";

    // code here can use carName
}

-----------------------

Global JavaScript Variables

var carName = " Volvo";

// code here can use carName
function myFunction() {

    // code here can use carName 
}
----------------------------

Automatically Global

// code here can use carName
function myFunction() {
    carName = "Volvo";

    // code here can use carName
}