2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Control
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2013-05-14 07:32:09 +04:00
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of CodePlex Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
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
|
2013-06-02 00:09:04 +04:00
|
|
|
* @param {Element} element - the control element to be anchored in the container.
|
2013-06-07 18:24:12 +04:00
|
|
|
* @param {Object | OpenSeadragon.ControlAnchor } options - All required and optional settings for configuring a control element. A deprecated
|
|
|
|
* alternative to passing an object with properties is to just pass an OpenSeadragon.ControlAnchor. The target
|
|
|
|
* removal date for this deprecated alternative is December 2013.
|
2013-06-02 00:09:04 +04:00
|
|
|
* @param {OpenSeadragon.ControlAnchor} [options.anchor=OpenSeadragon.ControlAnchor.NONE] - the position of the control
|
|
|
|
* relative to the container.
|
|
|
|
* @param {Boolean} [options.attachToViewer=true] - Whether the control should be added directly to the viewer, or
|
|
|
|
* directly to the container
|
|
|
|
* @param {Boolean} [options.autoFade=true] - Whether the control should have the autofade behavior
|
2012-01-25 23:14:02 +04:00
|
|
|
* @param {Element} container - the element to control will be anchored too.
|
2013-06-02 00:09:04 +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.
|
2013-06-02 00:09:04 +04:00
|
|
|
* @property {Boolean} autoFade - Whether the control should have the autofade behavior
|
|
|
|
* @property {Element} container - the element within with the control is
|
2012-01-25 23:14:02 +04:00
|
|
|
* positioned.
|
2013-06-02 00:09:04 +04:00
|
|
|
* @property {Element} wrapper - a neutral element surrounding the control
|
2012-01-25 23:14:02 +04:00
|
|
|
* element.
|
|
|
|
*/
|
2013-03-15 18:59:47 +04:00
|
|
|
$.Control = function ( element, options, container ) {
|
|
|
|
var parent = element.parentNode;
|
2013-06-07 18:24:12 +04:00
|
|
|
//Deprecated. Target removal date is December 2013
|
|
|
|
if (typeof options === 'number')
|
|
|
|
{
|
|
|
|
options = {anchor: options};
|
|
|
|
}
|
2013-03-15 18:59:47 +04:00
|
|
|
options.attachToViewer = (typeof options.attachToViewer === 'undefined') ? true : options.attachToViewer;
|
|
|
|
this.autoFade = (typeof options.autoFade === 'undefined') ? true : options.autoFade;
|
2012-02-01 06:01:37 +04:00
|
|
|
this.element = element;
|
2013-03-15 18:59:47 +04:00
|
|
|
this.anchor = options.anchor;
|
2012-01-24 07:48:45 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-15 18:59:47 +04:00
|
|
|
if (options.attachToViewer ) {
|
|
|
|
if ( this.anchor == $.ControlAnchor.TOP_RIGHT ||
|
|
|
|
this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) {
|
|
|
|
this.container.insertBefore(
|
|
|
|
this.wrapper,
|
|
|
|
this.container.firstChild
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.container.appendChild( this.wrapper );
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2013-03-15 18:59:47 +04:00
|
|
|
parent.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 ));
|