aboutsummaryrefslogtreecommitdiffstats
path: root/demos/dialog/modal-form.html
Commit message (Collapse)AuthorAgeFilesLines
* Docs: Change a few most common domains from HTTP to HTTPSMichał Gołębiowski-Owczarek2024-04-261-1/+1
| | | | | Also, update a few stale URLs to what they redirect now to. Closes gh-2244
* Demos: Add device-width viewport meta to all demosJörn Zaefferer2015-09-301-0/+1
| | | | Ref 343c2651729af2fdf020dd538fce0855785f5a0d
* Dialog: Switch demos to use AMDAlexander Schmitz2015-07-211-13/+2
| | | | Ref #10119
* Dialog: Updating demo style based on changes to theme and demo CSSAlexander Schmitz2014-11-181-1/+1
| | | | | Fixes #10693 Closes #1385
* Theme: Change default widget font-size to 1emTJ VanToll2014-10-241-1/+0
| | | | | Fixes #10131 Closes gh-1374
* Build: Reorganize external directoryScott González2014-06-241-1/+1
| | | | | | | Put each external library into its own directory. Move jquery.js to external. Ref gh-1266
* Dialog demo: Update modal form demoJörn Zaefferer2014-04-241-40/+52
| | | | | | | | | | - Removes an invalid jquery.ui.button.js reference (button.js is loaded) - Updates the email regex to use the one from the HTML5 spec - Refactors the code to add the user on both button click and form submit - Reset the form to its original state on submit - Initialize the form with values that can be submitted immediately, better for a demo - Rename bValid to valid
* All: Rename jquery.js to exclude version in filenameJörn Zaefferer2014-03-051-1/+1
|
* All: Rename all files, removing the "jquery.ui." prefix;Rafael Xavier de Souza2014-01-241-10/+10
| | | | | | | - By executing https://gist.github.com/jzaefferer/893fcf70b7eebc1dc271; Fixes #9464 Closes gh-1029
* Updating jQuery to 1.10.2.Bruno M. Custódio2013-07-051-1/+1
| | | | | Adding jQuery 1.10.0, 1.10.1, 1.10.2, 2.0.0, 2.0.1, 2.0.2 and 2.0.3 to the tests directory.
* Updating 'jQuery' to 1.9.1.Bruno M. Custódio2013-02-051-1/+1
|
* Updating to jQuery 1.9.0Kris Borchers2013-01-171-1/+1
|
* Dialog: Use button widget for close button (was already listed as dependency)Jörn Zaefferer2012-11-261-3/+4
|
* Upgrade jQuery to 1.8.3.Scott González2012-11-141-1/+1
|
* Removed bgiframe.Scott González2012-10-261-1/+0
|
* Upgrade jQuery to 1.8.2.Scott González2012-09-201-1/+1
|
* Demos: Cleanup.Scott González2012-09-101-13/+3
|
* Upgrade jQuery to 1.8.0.Scott González2012-08-131-1/+1
|
* Effects: Renamed all files.Scott González2012-06-151-1/+1
|
* Upgrade jQuery to 1.7.2.Scott González2012-03-221-1/+1
|
* Upgrade jQuery to 1.7.1.Scott González2011-11-221-1/+1
|
* Upgrade jQuery to 1.7.Scott González2011-11-091-1/+1
|
* Upgraded jQuery to 1.6.4.Scott González2011-10-181-1/+1
|
* Upgrade jQuery to 1.6.2.Scott González2011-07-251-1/+1
|
* Switched to latest stable jQuery 1.5.1Richard Worth2011-03-021-1/+1
|
* Upgraded jQuery to 1.4.4.Scott González2010-11-121-1/+1
|
* Upgraded jQuery to 1.4.3.Scott González2010-10-211-1/+1
|
* External: Updated bgiframe to 2.1.2. Fixes #6190 - Dialog demos don't work ↵Scott González2010-10-191-1/+1
| | | | in IE9 because of bgiframe.
* Dialog demos: safer selectors for the demo system workaround.Scott González2010-09-271-1/+1
|
* Dialog demo: syntax error, errant single quote from last style guide update. ↵Richard D. Worth2010-09-191-1/+1
| | | | Fixed #6074 - Dialog: demo of modal form broken
* Dialog demos: Coding standards.Scott González2010-09-101-69/+59
|
* html pages: added HTML5 meta charset UTF-8 tag, changed DOCTYPE to uppercaseRichard Worth2010-03-121-1/+2
|
* Fixed #5182 - Update to jQuery 1.4.2Richard Worth2010-02-161-1/+1
|
* fixed #5163 - themes: css files need to be renamed to be consistent with js ↵Richard Worth2010-02-161-1/+1
| | | | file renames in 1.8a1
* switched to jQuery 1.4.1Richard Worth2010-01-271-1/+1
|
* switched to jQuery 1.4Richard Worth2010-01-201-1/+1
|
* Dialog, position: Removed bgiframe option; always use bgiframe when available.Scott González2010-01-191-1/+0
| | | | Fixes #5071 - Remove bgiframe option from all plugins.
* Replaced stackfix with bgiframe.Scott González2010-01-141-2/+2
| | | | Fixes #5061 - Remove stackfix.
* Merged in /branches/dev r3251:3620 (excluding autocomplete, modal, tooltip, ↵Scott González2010-01-071-25/+7
| | | | menu; including menu static tests).
* Added jquery.ui.mouse.js to non-interaction demos/tests that use interaction ↵Scott González2009-12-231-0/+1
| | | | plugins.
* extracting widget factory into jquery.ui.widget.jsJörn Zaefferer2009-12-161-0/+1
|
* renamed all ui.*.js files to jquery.ui.*.js, all effects.*.js files to ↵Richard Worth2009-09-171-7/+7
| | | | jquery.effects.*.js per announcement and discussion here http://groups.google.com/group/jquery-ui-dev/msg/d565a0c56e0cb935
* Dialog demo: Use the ui-state-highlight class instead of a hard-coded color. ↵Scott González2009-08-291-6/+11
| | | | Fixes #4808 - Modal dialog form validation demo - error message uses hard-coded color.
* Dialog: Support hash, array, string for cursorAt option. Use position ↵Scott González2009-08-031-0/+1
| | | | plugin. Partial fix for #2525 - Standardised way to pass coordinates to plugins.
* workaround for #4375Jörn Zaefferer2009-07-111-3/+5
|
* replacing bgiframe with ui.stackfix, updated dialog and its demos accordinglyJörn Zaefferer2009-07-091-2/+2
|
* Dialog Modal Form Demo: Added ui-state-focus class on focus (fixes #4568 - ↵Scott González2009-05-311-7/+14
| | | | Demo: Dialog modal form demo doesn't react to focus on button).
* replaced svn:externals with versioned files within trunk/externalsJörn Zaefferer2009-05-271-1/+1
|
* Dialog demo: Removed misplaced !important.Scott González2009-04-181-3/+3
|
* Switched to jQuery 1.3.2Richard Worth2009-02-201-1/+1
|
rt/48532/stable28'>backport/48532/stable28 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/init.js
blob: 9e10a6941e14ad129b21a04a458a08c7c7107d5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

/* globals Snap */
import _ from 'underscore'
import $ from 'jquery'
import moment from 'moment'

import { initSessionHeartBeat } from './session-heartbeat.js'
import OC from './OC/index.js'
import { setUp as setUpContactsMenu } from './components/ContactsMenu.js'
import { setUp as setUpMainMenu } from './components/MainMenu.js'
import { setUp as setUpUserMenu } from './components/UserMenu.js'
import { interceptRequests } from './utils/xhr-request.js'
import { initFallbackClipboardAPI } from './utils/ClipboardFallback.ts'

// keep in sync with core/css/variables.scss
const breakpointMobileWidth = 1024

const initLiveTimestamps = () => {
	// Update live timestamps every 30 seconds
	setInterval(() => {
		$('.live-relative-timestamp').each(function() {
			const timestamp = parseInt($(this).attr('data-timestamp'), 10)
			$(this).text(moment(timestamp).fromNow())
		})
	}, 30 * 1000)
}

/**
 * Moment doesn't have aliases for every locale and doesn't parse some locale IDs correctly so we need to alias them
 */
const localeAliases = {
	zh: 'zh-cn',
	zh_Hans: 'zh-cn',
	zh_Hans_CN: 'zh-cn',
	zh_Hans_HK: 'zh-cn',
	zh_Hans_MO: 'zh-cn',
	zh_Hans_SG: 'zh-cn',
	zh_Hant: 'zh-hk',
	zh_Hant_HK: 'zh-hk',
	zh_Hant_MO: 'zh-mo',
	zh_Hant_TW: 'zh-tw',
}
let locale = OC.getLocale()
if (Object.prototype.hasOwnProperty.call(localeAliases, locale)) {
	locale = localeAliases[locale]
}

/**
 * Set users locale to moment.js as soon as possible
 */
moment.locale(locale)

/**
 * Initializes core
 */
export const initCore = () => {
	interceptRequests()
	initFallbackClipboardAPI()

	$(window).on('unload.main', () => { OC._unloadCalled = true })
	$(window).on('beforeunload.main', () => {
		// super-trick thanks to http://stackoverflow.com/a/4651049
		// in case another handler displays a confirmation dialog (ex: navigating away
		// during an upload), there are two possible outcomes: user clicked "ok" or
		// "cancel"

		// first timeout handler is called after unload dialog is closed
		setTimeout(() => {
			OC._userIsNavigatingAway = true

			// second timeout event is only called if user cancelled (Chrome),
			// but in other browsers it might still be triggered, so need to
			// set a higher delay...
			setTimeout(() => {
				if (!OC._unloadCalled) {
					OC._userIsNavigatingAway = false
				}
			}, 10000)
		}, 1)
	})
	$(document).on('ajaxError.main', function(event, request, settings) {
		if (settings && settings.allowAuthErrors) {
			return
		}
		OC._processAjaxError(request)
	})

	initSessionHeartBeat()

	OC.registerMenu($('#expand'), $('#expanddiv'), false, true)

	// toggle for menus
	$(document).on('mouseup.closemenus', event => {
		const $el = $(event.target)
		if ($el.closest('.menu').length || $el.closest('.menutoggle').length) {
			// don't close when clicking on the menu directly or a menu toggle
			return false
		}

		OC.hideMenus()
	})

	setUpMainMenu()
	setUpUserMenu()
	setUpContactsMenu()

	// just add snapper for logged in users
	// and if the app doesn't handle the nav slider itself
	if ($('#app-navigation').length && !$('html').hasClass('lte9')
		&& !$('#app-content').hasClass('no-snapper')) {

		// App sidebar on mobile
		const snapper = new Snap({
			element: document.getElementById('app-content'),
			disable: 'right',
			maxPosition: 300, // $navigation-width
			minDragDistance: 100,
		})

		$('#app-content').prepend('<div id="app-navigation-toggle" class="icon-menu" style="display:none" tabindex="0"></div>')

		// keep track whether snapper is currently animating, and
		// prevent to call open or close while that is the case
		// to avoid duplicating events (snap.js doesn't check this)
		let animating = false
		snapper.on('animating', () => {
			// we need this because the trigger button
			// is also implicitly wired to close by snapper
			animating = true
		})
		snapper.on('animated', () => {
			animating = false
		})
		snapper.on('start', () => {
			// we need this because dragging triggers that
			animating = true
		})
		snapper.on('end', () => {
			// we need this because dragging stop triggers that
			animating = false
		})
		snapper.on('open', () => {
			$appNavigation.attr('aria-hidden', 'false')
		})
		snapper.on('close', () => {
			$appNavigation.attr('aria-hidden', 'true')
		})

		// These are necessary because calling open or close
		// on snapper during an animation makes it trigger an
		// unfinishable animation, which itself will continue
		// triggering animating events and cause high CPU load,
		//
		// Ref https://github.com/jakiestfu/Snap.js/issues/216
		const oldSnapperOpen = snapper.open
		const oldSnapperClose = snapper.close
		const _snapperOpen = () => {
			if (animating || snapper.state().state !== 'closed') {
				return
			}
			oldSnapperOpen('left')
		}

		const _snapperClose = () => {
			if (animating || snapper.state().state === 'closed') {
				return
			}
			oldSnapperClose()
		}

		// Needs to be deferred to properly catch in-between
		// events that snap.js is triggering after dragging.
		//
		// Skipped when running unit tests as we are not testing
		// the snap.js workarounds...
		if (!window.TESTING) {
			snapper.open = () => {
				_.defer(_snapperOpen)
			}
			snapper.close = () => {
				_.defer(_snapperClose)
			}
		}

		$('#app-navigation-toggle').click((e) => {
			// close is implicit in the button by snap.js
			if (snapper.state().state !== 'left') {
				snapper.open()
			}
		})
		$('#app-navigation-toggle').keypress(e => {
			if (snapper.state().state === 'left') {
				snapper.close()
			} else {
				snapper.open()
			}
		})

		// close sidebar when switching navigation entry
		const $appNavigation = $('#app-navigation')
		$appNavigation.attr('aria-hidden', 'true')
		$appNavigation.delegate('a, :button', 'click', event => {
			const $target = $(event.target)
			// don't hide navigation when changing settings or adding things
			if ($target.is('.app-navigation-noclose')
				|| $target.closest('.app-navigation-noclose').length) {
				return
			}
			if ($target.is('.app-navigation-entry-utils-menu-button')
				|| $target.closest('.app-navigation-entry-utils-menu-button').length) {
				return
			}
			if ($target.is('.add-new')
				|| $target.closest('.add-new').length) {
				return
			}
			if ($target.is('#app-settings')
				|| $target.closest('#app-settings').length) {
				return
			}
			snapper.close()
		})

		let navigationBarSlideGestureEnabled = false
		let navigationBarSlideGestureAllowed = true
		let navigationBarSlideGestureEnablePending = false

		OC.allowNavigationBarSlideGesture = () => {
			navigationBarSlideGestureAllowed = true

			if (navigationBarSlideGestureEnablePending) {
				snapper.enable()

				navigationBarSlideGestureEnabled = true
				navigationBarSlideGestureEnablePending = false
			}
		}

		OC.disallowNavigationBarSlideGesture = () => {
			navigationBarSlideGestureAllowed = false

			if (navigationBarSlideGestureEnabled) {
				const endCurrentDrag = true
				snapper.disable(endCurrentDrag)

				navigationBarSlideGestureEnabled = false
				navigationBarSlideGestureEnablePending = true
			}
		}

		const toggleSnapperOnSize = () => {
			if ($(window).width() > breakpointMobileWidth) {
				$appNavigation.attr('aria-hidden', 'false')
				snapper.close()
				snapper.disable()

				navigationBarSlideGestureEnabled = false
				navigationBarSlideGestureEnablePending = false
			} else if (navigationBarSlideGestureAllowed) {
				snapper.enable()

				navigationBarSlideGestureEnabled = true
				navigationBarSlideGestureEnablePending = false
			} else {
				navigationBarSlideGestureEnablePending = true
			}
		}

		$(window).resize(_.debounce(toggleSnapperOnSize, 250))

		// initial call
		toggleSnapperOnSize()

	}

	initLiveTimestamps()
}