dialog.js
3.55 KB
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
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
define('screens/player/ui/dialog', [
'jquery'
], function($) {
'use strict';
/**
* Default options for the component.
*
* @typedef {Object} Dialog.ActivityOptions
* @type {Object}
* @property {String} [baseCssClass] The base CSS class for the component.
*/
var DEFAULTS = {
baseCssClass: 'aem-ScreensPlayer-dialog',
parent: '.channel-container'
};
/**
* Dialog for the player.
*
* @class Dialog
*
* @param {Dialog.DialogOptions} [options] Options for the component.
*/
var Dialog = function(options) {
this.options = $.extend({}, DEFAULTS, options);
this.$el = $(document.createElement('div')).addClass(this.options.baseCssClass);
this.$el.append('<p class="aem-ScreensPlayer-dialog-message"></p>\
<div class="aem-ScreensPlayer-dialog-buttons">\
<span class="aem-ScreensPlayer-dialog-button btn-dialog-cancel">Cancel</span>\
<span class="aem-ScreensPlayer-dialog-button btn-dialog-submit">Confirm</span>\
</div>');
this.$cancel = this.$el.find('.btn-dialog-cancel');
this.$submit = this.$el.find('.btn-dialog-submit');
this.hide();
$('body').append(this.$el);
};
/**
* Show the dialog.
* @memberof Dialog
*
* @param {Function} [cb] The function to call once the dialog is shown
*/
Dialog.prototype.show = function(cb) {
$(this.options.parent).addClass(this.options.baseCss + '--blur');
this.$el.removeClass('is-hidden').addClass('is-visible').fadeIn(300, cb);
};
/**
* Hide the dialog.
* @memberof Dialog
*
* @param {Function} [cb] The function to call once the dialog is hidden
*/
Dialog.prototype.hide = function(cb) {
$(this.options.parent).removeClass(this.options.baseCss + '--blur');
this.$el.removeClass('is-visible').addClass('is-hidden').fadeOut(300, cb);
this.$cancel.off('click');
this.$submit.off('click');
};
Dialog.prototype.confirm = function(msg) {
var self = this;
var message = this.$el.find('.aem-ScreensPlayer-dialog-message');
message.text(msg);
this.show();
return new Promise(function(resolve, reject) {
// cancel button closes the dialog box
self.$cancel.one('click', function listener() {
self.hide();
resolve(false);
});
// submit button
self.$submit.one('click', function listener() {
self.hide();
resolve(true);
});
});
};
/**
* Destroy the dialog.
* @memberof Dialog
*/
Dialog.prototype.destroy = function() {
this.hide();
this.$el.remove();
this.$el = null;
};
return Dialog;
});