Created
September 26, 2016 08:13
-
-
Save luniki/d34846a18d57ad2e8929f6b76bae354a to your computer and use it in GitHub Desktop.
STUDIP.Dialog und Backbone.View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Backbone from 'backbone' | |
import _ from 'underscore' | |
import Promise from 'bluebird' | |
const showDialog = function (backboneView, dialogOptions) { | |
return new Promise(function (resolve, reject) { | |
const hygenicDialogClass = _.uniqueId('cliqr--dialog-') | |
Backbone.$(document).on( | |
`dialog-update.${hygenicDialogClass}`, | |
(event, data) => { | |
if (data.dialog.closest('.ui-dialog').hasClass(hygenicDialogClass)) { | |
data.dialog.append(backboneView.$el).dialog('open') | |
resolve(() => data.dialog.dialog('close')) | |
} | |
}) | |
Backbone.$(document).on( | |
`dialogcreate.${hygenicDialogClass}`, | |
`.${hygenicDialogClass}`, | |
function (event, data) { | |
Backbone.$(event.target).dialog('option', 'autoOpen', false) | |
} | |
) | |
Backbone.$(document).on( | |
`dialogclose.${hygenicDialogClass}`, | |
`.${hygenicDialogClass}`, | |
function (event) { | |
if (Backbone.$(this).hasClass(hygenicDialogClass)) { | |
backboneView.remove() | |
Backbone.$(document).off(`.${hygenicDialogClass}`) | |
} | |
} | |
) | |
window.STUDIP.Dialog.show('', { | |
buttons: null, | |
id: hygenicDialogClass, | |
...dialogOptions, | |
dialogClass: `cliqr--dialog ${hygenicDialogClass}` | |
}) | |
}) | |
} | |
export default showDialog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment