mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-31 23:21:42 +03:00
Add addClass()/removeClass() utility functions
This commit is contained in:
parent
4e5393efe7
commit
522bcbf058
@ -377,7 +377,7 @@ $.Drawer.prototype = {
|
|||||||
element.href = "#/overlay/"+id;
|
element.href = "#/overlay/"+id;
|
||||||
}
|
}
|
||||||
element.id = id;
|
element.id = id;
|
||||||
element.className = element.className + " " + ( overlay.className ?
|
$.addClass( element, overlay.className ?
|
||||||
overlay.className :
|
overlay.className :
|
||||||
"openseadragon-overlay"
|
"openseadragon-overlay"
|
||||||
);
|
);
|
||||||
|
@ -1025,6 +1025,48 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the specified CSS class to the element if not present.
|
||||||
|
* @name $.addClass
|
||||||
|
* @function
|
||||||
|
* @param {Element|String} element
|
||||||
|
* @param {String} className
|
||||||
|
*/
|
||||||
|
addClass: function( element, className ) {
|
||||||
|
element = $.getElement( element );
|
||||||
|
|
||||||
|
if ( ! element.className ) {
|
||||||
|
element.className = className;
|
||||||
|
} else if ( ( ' ' + element.className + ' ' ).
|
||||||
|
indexOf( ' ' + className + ' ' ) === -1 ) {
|
||||||
|
element.className += ' ' + className;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified CSS class from the element.
|
||||||
|
* @name $.removeClass
|
||||||
|
* @function
|
||||||
|
* @param {Element|String} element
|
||||||
|
* @param {String} className
|
||||||
|
*/
|
||||||
|
removeClass: function( element, className ) {
|
||||||
|
var oldClasses,
|
||||||
|
newClasses = [],
|
||||||
|
i;
|
||||||
|
|
||||||
|
element = $.getElement( element );
|
||||||
|
oldClasses = element.className.split( /\s+/ );
|
||||||
|
for ( i = 0; i < oldClasses.length; i++ ) {
|
||||||
|
if ( oldClasses[ i ] && oldClasses[ i ] !== className ) {
|
||||||
|
newClasses.push( oldClasses[ i ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
element.className = newClasses.join(' ');
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an event listener for the given element, eventName and handler.
|
* Adds an event listener for the given element, eventName and handler.
|
||||||
* @function
|
* @function
|
||||||
|
@ -515,10 +515,7 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
|||||||
|
|
||||||
//Make sure the user has some ability to style the toolbar based
|
//Make sure the user has some ability to style the toolbar based
|
||||||
//on the mode
|
//on the mode
|
||||||
this.toolbar.element.setAttribute(
|
$.addClass( this.toolbar.element, 'fullpage' );
|
||||||
'class',
|
|
||||||
this.toolbar.element.className +" fullpage"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body.appendChild( this.element );
|
body.appendChild( this.element );
|
||||||
@ -602,10 +599,7 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
|||||||
|
|
||||||
//Make sure the user has some ability to style the toolbar based
|
//Make sure the user has some ability to style the toolbar based
|
||||||
//on the mode
|
//on the mode
|
||||||
this.toolbar.element.setAttribute(
|
$.removeClass( this.toolbar.element, 'fullpage' );
|
||||||
'class',
|
|
||||||
this.toolbar.element.className.replace('fullpage','')
|
|
||||||
);
|
|
||||||
//this.toolbar.element.style.position = 'relative';
|
//this.toolbar.element.style.position = 'relative';
|
||||||
this.toolbar.parentNode.insertBefore(
|
this.toolbar.parentNode.insertBefore(
|
||||||
this.toolbar.element,
|
this.toolbar.element,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user