OOUI/PHP examples/ja

OOUI を…


 * MediaWiki 拡張機能内で使用する場合は、 を参照してください.
 * スタンドアロンの PHP プロジェクトで使用する場合は、 を実行してください.

A more extensive set of most PHP widget examples is available in the source code repository. When you clone the repository and/or install it using composer, take a look at.



ライブラリのセットアップ
Before you display any OOUI widgets, you need to set up the library by calling the following functions:

You also need to load the CSS:



ボタンの作成
To create a button, use the  class. The first and only argument to a button's constructor is its configuration.

Before the button is converted to HTML and emitted, the label, target and href can be changed using the  and   methods.

The button is now created, and has a label which reads "Still click me!", but is not yet visible to the user, as it must first converted to HTML and echoed into the document:



JavaScript の挙動の追加
Setting the  property will ensure that clicking the button loads a new PHP page. But if you want to use the technique of progressive enhancement to add client-side JavaScript behaviors to the button, you can "infuse" the object on the client side with the JavaScript OO.ui.infuse method. You must set set the  property when the widget is configured:

Then you'd load some client-side JavaScript to enhance this widget:



リスクを避ける方法
For extra type safety, you can use the  method of the specific type of widget you expect. That is:

This will throw an exception at runtime if PHP and JavaScript disagree about the widget type of. (As of 2015-05, this is not implemented yet, but will be in the future.)