Moodle Amd Javascriptのロゴ

Moodle Amd Javascript

コミュニティ
SaadRahman01
moodle-amd-javascript

Use when writing JavaScript for Moodle — AMD modules, ES6 source, grunt build, RequireJS loading, core/ajax + core/str + core/templates + core/modal + core/notification, Mustache template hydration, and AMD unit tests.

概要

公開者SaadRahman01
リポジトリclaude-moodle-dev
スキル名moodle-amd-javascript
スター
42
フォーク
7
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    SaadRahman01がGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルMoodle Amd JavascriptをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/SaadRahman01/claude-moodle-dev/tree/main/skills/moodle-amd-javascript
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/SaadRahman01/claude-moodle-dev.git /tmp/claude-moodle-dev
mkdir -p .claude/skills
cp -r /tmp/claude-moodle-dev/skills/moodle-amd-javascript .claude/skills/moodle-amd-javascript
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでMoodle Amd Javascriptを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にMoodle Amd Javascriptを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Moodle Amd Javascriptは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Moodle AMD JavaScript

Overview

Moodle uses AMD (RequireJS) for browser JS. Source goes in <plugin>/amd/src/*.js (ES6+), built into minified AMD in amd/build/*.min.js via grunt. Never edit amd/build/ directly. Modules import Moodle core helpers via string IDs (core/ajax, core/str, core/templates).

When to Use

  • Adding interactive JS to a plugin
  • Calling a web service from the browser (core/ajax)
  • Rendering a Mustache template client-side
  • Showing a modal, notification, or toast
  • Building a custom AMD module + grunt config
  • Debugging "module not found" / "build out of date" warnings

Skip when: writing pure backend PHP — use moodle-plugin-development.

File layout

<plugin>/
  amd/
    src/
      foo.js              # ES6 source — edit this
      bar.js
    build/                # generated; commit but never hand-edit
      foo.min.js
      foo.min.js.map

Module ID at runtime = <component>/<filename> (no extension):

  • local/example/amd/src/marker.js → local_example/marker
  • mod/quiz/amd/src/preflight.js → mod_quiz/preflight

Module skeleton

javascript
// amd/src/marker.js
import Ajax from 'core/ajax';
import Notification from 'core/notification';
import {get_string as getString} from 'core/str';
import Templates from 'core/templates';

const SELECTORS = {
    BUTTON: '[data-action="mark-present"]',
    ROW: '[data-region="attendance-row"]',
};

/**
 * Initialise: bind click handlers.
 *
 * @param {number} sessionid
 */
export const init = (sessionid) => {
    document.addEventListener('click', async (e) => {
        const btn = e.target.closest(SELECTORS.BUTTON);
        if (!btn) {
            return;
        }
        e.preventDefault();
        const userid = parseInt(btn.dataset.userid, 10);
        try {
            const result = await markPresent(sessionid, userid);
            const html = await Templates.render('local_example/row', result);
            const row = btn.closest(SELECTORS.ROW);
            Templates.replaceNode(row, html, '');
        } catch (err) {
            Notification.exception(err);
        }
    });
};

const markPresent = (sessionid, userid) => {
    const request = Ajax.call([{
        methodname: 'local_example_mark_present',
        args: {sessionid, userid},
    }]);
    return request[0];
};

Loading from PHP

php
$PAGE->requires->js_call_amd('local_example/marker', 'init', [$sessionid]);

The third argument array is JSON-encoded and passed to your init function.

grunt build

Moodle ships a root Gruntfile.js. From Moodle root:

bash
nvm use                # uses .nvmrc — match Moodle's required Node
npm ci
npx grunt amd          # build all AMD
npx grunt amd --root=local/example   # only your plugin
npx grunt watch        # rebuild on change

