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

  • concrete5 Cookbook
  • David Strack
  • 191字
  • 2021-08-13 16:16:01

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
主站蜘蛛池模板: 延长县| 湖北省| 阆中市| 河源市| 凉山| 昆山市| 饶平县| 永仁县| 衡水市| 闸北区| 逊克县| 淮阳县| 汨罗市| 三台县| 岳池县| 永善县| 习水县| 萨迦县| 莫力| 星座| 贡嘎县| 修武县| 海安县| 若羌县| 遂宁市| 平塘县| 城口县| 黄浦区| 贵州省| 濮阳县| 石林| 闽侯县| 宜君县| 莱阳市| 忻州市| 溆浦县| 嘉峪关市| 衡南县| 共和县| 磴口县| 西吉县|