ลงทะเบียน
ใกล้กัน ช่วยให้คุณแชร์เรื่องราวต่างๆ กับผู้คนมากมาย

สำหรับนักพัฒนาเว็บไซต์ก็อปไปใช้จะช่วยเพิ่มความเร็วในการ เขียนโค๊ด

 

เปิดลิงค์ใน Tab ใหม่ ใช้ได้กับทุก Browser 

function windowOpen() {
      window.open("https://www.guimee.com""_blank");
}
 

ใช้ Javascript เปลี่ยนเป็น SSL โดยไม่่ต้องต้องค่า Rewriter URL ของ Server


วิธีใช้: เพียงก็อปโค๊ดด้านล่างไปติดในทุกหน้าของเว็บไซต์

function toSSL() {
var strLocation = location.href;

//ให้มี www ทุกลิงคื
if (strLocation.indexOf("localhost") == "-1") {
if (location.protocol != 'https:') {
var strLocation = window.location.href.substring(window.location.protocol.length);

if (!/\.www\.|^www\./gi.test(strLocation)) {
strLocation = strLocation.replace("://", "://www.");
}

location.href = 'https:' + strLocation;
}
else {
if (!/\.www\.|^www\./gi.test(location.hostname)) location.href = location.href.replace("://", "://www.");
}
}
}

 

function noneSSL() {
var strLocation = location.href;

if(strLocation.indexOf("localhost")=="-1") {
if (location.protocol != 'http:')
{
location.href = 'http:' + window.location.href.substring(window.location.protocol.length);
}
}
}

 
ตัวอย่างฟังค์ชั่นที่ใช้บ่อย ก็อปแค่เพียงบางส่วนหรือทั้งหมดจะช่วยให้งานเสร็จเร็วขึ้น

function calSqWah() {
let rai = (parseFloat($("#rai").val()) * 400);
let Ngan = (parseFloat($("#ngan").val()) * 100);
let SqWah = parseFloat($("#sqWah").val());
let area = rai + Ngan + SqWah;
$('.input-totalSqWah').val(Math.round(area));
calLandPice(Math.round(area));
}

 
var Common = Common || {};
Common.allRules = null;
Common.defineProp = function (obj, key, value) {
    var config = {
        value: value,
        writable: true,
        enumerable: true,
        configurable: true
    };
    Object.defineProperty(obj, key, config);
};
Common.resizeImage = function (url, width, height, callback) {
    var sourceImage = new Image();
 
    sourceImage.onload = function () {
        // Create a canvas with the desired dimensions
        var canvas = document.createElement("canvas");
        canvas.width = width;
        canvas.height = height;
 
        // Scale and draw the source image to the canvas
        canvas.getContext("2d").drawImage(sourceImage, 0, 0, width, height);
 
        // Convert the canvas to a data URL in PNG format
        callback(canvas.toDataURL());
    }
 
    sourceImage.src = url;
};
 
// page : array path chain
// ["home", "index"] => "home/index"
Common.windowRedirection = function (page) {
    var pagePath = "";
 
    if (page != undefined) {
        pagePath = page.join("/");
    }
    window.location = "//" + window.location.host + "/" + pagePath.toLowerCase();
};
 
Common.windowRefresh = function () {
    location.reload(true);
};
 
Common.windowHistoryBack = function () {
    history.go(-1);
};
 
Common.initImageCallback = function () {
    $(".img-error-checker")
        .error(function () {
            console.log("[Not Found] : " + $(this).attr("src"));
            $(this).attr("src", '../Images/no-image.png');
        });
};
 
/****************************************************** *****/
/******************** Validation Engine ********************/
Common.ajaxValidationCallback = function (status, form, json, options) {
 
    if (status === true) {
        alert("the form is valid!");
        // uncomment these lines to submit the form to form.action
        // form.validationEngine('detach');
        // form.submit();
        // or you may use AJAX again to submit the data
    }
};
 
