PageSourceSearch

https://partner.babyono.com/core/js/jquery.ocdialog.js?v=2bb96f5b911e8630e09e439d4d61e03a

js babyono.com collected 2026-09-26 12:55:08 UTC 4,994 bytes, 194 lines download raw bytes

1(function($) {
2	$.widget('oc.ocdialog', {
3		options: {
4			closeButton: true,
5			closeOnEscape: true,
6			modal: false
7		},
8		_create: function() {
9			var self = this;
10
11			this.originalTitle = this.element.attr('title');
12			this.options.title = this.options.title || this.originalTitle;
13
14			this.$dialog = $('<div class="oc-dialog" />')
15				.attr({
16					// Setting tabIndex makes the div focusable
17					tabIndex: -1,
18					role: 'dialog'
19				})
20				.insertBefore(this.element);
21			this.$dialog.append(this.element.detach());
22			this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog);
23
24			$(document).on('keydown keyup', function(event) {
25				if (
26					event.target !== self.$dialog.get(0) &&
27					self.$dialog.find($(event.target)).length === 0
28				) {
29					return;
30				}
31				// Escape
32				if (
33					event.keyCode === 27 &&
34					event.type === 'keydown' &&
35					self.options.closeOnEscape
36				) {
37					event.stopImmediatePropagation();
38					self.close();
39					return false;
40				}
41				// Enter
42				if (event.keyCode === 13) {
43					event.stopImmediatePropagation();
44					if (event.type === 'keyup') {
45						event.preventDefault();
46						return false;
47					}
48					// If no button is selected we trigger the primary
49					if (
50						self.$buttonrow &&
51						self.$buttonrow.find($(event.target)).length === 0
52					) {
53						var $button = self.$buttonrow.find('button.primary');
54						if ($button) {
55							$button.trigger('click');
56						}
57					} else if (self.$buttonrow) {
58						$(event.target).trigger('click');
59					}
60					return false;
61				}
62			});
63			this._setOptions(this.options);
64			this._createOverlay();
65		},
66		_init: function() {
67			this.$dialog.focus();
68			this._trigger('open');
69		},
70		_setOption: function(key, value) {
71			var self = this;
72			switch (key) {
73				case 'title':
74					if (this.$title) {
75						this.$title.text(value);
76					} else {
77						var $title = $('<h3 class="oc-dialog-title">' +
78							value +
79							'</h3>');
80						this.$title = $title.prependTo(this.$dialog);
81					}
82					break;
83				case 'buttons':
84					if (this.$buttonrow) {
85						this.$buttonrow.empty();
86					} else {
87						var $buttonrow = $('<div class="oc-dialog-buttonrow" />');
88						this.$buttonrow = $buttonrow.appendTo(this.$dialog);
89					}
90					if (value.length === 1) {
91						this.$buttonrow.addClass('onebutton');
92					} else if (value.length === 2) {
93						this.$buttonrow.addClass('twobuttons');
94					} else if (value.length === 3) {
95						this.$buttonrow.addClass('threebuttons');
96					}
97					$.each(value, function(idx, val) {
98						var $button = $('<button>').text(val.text);
99						if (val.classes) {
100							$button.addClass(val.classes);
101						}
102						if (val.defaultButton) {
103							$button.addClass('primary');
104							self.$defaultButton = $button;
105						}
106						self.$buttonrow.append($button);
107						$button.click(function() {
108							val.click.apply(self.element[0], arguments);
109						});
110					});
111					this.$buttonrow.find('button')
112						.on('focus', function(event) {
113							self.$buttonrow.find('button').removeClass('primary');
114							$(this).addClass('primary');
115						});
116					break;
117				case 'closeButton':
118					if (value) {
119						var $closeButton = $('<a class="oc-dialog-close"></a>');
120						this.$dialog.prepend($closeButton);
121						$closeButton.on('click', function() {
122							self.close();
123						});
124					} else {
125						this.$dialog.find('.oc-dialog-close').remove();
126					}
127					break;
128				case 'close':
129					this.closeCB = value;
130					break;
131			}
132			//this._super(key, value);
133			$.Widget.prototype._setOption.apply(this, arguments);
134		},
135		_setOptions: function(options) {
136			//this._super(options);
137			$.Widget.prototype._setOptions.apply(this, arguments);
138		},
139		_createOverlay: function() {
140			if (!this.options.modal) {
141				return;
142			}
143
144			var self = this;
145			this.overlay = $('<div>')
146				.addClass('oc-dialog-dim')
147				.appendTo($('#content'));
148			this.overlay.on('click keydown keyup', function(event) {
149				if (event.target !== self.$dialog.get(0) && self.$dialog.find($(event.target)).length === 0) {
150					event.preventDefault();
151					event.stopPropagation();
152					return;
153				}
154			});
155		},
156		_destroyOverlay: function() {
157			if (!this.options.modal) {
158				return;
159			}
160
161			if (this.overlay) {
162				this.overlay.off('click keydown keyup');
163				this.overlay.remove();
164				this.overlay = null;
165			}
166		},
167		widget: function() {
168			return this.$dialog;
169		},
170		close: function() {
171			this._destroyOverlay();
172			var self = this;
173			// Ugly hack to catch remaining keyup events.
174			setTimeout(function() {
175				self._trigger('close', self);
176				self.$dialog.hide();
177			}, 200);
178		},
179		destroy: function() {
180			if (this.$title) {
181				this.$title.remove();
182			}
183			if (this.$buttonrow) {
184				this.$buttonrow.remove();
185			}
186
187			if (this.originalTitle) {
188				this.element.attr('title', this.originalTitle);
189			}
190			this.element.removeClass('oc-dialog-content').detach().insertBefore(this.$dialog);
191			this.$dialog.remove();
192		}
193	});
194}(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.