/*!
 * SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
 * (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
 */
sap.ui.define(['jquery.sap.global'],function(q){"use strict";var I={};(function(){var r={},e=[];var p="_POPOVER_",d="_DIALOG_";I.addInstance=function(c,i){if(!r[c]){r[c]=[];}if(r[c].indexOf(i)===-1){r[c].push(i);}return this;};I.removeInstance=function(c,o){var C=r[c],i;if(!C){q.sap.log.warning("Can't remove control from a non-managed category id: "+c);return null;}i=C.indexOf(o);return(i===-1)?null:C.splice(i,1);};I.getInstancesByCategoryId=function(c){return r[c]||e;};I.isInstanceManaged=function(c,i){var C=r[c];if(!C||!i){return false;}return C.indexOf(i)!==-1;};I.isCategoryEmpty=function(c){var C=r[c];return!C||C.length===0;};I.addPopoverInstance=function(P){if(typeof P.close==="function"){I.addInstance(p,P);}else{q.sap.log.warning("In method addPopoverInstance: the parameter doesn't have a close method and can't be managed.");}return this;};I.addDialogInstance=function(D){if(typeof D.close==="function"){I.addInstance(d,D);}else{q.sap.log.warning("In method addDialogInstance: the parameter doesn't have a close method and can't be managed.");}return this;};I.removePopoverInstance=function(P){return I.removeInstance(p,P);};I.removeDialogInstance=function(D){return I.removeInstance(d,D);};I.hasOpenPopover=function(){return!I.isCategoryEmpty(p);};I.hasOpenDialog=function(){return!I.isCategoryEmpty(d);};I.isDialogOpen=function(D){return I.isInstanceManaged(d,D);};I.isPopoverOpen=function(P){return I.isInstanceManaged(p,P);};I.getOpenPopovers=function(){return I.getInstancesByCategoryId(p);};I.getOpenDialogs=function(){return I.getInstancesByCategoryId(d);};I.closeAllPopovers=function(){var a=I.getOpenPopovers(),i;for(i=0;i<a.length;i++){a[i].close();}return this;};I.closeAllDialogs=function(c){var D,a=[],b=I.getOpenDialogs(),f,i;for(i=0;i<b.length;i++){f=b[i];if(c){D=new q.Deferred().done();a.push(D);f.attachEvent("afterClose",(function(g){return function(){g.resolve();};}(D)));}f.close();}if(c){q.when.apply(this,a).then(c);}return this;};}());return I;},true);
