[MovableType]数値切り上げ

<mt:Var name="target" regex_replace="/^\-?\d+\.(\d*)$/","$1" setvar="_one_tenth">
<mt:Var name="target" regex_replace="/^(\d+)\.\d+$/","$1" setvar="_result">
<mt:If name="_one_tenth" ne="$target">
    <mt:If name="_one_tenth" gt="0">
        <mt:SetVar name="_result" op="+" value="1">
    </mt:If>
</mt:If>

[JavaScript]getRGBAByHex

getRGBAByHex(hex,alpha){
    if (hex.slice(0,1) == "#")hex = hex.slice(1) ;
    if (hex.length == 3)hex = hex.slice(0,1) + hex.slice(0,1) + hex.slice(1,2) + hex.slice(1,2) + hex.slice(2,3) + hex.slice(2,3);
    let rgb = [hex.slice(0,2),hex.slice(2,4),hex.slice(4,6)].map(function(str){
        return parseInt(str,16);
    });
    return `rgba(${rgb[0]},${rgb[1]},${rgb[2]},${alpha})`;
}

[JavaScript]canvas.clip

animate() {
    requestAnimationFrame(()=>{
        this.animate();
    });
    const ctx;
    ctx = canvas.getContext('2d');
    ctx.globalCompositeOperation = "source-over";
    ctx.globalAlpha = 1.0;
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.save();
    ctx.beginPath();
    ctx.rect(0,0,canvas.width,100);
    ctx.clip();
    //ここに描画処理
    ctx.restore();
}

[JavaScript]スクロール無効化

window.addEventListener('touchmove', (e)=>{this.cancelScroll(e);}, { passive: false });
window.addEventListener('mousewheel', (e)=>{this.cancelScroll(e);}, { passive: false });

cancelScroll(e) {
    e.preventDefault();
}

[PHP]idiorm #7 raw_execute + AES_ENCRYPT

define('DB_ENCRYPT_KEY','aabbccddeeff');
require_once __DIR__ . '/idiorm.php';
ORM::configure('mysql:host=localhost;dbname=xxxx');
ORM::configure('username', 'yyy');
ORM::configure('password', 'zzz');
ORM::configure('driver_options', [
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
]);

$query = "INSERT INTO {$table_name}(`e_id`,`description`) VALUES(:e_id,AES_ENCRYPT(:description,'xxyyzz'))";
result = ORM::for_table('users')->raw_execute($query,['e_id'=>1,'description'=>'あいうえお']);

$query = "UPDATE {$table_name} SET `description`=AES_ENCRYPT(:description,'xxyyzz') WHERE `e_id` = :e_id";
result = ORM::for_table('users')->raw_execute($query,['e_id'=>1,'description'=>'あいうえお']);

[Liquid]ショートコード

ブログ記事内やページ内で特定の記述をした部分を特定のhtmlへ変換する機能。

https://github.com/culturekings/shopify-shortcodes
のshortcode-render.liquidとshortcode.liquidをassetsフォルダへ配置

 
templates/article.liquid の記事部分を下記へ書き換える

{% include 'shortcode' load:article.content %}

 
記事編集で下記コードを入力する。xxxxの部分は商品ハンドル

[product_in_blog handle="xxxx"]

 
「product_in_blog」という名称のショートコードを作成する時は、「shortcode-product_in_blog.liquid」というファイルを作成する。

 
引数「handle」を設定する場合、「shortcode-product_in_blog.liquid」で値を取得する処理は下記。

{%- capture product_handle -%}{%- include 'shortcode-render' render:'handle' default:'' -%}{%- endcapture -%}

 

[Liquid]バリエーション選択select

<select name="id" class="js_variantsSelect" data-product="{{ product.id }}">
    {%- for variant in product.variants -%}
        <option value="{{ variant.id }}">{{ variant.title | escape }}</option>
    {%- endfor -%}
</select>

[Liquid]メニュー

{%- for link in linklists.sidemenu.links -%}
    {%- if link.links.size <= 0 -%}
        子項目が無いとき
    {%- else -%}
    	子項目があるとき
	    {%- for childlink in link.links -%}
	        
	    {%- endfor -%}
    {%- endif -%}
{%- endfor -%}