Image Gallery Implementation Example
====================================
The purpose of this page is to explain how an image gallery built with jQuery's
jCarousel plugin and based on data loaded via AJAX can be integrated into
WYMEditor. The example is built using `CodeIgniter
`_ (CI) for structure and queries. It uses a
series of JS includes in the image dialog, a CI controller function called via
AJAX, and a CI model function containing an active record query on an images
database. This example presupposes that you have a functioning install of
WYMEditor v0.4 and you are relatively familiar with hacking it. It also assumes
that you have the source files for and know how to implement an image gallery
based on jCarousel. More information and source downloads for jCarousel can be
found here: http://sorgalla.com/jcarousel/
1. Including Plugin Code
------------------------
You will need to include 3 js files and 2 css files into the dialogs' HTML.
This is done by using the ``dialogHtml`` option, which makes up the outer shell
of the dialog boxes that are opened by the top buttons in WYMeditor. You will
need to change the paths here to match up with whatever your setup is:
.. code-block:: javascript
$('.wymeditor').wymeditor({
//options
dialogHtml: ""
+ "
"
+ ""
//other options
});
.. note::
Options specified when calling a new WYMEditor instance must be separated
by commas. If you add in some other options to the example shown above, you
will need to add a comma to the end of the dialogImageHtml assignment as
well as all the rest of the new options except the last one.
jquery.js, easing.js, and jquery.jcarousel.js are all pre-built components that
can be downloaded from various sites - see the jCarousel link above.
jquery.imager.js is a custom script that will be built below.
jquery.jcarousel.css and skins/tango/skin.css are parts of jCarousel, please
refer to the jCarousel link above for more information. The header styles are
used to make jCarousel expand / contract based on the width of the dialog
window.
2. Adding Injection Target to Dialog Body
-----------------------------------------
OK, now all of our scripts should be in place. Upload the file, refresh your
WYMEditor install and open the image dialog; you should see all that stuff in
the head of the document. It's usually a good idea to copy the paths out of the
source here, paste them into another browser window, and make sure they open;
this is just to make sure you have the paths correct and all the files are in
the right place.
The next step is to add a target ``div`` to the image dialog body HTML. This
gives us a place to inject our dynamic image list a bit later once we have
built it with AJAX and PHP. In the ``dialogImageHtml`` string (around line 619)
add the following line:
.. code-block:: javascript
+ "
Loading images, please wait...
"
This line should go after the form but before the close body tag, like so:
.. code-block:: javascript
+ ""
+ ""
+ ""
+ "