2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* An enumeration of supported locations where controls can be anchored,
|
|
|
|
* including NONE, TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, and BOTTOM_LEFT.
|
|
|
|
* The anchoring is always relative to the container
|
|
|
|
* @static
|
|
|
|
*/
|
2011-12-14 02:57:40 +04:00
|
|
|
$.ControlAnchor = {
|
|
|
|
NONE: 0,
|
|
|
|
TOP_LEFT: 1,
|
|
|
|
TOP_RIGHT: 2,
|
|
|
|
BOTTOM_RIGHT: 3,
|
|
|
|
BOTTOM_LEFT: 4
|
|
|
|
};
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* A Control represents any interface element which is meant to allow the user
|
|
|
|
* to interact with the zoomable interface. Any control can be anchored to any
|
|
|
|
* element.
|
|
|
|
* @class
|
2012-02-01 06:01:37 +04:00
|
|
|
* @param {Element} element - the contol element to be anchored in the container.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {OpenSeadragon.ControlAnchor} anchor - the location to anchor at.
|
|
|
|
* @param {Element} container - the element to control will be anchored too.
|
|
|
|
*
|
2012-02-01 06:01:37 +04:00
|
|
|
* @property {Element} element - the element providing the user interface with
|
2012-01-25 23:14:02 +04:00
|
|
|
* some type of control. Eg a zoom-in button
|
|
|
|
* @property {OpenSeadragon.ControlAnchor} anchor - the position of the control
|
|
|
|
* relative to the container.
|
|
|
|
* @property {Element} container - the element within with the control is
|
|
|
|
* positioned.
|
|
|
|
* @property {Element} wrapper - a nuetral element surrounding the control
|
|
|
|
* element.
|
|
|
|
*/
|
2012-02-01 06:01:37 +04:00
|
|
|
$.Control = function ( element, anchor, container ) {
|
|
|
|
this.element = element;
|
2012-01-24 07:48:45 +04:00
|
|
|
this.anchor = anchor;
|
|
|
|
this.container = container;
|
|
|
|
this.wrapper = $.makeNeutralElement( "span" );
|
2011-12-06 07:50:25 +04:00
|
|
|
this.wrapper.style.display = "inline-block";
|
2012-02-01 06:01:37 +04:00
|
|
|
this.wrapper.appendChild( this.element );
|
2011-12-14 02:57:40 +04:00
|
|
|
|
2012-01-24 07:48:45 +04:00
|
|
|
if ( this.anchor == $.ControlAnchor.NONE ) {
|
2011-12-14 02:57:40 +04:00
|
|
|
// IE6 fix
|
|
|
|
this.wrapper.style.width = this.wrapper.style.height = "100%";
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-14 02:57:40 +04:00
|
|
|
if ( this.anchor == $.ControlAnchor.TOP_RIGHT ||
|
|
|
|
this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) {
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container.insertBefore(
|
|
|
|
this.wrapper,
|
|
|
|
this.container.firstChild
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container.appendChild( this.wrapper );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.Control.prototype = {
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Removes the control from the container.
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
destroy: function() {
|
2012-02-01 06:01:37 +04:00
|
|
|
this.wrapper.removeChild( this.element );
|
2012-01-24 07:48:45 +04:00
|
|
|
this.container.removeChild( this.wrapper );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Determines if the control is currently visible.
|
|
|
|
* @function
|
|
|
|
* @return {Boolean} true if currenly visible, false otherwise.
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
isVisible: function() {
|
|
|
|
return this.wrapper.style.display != "none";
|
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Toggles the visibility of the control.
|
|
|
|
* @function
|
|
|
|
* @param {Boolean} visible - true to make visible, false to hide.
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
setVisible: function( visible ) {
|
|
|
|
this.wrapper.style.display = visible ?
|
|
|
|
"inline-block" :
|
|
|
|
"none";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 07:48:45 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* Sets the opacity level for the control.
|
|
|
|
* @function
|
|
|
|
* @param {Number} opactiy - a value between 1 and 0 inclusively.
|
|
|
|
*/
|
2012-01-24 07:48:45 +04:00
|
|
|
setOpacity: function( opacity ) {
|
2012-02-01 06:01:37 +04:00
|
|
|
if ( this.element[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
|
|
|
|
$.setElementOpacity( this.element, opacity, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2012-01-24 07:48:45 +04:00
|
|
|
$.setElementOpacity( this.wrapper, opacity, true );
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|