-
Book Overview & Buying
-
Table Of Contents
concrete5 Cookbook
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.
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.
The steps for including JavaScript in block forms are as follows:
Open your block's directory.
Create a new file called auto.js.
Add a basic alert function to auto.js:
alert('Hello!');Visit a page that contains your block.
Enter edit mode and edit the block.
You should see your alert message appear as shown in the following screenshot:

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...
Change the font size
Change margin width
Change background colour