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

  • 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
主站蜘蛛池模板: 合江县| 祁门县| 宁海县| 贵阳市| 新宾| 那坡县| 长丰县| 宝鸡市| 西乌珠穆沁旗| 九台市| 都匀市| 古交市| 商河县| 达州市| 综艺| 若尔盖县| 隆子县| 涿鹿县| 台前县| 稷山县| 阜阳市| 睢宁县| 乡宁县| 金华市| 新干县| 绍兴县| 庄河市| 武邑县| 剑川县| 大荔县| 慈利县| 威海市| 大宁县| 临西县| 梨树县| 美姑县| 天津市| 武威市| 井研县| 海城市| 潼关县|