1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00
documize/gui/app/mixins/modal.js

87 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-12-05 19:03:38 +00:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import $ from 'jquery';
2017-12-05 19:03:38 +00:00
import Mixin from '@ember/object/mixin';
2017-12-07 19:43:46 +00:00
// ID values expected format:
// modal: #document-template-modal
// element: #new-template-name
// See https://getbootstrap.com/docs/4.0/components/modal/#via-javascript
2017-12-05 19:03:38 +00:00
export default Mixin.create({
2017-12-15 13:41:20 +00:00
modalOpen(modalId, options, focusId) {
2017-12-07 19:43:46 +00:00
$(modalId).modal('dispose');
$(modalId).modal(options);
2017-12-15 13:41:20 +00:00
if (!_.isUndefined(focusId)) {
2017-12-15 13:41:20 +00:00
$(focusId).trigger('focus');
}
2017-12-07 19:43:46 +00:00
},
2017-12-05 19:03:38 +00:00
modalInputFocus(modalId, inputId) {
$(modalId).one('shown.bs.modal', function(event) { // eslint-disable-line no-unused-vars
2017-12-15 13:41:20 +00:00
$(inputId).trigger('focus');
2017-12-05 19:03:38 +00:00
});
},
2017-12-07 19:43:46 +00:00
// Destroys the elements modal.
modalDispose(modalId) {
$(modalId).modal('dispose');
},
// Manually hides a modal. Returns to the caller before the modal has actually
// been hidden (i.e. before the hidden.bs.modal event occurs).
modalHide(modalId) {
$(modalId).modal('hide');
},
// Manually hides a modal. Returns to the caller before the modal
// has actually been hidden (i.e. before the hidden.bs.modal event occurs).
// Then destroys the element's modal.
2017-12-05 19:03:38 +00:00
modalClose(modalId) {
$(modalId).modal('hide');
$(modalId).modal('dispose');
},
2017-12-07 19:43:46 +00:00
// This event fires immediately when the show instance method is called.
// If caused by a click, the clicked element is available as the relatedTarget
// property of the event.
modalOnShow(modalId, callback) {
$(modalId).one('show.bs.modal', function(e) {
2017-12-07 19:43:46 +00:00
callback(e);
});
},
// This event is fired when the modal has been made visible to the user
// (will wait for CSS transitions to complete). If caused by a click,
// the clicked element is available as the relatedTarget property of the event.
modalOnShown(modalId, callback) {
$(modalId).one('shown.bs.modal', function(e) {
2017-12-07 19:43:46 +00:00
callback(e);
});
},
// This event is fired immediately when the hide instance method has been called.
modalOnHide(modalId, callback) {
$(modalId).one('hide.bs.modal', function(e) {
2017-12-07 19:43:46 +00:00
callback(e);
});
},
// This event is fired when the modal has finished being hidden from the user
// (will wait for CSS transitions to complete).
modalOnHidden(modalId, callback) {
$(modalId).one('hidden.bs.modal', function(e) {
2017-12-07 19:43:46 +00:00
callback(e);
});
2017-12-05 19:03:38 +00:00
}
});