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

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
主站蜘蛛池模板: 溧水县| 铁岭县| 九台市| 驻马店市| 铜川市| 揭西县| 神池县| 梧州市| 常山县| 民勤县| 栾川县| 博野县| 内乡县| 琼海市| 宜兰县| 香港| 华坪县| 辽源市| 丁青县| 西藏| 永安市| 蕉岭县| 梓潼县| 双流县| 修文县| 乐都县| 贵阳市| 井冈山市| 洪湖市| 兴山县| 阿合奇县| 娄烦县| 台中市| 吉木萨尔县| 微博| 抚州市| 漠河县| 邯郸县| 乐都县| 广东省| 伊春市|