Common.initValidator = function ($form, callback) {
    var checkAjaxField = callback == undefined ? false : true;
    var validatorOption = {
        showArrowOnRadioAndCheckbox: true,
        scroll: false,
        fadeDuration: 0,
        autoHidePrompt: true,
        promptPosition: "bottomLeft"
    };
 
 
    if (checkAjaxField) {
        validatorOption.ajaxFormValidation = true;
        validatorOption.ajaxFormValidationMethod = 'post';
        validatorOption.onAjaxFormComplete = callback;
 
        $form.validationEngine(validatorOption);
 
        $form.bind("jqv.field.result", function (event, field, errorFound, prompText) {
            var $field = $(field);
 
            if ($field.attr("data-check-ajax-request") != undefined && $field.attr("data-callback-function") != undefined) {
                if ($field.attr("data-check-ajax-request") === "true") {
 
                    // call function that set act like callback function
                    eval($field.attr("data-callback-function") + "('" + $field.attr("id") + "', '" + prompText + "')");
                }
            }
        });
    } else {
        $form.validationEngine(validatorOption);
    }
};
 
Common.showErrors = function ($input, message, validate, type) {
    $input
        .validationEngine('showPrompt', (message !== "" ? message : Common.allRules[validate][type]), 'red', "topLeft", true);
};
 
Common.HideErrors = function ($input) {
    $input.validationEngine('hide');
};
 
Common.hideAllErrors = function ($form) {
    $form.validationEngine('hideAll');
};
 
Common.isValidForm = function ($form) {
    // $form.validationEngine('hideAll');
    return $form.validationEngine('validate');
};
 
Common.onFormChange = function ($form) {
    var $button = $form.find('button[type="submit"]');
    if ($button.length > 0) {
        $button.attr('disabled', !Common.isValidForm($form));
    }
};
/******************* END Validation Engine *****************/
/****************************************************** *****/
 
 
/****************************************************** *****/
/********************** Scroll Effect **********************/
Common.scrollToTop = function () {
    $('html, body')
    .animate({
        scrollTop: $(document.body).offset().top
    }, 'slow');
};
 
