Chico UI - Doc

v1.0.0

ch.Zoom

Description

Zoom shows a contextual reference to an augmented version of a declared image.

How-to

// Create a new Zoom.
var zoom = new ch.Zoom($el, [options]);
// Create a new Zoom with jQuery or Zepto.
var zoom = $(selector).zoom([options]);
// Create a new Zoom with a defined width (half of the screen).
$(selector).zoom({
    'width': (ch.viewport.width / 2) + 'px'
});

Parameters

  • $el - jQuerySelector | ZeptoSelector : A jQuery or Zepto Selector to create an instance of ch.Zoom.
  • options - Object : Options to customize an instance.
    • addClass - String : CSS class names that will be added to the container on the widget initialization.
    • fx - String : Enable or disable UI effects. You must use: "slideDown", "fadeIn" or "none". Default: "none".
    • width - String : Set a width for the container. Default: "300px".
    • height - String : Set a height for the container. Default: "300px".
    • shownby - String : Determines how to interact with the trigger to show the container. You must use: "pointertap", "pointerenter" or "none". Default: "pointerenter".
    • hiddenby - String : Determines how to hide the widget. You must use: "button", "pointers", "pointerleave", "all" or "none". Default: "pointerleave".
    • reference - jQuerySelector | ZeptoSelector : It's a reference to position and size of element that will be considered to carry out the position. Default: the trigger element.
    • side - String : The side option where the target element will be positioned. Its value can be: "left", "right", "top", "bottom" or "center". Default: "right".
    • align - String : The align options where the target element will be positioned. Its value can be: "left", "right", "top", "bottom" or "center". Default: "top".
    • offsetX - Number : Distance to displace the target horizontally. Default: 20.
    • offsetY - Number : Distance to displace the target vertically. Default: 0.
    • position - String : The type of positioning used. Its value must be "absolute" or "fixed". Default: "absolute".
    • method - String : The type of request ("POST" or "GET") to load content by ajax. Default: "GET".
    • params - String : Params like query string to be sent to the server.
    • cache - Boolean : Force to cache the request by the browser. Default: true.
    • async - Boolean : Force to sent request asynchronously. Default: true.
    • waiting - String | jQuerySelector | ZeptoSelector : Temporary content to use while the ajax request is loading. Default: 'Loading zoom...'.
    • content - jQuerySelector | ZeptoSelector | HTMLElement | String : The content to be shown into the Zoom container.

Extends

Properties

.$container jQuerySelector | ZeptoSelector

The popover container. It's the element that will be shown and hidden.

.$trigger jQuerySelector | ZeptoSelector

The popover trigger. It's the element that will show and hide the container.

.Layer#name String

The name of the widget.

.Popover#name String

The name of the widget.

.uid Number

A unique id to identify the instance of a widget.

.Widget#name String

The name of a widget.

// You can reach the instance associated.
var widget = $(selector).data(name);

.Zoom#name String

The name of the widget.

Methods

.emit(event, var_args)



    

Execute each item in the listener collection in order with the specified data.

  • event - String : The name of the event you want to emit.
  • var_args - Object : Data to pass to the listeners.
// Will emit the 'ready' event with 'param1' and 'param2' as arguments.
widget.emit('ready', 'param1', 'param2');

.getListeners(event) → {Array}



    

Returns all listeners from the collection for a specified event.

  • event - String : The event name.
// Returns listeners from 'ready' event.
widget.getListeners('ready');

.off(event, listener) → {Object}



    

Removes a listener from the collection for a specified event.

  • event - String : Event name.
  • listener - Function : Listener function.
// Will remove event listener to 'ready' event.
widget.off('ready', listener);

.on(event, listener, once)



    

Adds a listener to the collection for a specified event.

  • event - String : The event name to subscribe.
  • listener - Function : Listener function.
  • once - Boolean : Indicate if a listener function will be called only one time.
// Will add an event listener to 'ready' event.
widget.on('ready', listener);

.once(event, listener) → {Object}



    

Adds a listener to the collection for a specified event to will execute only once.

  • event - String : Event name.
  • listener - Function : Listener function.
// Will add an event handler to 'contentLoad' event once.
widget.once('contentLoad', listener);

.constructor()



    

Returns a reference to the constructor function.

.show(content, options) → {layer}



    

Shows the layer container and hides other layers.

  • content - String | jQuerySelector | ZeptoSelector : The content that will be used by layer.
  • options - Object : A custom options to be used with content loaded by ajax.
// Shows a basic layer.
layer.show();
// Shows a layer with new content
layer.show('Some new content here!');
// Shows a layer with a new content that will be loaded by ajax with some custom options
layer.show('http://domain.com/ajax/url', {
    'cache': false,
    'params': 'x-request=true'
});

