<commit_before>ART.WindowManager = new Class({

	Extends: Stacker,

	initialize: function(){
		this.parent.apply(this, arguments);
		this.keyboard = new Keyboard({
			active: true
		});
		this.keyboard.widget = 'window manager';
	},

	register: function(instance){
		this.parent.apply(this, arguments);
		this.keyboard.manage(instance.keyboard);
	},

	enable: function() {
		this.parent.apply(this, arguments);
		this.keyboard.enable();
		this.enabled.keyboard.enable();
	},

	unregister: function(instance) {
		this.parent.apply(this, arguments);
		Keyboard.manager.manage(instance.keyboard);
	}

});

ART.StickyWin = new Class({

	Extends: ART.Widget,

	name: 'stickywin',

	options: { 
		/*
		inject: {
			target: document.body,
			where: 'bottom'
		},
		content: null,
		timeout: 0,
		width: null,
		height: null,
		iframeShimSelector: '',
		closeOnClickOut: false,
		closeOnEsc: false,
		windowManager: instanceOfStacker,
		destroyOnClose: false,
		windowManagerLayer: 'default',
		
		//events:
		'drag:start': $empty,
		'drag:move': $empty(x,y),
		'drag:end': $empty,
		'shade': $empty

		//these are the defaults for Element.position anyway
		************************************************
		edge: false, //see Element.position
		position: 'center', //center, corner == upperLeft, upperRight, bottomLeft, bottomRight
		offset: {x:0,y:0},
		relativeTo: document.body,
		allowNegative: false,
		posMin: {x: , y:}, //passed as 'minimum' to element.position
		posMax: {x: , y: },//passed as 'maximum' to element.position
		************************************************

		mask: false,
		maskTarget: document.body,
		*/
		maskOptions: {},
		hideOnMaskClick: true,
		greyContentsOnDrag: true,
		closeClass: 'closeWin',
		close: true,
		draggable: false,
		dragHandle: false,
		showNow: true,
		useIframeShim: true,
		cascaded: false,
		constrainToContainer: false
	},

	initialize: function(options) {
		this.requireToRender('window:managed', 'window:displayed');
		if (!this.options.inject) {
			this.options.inject = {
				target: document.body,
				where: 'bottom'
			};
		}
		options = options || {};
		this.windowManager = options.windowManager || this.options.windowManager || ART.StickyWin.DefaultManager;
		delete this.options.windowManager;
		delete options.windowManager;
		//the window manager enables the windows; so we must start with disabled = true
		this.disabled = true;
		this.parent(options);
		this.element.store('StickyWin', this);
		this.build();
		this.windowManager.register(this, this.options.windowManagerLayer);
		this.readyToRender('window:managed');
		
		if (this.options.content) this.setContent(this.options.content);
		
		if (this.options.draggable) this.makeDraggable();
		if (this.options.timeout) {
			this.addEvent('show', function(){
				this.hide.delay(this.options.timeout, this);
			}.bind(this));
		}
		if (this.options.closeOnClickOut || this.options.closeOnEsc) this.attach();
		if (this.options.destroyOnClose) this.addEvent('hide', this.destroy.bind(this));
		this.element.setStyle('display', 'none');
		if (this.options.useIframeShim) this.hideIframeShim();
		this.hidden = true;
		if (this.options.showNow) this.show();
		
		this.element.addEvent('click:relay(.' + this.options.closeClass + ')', function(){
			this.hide();
		}.bind(this));
	},

	attach: function(attach){
		var method = $pick(attach, true) ? 'addEvents' : 'removeEvents';
		var events = {};
		if (this.options.closeOnClickOut) events.click = this.esc;
		if (this.options.closeOnEsc) events.keyup = this.esc;
		document[method](events);
	},

	esc: function(e) {
		if ((e.type == "click" && this.element != e.target && !this.element.hasChild(e.target)) || e.key == "esc") this.hide();
	},

	initialSize: function(element){
		['height', 'width'].each(function(axis) {
			var val = this.options[axis];
			if (val) {
				this['current'+axis.capitalize()] = val;
				(element || this.element).setStyle(axis, val);
			}
		}, this);
	},

	build: function(){
		this.element.setStyles({
			display: 'none',
			position: 'absolute'
		}).inject(this.options.inject.target, this.options.inject.where);
	},

	hide: function(){
		this.element.setStyle('display', 'none');
		if (this.options.useIframeShim) this.hideIframeShim();
		this.parent();
	},

	show: function(){
		this.readyToRender('window:displayed');
		this.element.setStyles({
			opacity: 0,
			display: 'block'
		});
		this.parent();
		this.windowManager.enable(this);
		if (!this.positioned) this.position();
		if (this.options.useIframeShim) this.showIframeShim();
		this.element.setStyle('opacity', 1);
		
		if (this.options.mask) {
			var target = $(this.options.maskTarget);
			if (!target && this.options.maskOptions.inject && this.options.maskOptions.inject.target)
				target = $(this.options.maskOptions.inject.target) || $(document.body);
			var zIndex = this.options.maskOptions.zIndex;
			if (zIndex == null) {
				if (target != document.body && target.getStyle('zIndex') != "auto") zIndex = $(target).getStyle('zIndex') + 1;
				if (target == document.body || zIndex > $(this).getStyle('zIndex').toInt() || zIndex == null)
					zIndex = $(this).getStyle('zIndex').toInt() - 1;
					if (zIndex < 0) zIndex = 0;
			}
			target.mask(
				$merge({
					style: {
						zIndex: zIndex
					},
					destroyOnHide: true,
					hideOnClick: this.options.hideOnMaskClick
				}, this.options.maskOptions)
			).get('mask').addEvent('hide', function(){
				if (!this.hidden) this.hide();
			}.bind(this));
			this.addEvent('hide', function(){
				var mask = target.get('mask');
				if (!mask.hidden) mask.hide();
			});
		}
	},

	position: function(options){
		this.positioned = true;
		this.setOptions(options);
		if (this.options.cascaded && !this.windowManager.positionNew(this, this.options)) {
			if ($defined(this.options.top) && $defined(this.options.left)) {
				this.element.setStyles({<commit_msg>fixing zindex management with stickywins and mask.<commit_after>ART.WindowManager = new Class({

	Extends: Stacker,

	initialize: function(){
		this.parent.apply(this, arguments);
		this.keyboard = new Keyboard({
			active: true
		});
		this.keyboard.widget = 'window manager';
	},

	register: function(instance){
		this.parent.apply(this, arguments);
		this.keyboard.manage(instance.keyboard);
	},

	enable: function() {
		this.parent.apply(this, arguments);
		this.keyboard.enable();
		this.enabled.keyboard.enable();
	},

	unregister: function(instance) {
		this.parent.apply(this, arguments);
		Keyboard.manager.manage(instance.keyboard);
	}

});

ART.StickyWin = new Class({

	Extends: ART.Widget,

	name: 'stickywin',

	options: { 
		/*
		inject: {
			target: document.body,
			where: 'bottom'
		},
		content: null,
		timeout: 0,
		width: null,
		height: null,
		iframeShimSelector: '',
		closeOnClickOut: false,
		closeOnEsc: false,
		windowManager: instanceOfStacker,
		destroyOnClose: false,
		windowManagerLayer: 'default',
		
		//events:
		'drag:start': $empty,
		'drag:move': $empty(x,y),
		'drag:end': $empty,
		'shade': $empty

		//these are the defaults for Element.position anyway
		************************************************
		edge: false, //see Element.position
		position: 'center', //center, corner == upperLeft, upperRight, bottomLeft, bottomRight
		offset: {x:0,y:0},
		relativeTo: document.body,
		allowNegative: false,
		posMin: {x: , y:}, //passed as 'minimum' to element.position
		posMax: {x: , y: },//passed as 'maximum' to element.position
		************************************************

		mask: false,
		maskTarget: document.body,
		*/
		maskOptions: {},
		hideOnMaskClick: true,
		greyContentsOnDrag: true,
		closeClass: 'closeWin',
		close: true,
		draggable: false,
		dragHandle: false,
		showNow: true,
		useIframeShim: true,
		cascaded: false,
		constrainToContainer: false
	},

	initialize: function(options) {
		this.requireToRender('window:managed', 'window:displayed');
		if (!this.options.inject) {
			this.options.inject = {
				target: document.body,
				where: 'bottom'
			};
		}
		options = options || {};
		this.windowManager = options.windowManager || this.options.windowManager || ART.StickyWin.DefaultManager;
		delete this.options.windowManager;
		delete options.windowManager;
		//the window manager enables the windows; so we must start with disabled = true
		this.disabled = true;
		this.parent(options);
		this.element.store('StickyWin', this);
		this.build();
		this.windowManager.register(this, this.options.windowManagerLayer);
		this.readyToRender('window:managed');
		
		if (this.options.content) this.setContent(this.options.content);
		
		if (this.options.draggable) this.makeDraggable();
		if (this.options.timeout) {
			this.addEvent('show', function(){
				this.hide.delay(this.options.timeout, this);
			}.bind(this));
		}
		if (this.options.closeOnClickOut || this.options.closeOnEsc) this.attach();
		if (this.options.destroyOnClose) this.addEvent('hide', this.destroy.bind(this));
		this.element.setStyle('display', 'none');
		if (this.options.useIframeShim) this.hideIframeShim();
		this.hidden = true;
		if (this.options.showNow) this.show();
		
		this.element.addEvent('click:relay(.' + this.options.closeClass + ')', function(){
			this.hide();
		}.bind(this));
	},

	attach: function(attach){
		var method = $pick(attach, true) ? 'addEvents' : 'removeEvents';
		var events = {};
		if (this.options.closeOnClickOut) events.click = this.esc;
		if (this.options.closeOnEsc) events.keyup = this.esc;
		document[method](events);
	},

	esc: function(e) {
		if ((e.type == "click" && this.element != e.target && !this.element.hasChild(e.target)) || e.key == "esc") this.hide();
	},

	initialSize: function(element){
		['height', 'width'].each(function(axis) {
			var val = this.options[axis];
			if (val) {
				this['current'+axis.capitalize()] = val;
				(element || this.element).setStyle(axis, val);
			}
		}, this);
	},

	build: function(){
		this.element.setStyles({
			display: 'none',
			position: 'absolute'
		}).inject(this.options.inject.target, this.options.inject.where);
	},

	hide: function(){
		this.element.setStyle('display', 'none');
		if (this.options.useIframeShim) this.hideIframeShim();
		this.parent();
	},

	show: function(){
		this.readyToRender('window:displayed');
		this.element.setStyles({
			opacity: 0,
			display: 'block'
		});
		this.parent();
		this.windowManager.enable(this);
		if (!this.positioned) this.position();
		if (this.options.useIframeShim) this.showIframeShim();
		this.element.setStyle('opacity', 1);
		
		if (this.options.mask) {
			var target = $(this.options.maskTarget);
			if (!target && this.options.maskOptions.inject && this.options.maskOptions.inject.target)
				target = $(this.options.maskOptions.inject.target) || $(document.body);
			var zIndex = this.options.maskOptions.zIndex;
			if (zIndex == null) {
				if (target != document.body && target.getStyle('zIndex') != "auto") zIndex = $(target).getStyle('zIndex').toInt() + 1;
				if (target == document.body || zIndex > $(this).getStyle('zIndex').toInt() || zIndex == null)
					zIndex = $(this).getStyle('zIndex').toInt() - 1;
				if (zIndex < 0 || isNaN(NaN)) zIndex = 0;
			}
			if (zIndex >= $(this).getStyle('zIndex').toInt()) $(this).setStyle('z-index', zIndex + 1);
			target.mask(
				$merge({
					style: {
						zIndex: zIndex
					},
					destroyOnHide: true,
					hideOnClick: this.options.hideOnMaskClick
				}, this.options.maskOptions)
			).get('mask').addEvent('hide', function(){
				if (!this.hidden) this.hide();
			}.bind(this));
			this.addEvent('hide', function(){
				var mask = target.get('mask');
				if (!mask.hidden) mask.hide();
			});
		}
	},

	position: function(options){
		this.positioned = true;
		this.setOptions(options);
		if (this.options.cascaded && !this.windowManager.positionNew(this, this.options)) {
			if ($defined(this.options.top) && $defined(this.options.left)) {
				this.element.setStyles({
{'fraction_non_alphanumeric': 0.18391866913123844, 'fraction_numerical': 0.0015963703579230382, 'mean_word_length': 4.123977615152819, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1858332', 'n_tokens_mistral': 4484, 'n_tokens_neox': 3916, 'n_words': 766}