Skip to content

Instantly share code, notes, and snippets.

View dixonsiu's full-sized avatar

Dixon Siu dixonsiu

View GitHub Profile

For my testing environment

Add

  1. Calorie Smile

    mklink /D Y:\Apache24\htdocs\hn-app-genki__\src Z:\K5\Personium\forked\calorie-smile-app\src

  2. UnitManager

    mklink /D Y:\Apache24\htdocs\unit-manager Z:\K5\Personium\forked\unit-manager\src

@dixonsiu
dixonsiu / change_attr.md
Created August 3, 2017 04:41
i18next tips

Issue

When message/label is translated and written directly to the HTML tag, switching to other language will not re-translate such HTML tag.

Wrong way

  1. Execute the following JavaScript to put English message.

     $('dispMsg').html(i18next.t("msg.error.fileNotFound");
    
  2. Result.

$('dispMsg').html(i18next.t("msg.error.fileNotFound");
@dixonsiu
dixonsiu / sample.js
Created August 4, 2017 05:59
Look up special cookie instead of i18next to avoid conflicting settings in same domain
i18next
.use(i18nextXHRBackend)
.use(i18nextBrowserLanguageDetector)
.init({
detection: {
lookupCookie: "i18nextFujitsu"
},
fallbackLng: 'en',
debug: true,
backend: {
@dixonsiu
dixonsiu / passing_options_to_localize.md
Created August 21, 2017 08:01
Proper way to translate sentence with variable

Modifying element's attribute does not work.

    is.displaySearchResult = function(count) {
        $('#searchResult')
            .attr("data-i18n", "candidateFilter:searchResult")
            .attr("data-i18n-options", '{ "count": ' + count + ' }')
            .localize();
    };

Passing the data-i18n-options as options of localize.

@dixonsiu
dixonsiu / i18next_tips.md
Created August 24, 2017 23:57
Make sure you specify "[html]" when assigning "data-i18n" attribute to avoid escaped characters!!

I have defined the following strings.

var sTerm="2017/08/01";
var eTerm="2017/09/01";

The following will produce escaped "/" as "/".

$("#refSearchTerm").attr("data-i18n","glossary:survey.surveyPeriod").localize({ startDate: sTerm, endDate: eTerm });

2017/08/01 ~ 2017/09/01
@dixonsiu
dixonsiu / check_input.js
Created September 4, 2017 02:10
Using underscore.js methods to make validation logic simplier
function checkInput(id, msgId) {
/*
* someFieldsMissingValue is true if at least one input element's value is empty
*/
var someFieldsMissingValue = _.some(
$("form input"),
function(aDom) {
return _.isEmpty($(aDom).val());
}
);
@dixonsiu
dixonsiu / validate.js
Created September 7, 2017 02:28
Validate a field and raise error according to length, character types, etc.
function validateCheck(displayNameID, formFieldMsgId) {
var displayName = $("#" + displayNameID).val();
var MINLENGTH = 1;
var MAXLENGTH = 128;
var allowedLetters = /^[0-9a-zA-Z-_]+$/;
var lenDisplayName = displayName.length;
$("#" + formFieldMsgId).empty();
if(lenDisplayName < MINLENGTH || displayName == undefined || displayName == null || displayName == "") {
$("#" + formFieldMsgId).html(i18next.t("create_form.validate.warning.less_minimum_length", { value: MINLENGTH}));
@dixonsiu
dixonsiu / qr_api_bookmark.js
Last active September 26, 2017 07:09
Create a new bookmark with the following source codes and you can create a QR code image on the fly
javascript:(function(){var target = window.prompt("Enter a url or string to encode in QR code!","");if(target!=null){var url="https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + target;var win=window.open(url, "_blank")}})()
@dixonsiu
dixonsiu / MomentJS_demo.html
Created February 5, 2018 05:49
How to handle Personium Date Format
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.3/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
input[type="text"] {
margin-right: 10px;