PageSourceSearch

https://nas.c-roads.eu/nextcloud/core/js/jquery.ocdialog.js?v=052ac0746d482577055db8f18a05c6b4

js c-roads.eu collected 2026-10-02 07:50:12 UTC 6,694 bytes, 251 lines download raw bytes

1(function($) {
2	$.widget('oc.ocdialog', {
3		options: {
4			width: 'auto',
5			height: 'auto',
6			closeButton: true,
7			closeOnEscape: true,
8			modal: false
9		},
10		_create: function() {
11			var self = this;
12
13			this.originalCss = {
14				display: this.element[0].style.display,
15				width: this.element[0].style.width,
16				height: this.element[0].style.height
17			};
18
19			this.originalTitle = this.element.attr('title');
20			this.options.title = this.options.title || this.originalTitle;
21
22			this.$dialog = $('<div class="oc-dialog" />')
23				.attr({
24					// Setting tabIndex makes the div focusable
25					tabIndex: -1,
26					role: 'dialog'
27				})
28				.insertBefore(this.element);
29			this.$dialog.append(this.element.detach());
30			this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog);
31
32			this.$dialog.css({
33				display: 'inline-block',
34				position: 'fixed'
35			});
36
37			$(document).on('keydown keyup', function(event) {
38				if (
39					event.target !== self.$dialog.get(0) &&
40					self.$dialog.find($(event.target)).length === 0
41				) {
42					return;
43				}
44				// Escape
45				if (
46					event.keyCode === 27 &&
47					event.type === 'keydown' &&
48					self.options.closeOnEscape
49				) {
50					event.stopImmediatePropagation();
51					self.close();
52					return false;
53				}
54				// Enter
55				if(event.keyCode === 13) {
56					event.stopImmediatePropagation();
57					if(event.type === 'keyup') {
58						event.preventDefault();
59						return false;
60					}
61					// If no button is selected we trigger the primary
62					if (
63						self.$buttonrow &&
64						self.$buttonrow.find($(event.target)).length === 0
65					) {
66						var $button = self.$buttonrow.find('button.primary');
67						if($button) {
68							$button.trigger('click');
69						}
70					} else if(self.$buttonrow) {
71						$(event.target).trigger('click');
72					}
73					return false;
74				}
75			});
76			$(window).resize(function() {
77				self.parent = self.$dialog.parent().length > 0 ? self.$dialog.parent() : $('body');
78				var pos = self.parent.position();
79				self.$dialog.css({
80					left: pos.left + ($(window).innerWidth() - self.$dialog.outerWidth())/2,
81					top: pos.top + ($(window).innerHeight() - self.$dialog.outerHeight())/2,
82					width: Math.min(self.options.width, $(window).innerWidth() - 20 ),
83					height: Math.min(self.options.height, $(window).innerHeight() - 20)
84				});
85				// set sizes of content
86				self._setSizes();
87			});
88
89			this._setOptions(this.options);
90			$(window).trigger('resize');
91			this._createOverlay();
92		},
93		_init: function() {
94			this.$dialog.focus();
95			this._trigger('open');
96		},
97		_setOption: function(key, value) {
98			var self = this;
99			switch(key) {
100				case 'title':
101					if(this.$title) {
102						this.$title.text(value);
103					} else {
104						var $title = $('<h3 class="oc-dialog-title">'
105							+ value
106							+ '</h3>');
107						this.$title = $title.prependTo(this.$dialog);
108					}
109					this._setSizes();
110					break;
111				case 'buttons':
112					if(this.$buttonrow) {
113						this.$buttonrow.empty();
114					} else {
115						var $buttonrow = $('<div class="oc-dialog-buttonrow" />');
116						this.$buttonrow = $buttonrow.appendTo(this.$dialog);
117					}
118					if (value.length === 1) {
119						this.$buttonrow.addClass('onebutton');
120					} else if (value.length === 2) {
121						this.$buttonrow.addClass('twobuttons');
122					} else if (value.length === 3) {
123						this.$buttonrow.addClass('threebuttons');
124					}
125					$.each(value, function(idx, val) {
126						var $button = $('<button>').text(val.text);
127						if (val.classes) {
128							$button.addClass(val.classes);
129						}
130						if(val.defaultButton) {
131							$button.addClass('primary');
132							self.$defaultButton = $button;
133						}
134						self.$buttonrow.append($button);
135						$button.click(function() {
136							val.click.apply(self.element[0], arguments);
137						});
138					});
139					this.$buttonrow.find('button')
140						.on('focus', function(event) {
141							self.$buttonrow.find('button').removeClass('primary');
142							$(this).addClass('primary');
143						});
144					this._setSizes();
145					break;
146				case 'closeButton':
147					if(value) {
148						var $closeButton = $('<a class="oc-dialog-close"></a>');
149						this.$dialog.prepend($closeButton);
150						$closeButton.on('click', function() {
151							self.close();
152						});
153					} else {
154						this.$dialog.find('.oc-dialog-close').remove();
155					}
156					break;
157				case 'width':
158					this.$dialog.css('width', value);
159					break;
160				case 'height':
161					this.$dialog.css('height', value);
162					break;
163				case 'close':
164					this.closeCB = value;
165					break;
166			}
167			//this._super(key, value);
168			$.Widget.prototype._setOption.apply(this, arguments );
169		},
170		_setOptions: function(options) {
171			//this._super(options);
172			$.Widget.prototype._setOptions.apply(this, arguments);
173		},
174		_setSizes: function() {
175			var content_height = this.$dialog.height();
176			if(this.$title) {
177				content_height -= this.$title.outerHeight(true);
178			}
179			if(this.$buttonrow) {
180				content_height -= this.$buttonrow.outerHeight(true);
181			}
182			this.parent = this.$dialog.parent().length > 0 ? this.$dialog.parent() : $('body');
183			content_height = Math.min(content_height, this.parent.height()-20);
184			if (content_height> 0) {
185				this.element.css({
186					height: content_height + 'px',
187					width: this.$dialog.innerWidth()-20 + 'px'
188				});
189			} else {
190				this.element.css({
191					width : this.$dialog.innerWidth() - 20 + 'px'
192				});
193			}
194		},
195		_createOverlay: function() {
196			if(!this.options.modal) {
197				return;
198			}
199
200			var self = this;
201			this.overlay = $('<div>')
202				.addClass('oc-dialog-dim')
203				.appendTo($('#content'));
204			this.overlay.on('click keydown keyup', function(event) {
205				if(event.target !== self.$dialog.get(0) && self.$dialog.find($(event.target)).length === 0) {
206					event.preventDefault();
207					event.stopPropagation();
208					return;
209				}
210			});
211		},
212		_destroyOverlay: function() {
213			if (!this.options.modal) {
214				return;
215			}
216
217			if (this.overlay) {
218				this.overlay.off('click keydown keyup');
219				this.overlay.remove();
220				this.overlay = null;
221			}
222		},
223		widget: function() {
224			return this.$dialog;
225		},
226		close: function() {
227			this._destroyOverlay();
228			var self = this;
229			// Ugly hack to catch remaining keyup events.
230			setTimeout(function() {
231				self._trigger('close', self);
232				self.$dialog.hide();
233			}, 200);
234		},
235		destroy: function() {
236			if(this.$title) {
237				this.$title.remove();
238			}
239			if(this.$buttonrow) {
240				this.$buttonrow.remove();
241			}
242
243			if(this.originalTitle) {
244				this.element.attr('title', this.originalTitle);
245			}
246			this.element.removeClass('oc-dialog-content')
247					.css(this.originalCss).detach().insertBefore(this.$dialog);
248			this.$dialog.remove();
249		}
250	});
251}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.