var list = $('<ul>')
.addClass('anselGalleryList')
.attr({ 'data-role': 'listview' }), item;
-
$('#anselgallerylist ul').detach();
$.each(galleries, function(k, g) {
- var item = $('<li>');
+ var item = $('<li>').attr({ 'class': 'ansel-gallery', 'ansel-gallery-id': g.id });
item.append($('<img>').attr({ src: g.ki }));
item.append($('<h3>').append($('<a>').attr({ href: '#' }).text(g.n)));
item.append($('<p>').text(g.d));
},
/**
+ * Load the specified gallery
+ */
+ toGallery: function(id)
+ {
+ HordeMobile.doAction('getGallery', { id: id }, AnselMobile.galleryLoaded);
+ },
+
+ /**
+ * Callback for after a gallery is loaded.
+ */
+ galleryLoaded: function(r)
+ {
+ console.log(r);
+ },
+
+ /**
* Global click handler
*
*/
clickHandler: function(e)
{
+ var elt = $(e.target), id;
+
+ while (elt && elt != window.document && elt.parent().length) {
+ // Navigate to a gallery
+ if (elt.hasClass('ansel-gallery')) {
+ alert(elt.attr('ansel-gallery-id'));
+ AnselMobile.toGallery(elt.attr('ansel-gallery-id'));
+ }
+ elt = elt.parent();
+ }
},
/**
*/
public $notify = true;
-
+ /**
+ * Obtain a gallery
+ *
+ * @return mixed False on failure, object representing the gallery with
+ * the following structure:
+ * <pre>
+ * 'n' - gallery name
+ * 'dc' - date created
+ * 'dm' - date modified
+ * 'd' - description
+ * 'ki' - key image
+ * 'sg' - an object with the following properties:
+ * 'n' - gallery name
+ * 'dc' - date created
+ * 'dm' - date modified
+ * 'd' - description
+ * 'ki' - key image
+ *
+ * 'imgs' - an array of image objects with the following properties:
+ * 'id' - the image id
+ * 'url' - the image url
+ * </pre>
+ */
+ public function getGallery()
+ {
+ $id = $this->_vars->id;
+ return $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($id)->toJson(true);
+ }
}
parent::unserialize($data);
$this->_setModeHelper($this->get('view_mode'));
}
+
+ /**
+ * Returns a json representation of this gallery.
+ *
+ * @param boolean $full Return all information (subgalleries and images)?
+ *
+ * @return StdClass An object describing the gallery
+ */
+ public function toJson($full = false)
+ {
+ $json = new StdClass();
+ $json->id = $this->getId();
+ $json->n = $this->get('name');
+ $json->dc = $this->get('date_created');
+ $json->dm = $this->get('date_modified');
+ $json->d = $this->get('desc');
+ $json->ki = Ansel::getImageUrl($this->getKeyImage(), 'mini', false, 'ansel_default')->toString();
+
+ if ($full) {
+ $json->sg = array();
+ if ($this->hasSubGalleries()) {
+ $sgs = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('parent' => $this->getId(), 'all_levels' => false));
+ foreach ($sgs as $g) {
+ $json->sg[] = $g->toJson();
+ }
+ }
+
+ $images = $this->listImages();
+ foreach ($images as $img) {
+ $i = new StdClass();
+ $i->id = $img;
+ $i->url = Ansel::getImageUrl($img, 'mini', false, Ansel::getStyleDefinition('ansel_mobile'))->toString();
+ $json->imgs[] = $i;
+ }
+ }
+
+ return $json;
+ }
+
}
*/
protected function _create()
{
- $this->_image->resize(min(50, $this->_dimensions['width']),
- min(50, $this->_dimensions['height']),
- true);
- if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) {
- try {
- $this->_image->addEffect('Unsharpmask',
- array('radius' => $GLOBALS['conf']['thumbnail']['radius'],
- 'threshold' => $GLOBALS['conf']['thumbnail']['threshold'],
- 'amount' => $GLOBALS['conf']['thumbnail']['amount']));
- $this->_image->applyEffects();
- } catch (Horde_Image_Exception $e) {
- throw new Ansel_Exception($e);
- }
- }
-
- return $this->_image->getHordeImage();
+ $generator = Ansel_ImageGenerator::factory('SquareThumb', array('width' => min(50, $this->_dimensions['width']),
+ 'height' => min(50, $this->_dimensions['height']),
+ 'image' => $this->_image));
+ return $generator->create();
}
}
protected function _create()
{
// Take the largest requested dimension
- if (empty($this->_dimensions['width'])) {
- $size = max($GLOBALS['conf']['thumbnail']['height'], $GLOBALS['conf']['thumbnail']['width']);
+ if (empty($this->_params['width'])) {
+ $size = min($GLOBALS['conf']['thumbnail']['height'], $GLOBALS['conf']['thumbnail']['width']);
} else {
- $size = max($this->_dimensions['width'], $this->_dimensions['height']);
+ $size = min($this->_params['width'], $this->_params['height']);
}
// Use smartcrop algorithm if we have it, otherwise a plain center crop.
$galleries = array();
foreach ($gallerylist as $gallery) {
- $galleries[$gallery->id] = array(
- 'n' => $gallery->get('name'),
- 'dc' => $gallery->get('date_created'),
- 'dm' => $gallery->get('date_modified'),
- 'd' => $gallery->get('desc'),
- 'ki' => Ansel::getImageUrl($gallery->getKeyImage(), 'prettythumb', false, 'ansel_mobile')->toString()
- );
+ $galleries[] = $gallery->toJson();
}
$code['conf']['galleries'] = $galleries;