/** * @fileOverview Misc jQuery plugins maintained by the phpVirtualBox project for * the phpVirtualBox project. These are either solely authored by * the project or so heavily modified that they can no longer be * separately maintained * @author Ian Moore (imoore76 at yahoo dot com) * @version $Id: jquery.projectPlugins.js 595 2015-04-17 09:50:36Z imoore76 $ * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com) * */ /** * Override _title method of dialog to accept HTML * * http://stackoverflow.com/questions/14488774/using-html-in-a-dialogs-title-in-jquery-ui-1-10 */ $.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, { _title: function(title) { title.html(this.options.title ? this.options.title : " "); } })); /** * Adds deprecated enable/disableSelection to jquery. * * Taken from jQuery source. * */ $.support.selectstart = "onselectstart" in document.createElement( "div" ); $.fn.extend({ disableSelection: function() { return this.on( ( $.support.selectstart ? "selectstart" : "mousedown" ) + ".ui-disableSelection", function( event ) { event.preventDefault(); }); }, enableSelection: function() { return this.off( ".ui-disableSelection" ); } }); /** * * Add hover and hoverClass functionality to jquery * */ (function($) { /* Mimic jquery hover function deprecated in jquery 1.9 */ $.fn.hover = function(onenter, onleave) { this.each(function() { $(this).on("mouseenter", onenter).on("mouseleave", onleave); }); return $(this); } /* Add / remove class onmouseenter/leave */ $.fn.hoverClass = function(hclass) { this.each(function() { $(this).on("mouseenter",function(){ $(this).addClass(hclass); }).on("mouseleave", function(){ $(this).removeClass(hclass); }); }); return $(this); } })(jQuery); /** * Restore jQuery.browser functionality. Taken from: * * https://github.com/jquery/jquery-migrate/blob/master/src/core.js * */ jQuery.uaMatch = function( ua ) { ua = ua.toLowerCase(); var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; return { browser: match[ 1 ] || "", version: match[ 2 ] || "0" }; }; // Don't clobber any existing jQuery.browser in case it's different if ( !jQuery.browser ) { matched = jQuery.uaMatch( navigator.userAgent ); browser = {}; if ( matched.browser ) { browser[ matched.browser ] = true; browser.version = matched.version; } // Chrome is Webkit, but Webkit is also Safari. if ( browser.chrome ) { browser.webkit = true; } else if ( browser.webkit ) { browser.safari = true; } jQuery.browser = browser; } /** * Modified version of http://archive.plugins.jquery.com/project/TextFill */ ;(function($) { $.fn.textFill = function(options) { var maxFontSize = options.maxFontPixels; var maxHeight = parseInt(options.height); var maxWidth = parseInt(options.width); var ourText = $(this); var fontSize = parseInt(ourText.css('font-size')); var fontSizeOrig = fontSize; var textHeight = $(ourText).outerHeight(true); var textWidth = $(ourText).outerWidth(true); do { ourText.css('font-size', fontSize++); textHeight = $(ourText).outerHeight(true); textWidth = $(ourText).outerWidth(true); } while(textHeight <= maxHeight && textWidth <= maxWidth && fontSize <= maxFontSize); fontSize--; return ourText.css({'font-size':(fontSize)+'px','top':(fontSize > fontSizeOrig ? '-1' : '0') + 'px'}); }; })(jQuery); /** * * phpVirtualBox tree view for snapshots * */ (function($) { $.fn.vbtree = function(options, toplevel) { if(!toplevel) var toplevel = this; this.each(function() { $(this).addClass('vboxTreeView').children('li').each(function(i,li){ // Change class ///////////////////// var children = $(li).children('ul').length; var last = !$(this).next().is('li'); var classadd = null; // Children and last if(children && !last) { classadd = 'collapsable'; // Children but no last } else if(children && last) { classadd = 'lastCollapsable'; } else if(!children && last) { classadd = 'last'; } $(li).addClass(classadd); // Insert hitarea var d = document.createElement('div'); $(d).addClass('hitarea').addClass((classadd ? classadd + '-hitarea' : '')).click(function(){ if(!$(this).data('toggleClicked')) { $(this).data('toggleClicked', true); if($(this).hasClass('last-hitarea')) return; if($(this).hasClass('lastCollapsable-hitarea')) $(this).addClass('lastExpandable-hitarea').removeClass('lastCollapsable-hitarea').parent().parent().children('ul').css({'display':'none'}); else $(this).addClass('expandable-hitarea').removeClass('collapsable-hitarea').parent().parent().children('ul').css({'display':'none'}); } else { $(this).data('toggleClicked', false); if($(this).hasClass('last-hitarea')) return; if($(this).hasClass('lastExpandable-hitarea')) $(this).addClass('lastCollapsable-hitarea').removeClass('lastExpandable-hitarea').parent().parent().children('ul').css({'display':''}); else $(this).addClass('collapsable-hitarea').removeClass('expandable-hitarea').parent().parent().children('ul').css({'display':''}); } return false; }); $(li).children('div').first().prepend(d); // Tree each UL under li one $(li).children('ul').vbtree({},toplevel); }); }); return this; }; })(jQuery); /** * * phpVirtualBox medium (disk / CD image etc.) select box * * Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com) * */ (function($) { $.fn.mediumselect = function(options) { /* Public access to select medium */ if(options.selectMedium) { $('#'+$(this).attr('id')+'-mediumselect-'+options.selectMedium).click(); return; } /* Defaults */ if(!options.type) options.type = 'HardDisk'; if(!options.media) options.media = []; /* Internal Select Medium */ function _selectmedium(d,sel) { if($(d).hasClass('vboxMediumReadOnly')) { $(sel).addClass('vboxMediumSelectReadOnly').addClass('vboxMediumReadOnly'); } else { $(sel).removeClass('vboxMediumSelectReadOnly').removeClass('vboxMediumReadOnly'); } // Set text $(sel).html(($(d).data('label') ? $(d).data('label') : '')); // Hide list $('#'+$(sel).attr('id')+'-list').hide(); // Set hidden select box value and // trigger change var old = $('#'+$(sel).data('origId')); $(old).val($(d).data('id')); $(old).trigger('change',old); } /* Generate and return list item */ function listItem(m,sel,old,children) { var li = document.createElement('li'); var d = document.createElement('div'); d.setAttribute('id',$(sel).attr('id')+'-'+m.attachedId); var opt = $(old).children('option[value='+m.attachedId+']'); if($(opt).hasClass('vboxMediumReadOnly')) { $(d).addClass('vboxMediumReadOnly'); $(li).addClass('vboxMediumReadOnly'); } if($(opt).attr('title')) { $(d).attr('title',$(opt).attr('title')); $(d).tipped({'source':'title'}); } $(d).addClass('vboxMediumSelectDiv').on("mouseenter",function(){$(this).addClass('vboxMediumSelectHover');}).on("mouseleave",function(){$(this).removeClass('vboxMediumSelectHover');}); $(d).html(m.label); $(d).data('label',m.label); $(d).data('id',m.attachedId); $(d).click(function(){_selectmedium(this,sel);}); $(li).append(d); // Traverse children if(children && m.children && m.children.length) { var ul = document.createElement('ul'); for(var c = 0; c < m.children.length; c++) { $(ul).append(listItem(m.children[c],sel,old,true)); } $(li).append(ul); } return li; } /* Show list */ function showList(sel) { var list = $('#'+$(sel).attr('id')+'-list'); var sTop = $(sel).offset().top + $(sel).outerHeight(); var sLeft = $(sel).offset().left; var sWidth = $(sel).outerWidth() + $(sel).closest('table').find('.vboxMediumSelectImg').outerWidth(); // Hide menu when clicking anywhere else $(document).one('click',function(){$(list).hide();}); $(list).css({'left':sLeft+'px','top':sTop+'px','min-width':sWidth}).show(); return false; } /* * Main */ this.each(function() { // Generate select box replacement if(!$('#'+$(this).attr('id')+'-mediumselect').attr('id')) { var sel = document.createElement('div'); $(sel).data('origId', $(this).attr('id')); $(sel).attr('id',$(this).attr('id')+'-mediumselect'); $(sel).attr('class','vboxMediumSelect'); $(sel).on('click',function(){ if($('#'+$(this).data('origId')+'-table').hasClass('vboxDisabled')) return; return showList(this); }); $(this).hide(); var img = document.createElement('div'); img.setAttribute('id',$(this).attr('id')+'-mediumselectimg'); img.setAttribute('class','vboxMediumSelectImg'); $(img).click(function(e){ $(e.target).closest('table').find('div.vboxMediumSelect').trigger('click'); return false; }); var tbl = document.createElement('table'); $(tbl).attr('id',$(this).attr('id')+'-table'); $(tbl).attr('class','vboxMediumSelect'); $(tbl).css({'padding':'0px','margin':'0px','border':'0px','width':'100%','border-spacing':'0px'}); var tr = document.createElement('tr'); var td = document.createElement('td'); $(td).attr({'class':'vboxMediumSelectTableLeft'}).css({'padding':'0px','margin':'0px','width':'100%'}); $(td).append(sel); $(tr).append(td); var td = document.createElement('td'); $(td).attr({'class':'vboxMediumSelectTableRight'}).css({'padding':'0px','margin':'0px','width':'auto'}); $(td).append(img); $(tr).append(td); $(tbl).append(tr); // Handle enabled / disabled $(tbl).on('enable',function(){ $(this).removeClass('vboxDisabled'); }).on('disable',function(){ $(this).addClass('vboxDisabled'); }); $(this).before(tbl); var list = document.createElement('ul'); $(list).attr('id',$(this).attr('id')+'-mediumselect-list'); $(list).attr('class', 'vboxMediumSelect'); $(list).css({'display':'none'}); $('#vboxPane').append(list); } // Hide list if it exists $('#'+$(this).attr('id')+'-mediumselect-list').hide(); $('#'+$(this).attr('id')+'-mediumselectimg').css({'background-image':'url(images/downArrow.png)'}); // Compile list var list = $('#'+$(this).attr('id')+'-mediumselect-list'); $(list).children().remove(); var sel = $('#'+$(this).attr('id')+'-mediumselect'); var old = this; for(var i = 0; i < options.media.length; i++) { if(options.media[i].base && options.media[i].id != options.media[i].base) continue; $(list).append(listItem(options.media[i],sel,old,options.showdiff)); } // Set initial text and styles var oldopt = $(this).children('option:eq('+Math.max($(this).prop('selectedIndex'),0)+')'); if(!$(oldopt).val()) { _selectmedium($(list).find('div').first(), sel, old); } else { _selectmedium($('#'+$(sel).attr('id')+'-'+$(oldopt).val()), sel, old); } }); // return this; }; // })(jQuery); //jQuery File Tree Plugin // // Version 1.01 // // Cory S.N. LaViska // A Beautiful Site (http://abeautifulsite.net/) // 24 March 2008 // // Visit http://abeautifulsite.net/notebook.php?article=58 for more information // // Usage: $('.fileTreeDemo').fileTree( options, callback ) // // Options: root - root folder to display; default = / // script - location of the serverside AJAX file to use; default = jqueryFileTree.php // folderEvent - event to trigger expand/collapse; default = click // expandSpeed - default = 500 (ms); use -1 for no animation // collapseSpeed - default = 500 (ms); use -1 for no animation // expandEasing - easing function to use on expand (optional) // collapseEasing - easing function to use on collapse (optional) // multiFolder - whether or not to limit the browser to one subfolder at a time // loadMessage - Message to display while initial tree loads (can be HTML) // // History: // // 1.01 - updated to work with foreign characters in directory/file names (12 April 2008) // 1.00 - released (24 March 2008) // // TERMS OF USE // // This plugin is dual-licensed under the GNU General Public License and the MIT License and // is copyright 2008 A Beautiful Site, LLC. // // 2010-05-12 - Modified by Ian Moore for phpVirtualBox // // if(jQuery) (function($){ $.extend($.fn, { fileTree: function(o, h) { // Defaults if( !o ) var o = {}; if( o.root == undefined ) o.root = '/'; if( o.script == undefined ) o.script = vboxEndpointConfig.filebrowser; if( o.expandSpeed == undefined ) o.expandSpeed= 500; if( o.collapseSpeed == undefined ) o.collapseSpeed= 500; if( o.expandEasing == undefined ) o.expandEasing = null; if( o.collapseEasing == undefined ) o.collapseEasing = null; if( o.multiFolder == undefined ) o.multiFolder = true; if( o.loadMessage == undefined ) o.loadMessage = trans('Loading ...','UIVMDesktop'); if( o.scrollTo == undefined ) o.scrollTo = null; if( o.dirsOnly == undefined) o.dirsOnly = false; var top = this; $(this).each( function() { function showTree(c, t, fullpath) { // If a UL is not the target, find or create it if($(c).prop('tagName') != 'UL') { var target = $(c).children('UL').first(); if(target.length) { c = $(target); } else { var rootList = $('