.constructor()



    

Returns a reference to the constructor function.

.destroy() → {popover}



    

Destroys a Popover instance.

// Destroy a popover
popover.destroy();
// Empty the popover reference
popover = undefined;

.disable() → {popover}



    

Disables a Popover instance.

// Disable a popover
popover.disable();

.enable() → {popover}



    

Enables a Popover instance.

// Enable a popover
popover.enable();

.height(data) → {Number|popover}



    

Sets or gets the height of the container.

  • data - String : Set a height for the container.
// Set a new popover height
widget.height('300px');
// Get the current popover height
widget.height(); // '300px'

.hide() → {popover}



    

Hides the popover container and deletes it from the body.

// Close a popover
popover.hide();

.isShown() → {Boolean}



    

Returns a Boolean specifying if the container is shown or not.

// Check the popover status
popover.isShown();
// Check the popover status after an user action
$(window).on(ch.onpointertap, function () {
    if (popover.isShown()) {
        alert('Popover: visible');
    } else {
        alert('Popover: not visible');
    }
});

.refreshPosition() → {popover}



    

Updates the current position of the container with given options or defaults.

// Update the current position
popover.refreshPosition();
// Update the current position with a new offsetX and offsetY
popover.refreshPosition({
    'offestX': 100,
    'offestY': 10
});

.show(content, options) → {popover}



    

Shows the popover container and appends it to the body.

  • content - String | jQuerySelector | ZeptoSelector : The content that will be used by popover.
  • options - Object : A custom options to be used with content loaded by ajax.
// Shows a basic popover.
popover.show();
// Shows a popover with new content
popover.show('Some new content here!');
// Shows a popover with a new content that will be loaded by ajax with some custom options
popover.show('http://domain.com/ajax/url', {
    'cache': false,
    'params': 'x-request=true'
});

.width(data) → {Number|popover}



    

Sets or gets the width of the container.

  • data - String : Set a width for the container.
// Set a new popover width
widget.width('300px');
// Get the current popover width
widget.width(); // '300px'

.constructor()



    

Returns a reference to the constructor function.

.destroy()



    

Destroys an instance of Widget and remove its data from asociated element.

// Destroying an instance of Widget.
widget.destroy();

.disable() → {instance}



    

Disables an instance of Widget.

// Disabling an instance of Widget.
widget.disable();

.enable() → {instance}



    

Enables an instance of Widget.

// Enabling an instance of Widget.
widget.enable();

.require() → {instance}



    

Adds functionality or abilities from other classes.

// You can require some abilitiest to use in your widget.
// For example you should require the collpasible abitliy.
var widget = new Widget(element, options);
widget.require('Collapsible');

.constructor()



    

Returns a reference to the constructor function.

.destroy() → {zoom}



    

Destroys a Zoom instance.

// Destroy a zoom
zoom.destroy();
// Empty the zoom reference
zoom = undefined;

.hide() → {zoom}



    

Hides the zoom container and the Seeker.

// Close a zoom
zoom.hide();

.loadImage() → {zoom}



    

Adds the zoomed image source to the tag to trigger the request.

// Load the zoomed image on demand.
widget.loadImage();

.show(content, options) → {zoom}



    

Shows the zoom container and the Seeker, or show a loading feedback until the zoomed image loads.

  • content - String | jQuerySelector | ZeptoSelector : The content that will be used by dropdown.
  • options - Object : A custom options to be used with content loaded by ajax.
// Shows a basic zoom.
zoom.show();
// Shows a zoom with new content
zoom.show('Some new content here!');
// Shows a zoom with a new content that will be loaded by ajax with some custom options
zoom.show('http://domain.com/ajax/url', {
    'cache': false,
    'params': 'x-request=true'
});

Events

'destroy'



    

Emits when a widget is destroyed.

// Subscribe to "destroy" event.
widget.on('destroy', function () {
 // Some code here!
});

'disable'



    

Emits when a widget is disable.

// Subscribe to "disable" event.
widget.on('disable', function () {
 // Some code here!
});

'enable'



    

Emits when a widget is enable.

// Subscribe to "enable" event.
widget.on('enable', function () {
 // Some code here!
});

'imageload'



    

Event emitted when the zoomed image is downloaded.

// Subscribe to "imageload" event.
zoom.on('imageload', function () {
    alert('Zoomed image ready!');
});

'ready'



    

Event emitted when the widget is ready to use.

// Subscribe to "ready" event.
zoom.on('ready', function () {
    // Some code here!
});