loading・・・
curryQ
指定ノードをターゲットにした「チェーンメソッド」を実現
node$('セレクター').fn(カーリー化関数);
1.複合セレクター

文字列セレクタの単複混合代入,vanillasセレクターの単複混合代入、生成ノード -> OK!

  • テス0 ->
  • テス1 ->
  • テス2 ->
  • テス3 ->
  • テス0 -> hoge
  • テス1 -> hoge
  • テス2 -> hoge
  • テス3 ->
  • テス0 -> hoge
  • テス1 -> hoge
  • テス2 -> hoge
  • テス3 ->
ここに生成ノード

/* 引数、カンマ区切りどっちでも可  */
// node$('#top0,#top1,#top2,#top3').fn('addClass','d-inline-block m-2');
node$('#top0','#top1','#top2','#top3').fn('addClass','d-inline-block m-2');

// 以上だけなら、querySelectorAllで十分だけど、要素を動的に生成するケースでは、
生成ノード指定やエレメントセレクターの混合が可能になっていると使いやすい。
//メソッドのチェーンも可能になる。

/* セレクターの混合OK  */
let $nodeclass = document.querySelectorAll('.node0');
let $node = document.getElementById('node00');
node$($node,$nodeclass).fn('addClass','red text-white m-2');

//生成したノード



2.拡張セレクター3種類

.q(クエリ) = :子要素, .closest() = 先祖要素, .sib(対象,セレクター) = 兄弟要素



//ノード -> 先祖ノード
//closest -> 存在しない場合:fnは実行されず、エラーはおきない
node$('セレクター').closest('#node0').fn('addClass','p-3,pink,text-white')
node$('セレクター').q('a').closest('li').fn('addClass','p-2,red,text-white');

//ノード -> 兄弟ノード::存在しない場合:fnは実行されず、エラーはおきない
node$('セレクター').sib('beforeAll','.active').fn('addClass','m-1,p-1,yellow,text-black');
//node$('セレクター').sib('beforeAll/afterAll/all/after/before','セレクター')

3.カーリークエリ用関数
基本形:fun(オプション)(ノードエレメント); //返り値はなんでもOK!
node$(selector).fn(hoge(op)).fn(fuga(op));
//基本形
let hoge = function(op) {
  return function(el) {
    ここに処理
  }
}
//専用の名前空間に登録すると、メソッド名での実行が可能に
//opは可変長引数OK
node$(selector).fn('addClass',op);

//カンマ区切り、スペース区切り、引数わたしに対応
fn$.addClass = function() {
  const $argu = arguments;
  return function(el) {
	 if($argu.length == 1 && typeof $argu[0] === 'string') {
    $argu[0].split(/,|\s/).forEach(function(val) {
       el.classList.add(val);
    })
   }
  if($argu.length > 1) el.classList.add(...$argu);
	return el;
 }
};

デフォルト関数1:挿入関数:
node$('セレクター').insert('append/prepend/before/after',...挿入要素);

挿入要素の引数、配列による複数アイテム挿入に対応

挿入要素は、html文字列、文字列、ノード、ノードリストに対応

ただし、挿入要素がノード、ノードリストの場合は、対象が複数の場合「移動」になるので最後の要素に挿入される

node$('セレクター').insert('append/prepend/before/after',list$(個別配列,共通配列);

[重要]:返り値は、node$('挿入した要素')になるのでチェーンメソッドで、wrapしたり可能
[重要]fn$.insert('append/prepend/before/after',挿入要素)(挿入先エレメント);なら挿入要素は単数
    
    //セレクターが複数で、挿入要素がノードの場合は、当然、最後のセレクターに挿入される(それ以前のセレクターから移動するから)
    //クローンを挿入する手もありそうだけど・・・バグの温床になりそう
    node$('セレクター').insert('append/prepend/before/after',挿入要素);
    
    
    
    デフォルト:wrap関数:node$('セレクター').wrap(html文字列/ノードエレメント/テンプレート,テンプレデータ);
    各要素をそれぞれwrapする
    html文字列を使う
    アイテム アイテム アイテム アイテム アイテム
    
     node$('.indi').wrap('<div class="d-inline-block p-2 my-2 red text-white"></div>');
    
    el$用オブジェクトを使う
    アイテム アイテム アイテム アイテム アイテム
    //失敗
    //単一ノードなのでループで移動してしまう。
    node$('.indi2').wrap(el$({class:'d-inline-block p-2 mx-2 blue text-white'}));
    
    //成功 ノード用オブジェクト
    node$('.indi2').wrap({class:'d-inline-block p-2 mx-2 blue text-white'});
    
    テンプレを使う
    アイテム アイテム アイテム アイテム アイテム
    /* ラップ挿入 テンプレ */
      node$('.indi3').wrap('<div class="d-inline-block p-2 my-2 <%=color%> text-white"><%=raw self%></div>',{color:'yellow'});
    
    デフォルト:wrapAll関数:node$('セレクター').wrapAll(html文字列/ノードエレメント/テンプレート,テンプレデータ);
    指定要素をすべてまとめてwrapする(離れている場合は先頭の位置でまとまってWrapされる)
    アイテム1 アイテム2 アイテム3 アイテム4 アイテム5
    
      node$('.indiall').wrapAll('<div class="d-block p-2 my-2 blue"></div>');
    
    備考
    • ほぼjqueryだけどjqueryじゃない -> zeptojs
    • ->
    • ->
    • ->