Squarespace comes with tons of cool features and built-in templates right out of the box. In addition, they have built in the ability to inject client-side scripting to enable web developers the ability to completely customize their pages.
In this post, I’m going to show you how to take advantage of client-side scripting to create a cool image carousel component. Below is an example of what we’ll build:
asdfasfdsd sadf sad fasdf af asdf asdfsdfasdfasdfdasfsf sdf as fsdasadf
adfsdfas sa dfsadf saasdfsdfsdadfsadfa sdf saf
Code-Injection Points
For starters, please note that different Squarespace accounts come with different abilities. Advanced, Business, and Community accounts have code-injection point capability, whereas Basic and Pro accounts do not. But don’t worry, you can create this component whether you do or do not have Code-Injection Points as part of your Squarespace Account. If you do have code-injection capability, then you will be entering a portion of the script in the Extra Header Code section. If not, then you’ll be entering everything directly in the page you wish to show this component.
Using jQuery
JQuery is a library of very useful client-side scripts that perform many tasks that are typically more difficult to perform using JavaScript only. jQuery is very extensible and allows developers to create plug-ins that we can use. We will be using a plug-in here to create the image carousel. So let’s get started …
Step 1: Setup Squarespace folder structure
You will need to create directories in your Squarespace account to organize the files. Create the following folders in your Squarespace general storage:
-
File Storage > scripts
-
File Storage > scripts > jcarousel
-
File Storage > scripts > jcarousel > thickbox
-
File Storage > scripts > jcarousel > skins
-
File Storage > scripts > jcarousel > skins > ie7
Step 2: Setup jQuery
Now we’ll setup jQuery scripting for use in your site. There are two ways to do this.
Method 1:
Using a reference link to the latest jQuery library from the developer’s site. This is an easy way to make sure you are using the latest version. However, this is a slower method because the script must be downloaded every time. Plus you cannot always guarantee that the script will be available at the developer site.
To use this method, add the following script to your site.
<script src="http://code.jquery.com/jquery-latest.js"></script>
Note: If you have Code-Injection ability, add this script to the Extra Header Code section. If you do not, add this script to the page you want to show the component on.
Method 2 (PREFERRED):
Download the latest jQuery library, and upload to your Squarespace account general storage. This is the preferred method, as your script will be local to your page, and run much faster. First download the file at: http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js . Then upload to your general file storage under the “scripts” folder that you created.
To use this method, add the following script to your site.
<script type="text/javascript" src="/storage/scripts/jquery-1.2.6.min.js"></script>
Note: If you have Code-Injection ability, add this script to the Extra Header Code section. If you do not, add this script to the page you want to show the component on.
Step 3: Setup jCarousel and Thickbox plug-ins
Next we need to download and setup the plug-ins we’ll be using for this component. The first plugin we’ll need is called jCarousel, and can be found at: http://sorgalla.com/projects/jcarousel/ . You’ll first need to download the file from this page and unzip (download link is at top of this page). Please note that this developer was kind enough to include the second plug-in we’ll need called Thickbox in the same zip file. Not all of the files in the zip are required. You’ll only need to upload a few of the files to your general storage for use in this example.
In zip file under folder “lib”, upload the following files to “/storage/scripts/jcarousel” :
-
jquery.jcarousel.pack.js
-
jquery.jcarousel.css
In zip file under folder “lib/thickbox”, upload the following files to “/storage/scripts/ jcarousel/ thickbox”:
In zip file under folder “skins”, upload the following files to “/storage/scripts/ jcarousel/ skins/ie7”:
-
skin.css
-
next-horizontal.gif
-
prev-horizontal.gif
-
loading_small.gif
-
loading-small.gif
-
loading.gif
Step 4: Set up linkage file
Although plug-ins are typically easy to get up and running, they can be confusing and difficult for first-timers. Therefore, I created a single file that encapsulates the plug-in, and that will automatically reference and load the necessary files to create the Image Carousel component. Using my file will save a lot of steps, otherwise you would need to add several scripts throughout your site as per the plug-in developer’s instructions. But instead just use my script, which will do all the hard work. However if you need any customization, then you’ll need to follow the plug-in developer’s instructions on their site.
First download my file at: TBD. Then place the file under your folder “/storage/scripts/jcarousel”
Now we’ll setup this linkage file for use in your site. Add the following script to your site.
<script type="text/javascript" src="/storage/scripts/jcarousel/jcarousel.linkage.js "></script>
Note: If you have Code-Injection ability, add this script to the Extra Header Code section. If you do not, add this script to the page you want to show the component on.
Step 5: Define your images
Ok, almost done. Now we just need to define the images that you’ll be showing in the component. On the page you want to show these images, add the following script:
<script type="text/javascript">
var mycarousel_itemList = [
{url: "http://farm4.static.flickr.com/3204/2992655570_7747556e96.jpg?v=0", title: "Car 1"},
{url: "http://farm4.static.flickr.com/3195/2992497240_16cc45b40d.jpg?v=0", title: "Car 2"},
{url: "http://farm4.static.flickr.com/3283/2991649073_7817416046.jpg?v=0", title: "Car 3"},
{url: "http://farm4.static.flickr.com/3061/2996454654_003c1a2609.jpg?v=0", title: "Car 4"},
{url: "http://farm4.static.flickr.com/3139/3002568077_f467131f66.jpg?v=0", title: "Car 5"},
{url: "http://farm4.static.flickr.com/3196/2998873527_c7963c2637.jpg?v=0", title: "Car 6"},
{url: "http://farm4.static.flickr.com/3018/3003402834_d12412778e.jpg?v=0", title: "Car 7"}
];
</script>
Please note that the format is {url: “your image link”, title: “title of your image”}. So feel free to replace my examples with your own images and titles. You can reference local images in your account or other images on the internet.
Step 6: Add the component to your page
Ok, last step! Now we simply need to add the component to your page. Nothing fancy here, because all the hard work is being taken care by the scripts you’ve uploaded. Just make sure you label the component exactly as here. You can always customize later if you need to.
Please add the following script to the page you want to show the component:
<ul id="mycarousel" class="jcarousel-skin-ie7">
</ul>
That’s it!
Have fun with the component. Please keep in mind the following things:
-
There is another styling skin that comes with this plug-in called Tango, and you can always create and add your own. You’ll need to upload the new skin files and edit the “jcarousel.linkage.js” file to include the new skin. Also, change the class in the component to use your new name (ie . <ul id="mycarousel" class="jcarousel-skin-tango">)
-
To see working examples of this script, please review the plug-in developers website at: http://sorgalla.com/projects/jcarousel/
-
For more information on jQuery, go to their site at www.jquery.com. Information on various plug-ins can be found at: http://plugins.jquery.com/
About the Author: Chris Cox is an avid computer programmer, as well as President & CEO of Wirepoint Media, an enterprise, desktop, and mobile phone software development company. Please visit their site at: www.wirepointmedia.com
hj k hlkj hlj hkjh