Build also runs ESLint + minification. amd/build/*.min.js and *.min.js.map are commit-required (Moodle plugin policy).

Common core modules

ModuleUse
core/ajaxCall web services
core/strLoad lang strings (getString('foo', 'local_example'))
core/templatesRender Mustache (render, renderForPromise, replaceNode, appendNodeContents)
core/notificationToasts, alerts, exception handling (Notification.exception(err))
core/modal (Moodle 4.3+)Replaces core/modal_factory
core/modal_factory(deprecated 4.3+) — use core/modal
core/toastBootstrap-style ephemeral toasts (add(msg, {type}))
core/pendingMark async work pending — required for Behat to wait
core/eventCustom DOM events for cross-module pub/sub
core/logConsole logging (silenced in production)
core/fragmentServer-rendered HTML fragments via mod_x_output_fragment_*
core/urlBuild Moodle URLs
core/configAccess M.cfg (wwwroot, sesskey) safely

Mustache template + JS pair

php
// PHP
$data = ['items' => $items, 'sesskey' => sesskey()];
echo $OUTPUT->render_from_template('local_example/list', $data);
$PAGE->requires->js_call_amd('local_example/list', 'init');
mustache
{{! templates/list.mustache }}
<ul data-region="item-list">
  {{#items}}
  <li data-id="{{id}}">{{name}}</li>
  {{/items}}
</ul>
javascript
// amd/src/list.js
import {get_strings as getStrings} from 'core/str';

export const init = async () => {
    const [confirmTitle, confirmBody] = await getStrings([
        {key: 'confirm', component: 'core'},
        {key: 'confirmdelete', component: 'local_example'},
    ]);
    // ...
};

Pending — make Behat wait

Whenever JS does async work, mark it pending so Behat's I wait until the page is ready actually waits:

javascript
import Pending from 'core/pending';

const pending = new Pending('local_example/marker:save');
try {
    await markPresent(...);
} finally {
    pending.resolve();
}

Without Pending, Behat scenarios are flaky.

Modal (Moodle 4.3+)

javascript
import Modal from 'core/modal';
import ModalEvents from 'core/modal_events';

const modal = await Modal.create({
    title: 'Confirm',
    body: Templates.render('local_example/confirm', data),
    show: true,
    removeOnClose: true,
});
modal.getRoot().on(ModalEvents.save, () => { /* handler */ });

ESLint / coding style

Moodle ships .eslintrc in root. Run:

bash
npx grunt eslint --root=local/example

Rules:

  • ES2018+ source, transpile via grunt
  • Prefer const/let, never var
  • Arrow functions for callbacks
  • JSDoc on every exported function (@param, @return)
  • 4-space indent
  • Single quotes for strings
  • Semicolons mandatory
  • No console.log (use core/log)

Common Mistakes

MistakeFix
Editing amd/build/*.min.jsEdit amd/src/*.js, run npx grunt amd
Forgetting to commit amd/build/Plugin policy — commit both src + build
Wrong module ID (local_example/amd/marker)Use local_example/marker (no amd/)
require(['jquery'], ...) syntaxUse ES6 imports — grunt transpiles to AMD
No Pending around asyncBehat scenarios flake — wrap with core/pending
Hard-coded stringsLoad via core/str so they translate
core/modal_factory in 4.3+Switch to core/modal
Not passing args to js_call_amdArgs become init(arg1, arg2) parameters
Building with wrong Node versionnvm use from Moodle root respects .nvmrc
M.cfg.wwwroot directlyImport core/config for safe access

Calling web services

javascript
import Ajax from 'core/ajax';

const requests = Ajax.call([
    {methodname: 'local_example_get_items', args: {courseid: 5}},
    {methodname: 'local_example_get_users', args: {courseid: 5}},
]);
const [items, users] = await Promise.all(requests);

Methods must be declared 'ajax' => true in db/services.php. The web service token is auto-attached from session (no manual sesskey for AJAX).

Testing AMD

Moodle's AMD has limited unit-test infrastructure. Options:

  • Manual — load page, interact, watch console (Notification.exception surfaces errors)
  • Behat with @javascript — full browser testing
  • Jest (Moodle 4.4+) — npx grunt jest runs tests/jest/*.test.js if present

References

よくある質問

AIスキル「Moodle Amd Javascript」では何ができますか?

Use when writing JavaScript for Moodle — AMD modules, ES6 source, grunt build, RequireJS loading, core/ajax + core/str + core/templates + core/modal + core/notification, Mustache template hydration, and AMD unit tests.

TypingMindでMoodle Amd Javascriptを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Moodle Amd Javascriptはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにMoodle Amd Javascriptをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/SaadRahman01/claude-moodle-dev/tree/main/skills/moodle-amd-javascriptを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Moodle Amd Javascriptを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Moodle Amd Javascriptは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもMoodle Amd Javascriptを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Moodle Amd Javascript」は無料ですか?

はい。SaadRahman01がGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