Common.scrollToForm = function () {
    $('html, body')
    .animate({
        scrollTop: $(".panel-separator:visible:last").offset().top
    }, 'slow');
};
/******************** END Scroll Effect ********************/
/****************************************************** *****/
Common.getRandomIntInclusive = function (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
Common.isSupportDownloadAttribute = function () {
    // When used on an anchor, this attribute signifies that the browser should download the resource
    // the anchor points to rather than navigate to it.
    var a = document.createElement('a');
    return (typeof a.download != "undefined");
};
 
Common.getObjectFromForm = function ($form) {
    var obj = {};
    $.each(JSON.parse(JSON.stringify($form.serializeArray())), function (idx, val) {
        obj[val.name] = val.value;
    });
 
    return obj;
};
 
Common.defaultBlankData = function (text) {
    return (text === undefined || text === null || text === "") ? "-" : text;
};
 
Common.defaultEmptyString = function (text) {
    return (text === undefined || text === null || text === "") ? "" : text;
};
 
Common.getEpochTime = function () {
    return (new Date).getTime();
};
 
Common.frontendDatetimeFormat = function (datetime) {
    return moment(datetime).isValid() ? moment(datetime).format("DD/MM/YYYY HH:mm") : "-";
};
 
Common.backendDatetimeFormat = function (datetime) {
    return moment(datetime).isValid() ? moment(datetime).format("YYYY-MM-DD") : null;
};
 
// ใส่เครื่องหมายคอมม่าให้ตัวเลข แสดงผลลัพท์จะดูเข้าใจง่าย
Common.commaSeparateNumber = function(val) {
    while (/(\d+)(\d{3})/.test(val.toString())) {
        val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
    }
    return val;
}
Common.convertStringToJSDateFormat = function (stringDate) {
    var day = stringDate.substring(0, 2);
    var month = stringDate.substring(3, 5);
    var year = stringDate.substring(6, 10);
    var date = new Date(year, month, day);
    return date;
};
Common.JSONDate = function (dateStr) {
    var m, day;
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    m = d.getMonth() + 1;
    if (m < 10)
        m = '0' + m
    if (d.getDate() < 10)
        day = '0' + d.getDate()
    else
        day = d.getDate();
    return (day + '/' + m + '/' + parseInt(d.getFullYear()))
};
Common.JSONDay = function (dateStr) {
    var m, day;
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    day = d.getDate();
    return day
};
Common.JSONYear = function (dateStr) {
    var m, day;
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    return parseInt(d.getFullYear())
};
Common.JSONShortMonth = function (dateStr) {
    var m, day, monthtext = '';
    var month = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    m = d.getMonth() + 1;
    // if (m < 10)
    monthtext = month[m];  
    return monthtext
};
Common.JSONDateThai = function (dateStr) {
    //console.log(dateStr);
    var m, day,monthtext='';
    var month = ["","มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม"," มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิ กายน","ธันวาคม"]
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    m = d.getMonth()+1;
   // if (m < 10)
    monthtext = month[m];
    if (d.getDate() < 10)
        day = d.getDate()
    else
        day = d.getDate();
    return (day + ' ' + monthtext + ' ' +  parseInt(d.getFullYear() + 543))
};
Common.JSONDateEng = function (dateStr) {
    //console.log(dateStr);
    var m, day, monthtext = '';
    var month = ["", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    m = d.getMonth() + 1;
    // if (m < 10)
    monthtext = month[m];
    if (d.getDate() < 10)
        day = '0' + d.getDate()
    else
        day = d.getDate();
    return (day + ' ' + monthtext + ' ' + parseInt(d.getFullYear()))
};
Common.JSONDateWithTime = function (dateStr) {
    jsonDate = dateStr;
    var d = new Date(parseInt(jsonDate.substr(6)));
    var m, day;
    m = d.getMonth() + 1;
    if (m < 10)
        m = '0' + m
    if (d.getDate() < 10)
        day = '0' + d.getDate()
    else
        day = d.getDate();
    var formattedDate = day + "/" + m + "/" + d.getFullYear();
    var hours = (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
    var minutes = (d.getMinutes() < 10) ? "0" + d.getMinutes() : d.getMinutes();
    var formattedTime = hours + ":" + minutes;
    formattedDate = formattedDate + " " + formattedTime;
    return formattedDate;
};
 
// Convert a data URI to blob
Common.dataURItoBlob = function (dataURI, fileType) {
    var byteString = atob(dataURI.split(',')[1]);
    var ab = new ArrayBuffer(byteString.length);
    var ia = new Uint8Array(ab);
    for (var i = 0; i < byteString.length; i++) {
        ia = byteString.charCodeAt(i);
    }
    return new Blob([ab], {
        type: (fileType != undefined ? fileType : 'image/png')
    });
};
 
Common.init = function () {
    Common.allRules = $.validationEngineLanguage.allRules;
};
 
Common.getParameterByName = function (name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
     results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
};
Common.LandArea = {};
Common.ConversionSqrMateToRaiNganWah = function (sqrMate)
{
    var rai = 0, ngan = 0, sqrWah = 0;
    if (sqrMate > 0) {
        rai = Math.floor(sqrMate / 1600);
        ngan = Math.floor(((sqrMate / 1600) - rai) * 4);
        sqrWah = (sqrMate / 4) - ((rai * 400) + (ngan * 100));
        sqrWah = Math.round(sqrWah * 100) / 100;
    }
    return Common.LandArea = { rai: rai, ngan: ngan, wah: sqrWah };      
 };
 
Common.GetFriendlyTitle = function (title) {
    var encodedUrl = title.toString().toLowerCase();
    encodedUrl = encodedUrl.split(/\&+/).join("-and-");
    encodedUrl = encodedUrl.split(/[^a-z0-9ก-๙]/).join("-");
    encodedUrl = encodedUrl.split(/-+/).join("-");
    encodedUrl = encodedUrl.trim('-');
    return encodedUrl;
};

 

Javascript Framwork สำเร็จรูปพร้อมใช้ติดตามกับ Browser

https://www.javascripture.com/FileReader

Captcha Challenge
ลองรูปภาพใหม่
Type in the verification code above