<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,
		************************************************

		*/
		greyContentsOnDrag: true,
		closeClass: 'closeWin',
		close: true,
		draggable: false,
		dragHandle: false,
		showNow: true,
		useIframeShim: true,
		cascaded: false
	},

	initialize: function(options) {
		this.requireToRender('window:managed', 'window:displayed');
		if (!this.options.inject) {
			this.options.inject = {
				target: document.body,
				where: 'bottom'
			};
		}
		this.windowManager = this.options.windowManager || ART.StickyWin.DefaultManager;
		//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));
		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();
	},

	build: function(){
		var self = this;
		this.size = {};
		['height', 'width'].each(function(axis) {
			var val = this.options[axis];
			if (val) {
				this['current'+axis.capitalize()] = val;
				this.element.setStyle(axis, val);
			}
		}, this);
		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.windowManager.enable(this);
		this.position();
		if (this.options.useIframeShim) this.showIframeShim();
		this.element.setStyle('opacity', 1);
		this.parent();
	},

	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({
					top: this.options.top,
					left: this.options.left
				});
			} else {
				this.element.position({
					allowNegative: $pick(this.options.allowNegative, this.options.relativeTo != document.body),
					relativeTo: $(this.options.relativeTo) || $(document.body),
					position: this.options.position,
					offset: this.options.offset,
					edge: this.options.edge
				});
			}
		}
		if (this.shim) this.shim.position();
		return this;
	},

	pin: function(pin) {
		if (this.element.pin) {
			this.pinned = $pick(pin, true);
			this.element.pin(pin);
		}
		return this;
	},

	unpin: function(){
		return this.pin(false);
	},

	togglepin: function(){
		return this.pin(!this.pinned);
	},

	makeDraggable: function(handle){
		handle = handle || this.options.dragHandle || this.element;
		this.touchDrag = new Touch(handle);
		handle.setStyle('cursor', 'move');<commit_msg>adding min/max options for positioning.<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
		************************************************

		*/
		greyContentsOnDrag: true,
		closeClass: 'closeWin',
		close: true,
		draggable: false,
		dragHandle: false,
		showNow: true,
		useIframeShim: true,
		cascaded: false
	},

	initialize: function(options) {
		this.requireToRender('window:managed', 'window:displayed');
		if (!this.options.inject) {
			this.options.inject = {
				target: document.body,
				where: 'bottom'
			};
		}
		this.windowManager = this.options.windowManager || ART.StickyWin.DefaultManager;
		//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));
		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();
	},

	build: function(){
		var self = this;
		this.size = {};
		['height', 'width'].each(function(axis) {
			var val = this.options[axis];
			if (val) {
				this['current'+axis.capitalize()] = val;
				this.element.setStyle(axis, val);
			}
		}, this);
		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.windowManager.enable(this);
		this.position();
		if (this.options.useIframeShim) this.showIframeShim();
		this.element.setStyle('opacity', 1);
		this.parent();
	},

	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({
					top: this.options.top,
					left: this.options.left
				});
			} else {
				this.element.position({
					allowNegative: $pick(this.options.allowNegative, this.options.relativeTo != document.body),
					relativeTo: $(this.options.relativeTo) || $(document.body),
					position: this.options.position,
					offset: this.options.offset,
					edge: this.options.edge,
					minimum: this.options.posMin,
					maximum: this.options.posMax
				});
			}
		}
		if (this.shim) this.shim.position();
		return this;
	},

	pin: function(pin) {
		if (this.element.pin) {
			this.pinned = $pick(pin, true);
			this.element.pin(pin);
		}
		return this;
	},

	unpin: function(){
		return this.pin(false);
	},

	togglepin: function(){
		return this.pin(!this.pinned);
	},

	makeDraggable: function(handle){
		handle = handle || this.options.dragHandle || this.element;
		this.touchDrag = new Touch(handle);
		handle.setStyle('cursor', 'move');
{'fraction_non_alphanumeric': 0.18123587038432554, 'fraction_numerical': 0.0009419743782969103, 'mean_word_length': 4.05812291567413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4868214', 'n_tokens_mistral': 4032, 'n_tokens_neox': 3518, 'n_words': 673}