官术网_书友最值得收藏!

Including JavaScript in block forms

When adding or editing blocks, it is often desired to include more advanced functionality in the form of client-side JavaScript. concrete5 makes it extremely easy to automatically add a JavaScript file to a block's editor form.

Getting ready

We will be working with the block that was created in the first recipe of this chapter. If you need to catch up, feel free to download the code from this book's website.

How to do it...

The steps for including JavaScript in block forms are as follows:

  1. Open your block's directory.
  2. Create a new file called auto.js.
  3. Add a basic alert function to auto.js:
    alert('Hello!');
  4. Visit a page that contains your block.
  5. Enter edit mode and edit the block.
  6. You should see your alert message appear as shown in the following screenshot:

How it works...

concrete5 automatically looks for the auto.js file when it enters add or edit mode on a block. Developers can use this to their advantage to contain special client-side functionality for the block's edit mode.

See also

  • The Including JavaScript in the block view recipe
  • The Including CSS in the block view recipe
主站蜘蛛池模板: 科尔| 上饶县| 吉木乃县| 万源市| 彭山县| 内黄县| 汪清县| 绥中县| 肃北| 个旧市| 林西县| 邹平县| 上虞市| 温宿县| 仙游县| 景泰县| 镇巴县| 深州市| 泸州市| 桂林市| 岳池县| 清涧县| 怀远县| 和政县| 原阳县| 三台县| 交城县| 营山县| 景宁| 惠州市| 安康市| 达拉特旗| 卢氏县| 墨玉县| 五指山市| 合川市| 芮城县| 仙居县| 阳信县| 聊城市| 当涂县|