package/ui/phpvirtualbox/js/phpvirtualbox.js
/**
 * Toolbar class for a small toolbar
 * 
 * @constructor
 * @class vboxToolbarSmall
 * @super vboxToolbar
 * @param {Options}
 *            buttons - list of buttons for toolbar
 *            language_context - context to use for translations
 *            renderTo - element to render to
 *            buttonStyle - style to use for button elements
 *            noHover - do not add hover styling
 *            size - button size
 */
Toolbar class for a small toolbar


Toolbar class for a small toolbar
function vboxToolbarSmall(options) {
	var self = this;
	this.buttonStyle = options.buttonStyle;
	this.buttonCSS = {};
	renderTo = options.renderTo
    options.renderTo = undefined
	this.parentClass = vboxToolbar;
	this.parentClass(options);
	this.selected = null;
	this.lastItem = null;
	this.enabled = true;
	this.size = options.size ? options.size : 16;
	this.disabledString = 'disabled';
	this.noHover = options.noHover;
	this.language_context = options.language_context;
	this.enableButton = function(b) {
		if(b.noDisabledIcon)
			this._buttonElements[b.name].css('display','').prop('disabled',false);
		else
			this._buttonElements[b.name].css('background-image','url(images/vbox/' + b.icon + '_'+self.size+'px.png)').prop('disabled',false);
	};
	this.disableButton = function(b) {
		if(b.noDisabledIcon)
			this._buttonElements[b.name].css('display','none').prop('disabled',false).removeClass('vboxToolbarSmallButtonHover').addClass('vboxToolbarSmallButton').trigger('mouseleave');
		else
			this._buttonElements[b.name].css('background-image','url(images/vbox/' + b.icon + '_'+self.disabledString+'_'+self.size+'px.png)').prop('disabled',true).removeClass('vboxToolbarSmallButtonHover').addClass('vboxToolbarSmallButton').trigger('mouseleave');
	};
	this.addButtonCSS = function(b, css) {
		self.buttonCSS[b] = css;
	};
	this.buttonElement = function(b) {
		if(b.enabled && !b.noDisabledIcon) {
			var a = new Image();
			a.src = "images/vbox/" + b.icon + '_'+self.disabledString+'_'+self.size+'px.png';
		}
		var label = String(trans(b.toolbar_label ? b.toolbar_label: b.label, b.language_context ? b.language_context : self.language_context)).replace(/\.+$/g,'')
		var btn = $('<input />').attr({'type':'button','value':'',
			'class': 'vboxImgButton vboxToolbarSmallButton ui-corner-all',
			'title': label,
			'style': self.buttonStyle+' background-image: url(images/vbox/' + b.icon + '_'+self.size+'px.png);'
		}).click(b.click);		
		if(!self.noHover) {
			$(btn).hover(
					function(){if(!$(this).prop('disabled')){$(this).addClass('vboxToolbarSmallButtonHover').removeClass('vboxToolbarSmallButton');}},
					function(){$(this).addClass('vboxToolbarSmallButton').removeClass('vboxToolbarSmallButtonHover');}		
			);
		}
		if(self.buttonCSS[b.name]) btn.css(self.buttonCSS[b.name]);
		return btn;
	};
	this.renderTo = function(targetElm) {
		if(typeof(targetElm) == 'string') {
			targetElm = $('#'+targetElm);
		}
		if(!self.buttonStyle)
			self.buttonStyle = 'height: ' + (self.size+8) + 'px; width: ' + (self.size+8) + 'px; ';
		for(var i = 0; i < self.buttons.length; i++) {
			if(self.buttons[i].separator) {
				$(targetElm).append($('<hr />').attr({'style':'display: inline','class':'vboxToolbarSmall vboxSeparatorLine'}));
			}
			this._buttonElements[self.buttons[i].name] = self.buttonElement(self.buttons[i]);
			$(targetElm).append(this._buttonElements[self.buttons[i].name]); 
		}
		$(targetElm).attr({'name':self.name}).addClass('vboxToolbarSmall vboxEnablerTrigger vboxToolbarSmall'+self.size).on('disable',self.disable).on('enable',self.enable);
		return this;
	};
   if(renderTo)
        this.renderTo(renderTo);
}
function vboxToolbarSmall ( options ) { var self = this ; this . buttonStyle = options . buttonStyle ; this . buttonCSS = { } ; renderTo = options . renderTo options . renderTo = undefined this . parentClass = vboxToolbar ; this . parentClass ( options ) ; this . selected = null ; this . lastItem = null ; this . enabled = true ; this . size = options . size ? options . size : 16 ; this . disabledString = 'disabled' ; this . noHover = options . noHover ; this . language_context = options . language_context ; this . enableButton = function ( b ) { if ( b . noDisabledIcon ) this . _buttonElements [ b . name ] . css ( 'display' , '' ) . prop ( 'disabled' , false ) ; else this . _buttonElements [ b . name ] . css ( 'background-image' , 'url(images/vbox/' + b . icon + '_' + self . size + 'px.png)' ) . prop ( 'disabled' , false ) ; } ; this . disableButton = function ( b ) { if ( b . noDisabledIcon ) this . _buttonElements [ b . name ] . css ( 'display' , 'none' ) . prop ( 'disabled' , false ) . removeClass ( 'vboxToolbarSmallButtonHover' ) . addClass ( 'vboxToolbarSmallButton' ) . trigger ( 'mouseleave' ) ; else this . _buttonElements [ b . name ] . css ( 'background-image' , 'url(images/vbox/' + b . icon + '_' + self . disabledString + '_' + self . size + 'px.png)' ) . prop ( 'disabled' , true ) . removeClass ( 'vboxToolbarSmallButtonHover' ) . addClass ( 'vboxToolbarSmallButton' ) . trigger ( 'mouseleave' ) ; } ; this . addButtonCSS = function ( b , css ) { self . buttonCSS [ b ] = css ; } ; this . buttonElement = function ( b ) { if ( b . enabled && ! b . noDisabledIcon ) { var a = new Image ( ) ; a . src = "images/vbox/" + b . icon + '_' + self . disabledString + '_' + self . size + 'px.png' ; } var label = String ( trans ( b . toolbar_label ? b . toolbar_label : b . label , b . language_context ? b . language_context : self . language_context ) ) . replace ( / \.+$ / g , '' ) var btn = $ ( '<input />' ) . attr ( { 'type' : 'button' , 'value' : '' , 'class' : 'vboxImgButton vboxToolbarSmallButton ui-corner-all' , 'title' : label , 'style' : self . buttonStyle + ' background-image: url(images/vbox/' + b . icon + '_' + self . size + 'px.png);' } ) . click ( b . click ) ; if ( ! self . noHover ) { $ ( btn ) . hover ( function ( ) { if ( ! $ ( this ) . prop ( 'disabled' ) ) { $ ( this ) . addClass ( 'vboxToolbarSmallButtonHover' ) . removeClass ( 'vboxToolbarSmallButton' ) ; } } , function ( ) { $ ( this ) . addClass ( 'vboxToolbarSmallButton' ) . removeClass ( 'vboxToolbarSmallButtonHover' ) ; } ) ; } if ( self . buttonCSS [ b . name ] ) btn . css ( self . buttonCSS [ b . name ] ) ; return btn ; } ; this . renderTo = function ( targetElm ) { if ( typeof ( targetElm ) == 'string' ) { targetElm = $ ( '#' + targetElm ) ; } if ( ! self . buttonStyle ) self . buttonStyle = 'height: ' + ( self . size + 8 ) + 'px; width: ' + ( self . size + 8 ) + 'px; ' ; for ( var i = 0 ; i < self . buttons . length ; i ++ ) { if ( self . buttons [ i ] . separator ) { $ ( targetElm ) . append ( $ ( '<hr />' ) . attr ( { 'style' : 'display: inline' , 'class' : 'vboxToolbarSmall vboxSeparatorLine' } ) ) ; } this . _buttonElements [ self . buttons [ i ] . name ] = self . buttonElement ( self . buttons [ i ] ) ; $ ( targetElm ) . append ( this . _buttonElements [ self . buttons [ i ] . name ] ) ; } $ ( targetElm ) . attr ( { 'name' : self . name } ) . addClass ( 'vboxToolbarSmall vboxEnablerTrigger vboxToolbarSmall' + self . size ) . on ( 'disable' , self . disable ) . on ( 'enable' , self . enable ) ; return this ; } ; if ( renderTo ) this . renderTo ( renderTo ) ; }
Toolbar class for a small toolbar
Toolbar class for a small toolbar
/**
	 * Enable a single button
	 * 
	 * @memberOf vboxToolbarSmall
	 * @param {Object}
	 *            b - button to enable
	 * @return null
	 */ /**
	 * Disable a single button
	 * 
	 * @memberOf vboxToolbarSmall
	 * @param {Object}
	 *            b - button to disable
	 * @return null
	 */ /**
	 * Add CSS to be applied to button
	 * 
	 * @param {String}
	 *            b button name
	 * @param {Object}
	 *            css css to be applied to button
	 */ /**
	 * Generate HTML element for button
	 * 
	 * @memberOf vboxToolbarSmall
	 * @param {Object}
	 *            b - button object containing various button parameters
	 * @return {HTMLNode} button element
	 */ // Pre-load disabled version of icon if enabled function exists // Check for button specific CSS /**
	 * Render buttons to HTML node where id = id param
	 * 
	 * @memberOf vboxToolbarSmall
	 * @param {String|Object}
	 *            targetElm - HTMLNode or id to add buttons to
	 * @return null
	 */