When we refer to a resource, we mean any type of file that will be embedded with the widget. This can include images, sounds, PDF documents, JavaScript, CSS, XML files, and more.
In this chapter, we are going to create a CSS file, a JavaScript file, embed a video, and add them as resources to our widget. Let's get started!
Copy the following CSS content:
Paste it into your favorite text editor.
Save the file as "tickle.css" on your computer.
Copy the following JavaScript content:
Paste it into your text editor.
Save the file as "tickle.js."
Download the video "tickle.mp4" that we are going to embed here.
Now that we have all the resources locally on our computer, let's create the widget.
Create a new widget named "Tickle."
Select the Resources tab.
Click on "New resource."
Name it "TickleCss."
A resource has been created, but without any file attached to it. In this case, we need to upload our newly created "tickle.css" file.
Select the "TickleCss" resource if it is not already selected.
Click the "Browse" button in the details panel on the right.
Select the newly created "tickle.css" file on your computer.
Click "OK."
The last three steps may vary slightly depending on the browser you are using.
The file should now be uploaded, and under the "File" column in the resources overview, the cell should display "tickle.css."
Now, repeat the process to create two more resources for "tickle.js" and "tickle.mp4," naming them "TickleJs" and "TickleVideo," respectively.
Almost there!
Copy the HTML code below and paste it as a Script in the Widget Editor:
We introduce a new statement here called scriptreference
, which requires two arguments. The first one should be a unique key (more on that in later chapters), and the second one is the URL of the resource. We also introduce the FileUrl
function to retrieve the file URLs of all the resources.
Important Note: Every CSS and JavaScript file that you include in the widget will be globally interpreted in the browser. This means that if you are not careful, you could create CSS collisions or, even worse, overwrite JavaScript variables, functions, and classes! We will discuss this in more depth in later chapters.
For now, preview this widget, and hover over the video! :)